Compare commits
70 Commits
592b02226d
...
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 | |||
f4b7366d49 | |||
4e76cf3d5c | |||
f0a67a5d84 | |||
be004c5e02 | |||
8880a72560 | |||
3545ba6a48 | |||
6b0b40a292 | |||
c25b352041 | |||
ab66113c89 | |||
3a5cc47424 | |||
3bc5d16f8a | |||
83b5cd054b | |||
cb169f9242 | |||
5ec439cd1e | |||
048dee838a | |||
1b182c9932 | |||
476111c1b6 | |||
e8b22b84ca | |||
ebff7dc7f4 | |||
c9fd021634 | |||
91869b3183 | |||
a7180f9e50 | |||
bbdfaf1791 | |||
6e48707ec2 | |||
0d1b3aac2e | |||
9663fc3579 | |||
d38cfb041c | |||
deacaa76a1 | |||
650cdf7476 | |||
0edf59ba24 | |||
cae2b2ad75 | |||
b69e6a36c3 | |||
cd7c757daf | |||
a6e607334c | |||
f95226c7f0 | |||
45b64b3aca | |||
32410bab93 | |||
17bf48d7cc | |||
8bc26b384e | |||
fee3f55300 | |||
4dcfde8316 |
20
.eslintrc.js
20
.eslintrc.js
@ -2,23 +2,21 @@
|
||||
* 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>, April 2020
|
||||
* 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: [
|
||||
'@scode'
|
||||
],
|
||||
extends: [ '@sapphirecode' ],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
}
|
||||
}
|
||||
parserOptions: { ecmaVersion: 2018 }
|
||||
};
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
|
||||
# stryker temp files
|
||||
.stryker-tmp
|
||||
*.log
|
||||
|
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([
|
||||
versionNumberString:
|
||||
'${BUILDS_ALL_TIME}',
|
||||
versionPrefix: '1.2.',
|
||||
versionPrefix: '1.3.',
|
||||
worstResultForIncrement: 'SUCCESS'
|
||||
])
|
||||
}
|
||||
|
30
LICENSE
30
LICENSE
@ -1,29 +1,11 @@
|
||||
Copyright (c) 2020, Timo Hocker
|
||||
Copyright (c) <year> <author>. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
All rights reserved.
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of snippeteer nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
69
README.md
69
README.md
@ -1,60 +1,57 @@
|
||||
# Snippeteer
|
||||
# @sapphirecode/snippeteer
|
||||
|
||||
version: 1.3.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
|
||||
for node projects: automatically generates a jenkinsfile and jenkins.js for easy
|
||||
use in jenkins.
|
||||
|
||||
Creates a new nodejs project
|
||||
necessary scripts in the package.json:
|
||||
|
||||
```sh
|
||||
snippeteer node [name]
|
||||
```
|
||||
- ci: `yarn --frozen-lockfile && node jenkins.js`
|
||||
- compile: `tsc` or
|
||||
`tsc --allowJs --declaration --emitDeclarationOnly index.js`, ...
|
||||
|
||||
### Jenkins
|
||||
compile should be the general compile task, for typescript: tsc, for commonjs:
|
||||
creating type definitions, ...
|
||||
|
||||
Adds files necessary for jenkins
|
||||
#### node
|
||||
|
||||
optionally with a js script for npm modules by adding 'node' as argument
|
||||
initializes a node project with the standard structure used by sapphirecode
|
||||
modules
|
||||
|
||||
```sh
|
||||
snippeteer jenkins [node]
|
||||
```
|
||||
#### readme
|
||||
|
||||
### Vue
|
||||
create a template readme file
|
||||
|
||||
Adds files, dependencies and scripts for vue to a nodejs project
|
||||
## License
|
||||
|
||||
```sh
|
||||
snippeteer vue
|
||||
```
|
||||
BSD-3-Clause © Timo Hocker <timo@scode.ovh>
|
||||
|
@ -1,39 +0,0 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
VERSION = VersionNumber([
|
||||
versionNumberString:
|
||||
'${BUILDS_ALL_TIME}',
|
||||
versionPrefix: '1.0.',
|
||||
worstResultForIncrement: 'SUCCESS'
|
||||
])
|
||||
publish = 0
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Setup') {
|
||||
steps {
|
||||
script {
|
||||
currentBuild.displayName = env.VERSION
|
||||
}
|
||||
echo 'Setting up test environment'
|
||||
sh 'echo setup'
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
success {
|
||||
script {
|
||||
publish = sh script: "git log -1 | grep '\\[no publish\\]'", returnStatus: true
|
||||
if (publish != 0) {
|
||||
echo 'Deploying'
|
||||
sh 'echo deploy'
|
||||
} else {
|
||||
echo 'Build successful, Commit not marked for deploying'
|
||||
currentBuild.result = "UNSTABLE"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
VERSION = VersionNumber([
|
||||
versionNumberString:
|
||||
'${BUILDS_ALL_TIME}',
|
||||
versionPrefix: '1.0.',
|
||||
worstResultForIncrement: 'SUCCESS'
|
||||
])
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Building') {
|
||||
steps {
|
||||
script {
|
||||
currentBuild.displayName = env.VERSION
|
||||
}
|
||||
sh 'yarn ci ${VERSION}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/* 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' });
|
||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.test === 'string')
|
||||
child_process.execSync ('yarn test', { stdio: 'inherit' });
|
||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.compile === 'string')
|
||||
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'); }
|
||||
});
|
2
index.js
2
index.js
@ -4,7 +4,7 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
36
jenkins.js
36
jenkins.js
@ -2,32 +2,28 @@
|
||||
* 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>, April 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';
|
||||
|
||||
const https = require ('https');
|
||||
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'));
|
||||
[
|
||||
,, pkg.version
|
||||
const run_file = fs.createWriteStream ('.jenkins.run.js');
|
||||
|
||||
const [
|
||||
,, ...args
|
||||
] = process.argv;
|
||||
fs.writeFileSync ('package.json', JSON.stringify (pkg, null, 2));
|
||||
|
||||
child_process.execSync ('yarn lint', { stdio: 'inherit' });
|
||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.test === 'string')
|
||||
child_process.execSync ('yarn test', { stdio: 'inherit' });
|
||||
run_file.on ('close', () => {
|
||||
exec_sync (`node .jenkins.run.js ${args.join (' ')}`, { 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'); }
|
||||
});
|
||||
https.get (
|
||||
'https://git.scode.ovh/Timo/standard/raw/branch/master/jenkins.run.js',
|
||||
(msg) => {
|
||||
msg.pipe (run_file);
|
||||
}
|
||||
);
|
||||
|
@ -2,23 +2,23 @@
|
||||
* 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>, April 2020
|
||||
* 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: [
|
||||
'@scode/eslint-config-ts'
|
||||
],
|
||||
extends: [ '@sapphirecode/eslint-config-ts' ],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
}
|
||||
}
|
||||
parserOptions: { ecmaVersion: 2018 }
|
||||
};
|
||||
|
@ -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>, May 2020
|
||||
*/
|
||||
|
||||
import path from 'path';
|
||||
import child_process from 'child_process';
|
||||
import fs from 'fs-extra';
|
||||
@ -5,8 +12,8 @@ import fs from 'fs-extra';
|
||||
/**
|
||||
* write a template to a file
|
||||
*
|
||||
* @param {string} contents file contents
|
||||
* @param {string} destination file destination
|
||||
* @param contents - file contents
|
||||
* @param destination - file destination
|
||||
*/
|
||||
async function apply_template (
|
||||
contents: string,
|
||||
@ -27,8 +34,8 @@ type JSONMutator = {
|
||||
/**
|
||||
* modify a json file
|
||||
*
|
||||
* @param {Function} func function that modifies the object
|
||||
* @param {string} json_path path of json file
|
||||
* @param func - function that modifies the object
|
||||
* @param json_path - path of json file
|
||||
*/
|
||||
async function modify_json (
|
||||
func: JSONMutator,
|
||||
@ -37,14 +44,16 @@ async function modify_json (
|
||||
const file_path = path.join (process.cwd (), json_path);
|
||||
const content = JSON.parse (await fs.readFile (file_path, 'utf-8'));
|
||||
const new_obj = await func (content);
|
||||
if (typeof new_obj === 'undefined' || new_obj === null)
|
||||
return;
|
||||
await fs.writeFile (file_path, JSON.stringify (new_obj, null, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* run a command
|
||||
*
|
||||
* @param {string} command command to run
|
||||
* @param {string} folder folder to run in
|
||||
* @param command - command to run
|
||||
* @param folder - folder to run in
|
||||
*/
|
||||
function run_command (command: string, folder = ''): void {
|
||||
// eslint-disable-next-line no-sync
|
||||
|
@ -2,9 +2,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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
export interface Snippet {
|
||||
is_active(): boolean;
|
||||
start(cwd: string): Promise<void>;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
export class DialogHandler {
|
||||
|
2
lib/enquirer.d.ts
vendored
2
lib/enquirer.d.ts
vendored
@ -2,7 +2,7 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
declare module 'enquirer';
|
||||
|
31
lib/index.ts
31
lib/index.ts
@ -2,7 +2,7 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import path from 'path';
|
||||
@ -12,15 +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));
|
||||
|
@ -2,20 +2,25 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
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}
|
||||
*/
|
||||
|
||||
`;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
export class CopyrightOptions {
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
@ -12,7 +12,7 @@ import fs from 'fs-extra';
|
||||
export class FileMapper {
|
||||
public static async map_all_files (
|
||||
folder: string,
|
||||
mutator: Function,
|
||||
mutator: (data: string, file: string, args: Array<unknown>) => string|null,
|
||||
args: Array<unknown> = []
|
||||
): Promise<void> {
|
||||
const files = await fs.readdir (folder);
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-await-in-loop */
|
||||
@ -10,59 +10,85 @@ import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import { Confirm, Input, AutoComplete } from 'enquirer';
|
||||
// eslint-disable-next-line id-match
|
||||
import { findLicense } from 'license';
|
||||
import { findLicense, getLicense } from 'license';
|
||||
import { Snippet } from '../../Snippet';
|
||||
import { DialogHandler } from '../../dialog';
|
||||
import { modify_json } from '../../Helper';
|
||||
import { CopyrightGenerator } from './copyright_generator';
|
||||
import { FileMapper } from './file_mapper';
|
||||
import { CopyrightOptions } from './copyright_options';
|
||||
|
||||
export default class Copyright implements Snippet {
|
||||
private options: CopyrightOptions | null = null;
|
||||
private cwd = '';
|
||||
private loaded_from_config = false;
|
||||
public is_active (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
private _options: CopyrightOptions | null = null;
|
||||
private _cwd = '';
|
||||
private _loaded_from_config = false;
|
||||
|
||||
async start (cwd: string): Promise<void> {
|
||||
this.cwd = cwd;
|
||||
this._cwd = cwd;
|
||||
await this.load_options_file ();
|
||||
if (!this.options)
|
||||
if (!this._options)
|
||||
await this.gather_options ();
|
||||
|
||||
const options = this._options as CopyrightOptions;
|
||||
|
||||
await FileMapper.map_all_files (
|
||||
this.cwd,
|
||||
this._cwd,
|
||||
this.fix_file_license.bind (this)
|
||||
);
|
||||
|
||||
if (!this.loaded_from_config && await new Confirm (
|
||||
{ message: 'should those settings be saved for the next run?' }
|
||||
await modify_json ((json) => {
|
||||
json.author = `${options.author} <${options.email}>`;
|
||||
json.license = options.has_license ? options.license : 'UNLICENSED';
|
||||
return json;
|
||||
});
|
||||
|
||||
if (options.has_license) {
|
||||
await fs.writeFile (
|
||||
path.join (cwd, 'LICENSE'),
|
||||
getLicense (options.license, {
|
||||
name: options.author,
|
||||
email: options.email,
|
||||
project: options.software
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
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 ();
|
||||
}
|
||||
|
||||
private async gather_options (): Promise<void> {
|
||||
this.options = (new CopyrightOptions);
|
||||
this.options.author = await new Input ({ message: 'author' })
|
||||
this._options = (new CopyrightOptions);
|
||||
this._options.author = await new Input ({ message: 'author' })
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
this.options.email = await new Input ({ message: 'email' })
|
||||
this._options.email = await new Input ({ message: 'email' })
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
this.options.company = await new Input ({ message: 'company' })
|
||||
this._options.company = await new Input ({ message: 'company' })
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
this.options.software = await new Input ({ message: 'software name' })
|
||||
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) {
|
||||
this.options.license = await new AutoComplete ({
|
||||
if (this._options.has_license) {
|
||||
this._options.license = await new AutoComplete ({
|
||||
name: 'license',
|
||||
message: 'choose a license',
|
||||
limit: 10,
|
||||
@ -74,13 +100,11 @@ export default class Copyright implements Snippet {
|
||||
}
|
||||
|
||||
private async load_options_file (): Promise<void> {
|
||||
const file_path = path.join (this.cwd, '.liconfig.json');
|
||||
this.options = null;
|
||||
const file_path = path.join (this._cwd, '.liconfig.json');
|
||||
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}
|
||||
@ -94,36 +118,38 @@ license: ${options.license}`);
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
if (should_load) {
|
||||
this.options = options;
|
||||
this.loaded_from_config = true;
|
||||
this._options = options;
|
||||
this._loaded_from_config = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async save_options_file (): Promise<void> {
|
||||
const file_path = path.join (this.cwd, '.liconfig.json');
|
||||
const file_path = path.join (this._cwd, '.liconfig.json');
|
||||
await fs.writeFile (
|
||||
file_path,
|
||||
JSON.stringify (this.options, null, 2),
|
||||
JSON.stringify (this._options, null, 2),
|
||||
'utf-8'
|
||||
);
|
||||
}
|
||||
|
||||
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,13 +0,0 @@
|
||||
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,20 +0,0 @@
|
||||
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,14 +0,0 @@
|
||||
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,5 +0,0 @@
|
||||
import { Database } from './Database';
|
||||
|
||||
export interface PatchAction {
|
||||
apply(db: Database): void;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
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,9 +0,0 @@
|
||||
export class Relation {
|
||||
public column: string;
|
||||
public table: string;
|
||||
|
||||
public constructor (table: string, column: string) {
|
||||
this.column = column;
|
||||
this.table = table;
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
export interface Serializable {
|
||||
serialize(): string;
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
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,7 +0,0 @@
|
||||
import { Snippet } from '../../Snippet';
|
||||
|
||||
export default class Database implements Snippet {
|
||||
public start (): Promise<void> {
|
||||
// noop
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
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);
|
||||
const column = table?.get_column(this.column);
|
||||
column?.name = this.new_name;
|
||||
}
|
||||
}
|
@ -1,7 +1,16 @@
|
||||
/*
|
||||
* 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 max-len */
|
||||
|
||||
import { files } from '@sapphirecode/standard';
|
||||
|
||||
const general = { jenkinsfile: '' };
|
||||
const node = { jenkinsfile: '', js: '' };
|
||||
const node = { jenkinsfile: files.jenkinsfile, js: files.jenkins };
|
||||
|
||||
general.jenkinsfile = `pipeline {
|
||||
agent any
|
||||
@ -44,59 +53,4 @@ general.jenkinsfile = `pipeline {
|
||||
}
|
||||
`;
|
||||
|
||||
node.jenkinsfile = `pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
VERSION = VersionNumber([
|
||||
versionNumberString:
|
||||
'\${BUILDS_ALL_TIME}',
|
||||
versionPrefix: '1.0.',
|
||||
worstResultForIncrement: 'SUCCESS'
|
||||
])
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Building') {
|
||||
steps {
|
||||
script {
|
||||
currentBuild.displayName = env.VERSION
|
||||
}
|
||||
sh 'yarn ci \${VERSION}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
node.js = `/* 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' });
|
||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.test === 'string')
|
||||
child_process.execSync ('yarn test', { stdio: 'inherit' });
|
||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.compile === 'string')
|
||||
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'); }
|
||||
});
|
||||
`;
|
||||
|
||||
export { general, node };
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import { Confirm } from 'enquirer';
|
||||
@ -12,6 +12,10 @@ import { apply_template, modify_json } from '../../Helper';
|
||||
import { general, node } from './Assets';
|
||||
|
||||
export default class Jenkins implements Snippet {
|
||||
public is_active (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public async start (): Promise<void> {
|
||||
const is_node = await new Confirm ({
|
||||
message: 'is the current project using nodejs?',
|
||||
|
@ -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>, May 2020
|
||||
*/
|
||||
|
||||
const eslintrc = `module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
@ -5,7 +12,7 @@ const eslintrc = `module.exports = {
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@scode'
|
||||
'@sapphirecode'
|
||||
],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
@ -24,7 +31,7 @@ const eslintrc_ts = `module.exports = {
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@scode/eslint-config-ts'
|
||||
'@sapphirecode/eslint-config-ts'
|
||||
],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
@ -42,9 +49,6 @@ const gitignore = `/node_modules/
|
||||
/coverage/
|
||||
`;
|
||||
|
||||
const npmrc = `@scode:registry=https://npm.scode.ovh
|
||||
`;
|
||||
|
||||
const tsconfig = `{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
@ -53,9 +57,14 @@ const tsconfig = `{
|
||||
"rootDir": "./lib",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"declaration": true
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export { eslintrc, gitignore, npmrc, tsconfig, eslintrc_ts };
|
||||
const eslintignore = `/dist/
|
||||
*.d.ts
|
||||
`;
|
||||
|
||||
export { eslintrc, gitignore, tsconfig, eslintrc_ts, eslintignore };
|
||||
|
@ -2,32 +2,88 @@
|
||||
* 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>, April 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
import path from 'path';
|
||||
import { Input } from 'enquirer';
|
||||
import { Input, Confirm } from 'enquirer';
|
||||
import { scripts as standard_scripts } from '@sapphirecode/standard';
|
||||
import { Snippet } from '../../Snippet';
|
||||
import { apply_template, modify_json, run_command } from '../../Helper';
|
||||
|
||||
import { eslintrc, gitignore, npmrc, tsconfig, eslintrc_ts } from './Assets';
|
||||
import {
|
||||
eslintrc, gitignore,
|
||||
tsconfig, eslintrc_ts, eslintignore
|
||||
} from './Assets';
|
||||
|
||||
/**
|
||||
* initialize the package.json
|
||||
*
|
||||
* @param folder - folder
|
||||
* @param use_ts - use typescript
|
||||
* @param use_tests - use tests
|
||||
*/
|
||||
async function init_package (
|
||||
folder: string,
|
||||
use_ts: boolean,
|
||||
use_tests: boolean
|
||||
): Promise<void> {
|
||||
await modify_json ((obj: Record<string, unknown>) => {
|
||||
const scripts
|
||||
= {
|
||||
lint: standard_scripts.lint,
|
||||
test: standard_scripts.test.common,
|
||||
compile: standard_scripts.compile.common
|
||||
};
|
||||
const files = [ 'LICENSE' ];
|
||||
|
||||
if (use_ts) {
|
||||
scripts.compile = standard_scripts.compile.ts;
|
||||
scripts.test = standard_scripts.test.ts;
|
||||
files.push ('/dist/');
|
||||
}
|
||||
else {
|
||||
files.push ('*.js', '*.d.ts');
|
||||
}
|
||||
|
||||
if (!use_tests)
|
||||
scripts.test = standard_scripts.test.no;
|
||||
|
||||
obj.scripts = scripts;
|
||||
obj.files = files;
|
||||
return obj;
|
||||
}, path.join (folder, 'package.json'));
|
||||
}
|
||||
|
||||
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):' }
|
||||
)
|
||||
.run ();
|
||||
|
||||
const use_ts = await new confirm ({
|
||||
const use_ts = await new Confirm ({
|
||||
message: 'use typescript?',
|
||||
initial: false
|
||||
})
|
||||
.run ();
|
||||
|
||||
const use_tests = await new Confirm ({
|
||||
message: 'use tests?',
|
||||
initial: true
|
||||
})
|
||||
.run ();
|
||||
|
||||
await apply_template (eslintrc, path.join (folder, '.eslintrc.js'));
|
||||
await apply_template (npmrc, path.join (folder, '.npmrc'));
|
||||
await apply_template (gitignore, path.join (folder, '.gitignore'));
|
||||
await apply_template (
|
||||
eslintignore,
|
||||
path.join (folder, '.eslintignore')
|
||||
);
|
||||
if (use_ts) {
|
||||
await apply_template (tsconfig, path.join (folder, 'tsconfig.json'));
|
||||
await apply_template (
|
||||
@ -38,20 +94,12 @@ export default class Node implements Snippet {
|
||||
run_command ('git init', folder);
|
||||
run_command ('yarn init -y', folder);
|
||||
run_command (
|
||||
`yarn add --dev @scode/eslint-config${use_ts
|
||||
`yarn add --dev @sapphirecode/eslint-config${use_ts
|
||||
? '-ts typescript @ava/typescript'
|
||||
: ''} eslint nyc ava`,
|
||||
folder
|
||||
);
|
||||
|
||||
await modify_json ((obj: Record<string, unknown>) => {
|
||||
obj.scripts = {
|
||||
lint: 'eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs',
|
||||
test: 'nyc ava'
|
||||
};
|
||||
if (use_ts)
|
||||
obj.scripts.compile = 'tsc';
|
||||
return obj;
|
||||
}, path.join (folder, 'package.json'));
|
||||
await init_package (folder, use_ts, use_tests);
|
||||
}
|
||||
}
|
||||
|
40
lib/snippets/readme/Assets.ts
Normal file
40
lib/snippets/readme/Assets.ts
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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,
|
||||
description: string,
|
||||
dev: boolean,
|
||||
license: string,
|
||||
author: string
|
||||
): string {
|
||||
return `# ${software}
|
||||
|
||||
version: 0.0.0
|
||||
|
||||
${description}
|
||||
|
||||
## Installation
|
||||
|
||||
npm:
|
||||
|
||||
> npm i --save${dev ? '-dev' : ''} ${software}
|
||||
|
||||
yarn:
|
||||
|
||||
> yarn add ${dev ? '--dev ' : ''}${software}
|
||||
|
||||
## Usage
|
||||
|
||||
TODO: Add usage
|
||||
|
||||
## License
|
||||
|
||||
${license} © ${author}
|
||||
`;
|
||||
}
|
45
lib/snippets/readme/index.ts
Normal file
45
lib/snippets/readme/index.ts
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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?',
|
||||
default: false
|
||||
})
|
||||
.run ();
|
||||
const package_data = {
|
||||
software: '',
|
||||
description: '',
|
||||
license: '',
|
||||
author: ''
|
||||
};
|
||||
await modify_json ((json) => {
|
||||
package_data.software = json.name;
|
||||
package_data.description = json.description;
|
||||
package_data.license = json.license;
|
||||
package_data.author = json.author;
|
||||
});
|
||||
const readme = get_readme (
|
||||
package_data.software,
|
||||
package_data.description,
|
||||
dev,
|
||||
package_data.license,
|
||||
package_data.author
|
||||
);
|
||||
await apply_template (readme, 'README.md');
|
||||
}
|
||||
}
|
22
package.json
22
package.json
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@scode/snippeteer",
|
||||
"name": "@sapphirecode/snippeteer",
|
||||
"version": "1.0.0",
|
||||
"description": "macros for setting up projects or project parts",
|
||||
"main": "index.js",
|
||||
@ -9,7 +9,8 @@
|
||||
"scripts": {
|
||||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs",
|
||||
"ci": "yarn --frozen-lockfile && node jenkins.js",
|
||||
"test": "echo \"no test\""
|
||||
"test": "echo \"no test\"",
|
||||
"compile": "tsc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -17,19 +18,22 @@
|
||||
},
|
||||
"files": [
|
||||
"/dist/",
|
||||
"/assets/",
|
||||
"/lib/",
|
||||
"LICENSE"
|
||||
],
|
||||
"author": "Timo Hocker",
|
||||
"author": "Timo Hocker <timo@scode.ovh>",
|
||||
"license": "BSD-3-Clause",
|
||||
"devDependencies": {
|
||||
"@scode/eslint-config-ts": "^1.0.21",
|
||||
"@types/fs-extra": "^8.1.0",
|
||||
"@types/node": "^13.13.0",
|
||||
"eslint": "^6.8.0",
|
||||
"@sapphirecode/eslint-config-ts": "^1.0.22",
|
||||
"@types/fs-extra": "^9.0.0",
|
||||
"@types/node": "^14.0.1",
|
||||
"eslint": "^7.0.0",
|
||||
"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",
|
||||
"license": "^1.0.3"
|
||||
@ -37,4 +41,4 @@
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
}
|
||||
}
|
132
tsconfig.json
132
tsconfig.json
@ -1,66 +1,66 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "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. */
|
||||
// "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. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
}
|
||||
}
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "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. */
|
||||
// "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. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
}
|
||||
}
|
||||
|
1825
yarn-error.log
1825
yarn-error.log
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user