add typescript support to node snippet

This commit is contained in:
Timo Hocker 2020-04-23 16:19:31 +02:00
parent b7706f9a42
commit 3160ccd49c
2 changed files with 26 additions and 4 deletions

View File

@ -28,4 +28,17 @@ const index = '';
const npmrc = `@scode:registry=https://npm.scode.ovh
`;
export { eslintrc, gitignore, index, npmrc };
const tsconfig = `{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./lib",
"strict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
}
}
`;
export { eslintrc, gitignore, index, npmrc, tsconfig };

View File

@ -10,8 +10,7 @@ import { Input } from 'enquirer';
import { Snippet } from '../../Snippet';
import { apply_template, modify_json, run_command } from '../../Helper';
import { eslintrc, gitignore, index, npmrc } from './Assets';
import { eslintrc, gitignore, index, npmrc, tsconfig } from './Assets';
export default class Node implements Snippet {
public async start (): Promise<void> {
@ -20,15 +19,25 @@ export default class Node implements Snippet {
)
.run ();
const use_ts = await new confirm ({
message: 'use typescript?',
initial: false
})
.run ();
await apply_template (eslintrc, path.join (folder, '.eslintrc.js'));
await apply_template (npmrc, path.join (folder, '.npmrc'));
await apply_template (index, path.join (folder, 'index.js'));
await apply_template (gitignore, path.join (folder, '.gitignore'));
if (use_ts)
await apply_template (tsconfig, path.join (folder, 'tsconfig.json'));
run_command ('git init', folder);
run_command ('yarn init -y', folder);
run_command (
'yarn add --dev @scode/eslint-config eslint nyc ava',
`yarn add --dev @scode/eslint-config${use_ts
? '-ts typescript @ava/typescript'
: ''} eslint nyc ava`,
folder
);