@@ -6,40 +6,45 @@ import copyFolder from '../utils/copyFolder';
66import createPackageJson from '../stages/CreatePackageJson' ;
77import installDependencies from '../stages/InstallDependencies' ;
88import initializeGit from '../stages/InitializeGit' ;
9-
10- let projectName ;
9+ import Log from '../Log' ;
10+
11+ const createProject = ( name : string ) => {
12+ if ( name ) {
13+ Log . Instance . infoHeap ( `Creating the project` ) ;
14+
15+ const source = path . join ( __dirname , '/../../templates/project' ) ;
16+ const target = path . join ( process . cwd ( ) , name ) ;
17+
18+ try {
19+ Log . Instance . infoHeap ( `Copying files` ) ;
20+ fs . mkdirSync ( name ) ;
21+
22+ copyFolder ( source , target ) ;
23+ fs . renameSync (
24+ path . join ( target , 'gitignore' ) ,
25+ path . join ( target , '.gitignore' )
26+ ) ;
27+
28+ createPackageJson ( target , name ) ;
29+ installDependencies ( target ) ;
30+ initializeGit ( name ) ;
31+
32+ Log . Instance . successHeap ( `The ${ name } project was created.` ) ;
33+ Log . Instance . info ( `Path: ${ target } \n\n` ) ;
34+ } catch ( err ) {
35+ Log . Instance . exception ( err ) ;
36+ }
37+ } else {
38+ Log . Instance . errorHeap ( `Specify the name project.` ) ;
39+ Log . Instance . info (
40+ `For example: recife-cli project my-project-name\nRun --help for more information`
41+ ) ;
42+ }
43+ } ;
1144
1245commander
1346 . name ( `recife-cli project` )
1447 . arguments ( '<project-name>' )
15- . action ( name => ( projectName = name ) )
48+ . action ( name => createProject ( name ) )
1649 . allowUnknownOption ( false )
1750 . parse ( process . argv ) ;
18-
19- if ( projectName ) {
20- const source = path . join ( __dirname , '/../../templates/project' ) ;
21- const target = path . join ( process . cwd ( ) , projectName ) ;
22-
23- try {
24- fs . mkdirSync ( projectName ) ;
25-
26- copyFolder ( source , target ) ;
27- fs . renameSync (
28- path . join ( target , 'gitignore' ) ,
29- path . join ( target , '.gitignore' )
30- ) ;
31-
32- createPackageJson ( target , projectName ) ;
33- installDependencies ( target ) ;
34- initializeGit ( projectName ) ;
35-
36- console . info ( `\x1b[36mCreating the project ${ projectName } .` , '\x1b[0m' ) ;
37- console . info ( `Path: ${ target } ` , '\x1b[0m\n' ) ;
38- } catch ( err ) {
39- console . log ( `\x1b[31m${ err } \x1b[0m` ) ;
40- }
41- } else {
42- console . error ( '\x1b[31mSpecify the name project.' , '\x1b[0m' ) ;
43- console . log ( ` For example: recife-cli project my-project-name` ) ;
44- console . log ( ` Run --help for more information\n` ) ;
45- }
0 commit comments