add typescript support to node snippet
This commit is contained in:
		| @@ -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 }; | ||||
|   | ||||
| @@ -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 | ||||
|     ); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user