fixes, option for no tests
This commit is contained in:
parent
91869b3183
commit
c9fd021634
@ -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<void> {
|
||||
async function init_package (
|
||||
folder: string,
|
||||
use_ts: boolean,
|
||||
use_tests: boolean
|
||||
): Promise<void> {
|
||||
await modify_json ((obj: Record<string, unknown>) => {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user