Compare commits
29 Commits
f4b7366d49
...
dev
Author | SHA1 | Date | |
---|---|---|---|
ba16c60168 | |||
46be34c4b0 | |||
3e773b5327 | |||
146c9b661f | |||
214b113865 | |||
336edb84b1 | |||
d7d30fd417 | |||
6ff99c827d | |||
e3ddb9a069 | |||
1519290c1d | |||
e617141a5c | |||
830c82d69d | |||
aba411a17a | |||
92cb9d5c21 | |||
32deb35fec | |||
cd7041c2e1 | |||
97d4756eb1 | |||
b1a53a3ad1 | |||
c54fba0483 | |||
c68be00e16 | |||
08ec8d9182 | |||
190f20c7b9 | |||
d55b752958 | |||
b87c5bf2f1 | |||
9a0a4a4201 | |||
8e3a19221d | |||
a6da0f6836 | |||
21411e8684 | |||
20e66788c2 |
18
.eslintrc.js
18
.eslintrc.js
@ -5,20 +5,18 @@
|
|||||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
env: {
|
env: {
|
||||||
commonjs: true,
|
commonjs: true,
|
||||||
es6: true,
|
es6: true,
|
||||||
node: true
|
node: true
|
||||||
},
|
},
|
||||||
extends: [
|
extends: [ '@sapphirecode' ],
|
||||||
'@sapphirecode'
|
|
||||||
],
|
|
||||||
globals: {
|
globals: {
|
||||||
Atomics: 'readonly',
|
Atomics: 'readonly',
|
||||||
SharedArrayBuffer: 'readonly'
|
SharedArrayBuffer: 'readonly'
|
||||||
},
|
},
|
||||||
parserOptions: {
|
parserOptions: { ecmaVersion: 2018 }
|
||||||
ecmaVersion: 2018
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal 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
18
CHANGELOG.md
Normal 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
2
Jenkinsfile
vendored
@ -5,7 +5,7 @@ pipeline {
|
|||||||
VERSION = VersionNumber([
|
VERSION = VersionNumber([
|
||||||
versionNumberString:
|
versionNumberString:
|
||||||
'${BUILDS_ALL_TIME}',
|
'${BUILDS_ALL_TIME}',
|
||||||
versionPrefix: '1.2.',
|
versionPrefix: '1.3.',
|
||||||
worstResultForIncrement: 'SUCCESS'
|
worstResultForIncrement: 'SUCCESS'
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
# @sapphirecode/snippeteer
|
# @sapphirecode/snippeteer
|
||||||
|
|
||||||
[](https://packagequality.com/#?package=@sapphirecode/snippeteer)
|
version: 1.3.x
|
||||||
|
|
||||||
> macros for setting up projects or project parts
|
macros for setting up projects or project parts
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
37
jenkins.js
37
jenkins.js
@ -2,33 +2,28 @@
|
|||||||
* Copyright (C) SapphireCode - All Rights Reserved
|
* Copyright (C) SapphireCode - All Rights Reserved
|
||||||
* This file is part of Snippeteer which is released under BSD-3-Clause.
|
* This file is part of Snippeteer which is released under BSD-3-Clause.
|
||||||
* See file 'LICENSE' for full license details.
|
* See file 'LICENSE' for full license details.
|
||||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
* Created by Timo Hocker <timo@scode.ovh>, June 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable no-process-exit */
|
|
||||||
/* eslint-disable no-console */
|
|
||||||
/* eslint-disable no-sync */
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const https = require ('https');
|
||||||
const fs = require ('fs');
|
const fs = require ('fs');
|
||||||
const child_process = require ('child_process');
|
const { execSync: exec_sync } = require ('child_process');
|
||||||
|
|
||||||
const pkg = JSON.parse (fs.readFileSync ('package.json', 'utf-8'));
|
const run_file = fs.createWriteStream ('.jenkins.run.js');
|
||||||
[
|
|
||||||
,, pkg.version
|
const [
|
||||||
|
,, ...args
|
||||||
] = process.argv;
|
] = process.argv;
|
||||||
fs.writeFileSync ('package.json', JSON.stringify (pkg, null, 2));
|
|
||||||
|
|
||||||
child_process.execSync ('yarn lint', { stdio: 'inherit' });
|
run_file.on ('close', () => {
|
||||||
child_process.execSync ('yarn test', { stdio: 'inherit' });
|
exec_sync (`node .jenkins.run.js ${args.join (' ')}`, { stdio: 'inherit' });
|
||||||
child_process.execSync ('yarn compile', { stdio: 'inherit' });
|
});
|
||||||
|
|
||||||
child_process.exec ('git log -1 | grep \'\\[no publish\\]\'')
|
|
||||||
.addListener ('exit', (code) => {
|
|
||||||
if (code === 0) {
|
|
||||||
console.log ('build not marked for deployment');
|
|
||||||
process.exit (1);
|
|
||||||
}
|
|
||||||
else { child_process.execSync ('yarn publish --access public'); }
|
|
||||||
});
|
|
||||||
|
|
||||||
|
https.get (
|
||||||
|
'https://git.scode.ovh/Timo/standard/raw/branch/master/jenkins.run.js',
|
||||||
|
(msg) => {
|
||||||
|
msg.pipe (run_file);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
@ -5,20 +5,20 @@
|
|||||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
env: {
|
env: {
|
||||||
commonjs: true,
|
commonjs: true,
|
||||||
es6: true,
|
es6: true,
|
||||||
node: true
|
node: true
|
||||||
},
|
},
|
||||||
extends: [
|
extends: [ '@sapphirecode/eslint-config-ts' ],
|
||||||
'@sapphirecode/eslint-config-ts'
|
|
||||||
],
|
|
||||||
globals: {
|
globals: {
|
||||||
Atomics: 'readonly',
|
Atomics: 'readonly',
|
||||||
SharedArrayBuffer: 'readonly'
|
SharedArrayBuffer: 'readonly'
|
||||||
},
|
},
|
||||||
parserOptions: {
|
parserOptions: { ecmaVersion: 2018 }
|
||||||
ecmaVersion: 2018
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -9,13 +9,18 @@ import { CopyrightOptions } from './copyright_options';
|
|||||||
|
|
||||||
export class CopyrightGenerator {
|
export class CopyrightGenerator {
|
||||||
public static get_copyright_notice (
|
public static get_copyright_notice (
|
||||||
opt: CopyrightOptions
|
opt: CopyrightOptions,
|
||||||
|
date_str?: string
|
||||||
): string {
|
): string {
|
||||||
let notice = '';
|
let notice = '';
|
||||||
const date = (new Date);
|
let date_string = date_str;
|
||||||
const dtf = new Intl.DateTimeFormat ('en', { month: 'long' });
|
if (typeof date_str === 'undefined') {
|
||||||
const year = date.getFullYear ();
|
const date = (new Date);
|
||||||
const month = dtf.format (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) {
|
if (opt.has_license) {
|
||||||
notice = `${'/*'}
|
notice = `${'/*'}
|
||||||
@ -23,7 +28,7 @@ export class CopyrightGenerator {
|
|||||||
* This file is part of ${opt.software} which is released under ${
|
* This file is part of ${opt.software} which is released under ${
|
||||||
opt.license}.
|
opt.license}.
|
||||||
* See file 'LICENSE' for full license details.
|
* 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 {
|
else {
|
||||||
notice = `${'/*'}
|
notice = `${'/*'}
|
||||||
* Copyright (C) ${opt.company || opt.author} - All Rights Reserved
|
* 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}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
@ -12,7 +12,7 @@ import fs from 'fs-extra';
|
|||||||
export class FileMapper {
|
export class FileMapper {
|
||||||
public static async map_all_files (
|
public static async map_all_files (
|
||||||
folder: string,
|
folder: string,
|
||||||
mutator: Function,
|
mutator: (data: string, file: string, args: Array<unknown>) => string|null,
|
||||||
args: Array<unknown> = []
|
args: Array<unknown> = []
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const files = await fs.readdir (folder);
|
const files = await fs.readdir (folder);
|
||||||
|
@ -42,9 +42,7 @@ export default class Copyright implements Snippet {
|
|||||||
|
|
||||||
await modify_json ((json) => {
|
await modify_json ((json) => {
|
||||||
json.author = `${options.author} <${options.email}>`;
|
json.author = `${options.author} <${options.email}>`;
|
||||||
json.license = options.has_license
|
json.license = options.has_license ? options.license : 'UNLICENSED';
|
||||||
? options.license
|
|
||||||
: 'UNLICENSED';
|
|
||||||
return json;
|
return json;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -59,11 +57,14 @@ export default class Copyright implements Snippet {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._loaded_from_config && await new Confirm (
|
if (
|
||||||
{ message: 'should those settings be saved for the next run?' }
|
!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 ();
|
this.save_options_file ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,10 +82,9 @@ export default class Copyright implements Snippet {
|
|||||||
this._options.software = await new Input ({ message: 'software name' })
|
this._options.software = await new Input ({ message: 'software name' })
|
||||||
.run ()
|
.run ()
|
||||||
.catch (DialogHandler.catch);
|
.catch (DialogHandler.catch);
|
||||||
this._options.has_license = await new Confirm ({
|
this._options.has_license = await new Confirm (
|
||||||
message:
|
{ message: 'would you like to specify a license?' }
|
||||||
'would you like to specify a license?'
|
)
|
||||||
})
|
|
||||||
.run ()
|
.run ()
|
||||||
.catch (DialogHandler.catch);
|
.catch (DialogHandler.catch);
|
||||||
if (this._options.has_license) {
|
if (this._options.has_license) {
|
||||||
@ -104,9 +104,7 @@ export default class Copyright implements Snippet {
|
|||||||
this._options = null;
|
this._options = null;
|
||||||
|
|
||||||
if (await fs.pathExists (file_path)) {
|
if (await fs.pathExists (file_path)) {
|
||||||
const options = JSON.parse (
|
const options = JSON.parse (await fs.readFile (file_path, 'utf-8'));
|
||||||
await fs.readFile (file_path, 'utf-8')
|
|
||||||
);
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log (`author: ${options.author}
|
console.log (`author: ${options.author}
|
||||||
@ -135,21 +133,23 @@ license: ${options.license}`);
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private fix_file_license (
|
private fix_file_license (data: string, filename: string): string | null {
|
||||||
data: string,
|
// eslint-disable-next-line max-len
|
||||||
filename: string
|
const regex = /\/\*\s+\*\sCopyright[\s\S]*?(?:Created by.*?, (?<date>[a-z]+ [0-9]+)[\s\S]*?|\s)\*\/\n{0,2}/gui;
|
||||||
): string | null {
|
|
||||||
const regex = /\/\*\s+\*\sCopyright[\s\S]*?\*\/\n{0,2}/gu;
|
|
||||||
const shebang = /^#!.*?\n\n/gu;
|
const shebang = /^#!.*?\n\n/gu;
|
||||||
const shebang_line = shebang.exec (data);
|
const shebang_line = shebang.exec (data);
|
||||||
|
|
||||||
if (!(/\.(?:js|ts|mjs)$/u).test (filename) && !regex.test (data))
|
if (!(/\.(?:js|ts|mjs)$/u).test (filename) && !regex.test (data))
|
||||||
return null;
|
return null;
|
||||||
return (shebang_line ? shebang_line[0] : '')
|
const res = regex.exec (data);
|
||||||
+ CopyrightGenerator.get_copyright_notice (
|
return (
|
||||||
this._options as CopyrightOptions
|
(shebang_line ? shebang_line[0] : '')
|
||||||
)
|
+ CopyrightGenerator.get_copyright_notice (
|
||||||
+ data.replace (regex, '')
|
this._options as CopyrightOptions,
|
||||||
.replace (shebang, '');
|
res?.groups?.date
|
||||||
|
)
|
||||||
|
+ data.replace (regex, '')
|
||||||
|
.replace (shebang, '')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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'
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -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'
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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 ();
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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 */
|
/* eslint-disable max-len */
|
||||||
export function get_readme (
|
export function get_readme (
|
||||||
software: string,
|
software: string,
|
||||||
@ -8,9 +15,9 @@ export function get_readme (
|
|||||||
): string {
|
): string {
|
||||||
return `# ${software}
|
return `# ${software}
|
||||||
|
|
||||||
[](https://packagequality.com/#?package=${software})
|
version: 0.0.0
|
||||||
|
|
||||||
> ${description}
|
${description}
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -20,7 +27,7 @@ npm:
|
|||||||
|
|
||||||
yarn:
|
yarn:
|
||||||
|
|
||||||
> yarn add ${dev ? '--dev' : ''} ${software}
|
> yarn add ${dev ? '--dev ' : ''}${software}
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -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 { Confirm } from 'enquirer';
|
||||||
import { Snippet } from '../../Snippet';
|
import { Snippet } from '../../Snippet';
|
||||||
import { modify_json, apply_template } from '../../Helper';
|
import { modify_json, apply_template } from '../../Helper';
|
||||||
|
@ -18,18 +18,21 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"/dist/",
|
"/dist/",
|
||||||
|
"/lib/",
|
||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"author": "Timo Hocker <timo@scode.ovh>",
|
"author": "Timo Hocker <timo@scode.ovh>",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sapphirecode/eslint-config-ts": "^1.0.22",
|
"@sapphirecode/eslint-config-ts": "^1.0.22",
|
||||||
"@types/fs-extra": "^8.1.0",
|
"@types/fs-extra": "^9.0.0",
|
||||||
"@types/node": "^13.13.2",
|
"@types/node": "^14.0.1",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^7.0.0",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^3.8.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@sapphirecode/console-app": "^2.0.6",
|
||||||
|
"@sapphirecode/modelling": "^1.1.6",
|
||||||
"@sapphirecode/standard": "^1.0.1",
|
"@sapphirecode/standard": "^1.0.1",
|
||||||
"enquirer": "^2.3.5",
|
"enquirer": "^2.3.5",
|
||||||
"fs-extra": "^9.0.0",
|
"fs-extra": "^9.0.0",
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
// "checkJs": true, /* Report errors in .js files. */
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
"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. */
|
"rootDir": "./lib", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
|
Reference in New Issue
Block a user