1
1
const fs = require ( "fs.extra" ) ;
2
2
const path = require ( "path" ) ;
3
- var clone = require ( ' git-clone' ) ;
4
- const init = function ( ) { } ;
3
+ const clone = require ( " git-clone" ) ;
4
+ const init = function ( ) { } ;
5
5
const ora = require ( "ora" ) ;
6
6
7
7
/**
@@ -11,39 +11,35 @@ const ora = require("ora");
11
11
* @param {string } options - additional options for the project example: eslint configuration
12
12
* @param {function } cb - callback for status return
13
13
*/
14
-
15
- init . prototype . initialize = function ( projectName , gitrepository , eslint , cb ) {
14
+ init . prototype . initialize = function ( projectName , gitrepository , eslint , cb ) {
16
15
if ( gitrepository === undefined ) {
17
16
if ( eslint === undefined ) {
18
17
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
+ } ) ;
47
43
} else {
48
44
if ( eslint ) {
49
45
Promise . all ( [
@@ -65,50 +61,45 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
65
61
} else {
66
62
if ( eslint === undefined ) {
67
63
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 => {
87
86
setTimeout ( ( ) => {
88
- spinner . text = "template cloned successfully" ;
87
+ spinner . text =
88
+ "template cloned successfully" ;
89
89
spinner . succeed ( ) ;
90
90
cb ( true ) ;
91
91
} , 1000 ) ;
92
92
}
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
+ } ) ;
108
101
} else {
109
102
if ( eslint ) {
110
-
111
-
112
103
Promise . all ( [
113
104
this . copyTemplate ( projectName , "webpack.config.js" , false ) ,
114
105
this . copyTemplate ( projectName , "gitignore" , true ) ,
@@ -118,14 +109,13 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
118
109
. then ( values => {
119
110
const spinner = ora ( "cloning template" ) . start ( ) ;
120
111
121
- clone ( gitrepository , projectName + ' /src' , value => {
112
+ clone ( gitrepository , projectName + " /src" , value => {
122
113
setTimeout ( ( ) => {
123
114
spinner . text = "template cloned successfully" ;
124
115
spinner . succeed ( ) ;
125
116
cb ( true ) ;
126
117
} , 1000 ) ;
127
- }
128
- )
118
+ } ) ;
129
119
} )
130
120
. catch ( err => {
131
121
console . log ( err ) ;
@@ -140,13 +130,12 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
140
130
* copy common templates recursively
141
131
* @param {string } projectName - project name
142
132
*/
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 ) {
146
135
fs . copyRecursive (
147
136
path . join ( __dirname , ".." , "templates/src" ) ,
148
137
path . join ( projectName , "src" ) ,
149
- function ( err ) {
138
+ function ( err ) {
150
139
if ( err ) {
151
140
console . log ( err ) ;
152
141
reject ( err ) ;
@@ -163,9 +152,8 @@ init.prototype.copyCommonTemplates = function (projectName) {
163
152
* @param {string } projectName - project name
164
153
* @param {string } file - name of the file to be copied
165
154
*/
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 ) {
169
157
let destFile = null ;
170
158
if ( dotFile ) {
171
159
destFile = "." + file ;
@@ -176,7 +164,7 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
176
164
path . join ( __dirname , ".." , "templates" , file ) ,
177
165
path . join ( projectName , destFile ) ,
178
166
{ replace : false } ,
179
- function ( err ) {
167
+ function ( err ) {
180
168
if ( err ) {
181
169
console . log ( err ) ;
182
170
reject ( err ) ;
@@ -192,9 +180,8 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
192
180
* copy package.json file to project destination
193
181
* @param {string } projectName - project name
194
182
*/
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 ) {
198
185
fs . readFile (
199
186
path . join ( __dirname , ".." , "templates/package.json" ) ,
200
187
( err , buffer ) => {
0 commit comments