add node template
This commit is contained in:
parent
5be9e89e0f
commit
c21b5af22f
14
package-lock.json
generated
14
package-lock.json
generated
@ -25,13 +25,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@scode/eslint-config": {
|
"@scode/eslint-config": {
|
||||||
"version": "1.1.10",
|
"version": "1.1.11",
|
||||||
"resolved": "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-1.1.10.tgz",
|
"resolved": "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-1.1.11.tgz",
|
||||||
"integrity": "sha512-5v8YuMwD2p1Kdfo4fVXF76MqmUeR5Rv3W7/ybqTN+XrxNcIhGGp8fB8q+y6DtUD+4yQL0dFCoCFJlRWI/VttEg==",
|
"integrity": "sha512-2X04vnBFtZFQQh1fGOYy/aFmKgdCUYHmhmY6af3COdNVIV3UalwtInF93UVnTiPsnxLCChacpuPh04bn85odew==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"eslint-plugin-import": "^2.20.0",
|
"eslint-plugin-import": "^2.20.0",
|
||||||
"eslint-plugin-jsdoc": "^20.3.0",
|
"eslint-plugin-jsdoc": "^20.3.1",
|
||||||
"eslint-plugin-vue": "^6.1.2"
|
"eslint-plugin-vue": "^6.1.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -455,9 +455,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"eslint-plugin-jsdoc": {
|
"eslint-plugin-jsdoc": {
|
||||||
"version": "20.3.0",
|
"version": "20.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-20.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-20.3.1.tgz",
|
||||||
"integrity": "sha512-7tBrLcN02smsQsl8hOKZZx6sGM9qlkN6AmAf7ggpZjsAD/Qi4RsPK+JFzQkA4RysyyDnPZfrJhV19vrQut2dLA==",
|
"integrity": "sha512-JQ25OXvseVm84pX2mcVvKtGwrZDeAxgFUkq11f/pJpbGJMANYcLaMAUuW7U3cGhapWh+Gj04At/enAt26dpOeg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"comment-parser": "^0.7.2",
|
"comment-parser": "^0.7.2",
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
"author": "Timo Hocker",
|
"author": "Timo Hocker",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@scode/eslint-config": "^1.1.10",
|
"@scode/eslint-config": "^1.1.11",
|
||||||
"eslint": "^6.8.0"
|
"eslint": "^6.8.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
93
snippets/node/index.js
Normal file
93
snippets/node/index.js
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/* eslint-disable no-sync */
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
|
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.join (folder, args[0]);
|
||||||
|
const template = path.join (__dirname, 'template');
|
||||||
|
fs.mkdir (snip_folder);
|
||||||
|
fs.copy (template, snip_folder);
|
||||||
|
|
||||||
|
child_process.execSync (
|
||||||
|
'git init',
|
||||||
|
{ cwd: snip_folder, stdio: 'inherit' }
|
||||||
|
);
|
||||||
|
child_process.execSync (
|
||||||
|
'npm init -y',
|
||||||
|
{ cwd: snip_folder, stdio: 'inherit' }
|
||||||
|
);
|
||||||
|
child_process.execSync (
|
||||||
|
'npm i --save-dev @scode/eslint-config eslint',
|
||||||
|
{ 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 --fix .' };
|
||||||
|
|
||||||
|
await fs.writeFile (
|
||||||
|
path.join (snip_folder, 'package.json'),
|
||||||
|
JSON.stringify (package_json, null, 2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 };
|
17
snippets/node/template/.eslintrc.js
Normal file
17
snippets/node/template/.eslintrc.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
commonjs: true,
|
||||||
|
es6: true,
|
||||||
|
node: true
|
||||||
|
},
|
||||||
|
extends: [
|
||||||
|
'@scode'
|
||||||
|
],
|
||||||
|
globals: {
|
||||||
|
Atomics: 'readonly',
|
||||||
|
SharedArrayBuffer: 'readonly'
|
||||||
|
},
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 2018
|
||||||
|
}
|
||||||
|
}
|
1
snippets/node/template/.gitignore
vendored
Normal file
1
snippets/node/template/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/node_modules/
|
1
snippets/node/template/.npmrc
Normal file
1
snippets/node/template/.npmrc
Normal file
@ -0,0 +1 @@
|
|||||||
|
@scode:registry=https://npm.scode.ovh
|
0
snippets/node/template/index.js
Normal file
0
snippets/node/template/index.js
Normal file
Loading…
x
Reference in New Issue
Block a user