Compare commits
66 Commits
f0a67a5d84
...
master
Author | SHA1 | Date | |
---|---|---|---|
698674b46d
|
|||
eb1a668738
|
|||
95c90f2877
|
|||
5a3c7574aa
|
|||
11f8781a0d
|
|||
191cd90c2d | |||
b9bdd6bc9f | |||
3e4e5bba1c | |||
09530c439f | |||
702b2dae29 | |||
f38ff47fe2 | |||
da8c39c91b | |||
d3a568cfe4 | |||
3fac2ba503 | |||
b43bbe3459 | |||
58753bbd01 | |||
87995d515f | |||
0366226d79 | |||
636e32c64f | |||
db8f88047b | |||
64ed038b30 | |||
d097ba4ad7 | |||
530c215088 | |||
93f4592d16 | |||
0027bd9152 | |||
3a92db14de | |||
d76d0ad1fb | |||
b07be17744 | |||
a9b1052d9c | |||
bff56aa9d5 | |||
3ac16d0b16 | |||
64eafe7c20 | |||
813cda4183 | |||
20c3780f8e | |||
ba16c60168 | |||
043759f707 | |||
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 | |||
f4b7366d49 | |||
4e76cf3d5c |
14
.drone.yml
Normal file
14
.drone.yml
Normal file
@ -0,0 +1,14 @@
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: setup
|
||||
image: registry:5000/node-build
|
||||
commands:
|
||||
- yarn
|
||||
- curl https://git.scode.ovh/Timo/standard/raw/branch/master/ci.js > ci.js
|
||||
|
||||
- name: build
|
||||
image: registry:5000/node-build
|
||||
commands:
|
||||
- node ci.js
|
18
.eslintrc.js
18
.eslintrc.js
@ -5,20 +5,18 @@
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@sapphirecode'
|
||||
],
|
||||
extends: [ '@sapphirecode' ],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
}
|
||||
}
|
||||
parserOptions: { 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"
|
||||
}
|
||||
]
|
||||
}
|
28
CHANGELOG.md
Normal file
28
CHANGELOG.md
Normal file
@ -0,0 +1,28 @@
|
||||
# Changelog
|
||||
|
||||
## 1.5.0
|
||||
|
||||
Node template: use jasmine instead of ava
|
||||
|
||||
## 1.4.0
|
||||
|
||||
Drone template
|
||||
|
||||
Jenkins template: remove node specific template (replaced by drone)
|
||||
|
||||
## 1.3.0
|
||||
|
||||
Copyright function: carry previous creation date to prevent unnecessary modifications
|
||||
|
||||
## 1.2.0
|
||||
|
||||
- Fully interactive snippets
|
||||
- db migration generator removed
|
||||
|
||||
## 1.1.0
|
||||
|
||||
Knex database migration generator
|
||||
|
||||
## 1.0.0
|
||||
|
||||
initial version
|
23
Jenkinsfile
vendored
23
Jenkinsfile
vendored
@ -1,23 +0,0 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
VERSION = VersionNumber([
|
||||
versionNumberString:
|
||||
'${BUILDS_ALL_TIME}',
|
||||
versionPrefix: '1.2.',
|
||||
worstResultForIncrement: 'SUCCESS'
|
||||
])
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Building') {
|
||||
steps {
|
||||
script {
|
||||
currentBuild.displayName = env.VERSION
|
||||
}
|
||||
sh 'yarn ci ${VERSION}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
70
README.md
70
README.md
@ -1,60 +1,58 @@
|
||||
# Snippeteer
|
||||
# @sapphirecode/snippeteer
|
||||
|
||||
version: 1.5.x
|
||||
|
||||
macros for setting up projects or project parts
|
||||
|
||||
## Installation
|
||||
|
||||
to work with the @scode scope you have to add the following line to your npmrc.
|
||||
for this particular one you'll have to add it to the global npmrc stored in your home folder (~/.npmrc)
|
||||
> npm i -g @sapphirecode/snippeteer
|
||||
|
||||
```npmrc
|
||||
@scode:registry=https://npm.scode.ovh
|
||||
```
|
||||
## Requirements
|
||||
|
||||
then install the module using the following command
|
||||
installed on the system:
|
||||
|
||||
```sh
|
||||
npm i -g @scode/snippeteer
|
||||
```
|
||||
- yarn
|
||||
- git
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
snippeteer [snippet] [..args]
|
||||
```
|
||||
run `snippeteer` in console and choose a snippet, all necessary parameters will
|
||||
be asked interactively
|
||||
|
||||
All snippets will be executed relative to your current working directory!
|
||||
### Snippets
|
||||
|
||||
## Snippets
|
||||
#### copyright
|
||||
|
||||
### Snippet
|
||||
add copyright notice to .js, .ts and .mjs files, as well was generating a
|
||||
license file and adding fields like author and license to the package.json
|
||||
|
||||
Creates a new snippet template
|
||||
#### jenkins
|
||||
|
||||
```sh
|
||||
snippeteer snippet [name]
|
||||
```
|
||||
create a generic jenkinsfile
|
||||
|
||||
### Node
|
||||
#### drone
|
||||
|
||||
Creates a new nodejs project
|
||||
create a generic .drone.yml for deployment of node projects
|
||||
|
||||
```sh
|
||||
snippeteer node [name]
|
||||
```
|
||||
necessary scripts in the package.json:
|
||||
|
||||
### Jenkins
|
||||
- ci: `yarn --frozen-lockfile && node jenkins.js`
|
||||
- compile: `tsc` or
|
||||
`tsc --allowJs --declaration --emitDeclarationOnly index.js`, ...
|
||||
|
||||
Adds files necessary for jenkins
|
||||
compile should be the general compile task, for typescript: tsc, for commonjs:
|
||||
creating type definitions, ...
|
||||
|
||||
optionally with a js script for npm modules by adding 'node' as argument
|
||||
#### node
|
||||
|
||||
```sh
|
||||
snippeteer jenkins [node]
|
||||
```
|
||||
initializes a node project with the standard structure used by sapphirecode
|
||||
modules
|
||||
|
||||
### Vue
|
||||
#### readme
|
||||
|
||||
Adds files, dependencies and scripts for vue to a nodejs project
|
||||
create a template readme file
|
||||
|
||||
```sh
|
||||
snippeteer vue
|
||||
```
|
||||
## License
|
||||
|
||||
BSD-3-Clause © Timo Hocker <timo@scode.ovh>
|
||||
|
34
jenkins.js
34
jenkins.js
@ -1,34 +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
|
||||
*/
|
||||
|
||||
/* eslint-disable no-process-exit */
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable no-sync */
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs');
|
||||
const child_process = require ('child_process');
|
||||
|
||||
const pkg = JSON.parse (fs.readFileSync ('package.json', 'utf-8'));
|
||||
[
|
||||
,, pkg.version
|
||||
] = process.argv;
|
||||
fs.writeFileSync ('package.json', JSON.stringify (pkg, null, 2));
|
||||
|
||||
child_process.execSync ('yarn lint', { stdio: 'inherit' });
|
||||
child_process.execSync ('yarn test', { 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'); }
|
||||
});
|
||||
|
@ -5,20 +5,20 @@
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@sapphirecode/eslint-config-ts'
|
||||
],
|
||||
extends: [ '@sapphirecode/eslint-config-ts' ],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
}
|
||||
}
|
||||
parserOptions: { ecmaVersion: 2018 }
|
||||
};
|
||||
|
@ -6,5 +6,6 @@
|
||||
*/
|
||||
|
||||
export interface Snippet {
|
||||
is_active(): boolean;
|
||||
start(cwd: string): Promise<void>;
|
||||
}
|
||||
|
25
lib/index.ts
25
lib/index.ts
@ -12,17 +12,22 @@ import { Snippet } from './Snippet';
|
||||
|
||||
(async (): Promise<void> => {
|
||||
const snippets = await fs.readdir (path.join (__dirname, 'snippets'));
|
||||
const snippet = await new AutoComplete (
|
||||
{
|
||||
name: 'snippet',
|
||||
message: 'choose a snippet',
|
||||
choices: snippets
|
||||
}
|
||||
)
|
||||
const runners: Record<string, Snippet> = {};
|
||||
await Promise.all (
|
||||
snippets.map (async (s) => {
|
||||
const runner = (new (
|
||||
await import (`./snippets/${s}/index.js`)
|
||||
).default) as Snippet;
|
||||
runners[s] = runner;
|
||||
})
|
||||
);
|
||||
const snippet = await new AutoComplete ({
|
||||
name: 'snippet',
|
||||
message: 'choose a snippet',
|
||||
choices: snippets.filter ((s) => runners[s].is_active ())
|
||||
})
|
||||
.run ();
|
||||
const runner
|
||||
= new (await import (`./snippets/${snippet}/index.js`)).default as Snippet;
|
||||
runner.start (process.cwd ());
|
||||
runners[snippet].start (process.cwd ());
|
||||
}) ()
|
||||
// eslint-disable-next-line no-console
|
||||
.catch ((e) => console.log (e));
|
||||
|
@ -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}
|
||||
*/
|
||||
|
||||
`;
|
||||
|
@ -12,8 +12,8 @@ import fs from 'fs-extra';
|
||||
export class FileMapper {
|
||||
public static async map_all_files (
|
||||
folder: string,
|
||||
mutator: Function,
|
||||
args: Array<unknown> = []
|
||||
mutator: (data: string, file: string, args: Array<unknown>) => string|null,
|
||||
opts: Array<unknown> = []
|
||||
): Promise<void> {
|
||||
const files = await fs.readdir (folder);
|
||||
for (const file of files) {
|
||||
@ -21,11 +21,11 @@ export class FileMapper {
|
||||
continue;
|
||||
const abs_path = path.join (folder, file);
|
||||
if ((await fs.stat (abs_path)).isDirectory ()) {
|
||||
await FileMapper.map_all_files (abs_path, mutator, args);
|
||||
await FileMapper.map_all_files (abs_path, mutator, opts);
|
||||
continue;
|
||||
}
|
||||
const data = await fs.readFile (abs_path, 'utf-8');
|
||||
const res = mutator (data, file, args);
|
||||
const res = mutator (data, file, opts);
|
||||
if (res === null)
|
||||
continue;
|
||||
await fs.writeFile (abs_path, res, 'utf-8');
|
||||
|
@ -19,6 +19,10 @@ import { FileMapper } from './file_mapper';
|
||||
import { CopyrightOptions } from './copyright_options';
|
||||
|
||||
export default class Copyright implements Snippet {
|
||||
public is_active (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
private _options: CopyrightOptions | null = null;
|
||||
private _cwd = '';
|
||||
private _loaded_from_config = false;
|
||||
@ -37,10 +41,8 @@ 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.author = { name: options.author, email: options.email };
|
||||
json.license = options.has_license ? options.license : 'UNLICENSED';
|
||||
return json;
|
||||
});
|
||||
|
||||
@ -55,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 ();
|
||||
}
|
||||
|
||||
@ -77,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) {
|
||||
@ -100,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}
|
||||
@ -131,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, '')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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,14 +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 start (): Promise<void> {
|
||||
return new Promise ((res) => res ());
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
20
lib/snippets/drone/index.ts
Normal file
20
lib/snippets/drone/index.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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>, July 2020
|
||||
*/
|
||||
|
||||
import { files } from '@sapphirecode/standard';
|
||||
import { Snippet } from '../../Snippet';
|
||||
import { apply_template } from '../../Helper';
|
||||
|
||||
export default class Drone implements Snippet {
|
||||
public is_active (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public async start (): Promise<void> {
|
||||
await apply_template (files.drone, '.drone.yml');
|
||||
}
|
||||
}
|
@ -7,10 +7,7 @@
|
||||
|
||||
/* eslint-disable max-len */
|
||||
|
||||
import { files } from '@sapphirecode/standard';
|
||||
|
||||
const general = { jenkinsfile: '' };
|
||||
const node = { jenkinsfile: files.jenkinsfile, js: files.jenkins };
|
||||
|
||||
general.jenkinsfile = `pipeline {
|
||||
agent any
|
||||
@ -53,4 +50,4 @@ general.jenkinsfile = `pipeline {
|
||||
}
|
||||
`;
|
||||
|
||||
export { general, node };
|
||||
export { general };
|
||||
|
@ -5,31 +5,17 @@
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import { Confirm } from 'enquirer';
|
||||
import { Snippet } from '../../Snippet';
|
||||
import { apply_template, modify_json } from '../../Helper';
|
||||
import { apply_template } from '../../Helper';
|
||||
|
||||
import { general, node } from './Assets';
|
||||
import { general } from './Assets';
|
||||
|
||||
export default class Jenkins implements Snippet {
|
||||
public async start (): Promise<void> {
|
||||
const is_node = await new Confirm ({
|
||||
message: 'is the current project using nodejs?',
|
||||
initial: true
|
||||
})
|
||||
.run ();
|
||||
public is_active (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_node) {
|
||||
await apply_template (node.js, 'jenkins.js');
|
||||
await apply_template (node.jenkinsfile, 'Jenkinsfile');
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
await modify_json ((obj: any): any => {
|
||||
obj.scripts.ci = 'yarn && node jenkins.js';
|
||||
return obj;
|
||||
});
|
||||
}
|
||||
else {
|
||||
await apply_template (general.jenkinsfile, 'Jenkinsfile');
|
||||
}
|
||||
public async start (): Promise<void> {
|
||||
await apply_template (general.jenkinsfile, 'Jenkinsfile');
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,11 @@
|
||||
|
||||
import path from 'path';
|
||||
import { Input, Confirm } from 'enquirer';
|
||||
import { scripts as standard_scripts } from '@sapphirecode/standard';
|
||||
import {
|
||||
scripts as standard_scripts,
|
||||
files as standard_files
|
||||
} from '@sapphirecode/standard';
|
||||
import fs from 'fs-extra';
|
||||
import { Snippet } from '../../Snippet';
|
||||
import { apply_template, modify_json, run_command } from '../../Helper';
|
||||
|
||||
@ -16,6 +20,22 @@ import {
|
||||
tsconfig, eslintrc_ts, eslintignore
|
||||
} from './Assets';
|
||||
|
||||
|
||||
const packages = {
|
||||
common: [ 'eslint' ],
|
||||
js: [ '@sapphirecode/eslint-config' ],
|
||||
ts: [
|
||||
'typescript',
|
||||
'@sapphirecode/eslint-config-ts'
|
||||
],
|
||||
test: [
|
||||
'nyc',
|
||||
'jasmine',
|
||||
'@types/jasmine'
|
||||
],
|
||||
test_ts: [ 'ts-node' ]
|
||||
};
|
||||
|
||||
/**
|
||||
* initialize the package.json
|
||||
*
|
||||
@ -28,8 +48,22 @@ async function init_package (
|
||||
use_ts: boolean,
|
||||
use_tests: boolean
|
||||
): Promise<void> {
|
||||
run_command ('yarn init -y', folder);
|
||||
|
||||
const bundle = [
|
||||
...packages.common,
|
||||
...(use_ts ? packages.ts : packages.js),
|
||||
...(use_tests ? packages.test : []),
|
||||
...(use_ts && use_tests ? packages.test_ts : [])
|
||||
];
|
||||
|
||||
run_command (
|
||||
`yarn add --dev ${bundle.join (' ')}`,
|
||||
folder
|
||||
);
|
||||
|
||||
await modify_json ((obj: Record<string, unknown>) => {
|
||||
const scripts
|
||||
const scripts: Record<string, string>
|
||||
= {
|
||||
lint: standard_scripts.lint,
|
||||
test: standard_scripts.test.common,
|
||||
@ -39,7 +73,9 @@ async function init_package (
|
||||
|
||||
if (use_ts) {
|
||||
scripts.compile = standard_scripts.compile.ts;
|
||||
scripts.pretest = standard_scripts.test.ts_pre;
|
||||
scripts.test = standard_scripts.test.ts;
|
||||
scripts.posttest = standard_scripts.test.ts_post;
|
||||
files.push ('/dist/');
|
||||
}
|
||||
else {
|
||||
@ -56,6 +92,10 @@ async function init_package (
|
||||
}
|
||||
|
||||
export default class Node implements Snippet {
|
||||
public is_active (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public async start (): Promise<void> {
|
||||
const folder = await new Input (
|
||||
{ message: 'project name (leave empty for current folder):' }
|
||||
@ -88,13 +128,14 @@ export default class Node implements Snippet {
|
||||
);
|
||||
}
|
||||
run_command ('git init', folder);
|
||||
run_command ('yarn init -y', folder);
|
||||
run_command (
|
||||
`yarn add --dev @sapphirecode/eslint-config${use_ts
|
||||
? '-ts typescript @ava/typescript'
|
||||
: ''} eslint nyc ava`,
|
||||
folder
|
||||
);
|
||||
|
||||
if (use_tests) {
|
||||
await apply_template (
|
||||
standard_files.jasmine,
|
||||
path.join (folder, 'jasmine.json')
|
||||
);
|
||||
await fs.mkdirp (path.join (folder, 'test/spec'));
|
||||
}
|
||||
|
||||
await init_package (folder, use_ts, use_tests);
|
||||
}
|
||||
|
@ -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,
|
||||
@ -8,9 +15,9 @@ export function get_readme (
|
||||
): string {
|
||||
return `# ${software}
|
||||
|
||||
[](https://packagequality.com/#?package=${software})
|
||||
version: 0.0.0
|
||||
|
||||
> ${description}
|
||||
${description}
|
||||
|
||||
## Installation
|
||||
|
||||
@ -20,7 +27,7 @@ npm:
|
||||
|
||||
yarn:
|
||||
|
||||
> yarn add ${dev ? '--dev' : ''} ${software}
|
||||
> yarn add ${dev ? '--dev ' : ''}${software}
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -1,9 +1,20 @@
|
||||
/*
|
||||
* 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';
|
||||
import { get_readme } from './Assets';
|
||||
|
||||
export default class Readme implements Snippet {
|
||||
public is_active (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public async start (): Promise<void> {
|
||||
const dev = await new Confirm ({
|
||||
message: 'is the package used as dev dependency?',
|
||||
@ -20,7 +31,10 @@ export default class Readme implements Snippet {
|
||||
package_data.software = json.name;
|
||||
package_data.description = json.description;
|
||||
package_data.license = json.license;
|
||||
package_data.author = json.author;
|
||||
if (typeof json.author === 'object')
|
||||
package_data.author = `${json.author.name} <${json.author.email}>`;
|
||||
else
|
||||
package_data.author = json.author;
|
||||
});
|
||||
const readme = get_readme (
|
||||
package_data.software,
|
||||
|
32
package.json
32
package.json
@ -1,41 +1,49 @@
|
||||
{
|
||||
"name": "@sapphirecode/snippeteer",
|
||||
"version": "1.0.0",
|
||||
"version": "1.5.6",
|
||||
"description": "macros for setting up projects or project parts",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"snippeteer": "./index.js"
|
||||
},
|
||||
"bugs": "https://redmine.scode.ovh/projects/snippeteer",
|
||||
"scripts": {
|
||||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs",
|
||||
"ci": "yarn --frozen-lockfile && node jenkins.js",
|
||||
"test": "echo \"no test\"",
|
||||
"compile": "tsc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@git.scode.ovh:timo/snippeteer"
|
||||
"url": "https://git.scode.ovh:timo/snippeteer.git"
|
||||
},
|
||||
"files": [
|
||||
"/dist/",
|
||||
"/lib/",
|
||||
"LICENSE"
|
||||
],
|
||||
"author": "Timo Hocker <timo@scode.ovh>",
|
||||
"author": {
|
||||
"name": "Timo Hocker",
|
||||
"email": "timo@scode.ovh"
|
||||
},
|
||||
"license": "BSD-3-Clause",
|
||||
"devDependencies": {
|
||||
"@sapphirecode/eslint-config-ts": "^1.0.22",
|
||||
"@types/fs-extra": "^8.1.0",
|
||||
"@types/node": "^13.13.2",
|
||||
"eslint": "^6.8.0",
|
||||
"typescript": "^3.8.3"
|
||||
"@types/fs-extra": "^9.0.0",
|
||||
"@types/node": "^17.0.2",
|
||||
"eslint": "^8.5.0",
|
||||
"typescript": "^4.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sapphirecode/standard": "^1.0.1",
|
||||
"@sapphirecode/standard": "^1.5.5",
|
||||
"enquirer": "^2.3.5",
|
||||
"fs-extra": "^9.0.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"license": "^1.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"snippet",
|
||||
"template"
|
||||
]
|
||||
}
|
||||
|
@ -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. */
|
||||
|
Reference in New Issue
Block a user