@@ -5,6 +5,8 @@ import { getPackageJson } from './packageJson'
55import { tsconfigJson } from './tsconfigJson'
66import * as fs from 'fs'
77import { execSync } from 'child_process'
8+ import * as path from 'path'
9+ import * as chalk from 'chalk'
810
911const wantsCreateNewFolder = async ( ) =>
1012 await select ( {
@@ -68,51 +70,71 @@ const main = async () => {
6870 console . log ( '✅ tsconfig.json created' )
6971 fs . mkdirSync ( 'src' )
7072 console . log ( '✅ src folder created' )
71- fs . writeFileSync ( 'src/index.ts' , '' )
73+ fs . writeFileSync ( 'src/index.ts' , 'console.log("Hello NodeTS! 🚀") ' )
7274 console . log ( '✅ src/index.ts created' )
75+ console . log ( '' )
7376
7477 //install dev dependencies
7578 console . log ( 'Installing dev dependencies...' )
76- execSync ( 'npm install --save-dev typescript' , { stdio : 'inherit' } )
77- console . log ( '✅ typescript installed' )
78- execSync ( 'npm install --save-dev ts-node' , { stdio : 'inherit' } )
79- console . log ( '✅ ts-node installed' )
80- execSync ( 'npm install --save-dev jest' , { stdio : 'inherit' } )
81- console . log ( '✅ jest installed' )
82- execSync ( 'npm install --save-dev @types/jest' , { stdio : 'inherit' } )
83- console . log ( '✅ @types/jest installed' )
84- execSync ( 'npm install --save-dev @types/node' , { stdio : 'inherit' } )
85- console . log ( '✅ @types/node installed' )
86- execSync ( 'npm install --save-dev ts-jest' , { stdio : 'inherit' } )
87- console . log ( '✅ ts-jest installed' )
88- execSync ( 'npm install --save-dev husky' , { stdio : 'inherit' } )
89- console . log ( '✅ husky installed' )
90- execSync ( 'npm install --save-dev lint-staged' , { stdio : 'inherit' } )
91- console . log ( '✅ lint-staged installed' )
92- console . log ( '✅ All dev dependencies installed' )
79+ const devDependencies = [
80+ 'typescript' ,
81+ 'jest' ,
82+ 'ts-jest' ,
83+ 'husky' ,
84+ 'lint-staged' ,
85+ '@types/jest' ,
86+ '@types/node' ,
87+ 'ts-node'
88+ ]
89+ execSync ( `npm install --save-dev -s ${ devDependencies . join ( ' ' ) } ` , {
90+ stdio : 'inherit'
91+ } )
92+ console . log ( `✅ ${ chalk . greenBright ( 'typescript' ) } installed` )
93+ console . log ( `✅ ${ chalk . greenBright ( 'ts-node' ) } installed` )
94+ console . log ( `✅ ${ chalk . greenBright ( 'jest' ) } installed` )
95+ console . log ( `✅ ${ chalk . greenBright ( '@types/jest' ) } installed` )
96+ console . log ( `✅ ${ chalk . greenBright ( '@types/node' ) } installed` )
97+ console . log ( `✅ ${ chalk . greenBright ( 'ts-jest' ) } installed` )
98+ console . log ( `✅ ${ chalk . greenBright ( 'husky' ) } installed` )
99+ console . log ( `✅ ${ chalk . greenBright ( 'lint-staged' ) } installed` )
100+ console . log ( `✅ All dev dependencies installed` )
101+ console . log ( '' )
93102
94103 //copy all configuration files from template folder
95104 console . log ( 'Copying configuration files...' )
96- fs . copyFileSync ( '../template/jest.config.ts' , 'jest.config.ts' )
97- console . log ( '✅ jest.config.ts copied' )
98- fs . copyFileSync ( '../template/.gitignore' , '.gitignore' )
99- console . log ( '✅ .gitignore copied' )
100- fs . copyFileSync ( '../template/.prettierrc' , '.prettierrc' )
101- console . log ( '✅ .prettierrc copied' )
102- fs . copyFileSync ( '../template/.prettierignore' , '.prettierignore' )
103- console . log ( '✅ .prettierignore copied' )
105+ const templatePath = path . join ( __dirname , 'template' )
106+ const files = fs . readdirSync ( templatePath )
107+ files . forEach ( ( file ) => {
108+ fs . copyFileSync ( path . join ( templatePath , file ) , file )
109+ console . log ( `✅ ${ file } copied` )
110+ } )
111+
112+ //init git
113+ console . log ( '' )
114+ console . log ( 'Initializing git...' )
115+ const gitIgnore = [
116+ 'node_modules' ,
117+ 'dist' ,
118+ '.DS_Store' ,
119+ '.env.local' ,
120+ '.env.development.local' ,
121+ '.env.test.local' ,
122+ '.env.production.local' ,
123+ 'coverage' ,
124+ 'build'
125+ ]
126+ fs . writeFileSync ( '.gitignore' , gitIgnore . join ( '\n' ) )
127+ execSync ( 'git init -b main' , { stdio : 'inherit' } )
128+ console . log ( '✅ git initialized' )
104129
105130 //init and config husky and lint-staged
131+ console . log ( '' )
106132 console . log ( 'Configuring husky...' )
107133 execSync ( 'npx husky init' , { stdio : 'inherit' } )
108- execSync ( "echo 'npm test' >> .husky/pre-commit" , { stdio : 'inherit' } )
109- execSync ( "echo 'npx lint-staged' >> .husky/pre-commit" , { stdio : 'inherit' } )
134+ execSync ( "echo npx lint-staged >> .husky/pre-commit" , { stdio : 'inherit' } )
110135 console . log ( '✅ husky configured' )
111136
112- //init git
113- console . log ( 'Initializing git...' )
114- execSync ( 'git init -b main' , { stdio : 'inherit' } )
115-
137+ console . log ( '' )
116138 console . log ( '✅ All done!' )
117139 console . log ( 'Happy coding! 🚀' )
118140}
0 commit comments