Compare commits
125 Commits
d0c3e333a0
...
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 | |||
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 | |||
592b02226d | |||
f8f7c5d91c | |||
3ea7163e17 | |||
7a563862af | |||
5a6c874425 | |||
3160ccd49c | |||
b7706f9a42 | |||
858d778039 | |||
dde41c085e | |||
168fc577d9 | |||
c0c2881020 | |||
f383ed0ce4 | |||
3c44614298 | |||
fa5c631d23 | |||
1feda9d44f | |||
6a525d8120 | |||
05d4839dea | |||
2094287af8 | |||
90515c1679 | |||
bc06152359 |
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
|
@ -1 +1,2 @@
|
||||
**/*.template.js
|
||||
**/*.d.ts
|
||||
/dist/
|
||||
|
22
.eslintrc.js
22
.eslintrc.js
@ -1,24 +1,22 @@
|
||||
/*
|
||||
* 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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 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 }
|
||||
};
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
/node_modules/
|
||||
/dist/
|
||||
|
||||
# stryker temp files
|
||||
.stryker-tmp
|
||||
*.log
|
||||
|
8
.liconfig.json
Normal file
8
.liconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"has_license": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"author": "Timo Hocker",
|
||||
"company": "SapphireCode",
|
||||
"email": "timo@scode.ovh",
|
||||
"software": "Snippeteer"
|
||||
}
|
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.1.',
|
||||
worstResultForIncrement: 'SUCCESS'
|
||||
])
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Building') {
|
||||
steps {
|
||||
script {
|
||||
currentBuild.displayName = env.VERSION
|
||||
}
|
||||
sh 'yarn ci ${VERSION}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
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.
|
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>
|
||||
|
48
index.js
48
index.js
@ -1,52 +1,14 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, March 2020
|
||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable global-require */
|
||||
/* eslint-disable no-sync */
|
||||
|
||||
'use strict';
|
||||
|
||||
const { argv } = require ('yargs');
|
||||
const path = require ('path');
|
||||
const fs = require ('fs-extra');
|
||||
|
||||
const [
|
||||
template,
|
||||
...args
|
||||
] = argv._;
|
||||
|
||||
/**
|
||||
* main function
|
||||
*/
|
||||
function main () {
|
||||
if (typeof template !== 'string') {
|
||||
console.log ('please specify a template');
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!fs.existsSync (path.join (__dirname, 'snippets', template))
|
||||
|| !(/^[a-zA-Z]+$/u).test (template)
|
||||
) {
|
||||
console.log ('template does not exist');
|
||||
return;
|
||||
}
|
||||
|
||||
const snippet = require (`./snippets/${template}/index.js`);
|
||||
const folder = process.cwd ();
|
||||
|
||||
if (!snippet.assert (folder, args)) {
|
||||
console.log ('snippet rejected arguments');
|
||||
return;
|
||||
}
|
||||
|
||||
snippet.run (folder, args);
|
||||
}
|
||||
main ();
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line node/no-missing-require
|
||||
require ('./dist');
|
||||
|
33
jenkins.js
33
jenkins.js
@ -1,33 +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>, March 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' });
|
||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.test === 'string')
|
||||
child_process.execSync ('yarn test', { 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'); }
|
||||
});
|
24
lib/.eslintrc.js
Normal file
24
lib/.eslintrc.js
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 */
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [ '@sapphirecode/eslint-config-ts' ],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: { ecmaVersion: 2018 }
|
||||
};
|
66
lib/Helper.ts
Normal file
66
lib/Helper.ts
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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';
|
||||
|
||||
/**
|
||||
* write a template to a file
|
||||
*
|
||||
* @param contents - file contents
|
||||
* @param destination - file destination
|
||||
*/
|
||||
async function apply_template (
|
||||
contents: string,
|
||||
destination: string
|
||||
): Promise<void> {
|
||||
const dst = path.join (process.cwd (), destination);
|
||||
if (!await fs.pathExists (dst)) {
|
||||
await fs.mkdirp (path.dirname (dst));
|
||||
await fs.writeFile (dst, contents);
|
||||
}
|
||||
}
|
||||
|
||||
type JSONMutator = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(json: any): any;
|
||||
}
|
||||
|
||||
/**
|
||||
* modify a json file
|
||||
*
|
||||
* @param func - function that modifies the object
|
||||
* @param json_path - path of json file
|
||||
*/
|
||||
async function modify_json (
|
||||
func: JSONMutator,
|
||||
json_path = 'package.json'
|
||||
): Promise<void> {
|
||||
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 command - command to run
|
||||
* @param folder - folder to run in
|
||||
*/
|
||||
function run_command (command: string, folder = ''): void {
|
||||
// eslint-disable-next-line no-sync
|
||||
child_process.execSync (
|
||||
command,
|
||||
{ cwd: path.join (process.cwd (), folder), stdio: 'inherit' }
|
||||
);
|
||||
}
|
||||
|
||||
export { modify_json, apply_template, run_command };
|
11
lib/Snippet.ts
Normal file
11
lib/Snippet.ts
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* 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 Snippet {
|
||||
is_active(): boolean;
|
||||
start(cwd: string): Promise<void>;
|
||||
}
|
13
lib/dialog.ts
Normal file
13
lib/dialog.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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 DialogHandler {
|
||||
public static catch (): void {
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit ();
|
||||
}
|
||||
}
|
8
lib/enquirer.d.ts
vendored
Normal file
8
lib/enquirer.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
declare module 'enquirer';
|
33
lib/index.ts
Normal file
33
lib/index.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 fs from 'fs-extra';
|
||||
import { AutoComplete } from 'enquirer';
|
||||
import { Snippet } from './Snippet';
|
||||
|
||||
(async (): Promise<void> => {
|
||||
const snippets = await fs.readdir (path.join (__dirname, '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 ();
|
||||
runners[snippet].start (process.cwd ());
|
||||
}) ()
|
||||
// eslint-disable-next-line no-console
|
||||
.catch ((e) => console.log (e));
|
46
lib/snippets/copyright/copyright_generator.ts
Normal file
46
lib/snippets/copyright/copyright_generator.ts
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 { CopyrightOptions } from './copyright_options';
|
||||
|
||||
export class CopyrightGenerator {
|
||||
public static get_copyright_notice (
|
||||
opt: CopyrightOptions,
|
||||
date_str?: string
|
||||
): string {
|
||||
let notice = '';
|
||||
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 = `${'/*'}
|
||||
* Copyright (C) ${opt.company || opt.author} - All Rights Reserved
|
||||
* 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}>, ${date_string}
|
||||
*/
|
||||
|
||||
`;
|
||||
}
|
||||
else {
|
||||
notice = `${'/*'}
|
||||
* Copyright (C) ${opt.company || opt.author} - All Rights Reserved
|
||||
* Created by ${opt.author} <${opt.email}>, ${date_string}
|
||||
*/
|
||||
|
||||
`;
|
||||
}
|
||||
return notice;
|
||||
}
|
||||
}
|
15
lib/snippets/copyright/copyright_options.ts
Normal file
15
lib/snippets/copyright/copyright_options.ts
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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 CopyrightOptions {
|
||||
public has_license = false;
|
||||
public license = '';
|
||||
public author = '';
|
||||
public company = '';
|
||||
public email = '';
|
||||
public software = '';
|
||||
}
|
34
lib/snippets/copyright/file_mapper.ts
Normal file
34
lib/snippets/copyright/file_mapper.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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-await-in-loop */
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
export class FileMapper {
|
||||
public static async map_all_files (
|
||||
folder: string,
|
||||
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) {
|
||||
if ([ 'node_modules' ].includes (file))
|
||||
continue;
|
||||
const abs_path = path.join (folder, file);
|
||||
if ((await fs.stat (abs_path)).isDirectory ()) {
|
||||
await FileMapper.map_all_files (abs_path, mutator, opts);
|
||||
continue;
|
||||
}
|
||||
const data = await fs.readFile (abs_path, 'utf-8');
|
||||
const res = mutator (data, file, opts);
|
||||
if (res === null)
|
||||
continue;
|
||||
await fs.writeFile (abs_path, res, 'utf-8');
|
||||
}
|
||||
}
|
||||
}
|
155
lib/snippets/copyright/index.ts
Normal file
155
lib/snippets/copyright/index.ts
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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-await-in-loop */
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import { Confirm, Input, AutoComplete } from 'enquirer';
|
||||
// eslint-disable-next-line id-match
|
||||
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 {
|
||||
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;
|
||||
await this.load_options_file ();
|
||||
if (!this._options)
|
||||
await this.gather_options ();
|
||||
|
||||
const options = this._options as CopyrightOptions;
|
||||
|
||||
await FileMapper.map_all_files (
|
||||
this._cwd,
|
||||
this.fix_file_license.bind (this)
|
||||
);
|
||||
|
||||
await modify_json ((json) => {
|
||||
json.author = { name: options.author, email: 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))
|
||||
)
|
||||
this.save_options_file ();
|
||||
}
|
||||
|
||||
private async gather_options (): Promise<void> {
|
||||
this._options = (new CopyrightOptions);
|
||||
this._options.author = await new Input ({ message: 'author' })
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
this._options.email = await new Input ({ message: 'email' })
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
this._options.company = await new Input ({ message: 'company' })
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
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?' }
|
||||
)
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
if (this._options.has_license) {
|
||||
this._options.license = await new AutoComplete ({
|
||||
name: 'license',
|
||||
message: 'choose a license',
|
||||
limit: 10,
|
||||
choices: findLicense ('')
|
||||
})
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
}
|
||||
}
|
||||
|
||||
private async load_options_file (): Promise<void> {
|
||||
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'));
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log (`author: ${options.author}
|
||||
email: ${options.email}
|
||||
company: ${options.company}
|
||||
software name: ${options.software}
|
||||
license: ${options.license}`);
|
||||
const should_load = await new Confirm (
|
||||
{ message: 'should those options be used?' }
|
||||
)
|
||||
.run ()
|
||||
.catch (DialogHandler.catch);
|
||||
if (should_load) {
|
||||
this._options = options;
|
||||
this._loaded_from_config = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async save_options_file (): Promise<void> {
|
||||
const file_path = path.join (this._cwd, '.liconfig.json');
|
||||
await fs.writeFile (
|
||||
file_path,
|
||||
JSON.stringify (this._options, null, 2),
|
||||
'utf-8'
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
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, '')
|
||||
);
|
||||
}
|
||||
}
|
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');
|
||||
}
|
||||
}
|
53
lib/snippets/jenkins/Assets.ts
Normal file
53
lib/snippets/jenkins/Assets.ts
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 */
|
||||
|
||||
const general = { jenkinsfile: '' };
|
||||
|
||||
general.jenkinsfile = `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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export { general };
|
21
lib/snippets/jenkins/index.ts
Normal file
21
lib/snippets/jenkins/index.ts
Normal file
@ -0,0 +1,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>, May 2020
|
||||
*/
|
||||
|
||||
import { Snippet } from '../../Snippet';
|
||||
import { apply_template } from '../../Helper';
|
||||
|
||||
import { general } from './Assets';
|
||||
|
||||
export default class Jenkins implements Snippet {
|
||||
public is_active (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public async start (): Promise<void> {
|
||||
await apply_template (general.jenkinsfile, 'Jenkinsfile');
|
||||
}
|
||||
}
|
70
lib/snippets/node/Assets.ts
Normal file
70
lib/snippets/node/Assets.ts
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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,
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@sapphirecode'
|
||||
],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const eslintrc_ts = `module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@sapphirecode/eslint-config-ts'
|
||||
],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const gitignore = `/node_modules/
|
||||
/dist/
|
||||
/.nyc_output/
|
||||
/coverage/
|
||||
`;
|
||||
|
||||
const tsconfig = `{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./lib",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"declaration": true
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const eslintignore = `/dist/
|
||||
*.d.ts
|
||||
`;
|
||||
|
||||
export { eslintrc, gitignore, tsconfig, eslintrc_ts, eslintignore };
|
142
lib/snippets/node/index.ts
Normal file
142
lib/snippets/node/index.ts
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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 { Input, Confirm } from 'enquirer';
|
||||
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';
|
||||
|
||||
import {
|
||||
eslintrc, gitignore,
|
||||
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
|
||||
*
|
||||
* @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> {
|
||||
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: Record<string, string>
|
||||
= {
|
||||
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.pretest = standard_scripts.test.ts_pre;
|
||||
scripts.test = standard_scripts.test.ts;
|
||||
scripts.posttest = standard_scripts.test.ts_post;
|
||||
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 ({
|
||||
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 (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 (
|
||||
eslintrc_ts,
|
||||
path.join (folder, 'lib', '.eslintrc.js')
|
||||
);
|
||||
}
|
||||
run_command ('git init', 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);
|
||||
}
|
||||
}
|
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}
|
||||
`;
|
||||
}
|
48
lib/snippets/readme/index.ts
Normal file
48
lib/snippets/readme/index.ts
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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;
|
||||
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,
|
||||
package_data.description,
|
||||
dev,
|
||||
package_data.license,
|
||||
package_data.author
|
||||
);
|
||||
await apply_template (readme, 'README.md');
|
||||
}
|
||||
}
|
38
package.json
38
package.json
@ -1,35 +1,49 @@
|
||||
{
|
||||
"name": "@scode/snippeteer",
|
||||
"version": "1.0.0",
|
||||
"name": "@sapphirecode/snippeteer",
|
||||
"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\""
|
||||
"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": [
|
||||
"/snippets/",
|
||||
"/dist/",
|
||||
"/lib/",
|
||||
"LICENSE"
|
||||
],
|
||||
"author": "Timo Hocker",
|
||||
"author": {
|
||||
"name": "Timo Hocker",
|
||||
"email": "timo@scode.ovh"
|
||||
},
|
||||
"license": "BSD-3-Clause",
|
||||
"devDependencies": {
|
||||
"@scode/eslint-config": "^2.0.2",
|
||||
"eslint": "^6.8.0"
|
||||
"@sapphirecode/eslint-config-ts": "^1.0.22",
|
||||
"@types/fs-extra": "^9.0.0",
|
||||
"@types/node": "^17.0.2",
|
||||
"eslint": "^8.5.0",
|
||||
"typescript": "^4.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"fs-extra": "^9.0.0",
|
||||
"yargs": "^15.1.0"
|
||||
"@sapphirecode/standard": "^1.5.5",
|
||||
"enquirer": "^2.3.5",
|
||||
"fs-extra": "^10.0.0",
|
||||
"license": "^1.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"snippet",
|
||||
"template"
|
||||
]
|
||||
}
|
||||
|
@ -1,148 +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>, March 2020
|
||||
*/
|
||||
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
|
||||
/**
|
||||
* scan all files and execute a mutation on them
|
||||
*
|
||||
* @param {string} folder folder to scan
|
||||
* @param {Function} func function to execute on file contents
|
||||
*/
|
||||
async function map_all_files (folder, func) {
|
||||
const files = await fs.readdir (folder);
|
||||
for (const file of files) {
|
||||
if ([ 'node_modules' ].includes (file))
|
||||
continue;
|
||||
const abs_path = path.join (folder, file);
|
||||
if ((await fs.stat (abs_path)).isDirectory ()) {
|
||||
map_all_files (abs_path, func);
|
||||
continue;
|
||||
}
|
||||
const data = await fs.readFile (abs_path, 'utf-8');
|
||||
const res = func (data, file);
|
||||
if (res === null)
|
||||
continue;
|
||||
await fs.writeFile (abs_path, res, 'utf-8');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a copyright notice
|
||||
*
|
||||
* @param {string} license license name
|
||||
* @param {string} software software name
|
||||
* @returns {string} copyright notice
|
||||
*/
|
||||
function get_copyright_notice (license = '', software = '') {
|
||||
let notice = '';
|
||||
const date = (new Date);
|
||||
const dtf = new Intl.DateTimeFormat ('en', { month: 'long' });
|
||||
const year = date.getFullYear ();
|
||||
const month = dtf.format (date);
|
||||
|
||||
if (license) {
|
||||
notice = `${'/*'}
|
||||
* Copyright (C) Sapphirecode - All Rights Reserved
|
||||
* This file is part of ${software} which is released under ${license}.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@scode.ovh>, ${month} ${year}
|
||||
*/
|
||||
|
||||
`;
|
||||
}
|
||||
else {
|
||||
notice = `${'/*'}
|
||||
* Copyright (C) Sapphirecode - All Rights Reserved
|
||||
* Created by Timo Hocker <timo@scode.ovh>, ${month} ${year}
|
||||
*/
|
||||
|
||||
`;
|
||||
}
|
||||
return notice;
|
||||
}
|
||||
|
||||
/**
|
||||
* scans a folder and fixes all copyright notices
|
||||
*
|
||||
* @param {string} folder folder to scan
|
||||
* @param {string} license license name
|
||||
* @param {string} software software name
|
||||
*/
|
||||
async function fix_all_copy (folder, license = '', software = '') {
|
||||
const regex = /\/\*\s+\*\sCopyright[\s\S]*?\*\/\n{0,2}/gu;
|
||||
await map_all_files (folder, (data, filename) => {
|
||||
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] : '')
|
||||
+ get_copyright_notice (license, software)
|
||||
+ data.replace (regex, '')
|
||||
.replace (shebang, '');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* copies the full template to a new folder named after arg[0]
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
*/
|
||||
function run (folder, args) {
|
||||
fix_all_copy (folder, ...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the arguments meet the requirements
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
* @returns {boolean} true if arguments match requirements
|
||||
*/
|
||||
function assert (folder, args) {
|
||||
const tests = [
|
||||
{
|
||||
f: () => (args.length === 0 || args.length === 2),
|
||||
reason: 'invalid number of arguments'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0 || typeof args[0] === 'string'),
|
||||
reason: 'license is not a string'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0 || typeof args[1] === 'string'),
|
||||
reason: 'software name is not a string'
|
||||
},
|
||||
{
|
||||
f: () => (typeof folder === 'string'),
|
||||
reason: 'cwd is not a folder (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (fs.existsSync (folder)),
|
||||
reason: 'cwd does not exist (internal error)'
|
||||
}
|
||||
];
|
||||
for (const test of tests) {
|
||||
if (!test.f ()) {
|
||||
console.log (test.reason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { run, assert };
|
@ -1,228 +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>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-magic-numbers */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
|
||||
/**
|
||||
* convert short type notation to knex notation
|
||||
*
|
||||
* @param {string} short short type
|
||||
* @returns {string} type
|
||||
*/
|
||||
function get_type (short) {
|
||||
switch (short) {
|
||||
case '\'\'':
|
||||
return 'string';
|
||||
case '#':
|
||||
return 'integer';
|
||||
case '#.#':
|
||||
return 'double';
|
||||
case '✓':
|
||||
return 'boolean';
|
||||
case '🖹':
|
||||
return 'text';
|
||||
case '🕓':
|
||||
return 'timestamp';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns columns and attributes for a table
|
||||
*
|
||||
* @param {string} str table definition
|
||||
* @returns {object} table info
|
||||
*/
|
||||
function get_table_info (str) {
|
||||
const lines = str.split (/\n/ug);
|
||||
lines.splice (0, 2);
|
||||
lines.splice (lines.length - 2, 2);
|
||||
const name_line = lines.shift ();
|
||||
const { name } = (/<b>(?<name>\S+)<\/b>/u).exec (name_line).groups;
|
||||
const columns = [];
|
||||
while (lines.length > 0) {
|
||||
const col = {};
|
||||
const l = lines.shift ();
|
||||
const regex = /<tr><td.*?>(?<props>.*?)<\/td><\/tr>/u;
|
||||
const data = regex.exec (l).groups.props.split (/\s+/gu);
|
||||
if (data.length === 3 || data[0] === '🔑') {
|
||||
const opt = data.shift ();
|
||||
if (opt === '★')
|
||||
col.unique = true;
|
||||
if (opt === '🔑')
|
||||
col.type = 'increments';
|
||||
}
|
||||
|
||||
col.name = data.shift ();
|
||||
if (data.length > 0)
|
||||
col.type = get_type (data.shift ());
|
||||
|
||||
if (typeof col.type === 'undefined')
|
||||
console.error (`column type is undefined: ${col.name} table: ${name}`);
|
||||
|
||||
columns.push (col);
|
||||
}
|
||||
|
||||
return { name, columns, foreign_keys: [] };
|
||||
}
|
||||
|
||||
/**
|
||||
* get all tables from a structure file
|
||||
*
|
||||
* @param {string} file path to the structure file
|
||||
* @returns {Promise<object>} tables and foreign keys
|
||||
*/
|
||||
async function get_tables (file) {
|
||||
const lines = (await fs.readFile (file, 'utf-8')).split (/\n/gu);
|
||||
const curr = [];
|
||||
const tables = [];
|
||||
const foreign = [];
|
||||
for (const l of lines) {
|
||||
if (curr.length > 0 || (/\S+ \[label=</u).test (l))
|
||||
curr.push (l);
|
||||
|
||||
if ((/>.*?\]/u).test (l)) {
|
||||
const val = curr.join ('\n');
|
||||
if (val)
|
||||
tables.push (get_table_info (val));
|
||||
curr.splice (0, curr.length);
|
||||
}
|
||||
|
||||
get_foreign_key (l, foreign);
|
||||
}
|
||||
|
||||
for (const fk of foreign) {
|
||||
for (let i = 0; i < tables.length; i++) {
|
||||
if (tables[i].name === fk.table) {
|
||||
tables[i].foreign_keys.push (fk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets foreign keys from a line
|
||||
*
|
||||
* @param {string} line line to check
|
||||
* @param {Array<object>} foreign_keys array to add to
|
||||
*/
|
||||
function get_foreign_key (line, foreign_keys) {
|
||||
const fk = (/(?<col>\S+) -> (?<ref>\S+)/u).exec (line);
|
||||
if (fk) {
|
||||
const col = fk.groups.col.split (':');
|
||||
const ref = fk.groups.ref.split (':');
|
||||
|
||||
const foreign_key = {
|
||||
table: col[0],
|
||||
column: col[1],
|
||||
ref_table: ref[0],
|
||||
ref_column: ref[1]
|
||||
};
|
||||
|
||||
foreign_keys.push (foreign_key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a function for creating a table
|
||||
*
|
||||
* @param {object} table table to create a function for
|
||||
* @returns {string} function
|
||||
*/
|
||||
function create_table_function (table) {
|
||||
let func = `/**
|
||||
* create table ${table.name}
|
||||
*
|
||||
* @param {any} knex database connection
|
||||
* @returns {Promise} result
|
||||
*/
|
||||
function create_${table.name} (knex) {
|
||||
return knex.schema.createTable ('${table.name}', (table) => {
|
||||
${table.columns
|
||||
.map ((col) => `table.${col.type} ('${col.name}');`)
|
||||
.join ('\n ')}
|
||||
`;
|
||||
|
||||
const unique = table.columns.filter ((val) => val.unique);
|
||||
if (unique.length > 0) {
|
||||
func += `\n table.unique (${unique
|
||||
.map ((val) => `'${val.name}'`)
|
||||
.join (', ')});\n`;
|
||||
}
|
||||
|
||||
if (table.foreign_keys.length > 0) {
|
||||
func += '\n';
|
||||
for (const fk of table.foreign_keys) {
|
||||
func += ` table.foreign ('${fk.column}')
|
||||
.references ('${fk.ref_column}')
|
||||
.inTable ('${fk.ref_table}');\n`;
|
||||
}
|
||||
}
|
||||
|
||||
func += ` });
|
||||
}`;
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the migration function
|
||||
*
|
||||
* @param {Array<object>} tables table array
|
||||
* @returns {string} function
|
||||
*/
|
||||
function create_up_function (tables) {
|
||||
const func = `async function up (knex) {
|
||||
${tables.map ((val) => ` await create_${val.name} (knex);`)
|
||||
.join ('\n')}
|
||||
}`;
|
||||
return func;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the complete migration file for a graph
|
||||
*
|
||||
* @param {string} file_path file to scan
|
||||
* @returns {Promise<string>} file
|
||||
*/
|
||||
async function create_migration (file_path) {
|
||||
const tables = await get_tables (file_path);
|
||||
const functions = tables.map ((tab) => create_table_function (tab));
|
||||
|
||||
const file = `'use strict';
|
||||
|
||||
${functions.join ('\n\n')}
|
||||
|
||||
/**
|
||||
* run migration
|
||||
*
|
||||
* @param {any} knex db connection
|
||||
*/
|
||||
${create_up_function (tables)}
|
||||
|
||||
/**
|
||||
* revert migration
|
||||
*/
|
||||
function down () {
|
||||
// noop
|
||||
}
|
||||
|
||||
module.exports = { up, down };
|
||||
`;
|
||||
return file;
|
||||
}
|
||||
|
||||
module.exports = { get_tables, create_table_function, create_migration };
|
@ -1,66 +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>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-magic-numbers */
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
const dot_parser = require ('./dot_parser');
|
||||
|
||||
/**
|
||||
* copies the full template to a new folder named after arg[0]
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
*/
|
||||
async function run (folder, args) {
|
||||
const graph = path.join (folder, args[0]);
|
||||
const migration = path.join (folder, args[1]);
|
||||
|
||||
const db_migration = await dot_parser.create_migration (graph);
|
||||
await fs.writeFile (migration, db_migration, 'utf-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the arguments meet the requirements
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
* @returns {boolean} true if arguments match requirements
|
||||
*/
|
||||
function assert (folder, args) {
|
||||
const tests = [
|
||||
{
|
||||
f: () => (args.length === 2
|
||||
&& typeof args[0] === 'string'
|
||||
&& typeof args[1] === 'string'),
|
||||
reason: 'db [graph] [migration]'
|
||||
},
|
||||
{
|
||||
f: () => (typeof folder === 'string'),
|
||||
reason: 'cwd is not a folder (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (fs.existsSync (folder)),
|
||||
reason: 'cwd does not exist (internal error)'
|
||||
}
|
||||
];
|
||||
for (const test of tests) {
|
||||
if (!test.f ()) {
|
||||
console.log (test.reason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { run, assert };
|
@ -1,78 +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>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
|
||||
/**
|
||||
* copies the full template to a new folder named after arg[0]
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
*/
|
||||
function run (folder, args) {
|
||||
const is_node = args.length === 1 && (/^node$/ui).test (args[0]);
|
||||
|
||||
const template = path.join (
|
||||
__dirname,
|
||||
'template',
|
||||
is_node
|
||||
? 'node'
|
||||
: 'general'
|
||||
);
|
||||
|
||||
for (const f of fs.readdirSync (template)) {
|
||||
fs.copy (
|
||||
path.join (template, f),
|
||||
path.join (folder, f),
|
||||
{ filter: (src, dest) => !fs.existsSync (dest) }
|
||||
);
|
||||
}
|
||||
|
||||
if (is_node) {
|
||||
const pkg = path.join (folder, 'package.json');
|
||||
if (fs.existsSync (pkg)) {
|
||||
const json = JSON.parse (fs.readFileSync (pkg, 'utf-8'));
|
||||
json.scripts.ci = 'yarn && node jenkins.js';
|
||||
fs.writeFileSync (pkg, JSON.stringify (json, null, 2), 'utf-8');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the arguments meet the requirements
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @returns {boolean} true if arguments match requirements
|
||||
*/
|
||||
function assert (folder) {
|
||||
const tests = [
|
||||
{
|
||||
f: () => (typeof folder === 'string'),
|
||||
reason: 'cwd is not a folder (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (fs.existsSync (folder)),
|
||||
reason: 'cwd does not exist (internal error)'
|
||||
}
|
||||
];
|
||||
for (const test of tests) {
|
||||
if (!test.f ()) {
|
||||
console.log (test.reason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { run, assert };
|
39
snippets/jenkins/template/general/Jenkinsfile
vendored
39
snippets/jenkins/template/general/Jenkinsfile
vendored
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
snippets/jenkins/template/node/Jenkinsfile
vendored
23
snippets/jenkins/template/node/Jenkinsfile
vendored
@ -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,33 +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>, March 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' });
|
||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.test === 'string')
|
||||
child_process.execSync ('yarn test', { 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'); }
|
||||
});
|
@ -1,65 +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>, March 2020
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const csv = require ('csv-parse');
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
|
||||
/**
|
||||
* get all csv data that should be loaded
|
||||
*
|
||||
* @returns {Promise<Array<object>>} csv data
|
||||
*/
|
||||
async function get_csv () {
|
||||
const csv_list = await Promise.all ((
|
||||
await fs.readdir ('migrations/csv'))
|
||||
.map (
|
||||
async (file) => {
|
||||
if (path.extname (file) !== '.csv')
|
||||
return null;
|
||||
const name = path.basename (file, '.csv');
|
||||
|
||||
const data = [];
|
||||
const parser = csv (await fs.readFile (
|
||||
path.join ('migrations/csv', file)
|
||||
), { columns: true });
|
||||
|
||||
for await (const entry of parser)
|
||||
data.push (entry);
|
||||
|
||||
return { name, data };
|
||||
}
|
||||
));
|
||||
|
||||
return csv_list.filter ((val) => val !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* execute migration
|
||||
*
|
||||
* @param {any} knex database connection
|
||||
*/
|
||||
async function up (knex) {
|
||||
const data = await get_csv ();
|
||||
await Promise.all (
|
||||
data.map (
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
(table) => knex.bulkInsert (table.name, table.data, 64)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* revert migration
|
||||
*/
|
||||
function down () {
|
||||
// noop
|
||||
}
|
||||
|
||||
module.exports = { up, down };
|
@ -1,76 +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>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
|
||||
/**
|
||||
* copies the full template to a new folder named after arg[0]
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
*/
|
||||
async function run (folder, args) {
|
||||
const template = path.join (
|
||||
__dirname,
|
||||
args[0] === 'csv' ? 'csv.template.js' : 'template.js'
|
||||
);
|
||||
const target_name = args[0] === 'csv' ? '000001_csv_ingress' : args[0];
|
||||
const dest = path.join (folder, `${target_name}.js`);
|
||||
await fs.writeFile (dest, await fs.readFile (template));
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the arguments meet the requirements
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
* @returns {boolean} true if arguments match requirements
|
||||
*/
|
||||
function assert (folder, args) {
|
||||
const tests = [
|
||||
{
|
||||
f: () => (args.length < 2),
|
||||
reason: 'too many arguments'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 1 && typeof args[0] === 'string'),
|
||||
reason: 'name is not a string'
|
||||
},
|
||||
{
|
||||
f: () => ((/^(?:[0-9]+[-_][a-z-_]+|csv)$/iu).test (args[0])),
|
||||
reason: 'name has to match /^[0-9]+[-_][a-z-_]+$/'
|
||||
},
|
||||
{
|
||||
f: () => (typeof folder === 'string'),
|
||||
reason: 'cwd is not a folder (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (fs.existsSync (folder)),
|
||||
reason: 'cwd does not exist (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (!fs.existsSync (path.join (folder, args[0]))),
|
||||
reason: 'migration already exists'
|
||||
}
|
||||
];
|
||||
for (const test of tests) {
|
||||
if (!test.f ()) {
|
||||
console.log (test.reason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { run, assert };
|
@ -1,33 +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>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-magic-numbers */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* execute migration
|
||||
*
|
||||
* @param {any} knex database connections
|
||||
*/
|
||||
async function up (knex) {
|
||||
await knex.schema.createTable ('template', (table) => {
|
||||
table.increments ('id');
|
||||
table.string ('text', 64);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* revert migration
|
||||
*
|
||||
* @param {any} knex database connections
|
||||
*/
|
||||
async function down (knex) {
|
||||
await knex.schema.dropTable ('template');
|
||||
}
|
||||
|
||||
module.exports = { up, down };
|
@ -1,127 +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>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
const child_process = require ('child_process');
|
||||
|
||||
/**
|
||||
* copies the full template to a new folder named after arg[0]
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
*/
|
||||
async function run (folder, args) {
|
||||
const snip_folder_path = [ folder ];
|
||||
if (args.length > 0)
|
||||
snip_folder_path.push (args[0]);
|
||||
const snip_folder = path.join (...snip_folder_path);
|
||||
const template = path.join (__dirname, 'template');
|
||||
if (!fs.existsSync (snip_folder))
|
||||
fs.mkdir (snip_folder);
|
||||
for (const f of fs.readdirSync (template)) {
|
||||
fs.copy (
|
||||
path.join (template, f),
|
||||
path.join (snip_folder, f),
|
||||
{
|
||||
recursive: true,
|
||||
filter: (src, dest) => !fs.existsSync (dest)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
child_process.execSync (
|
||||
'git init',
|
||||
{ cwd: snip_folder, stdio: 'inherit' }
|
||||
);
|
||||
child_process.execSync (
|
||||
'yarn init -y',
|
||||
{ cwd: snip_folder, stdio: 'inherit' }
|
||||
);
|
||||
child_process.execSync (
|
||||
'yarn add --dev @scode/eslint-config eslint nyc ava',
|
||||
{ cwd: snip_folder, stdio: 'inherit' }
|
||||
);
|
||||
|
||||
const package_json = JSON.parse (
|
||||
await fs.readFile (path.join (snip_folder, 'package.json'), 'utf-8')
|
||||
);
|
||||
|
||||
package_json.scripts = {
|
||||
lint: 'eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs',
|
||||
test: 'nyc ava'
|
||||
};
|
||||
|
||||
await fs.writeFile (
|
||||
path.join (snip_folder, 'package.json'),
|
||||
JSON.stringify (package_json, null, 2)
|
||||
);
|
||||
|
||||
await fs.writeFile (
|
||||
path.join (snip_folder, '.gitignore'),
|
||||
`/node_modules/
|
||||
/dist/
|
||||
/.nyc_output/
|
||||
/coverage/`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the arguments meet the requirements
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
* @returns {boolean} true if arguments match requirements
|
||||
*/
|
||||
function assert (folder, args) {
|
||||
const tests = [
|
||||
{
|
||||
f: () => (args.length < 2),
|
||||
reason: 'too many arguments'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0 || typeof args[0] === 'string'),
|
||||
reason: 'name is not a string'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0 || (/^[a-z-]+$/iu).test (args[0])),
|
||||
reason: 'name can only contain [a-z-]'
|
||||
},
|
||||
{
|
||||
f: () => (typeof folder === 'string'),
|
||||
reason: 'cwd is not a folder (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (fs.existsSync (folder)),
|
||||
reason: 'cwd does not exist (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 1 || fs.readdirSync (folder).length === 0),
|
||||
reason: 'folder is not empty'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0
|
||||
|| !fs.existsSync (path.join (folder, args[0]))),
|
||||
reason: 'folder already exists'
|
||||
}
|
||||
];
|
||||
for (const test of tests) {
|
||||
if (!test.f ()) {
|
||||
console.log (test.reason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { run, assert };
|
@ -1,24 +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>, March 2020
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@scode'
|
||||
],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
@scode:registry=https://npm.scode.ovh
|
@ -1,7 +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>, March 2020
|
||||
*/
|
||||
|
@ -1,72 +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>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
|
||||
/**
|
||||
* copies the full template to a new folder named after arg[0]
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
*/
|
||||
async function run (folder, args) {
|
||||
const template = path.join (__dirname, 'template.js');
|
||||
const dest = path.join (folder, `${args[0]}.js`);
|
||||
await fs.writeFile (dest, await fs.readFile (template));
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the arguments meet the requirements
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
* @returns {boolean} true if arguments match requirements
|
||||
*/
|
||||
function assert (folder, args) {
|
||||
const tests = [
|
||||
{
|
||||
f: () => (args.length < 2),
|
||||
reason: 'too many arguments'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 1 && typeof args[0] === 'string'),
|
||||
reason: 'name is not a string'
|
||||
},
|
||||
{
|
||||
f: () => ((/^[a-z]+-[a-z]+$/iu).test (args[0])),
|
||||
reason: 'name has to match /^[a-z]+-[a-z]+$/'
|
||||
},
|
||||
{
|
||||
f: () => (typeof folder === 'string'),
|
||||
reason: 'cwd is not a folder (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (fs.existsSync (folder)),
|
||||
reason: 'cwd does not exist (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (!fs.existsSync (path.join (folder, args[0]))),
|
||||
reason: 'file already exists'
|
||||
}
|
||||
];
|
||||
for (const test of tests) {
|
||||
if (!test.f ()) {
|
||||
console.log (test.reason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { run, assert };
|
@ -1,17 +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>, March 2020
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = function handler (req, res, next, opts) {
|
||||
if (req.headers.example === 'abc')
|
||||
res.writeHead (1);
|
||||
else
|
||||
res.writeHead (2);
|
||||
|
||||
res.end (opts.text);
|
||||
};
|
@ -1,91 +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>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
|
||||
/**
|
||||
* copies the full template to a new folder named after arg[0]
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
*/
|
||||
function run (folder, args) {
|
||||
const snip_folder_path = [ folder ];
|
||||
if (args.length > 0)
|
||||
snip_folder_path.push (args[0]);
|
||||
const snip_folder = path.join (...snip_folder_path);
|
||||
const template = path.join (__dirname, 'template');
|
||||
if (!fs.existsSync (snip_folder))
|
||||
fs.mkdir (snip_folder);
|
||||
for (const f of fs.readdirSync (template)) {
|
||||
fs.copy (
|
||||
path.join (template, f),
|
||||
path.join (snip_folder, f),
|
||||
{
|
||||
recursive: true,
|
||||
filter: (src, dest) => !fs.existsSync (dest)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the arguments meet the requirements
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
* @returns {boolean} true if arguments match requirements
|
||||
*/
|
||||
function assert (folder, args) {
|
||||
const tests = [
|
||||
{
|
||||
f: () => (args.length < 2),
|
||||
reason: 'too many arguments'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0 || typeof args[0] === 'string'),
|
||||
reason: 'name is not a string'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0 || (/^[a-z]+$/iu).test (args[0])),
|
||||
reason: 'name can only contain [a-z]'
|
||||
},
|
||||
{
|
||||
f: () => (typeof folder === 'string'),
|
||||
reason: 'cwd is not a folder (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (fs.existsSync (folder)),
|
||||
reason: 'cwd does not exist (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 1 || fs.readdirSync (folder).length === 0),
|
||||
reason: 'folder is not empty'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0
|
||||
|| !fs.existsSync (path.join (folder, args[0]))),
|
||||
reason: 'folder already exists'
|
||||
}
|
||||
];
|
||||
for (const test of tests) {
|
||||
if (!test.f ()) {
|
||||
console.log (test.reason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { run, assert };
|
@ -1,91 +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>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
|
||||
/**
|
||||
* copies the full template to a new folder named after arg[0]
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
*/
|
||||
function run (folder, args) {
|
||||
const snip_folder_path = [ folder ];
|
||||
if (args.length > 0)
|
||||
snip_folder_path.push (args[0]);
|
||||
const snip_folder = path.join (...snip_folder_path);
|
||||
const template = path.join (__dirname, 'template');
|
||||
if (!fs.existsSync (snip_folder))
|
||||
fs.mkdir (snip_folder);
|
||||
for (const f of fs.readdirSync (template)) {
|
||||
fs.copy (
|
||||
path.join (template, f),
|
||||
path.join (snip_folder, f),
|
||||
{
|
||||
recursive: true,
|
||||
filter: (src, dest) => !fs.existsSync (dest)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the arguments meet the requirements
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
* @returns {boolean} true if arguments match requirements
|
||||
*/
|
||||
function assert (folder, args) {
|
||||
const tests = [
|
||||
{
|
||||
f: () => (args.length < 2),
|
||||
reason: 'too many arguments'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0 || typeof args[0] === 'string'),
|
||||
reason: 'name is not a string'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0 || (/^[a-z]+$/iu).test (args[0])),
|
||||
reason: 'name can only contain [a-z]'
|
||||
},
|
||||
{
|
||||
f: () => (typeof folder === 'string'),
|
||||
reason: 'cwd is not a folder (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (fs.existsSync (folder)),
|
||||
reason: 'cwd does not exist (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 1 || fs.readdirSync (folder).length === 0),
|
||||
reason: 'folder is not empty'
|
||||
},
|
||||
{
|
||||
f: () => (args.length === 0
|
||||
|| !fs.existsSync (path.join (folder, args[0]))),
|
||||
reason: 'folder already exists'
|
||||
}
|
||||
];
|
||||
for (const test of tests) {
|
||||
if (!test.f ()) {
|
||||
console.log (test.reason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { run, assert };
|
66
tsconfig.json
Normal file
66
tsconfig.json
Normal file
@ -0,0 +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. */
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user