diff --git a/lib/snippets/node/Assets.ts b/lib/snippets/node/Assets.ts index 7645528..a66285c 100644 --- a/lib/snippets/node/Assets.ts +++ b/lib/snippets/node/Assets.ts @@ -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 }; diff --git a/lib/snippets/node/index.ts b/lib/snippets/node/index.ts index 01a5d16..cd527fc 100644 --- a/lib/snippets/node/index.ts +++ b/lib/snippets/node/index.ts @@ -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 { @@ -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 );