11const fs = require ( "fs.extra" ) ;
22const path = require ( "path" ) ;
3- var clone = require ( ' git-clone' ) ;
4- const init = function ( ) { } ;
3+ const clone = require ( " git-clone" ) ;
4+ const init = function ( ) { } ;
55const ora = require ( "ora" ) ;
66
77/**
@@ -11,39 +11,35 @@ const ora = require("ora");
1111 * @param {string } options - additional options for the project example: eslint configuration
1212 * @param {function } cb - callback for status return
1313 */
14-
15- init . prototype . initialize = function ( projectName , gitrepository , eslint , cb ) {
14+ init . prototype . initialize = function ( projectName , gitrepository , eslint , cb ) {
1615 if ( gitrepository === undefined ) {
1716 if ( eslint === undefined ) {
1817 let projectPath = projectName ;
19- if ( ! fs . existsSync ( projectName ) ) {
20- fs . mkdirp ( projectPath , error => {
21- if ( error ) {
22- cb ( error ) ;
23- } else {
24- //resolve all promises async-ly
25- Promise . all ( [
26- this . copyCommonTemplates ( projectName ) ,
27- this . copyTemplate ( projectName , "webpack.config.js" , false ) ,
28- this . copyTemplate ( projectName , "reactclirc" , true ) ,
29- this . copyTemplate ( projectName , "gitignore" , true ) ,
30- this . copyPackageJson ( projectName )
31- ] )
32- . then ( values => {
33- cb ( true ) ;
34- } )
35- . catch ( err => {
36- console . log ( err ) ;
37- cb ( false ) ;
38- } ) ;
39- }
40- } ) ;
41- }
42- else {
43- console . log ( '\x1b[1m\x1b[31m%s\x1b[0m' , '\n This project name is already exists \n try with different project name' ) ;
44- cb ( false ) ;
45-
46- }
18+ fs . mkdirp ( projectPath , error => {
19+ if ( error ) {
20+ cb ( error ) ;
21+ } else {
22+ //resolve all promises async-ly
23+ Promise . all ( [
24+ this . copyCommonTemplates ( projectName ) ,
25+ this . copyTemplate (
26+ projectName ,
27+ "webpack.config.js" ,
28+ false
29+ ) ,
30+ this . copyTemplate ( projectName , "reactclirc" , true ) ,
31+ this . copyTemplate ( projectName , "gitignore" , true ) ,
32+ this . copyPackageJson ( projectName )
33+ ] )
34+ . then ( values => {
35+ cb ( true ) ;
36+ } )
37+ . catch ( err => {
38+ console . log ( err ) ;
39+ cb ( false ) ;
40+ } ) ;
41+ }
42+ } ) ;
4743 } else {
4844 if ( eslint ) {
4945 Promise . all ( [
@@ -65,50 +61,45 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
6561 } else {
6662 if ( eslint === undefined ) {
6763 let projectPath = projectName ;
68- if ( ! fs . existsSync ( projectName ) ) {
69-
70- fs . mkdirp ( projectPath , error => {
71- if ( error ) {
72- cb ( error ) ;
73- } else {
74- // resolve all promises async-ly
75- Promise . all (
76- [
77-
78- this . copyTemplate ( projectName , "webpack.config.js" , false ) ,
79- this . copyTemplate ( projectName , "reactclirc" , true ) ,
80- this . copyTemplate ( projectName , "gitignore" , true ) ,
81- this . copyPackageJson ( projectName )
82- ] )
83- . then ( values => {
84- const spinner = ora ( "cloning template" ) . start ( ) ;
85-
86- clone ( gitrepository , projectName + '/src' , value => {
64+ fs . mkdirp ( projectPath , error => {
65+ if ( error ) {
66+ cb ( error ) ;
67+ } else {
68+ // resolve all promises async-ly
69+ Promise . all ( [
70+ this . copyTemplate (
71+ projectName ,
72+ "webpack.config.js" ,
73+ false
74+ ) ,
75+ this . copyTemplate ( projectName , "reactclirc" , true ) ,
76+ this . copyTemplate ( projectName , "gitignore" , true ) ,
77+ this . copyPackageJson ( projectName )
78+ ] )
79+ . then ( values => {
80+ const spinner = ora ( "cloning template" ) . start ( ) ;
81+
82+ clone (
83+ gitrepository ,
84+ projectName + "/src" ,
85+ value => {
8786 setTimeout ( ( ) => {
88- spinner . text = "template cloned successfully" ;
87+ spinner . text =
88+ "template cloned successfully" ;
8989 spinner . succeed ( ) ;
9090 cb ( true ) ;
9191 } , 1000 ) ;
9292 }
93- )
94- } )
95- . catch ( err => {
96- console . log ( err ) ;
97- cb ( false ) ;
98- } ) ;
99-
100-
101- }
102- } ) ;
103- }
104- else {
105- console . log ( '\x1b[1m\x1b[31m%s\x1b[0m' , '\n This project name is already exists \n try with different project name' ) ;
106- cb ( false ) ;
107- }
93+ ) ;
94+ } )
95+ . catch ( err => {
96+ console . log ( err ) ;
97+ cb ( false ) ;
98+ } ) ;
99+ }
100+ } ) ;
108101 } else {
109102 if ( eslint ) {
110-
111-
112103 Promise . all ( [
113104 this . copyTemplate ( projectName , "webpack.config.js" , false ) ,
114105 this . copyTemplate ( projectName , "gitignore" , true ) ,
@@ -118,14 +109,13 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
118109 . then ( values => {
119110 const spinner = ora ( "cloning template" ) . start ( ) ;
120111
121- clone ( gitrepository , projectName + ' /src' , value => {
112+ clone ( gitrepository , projectName + " /src" , value => {
122113 setTimeout ( ( ) => {
123114 spinner . text = "template cloned successfully" ;
124115 spinner . succeed ( ) ;
125116 cb ( true ) ;
126117 } , 1000 ) ;
127- }
128- )
118+ } ) ;
129119 } )
130120 . catch ( err => {
131121 console . log ( err ) ;
@@ -140,13 +130,12 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
140130 * copy common templates recursively
141131 * @param {string } projectName - project name
142132 */
143-
144- init . prototype . copyCommonTemplates = function ( projectName ) {
145- return new Promise ( function ( resolve , reject ) {
133+ init . prototype . copyCommonTemplates = function ( projectName ) {
134+ return new Promise ( function ( resolve , reject ) {
146135 fs . copyRecursive (
147136 path . join ( __dirname , ".." , "templates/src" ) ,
148137 path . join ( projectName , "src" ) ,
149- function ( err ) {
138+ function ( err ) {
150139 if ( err ) {
151140 console . log ( err ) ;
152141 reject ( err ) ;
@@ -163,9 +152,8 @@ init.prototype.copyCommonTemplates = function (projectName) {
163152 * @param {string } projectName - project name
164153 * @param {string } file - name of the file to be copied
165154 */
166-
167- init . prototype . copyTemplate = function ( projectName , file , dotFile ) {
168- return new Promise ( function ( resolve , reject ) {
155+ init . prototype . copyTemplate = function ( projectName , file , dotFile ) {
156+ return new Promise ( function ( resolve , reject ) {
169157 let destFile = null ;
170158 if ( dotFile ) {
171159 destFile = "." + file ;
@@ -176,7 +164,7 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
176164 path . join ( __dirname , ".." , "templates" , file ) ,
177165 path . join ( projectName , destFile ) ,
178166 { replace : false } ,
179- function ( err ) {
167+ function ( err ) {
180168 if ( err ) {
181169 console . log ( err ) ;
182170 reject ( err ) ;
@@ -192,9 +180,8 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
192180 * copy package.json file to project destination
193181 * @param {string } projectName - project name
194182 */
195-
196- init . prototype . copyPackageJson = function ( projectName ) {
197- return new Promise ( function ( resolve , reject ) {
183+ init . prototype . copyPackageJson = function ( projectName ) {
184+ return new Promise ( function ( resolve , reject ) {
198185 fs . readFile (
199186 path . join ( __dirname , ".." , "templates/package.json" ) ,
200187 ( err , buffer ) => {
0 commit comments