@@ -84,6 +84,32 @@ For more information about service providers, visit:
84
84
}
85
85
} ;
86
86
87
+ const basicScaffoldDefaults = {
88
+ options : {
89
+ '--force' : 'Force overwrite of existing target' ,
90
+ '--type' : 'Script type: client, server' ,
91
+ '--filename' : 'Specify name instead of using interactive wizard'
92
+ }
93
+ } ;
94
+
95
+ const forceBasicScaffold = args =>
96
+ args . type && args . filename
97
+ ? {
98
+ ...args ,
99
+ target : path . join ( 'src' , args . type , args . filename ) ,
100
+ confirm : true
101
+ }
102
+ : false ;
103
+
104
+ const forcePackageScaffold = args =>
105
+ args . name
106
+ ? {
107
+ ...args ,
108
+ target : path . join ( 'src' , 'packages' , args . name ) ,
109
+ confirm : true
110
+ }
111
+ : false ;
112
+
87
113
const ask = ( type , s ) => inquirer . prompt ( [ {
88
114
name : 'type' ,
89
115
message : `Select ${ s . title } type` ,
@@ -149,12 +175,14 @@ const scaffoldPackage = type => async ({logger, options, args}) => {
149
175
. then ( raw => raw . replace ( / _ _ _ N A M E _ _ _ / g, name ) )
150
176
. then ( contents => fs . writeFile ( destination , contents ) )
151
177
. then ( ( ) => {
152
- logger . success ( 'Wrote' , filename ) ;
178
+ logger . success ( 'Wrote' , destination . replace ( options . root , '' ) ) ;
153
179
} ) ;
154
180
} ) ;
155
181
} ) ;
156
182
157
- const choices = await inquirer . prompt ( [ {
183
+ const force = forcePackageScaffold ( args ) ;
184
+
185
+ const choices = force ? force : await inquirer . prompt ( [ {
158
186
name : 'name' ,
159
187
message : 'Enter name of package ([A-z0-9_])' ,
160
188
default : defaultName ,
@@ -188,12 +216,11 @@ const scaffoldPackage = type => async ({logger, options, args}) => {
188
216
return Promise . resolve ( true ) ;
189
217
}
190
218
191
-
192
219
const destination = path . resolve ( options . root , choices . target ) ;
193
220
const exists = await fs . exists ( destination ) ;
194
221
let replace = true ;
195
222
196
- if ( exists ) {
223
+ if ( exists && ! args . force ) {
197
224
logger . warn ( 'Target directory already exists' ) ;
198
225
199
226
const { overwrite} = await inquirer . prompt ( [ {
@@ -217,15 +244,14 @@ const scaffoldPackage = type => async ({logger, options, args}) => {
217
244
replace = a . replace ;
218
245
}
219
246
220
-
221
247
await fs . ensureDir ( destination ) ;
222
248
223
249
return Promise . all ( promises ( choices . name , destination , replace ) )
224
250
. then ( ( ) => logger . info ( 'Running "npm install"' ) )
225
- . then ( ( ) => utils . spawnAsync ( npmBinary , [ 'install' ] , { cwd : destination } ) )
251
+ . then ( ( ) => args . dry ? false : utils . spawnAsync ( npmBinary , [ 'install' ] , { cwd : destination } ) )
226
252
. then ( ( ) => logger . success ( '...dependencies installed' ) )
227
253
. then ( ( ) => logger . info ( 'Running "npm run build"' ) )
228
- . then ( ( ) => utils . spawnAsync ( npmBinary , [ 'run' , 'build' ] , { cwd : destination } ) )
254
+ . then ( ( ) => args . dry ? false : utils . spawnAsync ( npmBinary , [ 'run' , 'build' ] , { cwd : destination } ) )
229
255
. then ( ( ) => logger . success ( '...build complete' ) )
230
256
. then ( ( ) => {
231
257
logger . info ( 'Package was generated and built.' ) ;
@@ -246,7 +272,8 @@ const scaffoldBasic = type => async ({logger, options, args}) => {
246
272
logger . info ( 'Scaffolding' , type ) ;
247
273
248
274
const s = scaffolds [ type ] ;
249
- const choices = await ask ( type , s ) ;
275
+ const forced = forceBasicScaffold ( args ) ;
276
+ const choices = forced ? forced : await ask ( type , s ) ;
250
277
251
278
if ( ! choices . confirm ) {
252
279
logger . info ( 'Scaffolding aborted...' ) ;
@@ -265,7 +292,7 @@ const scaffoldBasic = type => async ({logger, options, args}) => {
265
292
) ;
266
293
267
294
const exists = await fs . exists ( destination ) ;
268
- if ( exists ) {
295
+ if ( exists && ! args . force ) {
269
296
throw new Error ( 'Destination already exists!' ) ;
270
297
}
271
298
@@ -282,26 +309,40 @@ const scaffoldBasic = type => async ({logger, options, args}) => {
282
309
module . exports = {
283
310
'make:auth' : {
284
311
description : 'Create Authentication adapter script' ,
285
- action : scaffoldBasic ( 'auth' )
312
+ action : scaffoldBasic ( 'auth' ) ,
313
+ ...basicScaffoldDefaults
286
314
} ,
287
315
'make:settings' : {
288
316
description : 'Create Settings adapter script' ,
289
- action : scaffoldBasic ( 'settings' )
317
+ action : scaffoldBasic ( 'settings' ) ,
318
+ ...basicScaffoldDefaults
290
319
} ,
291
320
'make:provider' : {
292
321
description : 'Create Service provider script' ,
293
- action : scaffoldBasic ( 'providers' )
322
+ action : scaffoldBasic ( 'providers' ) ,
323
+ ...basicScaffoldDefaults
294
324
} ,
295
325
'make:vfs' : {
296
326
description : 'Create VFS adapter script' ,
297
- action : scaffoldBasic ( 'vfs' )
327
+ action : scaffoldBasic ( 'vfs' ) ,
328
+ ...basicScaffoldDefaults
298
329
} ,
299
330
'make:application' : {
300
331
description : 'Create Application package' ,
332
+ options : {
333
+ '--force' : 'Force overwrite of existing package' ,
334
+ '--dry' : 'Skip npm scripts' ,
335
+ '--name' : 'Specify name instead of using wizard'
336
+ } ,
301
337
action : scaffoldPackage ( 'application' )
302
338
} ,
303
339
'make:iframe-application' : {
304
340
description : 'Create IFrame Application package' ,
341
+ options : {
342
+ '--force' : 'Force overwrite of existing package' ,
343
+ '--dry' : 'Skip npm scripts' ,
344
+ '--name' : 'Specify name instead of using interactive wizard'
345
+ } ,
305
346
action : scaffoldPackage ( 'iframe-application' )
306
347
} ,
307
348
'create:package' : {
0 commit comments