@@ -5,6 +5,8 @@ import { getPackageJson } from './packageJson'
5
5
import { tsconfigJson } from './tsconfigJson'
6
6
import * as fs from 'fs'
7
7
import { execSync } from 'child_process'
8
+ import * as path from 'path'
9
+ import * as chalk from 'chalk'
8
10
9
11
const wantsCreateNewFolder = async ( ) =>
10
12
await select ( {
@@ -68,51 +70,71 @@ const main = async () => {
68
70
console . log ( '✅ tsconfig.json created' )
69
71
fs . mkdirSync ( 'src' )
70
72
console . log ( '✅ src folder created' )
71
- fs . writeFileSync ( 'src/index.ts' , '' )
73
+ fs . writeFileSync ( 'src/index.ts' , 'console.log("Hello NodeTS! 🚀") ' )
72
74
console . log ( '✅ src/index.ts created' )
75
+ console . log ( '' )
73
76
74
77
//install dev dependencies
75
78
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 ( '' )
93
102
94
103
//copy all configuration files from template folder
95
104
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' )
104
129
105
130
//init and config husky and lint-staged
131
+ console . log ( '' )
106
132
console . log ( 'Configuring husky...' )
107
133
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' } )
110
135
console . log ( '✅ husky configured' )
111
136
112
- //init git
113
- console . log ( 'Initializing git...' )
114
- execSync ( 'git init -b main' , { stdio : 'inherit' } )
115
-
137
+ console . log ( '' )
116
138
console . log ( '✅ All done!' )
117
139
console . log ( 'Happy coding! 🚀' )
118
140
}
0 commit comments