@@ -7,12 +7,19 @@ import path from "path";
77import { dependencies , devDependencies , devDependenciesTS } from "./constants" ;
88import { executeCommand } from "./util" ;
99
10+ /**
11+ * Creates a project directory and a package.json inside that new directory.
12+ * @param applicationName Name of application.
13+ * @param language Language of application
14+ */
1015export const createProjectDirectory = async (
1116 applicationName : string ,
1217 language : "js" | "ts"
1318) : Promise < void > => {
19+ // * Application Directory
1420 const root = path . resolve ( applicationName ) ;
1521
22+ // ? Needed?
1623 fs . ensureDirSync ( root ) ;
1724
1825 console . log ( ) ;
@@ -51,6 +58,7 @@ export const createProjectDirectory = async (
5158
5259 try {
5360 spinner . start ( ) ;
61+ // * Create package.json
5462 await fs . writeFile (
5563 path . join ( root , "package.json" ) ,
5664 JSON . stringify ( packageJson , null , 2 ) + os . EOL
@@ -64,9 +72,14 @@ export const createProjectDirectory = async (
6472 }
6573} ;
6674
75+ /**
76+ * Installs dependencies.
77+ * @param applicationName Name of application.
78+ */
6779export const installDependencies = async (
6880 applicationName : string
6981) : Promise < void > => {
82+ // * Application Directory
7083 const root = path . resolve ( applicationName ) ;
7184
7285 let spinner = ora ( "Installing dependencies" ) ;
@@ -76,6 +89,7 @@ export const installDependencies = async (
7689 const installCommand = "npm" ;
7790 let installArgs = [ "install" , "--save" ] ;
7891 installArgs = installArgs . concat ( dependencies ) ;
92+ // * Create a process that installs the dependencies
7993 await executeCommand ( installCommand , installArgs , { cwd : root } ) ;
8094 spinner . succeed ( "Dependencies installed successfully" ) ;
8195 } catch ( error ) {
@@ -84,10 +98,16 @@ export const installDependencies = async (
8498 }
8599} ;
86100
101+ /**
102+ * Installs dev dependencies.
103+ * @param applicationName Name of application.
104+ * @param language Language of application.
105+ */
87106export const installDevDependencies = async (
88107 applicationName : string ,
89108 language : "js" | "ts"
90109) : Promise < void > => {
110+ // * Application Directory
91111 const root = path . resolve ( applicationName ) ;
92112
93113 let spinner = ora ( "Installing devDependencies" ) ;
@@ -104,6 +124,7 @@ export const installDevDependencies = async (
104124 installArgs = installArgs . concat ( devDependencies ) ;
105125 }
106126
127+ // * Creates a process that installs the dev dependencies
107128 await executeCommand ( installCommand , installArgs , { cwd : root } ) ;
108129 spinner . succeed ( "DevDependencies installed successfully" ) ;
109130 } catch ( error ) {
@@ -112,16 +133,24 @@ export const installDevDependencies = async (
112133 }
113134} ;
114135
136+ // TODO - Refactor this function :)
137+ /**
138+ * Copies template files and inserts values into the files.
139+ * @param applicationName Name of application.
140+ * @param language Language of application.
141+ */
115142export const copyTemplateFiles = async (
116143 applicationName : string ,
117144 language : "js" | "ts"
118145) : Promise < void > => {
146+ // * Application Directory
119147 const root = path . resolve ( applicationName ) ;
120148
121149 let spinner = ora ( "Copying template files" ) ;
122150
123151 try {
124152 spinner . start ( ) ;
153+ // * Copy template files based on language
125154 await fs . copy (
126155 path . join ( __dirname , `template/${ language } /src` ) ,
127156 path . join ( root , "/src" )
@@ -252,13 +281,19 @@ export const copyTemplateFiles = async (
252281 }
253282} ;
254283
284+ /**
285+ * Creates a tsconfig.json file in the application directory.
286+ * @param applicationName Name of application.
287+ */
255288export const createTSConfig = async (
256289 applicationName : string
257290) : Promise < void > => {
291+ // * Application Directory
258292 const root = path . resolve ( applicationName ) ;
259293
260294 let spinner = ora ( "Creating tsconfig.json" ) ;
261295
296+ // * Basic tsconfig needed to build the application
262297 const tsConfig = {
263298 compilerOptions : {
264299 target : "es5" ,
@@ -274,6 +309,7 @@ export const createTSConfig = async (
274309
275310 try {
276311 spinner . start ( ) ;
312+ // * Create tsconfig.json file
277313 await fs . writeFile (
278314 path . join ( root , "tsconfig.json" ) ,
279315 JSON . stringify ( tsConfig , null , 2 ) + os . EOL
@@ -285,7 +321,12 @@ export const createTSConfig = async (
285321 }
286322} ;
287323
324+ /**
325+ * Display a success message to the user.
326+ * @param applicationName Name of application.
327+ */
288328export const displaySuccessMessage = ( applicationName : string ) : void => {
329+ // * Application Directory
289330 const root = path . resolve ( applicationName ) ;
290331
291332 console . log ( ) ;
0 commit comments