1+ #!/usr/bin/env node
12import { input , select } from '@inquirer/prompts'
23import * as logo from 'asciiart-logo'
34import { getPackageJson } from './packageJson'
45import { tsconfigJson } from './tsconfigJson'
5- import * as fs from 'fs'
6+ import * as fs from 'fs'
67import { execSync } from 'child_process'
78
89const wantsCreateNewFolder = async ( ) =>
@@ -26,94 +27,94 @@ const getProjectName = async () =>
2627 default : 'typescript-nodejs-project'
2728 } )
2829
29- const getFullLogo = ( ) => logo ( {
30- name : 'TypeScript NodeJS' ,
31- font : 'ANSI Shadow' ,
32- borderColor : 'grey' ,
33- logoColor : 'bold-cyan' ,
34- textColor : 'cyan'
35- } )
36- . emptyLine ( )
37- . center ( 'Create a Typescript NodeJS project' )
38- . emptyLine ( )
39- . emptyLine ( )
40- . right ( 'version 1.0.0' )
41- . right ( 'Author: @marchintosh' )
30+ const getFullLogo = ( ) =>
31+ logo ( {
32+ name : 'TypeScript NodeJS' ,
33+ font : 'ANSI Shadow' ,
34+ borderColor : 'grey' ,
35+ logoColor : 'bold-cyan' ,
36+ textColor : 'cyan'
37+ } )
38+ . emptyLine ( )
39+ . center ( 'Create a Typescript NodeJS project' )
40+ . emptyLine ( )
41+ . emptyLine ( )
42+ . right ( 'version 1.0.0' )
43+ . right ( 'Author: @marchintosh' )
4244
4345const main = async ( ) => {
4446 /* available fonts:
4547 Big Money-ne
4648 Broadway
4749 DOS Rebel
4850 */
49- const asciiLogo = getFullLogo ( ) ;
50- console . log ( asciiLogo . render ( ) ) ;
51- console . log ( " Welcome to Typescript NodeJS project creator" ) ;
52- const projectName = await getProjectName ( ) ;
53- const wantsCreateFolder = await wantsCreateNewFolder ( ) ;
51+ const asciiLogo = getFullLogo ( )
52+ console . log ( asciiLogo . render ( ) )
53+ console . log ( ' Welcome to Typescript NodeJS project creator' )
54+ const projectName = await getProjectName ( )
55+ const wantsCreateFolder = await wantsCreateNewFolder ( )
5456
55- if ( wantsCreateFolder === " yes" ) {
56- fs . mkdirSync ( projectName ) ;
57- process . chdir ( projectName ) ;
58- console . log ( `✅ Folder ${ projectName } created` ) ;
57+ if ( wantsCreateFolder === ' yes' ) {
58+ fs . mkdirSync ( projectName )
59+ process . chdir ( projectName )
60+ console . log ( `✅ Folder ${ projectName } created` )
5961 }
6062
61- const packageJson = getPackageJson ( projectName ) ;
62- fs . writeFileSync ( " package.json" , JSON . stringify ( packageJson , null , 2 ) ) ;
63- console . log ( " ✅ package.json created" ) ;
64- const tsconfig = tsconfigJson ;
65- fs . writeFileSync ( " tsconfig.json" , JSON . stringify ( tsconfig , null , 2 ) ) ;
66- console . log ( " ✅ tsconfig.json created" ) ;
67- fs . mkdirSync ( " src" ) ;
68- console . log ( " ✅ src folder created" ) ;
69- fs . writeFileSync ( " src/index.ts" , "" ) ;
70- console . log ( " ✅ src/index.ts created" ) ;
71-
63+ const packageJson = getPackageJson ( projectName )
64+ fs . writeFileSync ( ' package.json' , JSON . stringify ( packageJson , null , 2 ) )
65+ console . log ( ' ✅ package.json created' )
66+ const tsconfig = tsconfigJson
67+ fs . writeFileSync ( ' tsconfig.json' , JSON . stringify ( tsconfig , null , 2 ) )
68+ console . log ( ' ✅ tsconfig.json created' )
69+ fs . mkdirSync ( ' src' )
70+ console . log ( ' ✅ src folder created' )
71+ fs . writeFileSync ( ' src/index.ts' , '' )
72+ console . log ( ' ✅ src/index.ts created' )
73+
7274 //install dev dependencies
73- console . log ( " Installing dev dependencies..." ) ;
74- execSync ( " npm install --save-dev typescript" , { stdio : " inherit" } ) ;
75- console . log ( " ✅ typescript installed" ) ;
76- execSync ( " npm install --save-dev ts-node" , { stdio : " inherit" } ) ;
77- console . log ( " ✅ ts-node installed" ) ;
78- execSync ( " npm install --save-dev jest" , { stdio : " inherit" } ) ;
79- console . log ( " ✅ jest installed" ) ;
80- execSync ( " npm install --save-dev @types/jest" , { stdio : " inherit" } ) ;
81- console . log ( " ✅ @types/jest installed" ) ;
82- execSync ( " npm install --save-dev @types/node" , { stdio : " inherit" } ) ;
83- console . log ( " ✅ @types/node installed" ) ;
84- execSync ( " npm install --save-dev ts-jest" , { stdio : " inherit" } ) ;
85- console . log ( " ✅ ts-jest installed" ) ;
86- execSync ( " npm install --save-dev husky" , { stdio : " inherit" } ) ;
87- console . log ( " ✅ husky installed" ) ;
88- execSync ( " npm install --save-dev lint-staged" , { stdio : " inherit" } ) ;
89- console . log ( " ✅ lint-staged installed" ) ;
90- console . log ( " ✅ All dev dependencies installed" ) ;
91-
75+ 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' )
93+
9294 //copy all configuration files from template folder
93- console . log ( " Copying configuration files..." ) ;
94- fs . copyFileSync ( " ../template/jest.config.ts" , " jest.config.ts" ) ;
95- console . log ( " ✅ jest.config.ts copied" ) ;
96- fs . copyFileSync ( " ../template/.gitignore" , " .gitignore" ) ;
97- console . log ( " ✅ .gitignore copied" ) ;
98- fs . copyFileSync ( " ../template/.prettierrc" , " .prettierrc" ) ;
99- console . log ( " ✅ .prettierrc copied" ) ;
100- fs . copyFileSync ( " ../template/.prettierignore" , " .prettierignore" ) ;
101- console . log ( " ✅ .prettierignore copied" ) ;
95+ 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' )
102104
103105 //init and config husky and lint-staged
104- console . log ( " Configuring husky..." ) ;
105- execSync ( " npx husky init" , { stdio : " inherit" } ) ;
106- execSync ( "echo 'npm test' >> .husky/pre-commit" , { stdio : " inherit" } ) ;
107- execSync ( "echo 'npx lint-staged' >> .husky/pre-commit" , { stdio : " inherit" } ) ;
108- console . log ( " ✅ husky configured" ) ;
106+ console . log ( ' Configuring husky...' )
107+ 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' } )
110+ console . log ( ' ✅ husky configured' )
109111
110112 //init git
111- console . log ( " Initializing git..." ) ;
112- execSync ( " git init -b main" , { stdio : " inherit" } ) ;
113+ console . log ( ' Initializing git...' )
114+ execSync ( ' git init -b main' , { stdio : ' inherit' } )
113115
114- console . log ( " ✅ All done!" ) ;
115- console . log ( " Happy coding! 🚀" ) ;
116+ console . log ( ' ✅ All done!' )
117+ console . log ( ' Happy coding! 🚀' )
116118}
117119
118-
119- main ( )
120+ main ( )
0 commit comments