standardization

This commit is contained in:
Timo Hocker
2020-05-04 12:23:06 +02:00
parent a7180f9e50
commit 91869b3183
6 changed files with 47 additions and 84 deletions

View File

@ -59,8 +59,8 @@ const tsconfig = `{
}
`;
const eslintignore_ts = `/dist/
const eslintignore = `/dist/
*.d.ts
`;
export { eslintrc, gitignore, npmrc, tsconfig, eslintrc_ts, eslintignore_ts };
export { eslintrc, gitignore, npmrc, tsconfig, eslintrc_ts, eslintignore };

View File

@ -12,9 +12,37 @@ import { apply_template, modify_json, run_command } from '../../Helper';
import {
eslintrc, gitignore, npmrc,
tsconfig, eslintrc_ts, eslintignore_ts
tsconfig, eslintrc_ts, eslintignore
} from './Assets';
/**
* initialize the package.json
*
* @param {string} folder folder
*/
async function init_package (folder: string): 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'
};
const files = [ 'LICENSE' ];
if (use_ts) {
scripts.compile = 'tsc';
scripts.test = 'tsc && nyc ava';
files.push ('/dist/');
}
else {
files.push ('*.js', '*.d.ts');
}
obj.scripts = scripts;
obj.files = files;
return obj;
}, path.join (folder, 'package.json'));
}
export default class Node implements Snippet {
public async start (): Promise<void> {
const folder = await new Input (
@ -31,12 +59,12 @@ export default class Node implements Snippet {
await apply_template (eslintrc, path.join (folder, '.eslintrc.js'));
await apply_template (npmrc, path.join (folder, '.npmrc'));
await apply_template (gitignore, path.join (folder, '.gitignore'));
await apply_template (
eslintignore,
path.join (folder, '.eslintignore')
);
if (use_ts) {
await apply_template (tsconfig, path.join (folder, 'tsconfig.json'));
await apply_template (
eslintignore_ts,
path.join (folder, '.eslintignore')
);
await apply_template (
eslintrc_ts,
path.join (folder, 'lib', '.eslintrc.js')
@ -51,16 +79,6 @@ export default class Node implements Snippet {
folder
);
await modify_json ((obj: Record<string, unknown>) => {
obj.scripts = {
lint: 'eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs',
test: 'nyc ava'
};
if (use_ts) {
(obj.scripts as Record<string, unknown>).compile = 'tsc';
(obj.scripts as Record<string, unknown>).test = 'tsc && nyc ava';
}
return obj;
}, path.join (folder, 'package.json'));
await init_package (folder);
}
}