Compare commits

..

7 Commits

Author SHA1 Message Date
ba16c60168 remove database snippet 2020-07-04 16:49:16 +02:00
46be34c4b0 add copyright 2020-06-28 17:02:46 +02:00
3e773b5327 fix 2020-06-28 16:55:44 +02:00
146c9b661f initial menu design, simpler patch serialization 2020-06-28 14:51:37 +02:00
214b113865 complete feature 2020-06-27 19:50:34 +02:00
336edb84b1 fix 2020-06-27 19:42:46 +02:00
d7d30fd417 carry previous date string 2020-06-27 19:36:46 +02:00
22 changed files with 142 additions and 270 deletions

21
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\index.js",
"outFiles": [
"${workspaceFolder}/**/*.js"
],
"console": "externalTerminal"
}
]
}

18
CHANGELOG.md Normal file
View File

@ -0,0 +1,18 @@
# Changelog
## 1.3.0
Copyright function: carry previous creation date to prevent unnecessary modifications
## 1.2.0
- Fully interactive snippets
- db migration generator removed (new snipped in development)
## 1.1.0
Knex database migration generator
## 1.0.0
initial version

2
Jenkinsfile vendored
View File

@ -5,7 +5,7 @@ pipeline {
VERSION = VersionNumber([
versionNumberString:
'${BUILDS_ALL_TIME}',
versionPrefix: '1.2.',
versionPrefix: '1.3.',
worstResultForIncrement: 'SUCCESS'
])
}

View File

@ -1,6 +1,6 @@
# @sapphirecode/snippeteer
version: 1.2.x
version: 1.3.x
macros for setting up projects or project parts

View File

@ -1,3 +1,10 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, June 2020
*/
'use strict';
const https = require ('https');

View File

@ -9,13 +9,18 @@ import { CopyrightOptions } from './copyright_options';
export class CopyrightGenerator {
public static get_copyright_notice (
opt: CopyrightOptions
opt: CopyrightOptions,
date_str?: string
): string {
let notice = '';
const date = (new Date);
const dtf = new Intl.DateTimeFormat ('en', { month: 'long' });
const year = date.getFullYear ();
const month = dtf.format (date);
let date_string = date_str;
if (typeof date_str === 'undefined') {
const date = (new Date);
const dtf = new Intl.DateTimeFormat ('en', { month: 'long' });
const year = date.getFullYear ();
const month = dtf.format (date);
date_string = `${month} ${year}`;
}
if (opt.has_license) {
notice = `${'/*'}
@ -23,7 +28,7 @@ export class CopyrightGenerator {
* This file is part of ${opt.software} which is released under ${
opt.license}.
* See file 'LICENSE' for full license details.
* Created by ${opt.author} <${opt.email}>, ${month} ${year}
* Created by ${opt.author} <${opt.email}>, ${date_string}
*/
`;
@ -31,7 +36,7 @@ export class CopyrightGenerator {
else {
notice = `${'/*'}
* Copyright (C) ${opt.company || opt.author} - All Rights Reserved
* Created by ${opt.author} <${opt.email}>, ${month} ${year}
* Created by ${opt.author} <${opt.email}>, ${date_string}
*/
`;

View File

@ -42,9 +42,7 @@ export default class Copyright implements Snippet {
await modify_json ((json) => {
json.author = `${options.author} <${options.email}>`;
json.license = options.has_license
? options.license
: 'UNLICENSED';
json.license = options.has_license ? options.license : 'UNLICENSED';
return json;
});
@ -59,11 +57,14 @@ export default class Copyright implements Snippet {
);
}
if (!this._loaded_from_config && await new Confirm (
{ message: 'should those settings be saved for the next run?' }
if (
!this._loaded_from_config
&& (await new Confirm (
{ message: 'should those settings be saved for the next run?' }
)
.run ()
.catch (DialogHandler.catch))
)
.run ()
.catch (DialogHandler.catch))
this.save_options_file ();
}
@ -81,10 +82,9 @@ export default class Copyright implements Snippet {
this._options.software = await new Input ({ message: 'software name' })
.run ()
.catch (DialogHandler.catch);
this._options.has_license = await new Confirm ({
message:
'would you like to specify a license?'
})
this._options.has_license = await new Confirm (
{ message: 'would you like to specify a license?' }
)
.run ()
.catch (DialogHandler.catch);
if (this._options.has_license) {
@ -104,9 +104,7 @@ export default class Copyright implements Snippet {
this._options = null;
if (await fs.pathExists (file_path)) {
const options = JSON.parse (
await fs.readFile (file_path, 'utf-8')
);
const options = JSON.parse (await fs.readFile (file_path, 'utf-8'));
// eslint-disable-next-line no-console
console.log (`author: ${options.author}
@ -135,21 +133,23 @@ license: ${options.license}`);
);
}
private fix_file_license (
data: string,
filename: string
): string | null {
const regex = /\/\*\s+\*\sCopyright[\s\S]*?\*\/\n{0,2}/gu;
private fix_file_license (data: string, filename: string): string | null {
// eslint-disable-next-line max-len
const regex = /\/\*\s+\*\sCopyright[\s\S]*?(?:Created by.*?, (?<date>[a-z]+ [0-9]+)[\s\S]*?|\s)\*\/\n{0,2}/gui;
const shebang = /^#!.*?\n\n/gu;
const shebang_line = shebang.exec (data);
if (!(/\.(?:js|ts|mjs)$/u).test (filename) && !regex.test (data))
return null;
return (shebang_line ? shebang_line[0] : '')
+ CopyrightGenerator.get_copyright_notice (
this._options as CopyrightOptions
)
+ data.replace (regex, '')
.replace (shebang, '');
const res = regex.exec (data);
return (
(shebang_line ? shebang_line[0] : '')
+ CopyrightGenerator.get_copyright_notice (
this._options as CopyrightOptions,
res?.groups?.date
)
+ data.replace (regex, '')
.replace (shebang, '')
);
}
}

View File

@ -1,20 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
import { ColumnType } from './ColumnType';
import { Relation } from './Relation';
export class Column {
public name: string;
public type: ColumnType;
public relation?: Relation;
public constructor (name: string, type: ColumnType) {
this.name = name;
this.type = type;
}
}

View File

@ -1,27 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
export enum ColumnType {
string = 'string',
text = 'text',
integer = 'integer',
big_integer = 'bigInteger',
float = 'float',
decimal = 'decimal',
increments = 'increments',
big_increments = 'bigIncrements',
boolean = 'boolean',
date = 'date',
date_time ='datetime',
time = 'time',
timestamp = 'timestamp',
binary = 'binary',
enum = 'enu',
json='json',
jsonb='jsonb',
uuid='uuid'
}

View File

@ -1,21 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
import { Table } from './Table';
export class Database {
public tables: Array<Table> = [];
public get_table (name: string): Table|null {
for (const table of this.tables) {
if (table.name === name)
return table;
}
return null;
}
}

View File

@ -1,12 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
import { Database } from './Database';
export interface PatchAction {
apply(db: Database): void;
}

View File

@ -1,22 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
export enum PatchActions {
rename_column = 'rc',
add_column = 'ac',
drop_column = 'dc',
add_relation = 'ar',
drop_relation = 'dr',
set_column_type = 'tc',
add_table = 'at',
drop_table = 'dt',
rename_table = 'rt',
insert_data = 'id',
update_data = 'ud',
mutate_data = 'md',
delete_data = 'dd'
}

View File

@ -1,16 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
export class Relation {
public column: string;
public table: string;
public constructor (table: string, column: string) {
this.column = column;
this.table = table;
}
}

View File

@ -1,10 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
export interface Serializable {
serialize(): string;
}

View File

@ -1,26 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
import { Column } from './Column';
export class Table {
public name: string;
public columns: Array<Column> = [];
public constructor (name: string) {
this.name = name;
}
public get_column (name: string): Column|null {
for (const col of this.columns) {
if (col.name === name)
return col;
}
return null;
}
}

View File

@ -1,18 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
import { Snippet } from '../../Snippet';
export default class Database implements Snippet {
public is_active (): boolean {
return false;
}
public start (): Promise<void> {
return Promise.resolve ();
}
}

View File

@ -1,60 +0,0 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
import { Serializable } from '../classes/Serializable';
import { PatchAction } from '../classes/PatchAction';
import { Database } from '../classes/Database';
export class RenameColumn implements Serializable, PatchAction {
public table: string;
public column: string;
public new_name: string;
public constructor (
column: string,
new_name: string|null = null,
table: string|null = null
) {
if (new_name === null || table === null) {
const regex
= /(?<table>[a-z_]+) (?<column>[a-z_]+) (?<new_name>[a-z_]+)/iu;
const res = regex.exec (column);
if (res === null || typeof res.groups === 'undefined')
throw new Error ('invalid string to deserialize');
this.column = res.groups.column;
this.new_name = res.groups.new_name;
this.table = res.groups.table;
return;
}
this.column = column;
this.table = table;
this.new_name = new_name;
}
public serialize (): string {
return `${this.table} ${this.column} ${this.new_name}`;
}
public apply (db: Database): void {
const table = db.get_table (this.table);
if (typeof table === 'undefined' || table === null) {
throw new Error (
`table ${this.table} not found`
);
}
const column = table.get_column (this.column);
if (typeof column === 'undefined' || column === null) {
throw new Error (
`column ${this.column} not found in table ${this.table}`
);
}
column.name = this.new_name;
}
}

View File

@ -1,3 +1,10 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, June 2020
*/
/* eslint-disable max-len */
export function get_readme (
software: string,

View File

@ -1,3 +1,10 @@
/*
* Copyright (C) SapphireCode - All Rights Reserved
* This file is part of Snippeteer which is released under BSD-3-Clause.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, June 2020
*/
import { Confirm } from 'enquirer';
import { Snippet } from '../../Snippet';
import { modify_json, apply_template } from '../../Helper';

View File

@ -18,6 +18,7 @@
},
"files": [
"/dist/",
"/lib/",
"LICENSE"
],
"author": "Timo Hocker <timo@scode.ovh>",
@ -30,6 +31,8 @@
"typescript": "^3.8.3"
},
"dependencies": {
"@sapphirecode/console-app": "^2.0.6",
"@sapphirecode/modelling": "^1.1.6",
"@sapphirecode/standard": "^1.0.1",
"enquirer": "^2.3.5",
"fs-extra": "^9.0.0",
@ -38,4 +41,4 @@
"engines": {
"node": ">=10.0.0"
}
}
}

View File

@ -8,9 +8,9 @@
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": "./lib", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */

View File

@ -43,6 +43,18 @@
resolved "https://registry.yarnpkg.com/@ovyerus/licenses/-/licenses-6.4.4.tgz#596e3ace46ab7c70bcf0e2b17f259796a4bedf9f"
integrity sha512-IHjc31WXciQT3hfvdY+M59jBkQp70Fpr04tNDVO5rez2PNv4u8tE6w//CkU+GeBoO9k2ahneSqzjzvlgjyjkGw==
"@sapphirecode/console-app@^2.0.6":
version "2.0.6"
resolved "https://registry.yarnpkg.com/@sapphirecode/console-app/-/console-app-2.0.6.tgz#5034a2beddd9d0cb5f29e5b9ffff4c36cc647b31"
integrity sha512-dceIFY+hTMzCXpPH2ZIy+zVA7qwt1N7maNL9RjnkZNIoiJicyPnnkF3W8JHubh/i00ejzepXoBf6gJEgDeHclw==
dependencies:
"@sapphirecode/modelling" "^1.0.35"
"@sapphirecode/utilities" "^1.3.4"
enquirer "^2.3.5"
fs-extra "^9.0.0"
hjson "^3.2.1"
yargs "^15.3.1"
"@sapphirecode/eslint-config-es6@^1.1.1":
version "1.1.12"
resolved "https://registry.yarnpkg.com/@sapphirecode/eslint-config-es6/-/eslint-config-es6-1.1.12.tgz#cc38dcbf59c450ac09d8042f3d69cd784005aec9"
@ -69,11 +81,30 @@
eslint-plugin-node "^11.1.0"
eslint-plugin-sort-requires-by-path "^1.0.2"
"@sapphirecode/modelling@^1.0.35":
version "1.1.5"
resolved "https://registry.yarnpkg.com/@sapphirecode/modelling/-/modelling-1.1.5.tgz#71b1ec6a8938ad4e8a3ea13bd6bd9d54eaabedcd"
integrity sha512-5MkawJexd0FzcFDlD+bt/mmNuwtjRyMqntHHKpieov2pU4HJxJoQL1k5gnrDmKittXZsl2OOweNi/Xa2cYxmCA==
dependencies:
"@sapphirecode/utilities" "^1.3.2"
"@sapphirecode/modelling@^1.1.6":
version "1.1.6"
resolved "https://registry.yarnpkg.com/@sapphirecode/modelling/-/modelling-1.1.6.tgz#84b1b760e07a8fa3da326b7b973b23f52e149a0e"
integrity sha512-WxuMUNHtcC0wbPXtgzi5JX1mjFZbmoWpwCP3iICja3K6ecu4ptk7npnDM3klL+kThq9CMWAIffOheo4y5b4Cgg==
dependencies:
"@sapphirecode/utilities" "^1.3.2"
"@sapphirecode/standard@^1.0.1":
version "1.1.8"
resolved "https://registry.yarnpkg.com/@sapphirecode/standard/-/standard-1.1.8.tgz#07c48ea91c7d1555d0110419d5eeeb6f2d11b246"
integrity sha512-O3dO6fujxlnR/7DoRpLB5NtTG4FMnRgDN0574rAT9oaUsL2rf3rpinlyeB2V36C8wtpihbcAw7zA5FSEPO3sdw==
"@sapphirecode/utilities@^1.3.2", "@sapphirecode/utilities@^1.3.4":
version "1.5.1"
resolved "https://registry.yarnpkg.com/@sapphirecode/utilities/-/utilities-1.5.1.tgz#d7e5a3791aa558bf968bb201ab3cc34b60d3e650"
integrity sha512-CU19QMj6WjUuup5mpKK6QOY/NROIUBpoQ1pOokmD7J3wd7NND9xntU9bnzSxrPc5OfhqY5r+S30+hdrEsoAXbA==
"@types/color-name@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
@ -789,6 +820,11 @@ has@^1.0.3:
dependencies:
function-bind "^1.1.1"
hjson@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/hjson/-/hjson-3.2.1.tgz#20de41dc87fc9a10d1557d0230b0e02afb1b09ac"
integrity sha512-OhhrFMeC7dVuA1xvxuXGTv/yTdhTvbe8hz+3LgVNsfi9+vgz0sF/RrkuX8eegpKaMc9cwYwydImBH6iePoJtdQ==
hosted-git-info@^2.1.4:
version "2.8.8"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488"