@@ -7,29 +7,26 @@ import addDbAndOrm from "@helpers/db&Orms";
77import { makeDevEnv , makeProdEnv } from "@helpers/envMaker" ;
88import addFmtAndLinterConfig from "@helpers/fmt&Linters" ;
99import handleAdditionalOptions from "@helpers/handleOptions" ;
10+ import selectPkgManager from "@helpers/pkgManager" ;
11+ import printDependencies from "@helpers/printDependencies" ;
1012import { parseArgs , startUserInteraction } from "@utils/cli" ;
1113import handleError , { makeTargetPath } from "@utils/errorHandler" ;
12-
1314import { renameFile } from "@utils/fileSystem" ;
15+
16+ // Import external Module(s)
17+ import { gray , lightBlue , red } from "kolorist" ;
18+
1419// Import necessary Type(s)
1520import type {
1621 T_Arg_HandleArgs ,
1722 T_Arg_HandleCli ,
1823} from "./types/dependencyInstallers" ;
1924import type { T_UserInput } from "./types/prompt" ;
2025
21- let filePathArr : string [ ] ;
22- export let projectDirPath : string ;
23-
24- if ( process . platform === "win32" ) {
25- filePathArr = __dirname . split ( "\\" ) ;
26- filePathArr . pop ( ) ;
27- projectDirPath = filePathArr . join ( "\\" ) ;
28- } else {
29- filePathArr = __dirname . split ( "/" ) ;
30- filePathArr . pop ( ) ;
31- projectDirPath = filePathArr . join ( "/" ) ;
32- }
26+ const sysPathDisapator = process . platform === "win32" ? "\\" : "/" ;
27+ const filePathArr = __dirname . split ( sysPathDisapator ) ;
28+ filePathArr . pop ( ) ;
29+ export const projectDirPath = filePathArr . join ( sysPathDisapator ) ;
3330
3431( async ( ) => {
3532 const parsedArgs = parseArgs ( ) ;
@@ -46,6 +43,16 @@ if (process.platform === "win32") {
4643function copyTemplate ( targetPath : string , targetTemplate : string ) {
4744 try {
4845 const templatePath = `${ projectDirPath } /templates/${ targetTemplate } ` ;
46+ const exists = fs . existsSync ( targetPath ) ;
47+
48+ if ( exists ) {
49+ console . log (
50+ `\n${ red (
51+ "Program stopped" ,
52+ ) } \nReason -: A directory with the same name exists.`,
53+ ) ;
54+ process . exit ( 1 ) ;
55+ }
4956
5057 fs . cpSync ( templatePath , targetPath , { recursive : true } ) ;
5158 } catch ( err ) {
@@ -74,18 +81,24 @@ function performRenames(targetPath: string) {
7481}
7582
7683function installDependecies ( targetPath : string , userInput : T_UserInput ) {
77- const dependencyCmd = "npm i express pino pino-http pino-pretty" ;
78- let devDependencyCmd : string ;
84+ const pkgManagerInfo = selectPkgManager ( ) ;
85+
86+ const dependencyCmd = `${ pkgManagerInfo . prefix } express pino pino-http pino-pretty` ;
87+ let devDependencyCmd = "prettier" ;
7988
8089 function handleArgs ( {
8190 dependencyCmd,
8291 devDependencyCmd,
8392 targetPath,
8493 } : T_Arg_HandleArgs ) {
8594 const installCmd = `${ dependencyCmd } && ${ devDependencyCmd } ` ;
95+
96+ printDependencies ( dependencyCmd , devDependencyCmd , pkgManagerInfo ) ;
97+
8698 try {
8799 execSync ( installCmd , {
88100 cwd : targetPath ,
101+ stdio : "inherit" ,
89102 } ) ;
90103 } catch ( err ) {
91104 handleError ( err ) ;
@@ -98,18 +111,24 @@ function installDependecies(targetPath: string, userInput: T_UserInput) {
98111 devDependencyCmd,
99112 targetPath,
100113 } : T_Arg_HandleCli ) {
101- const installCmd = handleAdditionalOptions (
102- userInput ,
103- dependencyCmd ,
104- devDependencyCmd ,
105- ) ;
114+ // these are updated dependency and devDependecy commands which include all the extra options
115+ const { updtDependencyCmd, updtDevDependencyCmd } =
116+ handleAdditionalOptions ( userInput , dependencyCmd , devDependencyCmd ) ;
106117
107118 addFmtAndLinterConfig (
108119 userInput . formatterAndLinter ,
109120 targetPath ,
110121 projectDirPath ,
111122 ) ;
112123
124+ const installCmd = `${ updtDependencyCmd } && ${ updtDevDependencyCmd } ` ;
125+
126+ printDependencies (
127+ updtDependencyCmd ,
128+ updtDevDependencyCmd ,
129+ pkgManagerInfo ,
130+ ) ;
131+
113132 try {
114133 execSync ( installCmd , {
115134 cwd : targetPath ,
@@ -127,7 +146,7 @@ function installDependecies(targetPath: string, userInput: T_UserInput) {
127146 switch ( userInput . template ) {
128147 case "express/js" :
129148 {
130- devDependencyCmd = "npm i --save-dev @dotenvx/dotenvx nodemon" ;
149+ devDependencyCmd = ` ${ pkgManagerInfo . devPrefix } ${ devDependencyCmd } @dotenvx/dotenvx nodemon` ;
131150
132151 if ( userInput . type === "args" ) {
133152 handleArgs ( { dependencyCmd, devDependencyCmd, targetPath } ) ;
@@ -143,8 +162,7 @@ function installDependecies(targetPath: string, userInput: T_UserInput) {
143162 break ;
144163 case "express/ts" :
145164 {
146- devDependencyCmd =
147- "npm i --save-dev tsx typescript @dotenvx/dotenvx @types/express @types/node" ;
165+ devDependencyCmd = `${ pkgManagerInfo . devPrefix } ${ devDependencyCmd } tsx typescript @dotenvx/dotenvx @types/express @types/node` ;
148166
149167 if ( userInput . type === "args" ) {
150168 handleArgs ( { dependencyCmd, devDependencyCmd, targetPath } ) ;
@@ -174,4 +192,10 @@ function handleLogic(userInput: T_UserInput) {
174192 performRenames ( targetPath ) ;
175193 intialiseGitRepo ( targetPath ) ;
176194 installDependecies ( targetPath , userInput ) ;
195+
196+ console . log (
197+ `\n${ lightBlue ( "Project made at -:" ) } ${ gray (
198+ `${ targetPath } ,` ,
199+ ) } Hope you finish this one ;)`,
200+ ) ;
177201}
0 commit comments