diff --git a/lib/snippets/node/index.ts b/lib/snippets/node/index.ts index 07d7029..0d347fd 100644 --- a/lib/snippets/node/index.ts +++ b/lib/snippets/node/index.ts @@ -7,6 +7,7 @@ import path from 'path'; import { Input, Confirm } from 'enquirer'; +import { scripts as standard_scripts } from '@scode/standard'; import { Snippet } from '../../Snippet'; import { apply_template, modify_json, run_command } from '../../Helper'; @@ -19,24 +20,35 @@ import { * initialize the package.json * * @param {string} folder folder + * @param {boolean} use_ts use_ts + * @param {boolean} use_tests use_tests */ -async function init_package (folder: string): Promise { +async function init_package ( + folder: string, + use_ts: boolean, + use_tests: boolean +): Promise { await modify_json ((obj: Record) => { const scripts = { - lint: 'eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs', - test: 'nyc ava', - compile: 'tsc --allowJs --declaration --emitDeclarationOnly index.js' + lint: standard_scripts.lint, + test: standard_scripts.test.common, + compile: standard_scripts.compile.common }; const files = [ 'LICENSE' ]; + if (use_ts) { - scripts.compile = 'tsc'; - scripts.test = 'tsc && nyc ava'; + 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; @@ -56,6 +68,12 @@ export default class Node implements Snippet { }) .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')); @@ -79,6 +97,6 @@ export default class Node implements Snippet { folder ); - await init_package (folder); + await init_package (folder, use_ts, use_tests); } }