1
1
import type { CLI , MakeOptions } from '@stacksjs/types'
2
2
import process from 'node:process'
3
3
import {
4
+ createMigration ,
4
5
createModel ,
5
6
createNotification ,
7
+ createPage ,
6
8
invoke ,
7
9
makeAction ,
10
+ makeCertificate ,
8
11
makeComponent ,
9
12
makeDatabase ,
10
13
makeFunction ,
@@ -13,10 +16,9 @@ import {
13
16
makeQueueTable ,
14
17
makeStack ,
15
18
} from '@stacksjs/actions'
16
- import { intro , italic , outro , runCommand } from '@stacksjs/cli'
17
- import { localUrl } from '@stacksjs/config'
19
+ import { intro , italic , outro } from '@stacksjs/cli'
18
20
import { log } from '@stacksjs/logging'
19
- import { path as p } from '@stacksjs/path'
21
+
20
22
import { ExitCode } from '@stacksjs/types'
21
23
22
24
export function make ( buddy : CLI ) : void {
@@ -41,21 +43,21 @@ export function make(buddy: CLI): void {
41
43
}
42
44
43
45
buddy
44
- . command ( 'make' , 'The make command' )
46
+ . command ( 'make [make] ' , 'The make command' )
45
47
. option ( '-a, --action [action]' , descriptions . action , { default : false } )
46
- . option ( '-m, --model [model]' , descriptions . model , { default : false } )
47
48
. option ( '-c, --component [component]' , descriptions . component , { default : false } )
48
- . option ( '-p, --page [page]' , descriptions . page , { default : false } )
49
+ . option ( '-d, --database [database]' , descriptions . database , { default : false } )
50
+ . option ( '-f, --factory [factory]' , descriptions . factory , { default : false } )
49
51
. option ( '-f, --function [function]' , descriptions . function , { default : false } )
50
52
. option ( '-l, --language [language]' , descriptions . language , { default : false } )
51
- . option ( '-d, --database [database]' , descriptions . database , { default : false } )
53
+ . option ( '-m, --model [model]' , descriptions . model , { default : false } )
54
+ . option ( '-p, --page [page]' , descriptions . page , { default : false } )
52
55
. option ( '-m, --migration [migration]' , descriptions . migration , { default : false } )
53
- . option ( '-f, --factory [factory]' , descriptions . factory , { default : false } )
54
56
. option ( '-n, --notification [notification]' , descriptions . notification , { default : false } )
55
57
. option ( '-qt, --queue-table' , descriptions . queue , { default : false } )
56
58
. option ( '-s, --stack [stack]' , descriptions . stack , { default : false } )
57
59
. option ( '--verbose' , descriptions . verbose , { default : false } )
58
- . action ( async ( options : MakeOptions ) => {
60
+ . action ( async ( make : string | undefined , options : MakeOptions ) => {
59
61
log . debug ( 'Running `buddy make` ...' , options )
60
62
61
63
const name = buddy . args [ 0 ]
@@ -65,6 +67,47 @@ export function make(buddy: CLI): void {
65
67
process . exit ( )
66
68
}
67
69
70
+ switch ( make ) {
71
+ case 'action' :
72
+ await makeAction ( options )
73
+ break
74
+ case 'certificate' :
75
+ await makeCertificate ( )
76
+ break
77
+ case 'component' :
78
+ await makeComponent ( options )
79
+ break
80
+ case 'database' :
81
+ makeDatabase ( options )
82
+ break
83
+ case 'function' :
84
+ await makeFunction ( options )
85
+ break
86
+ case 'language' :
87
+ await makeLanguage ( options )
88
+ break
89
+ case 'migration' :
90
+ await createMigration ( options )
91
+ break
92
+ case 'model' :
93
+ await createModel ( options )
94
+ break
95
+ case 'page' :
96
+ await createPage ( options )
97
+ break
98
+ case 'notification' :
99
+ await createNotification ( options )
100
+ break
101
+ case 'queue:table' :
102
+ await makeQueueTable ( )
103
+ break
104
+ case 'stack' :
105
+ await makeStack ( options )
106
+ break
107
+
108
+ default :
109
+ }
110
+
68
111
// TODO: uncomment this when prompt is ready
69
112
// if (hasNoOptions(options)) {
70
113
// let answers = await prompt.require()
@@ -97,6 +140,36 @@ export function make(buddy: CLI): void {
97
140
process . exit ( ExitCode . Success )
98
141
} )
99
142
143
+ buddy
144
+ . command ( 'make:action [name]' , descriptions . action )
145
+ . option ( '-n, --name [name]' , descriptions . name , { default : false } )
146
+ . option ( '-p, --project [project]' , descriptions . project , { default : false } )
147
+ . option ( '--verbose' , descriptions . verbose , { default : false } )
148
+ . action ( async ( name : string , options : MakeOptions ) => {
149
+ log . info ( 'Running `buddy make:action` ...' )
150
+ log . debug ( 'Running `buddy make:action` ...' , name , options )
151
+
152
+ name = name ?? options . name
153
+ options . name = name
154
+
155
+ if ( ! name ) {
156
+ log . error ( 'You need to specify a name. Read more about the documentation here.' )
157
+ process . exit ( )
158
+ }
159
+
160
+ await makeAction ( options )
161
+ } )
162
+
163
+ buddy
164
+ . command ( 'make:certificate' , descriptions . certificate )
165
+ . alias ( 'make:cert' )
166
+ . example ( 'buddy make:certificate' )
167
+ . action ( async ( options : MakeOptions ) => {
168
+ log . debug ( 'Running `buddy make:certificate` ...' , options )
169
+
170
+ await makeCertificate ( )
171
+ } )
172
+
100
173
buddy
101
174
. command ( 'make:component [name]' , descriptions . component )
102
175
. option ( '-n, --name [name]' , descriptions . name , { default : false } )
@@ -158,13 +231,23 @@ export function make(buddy: CLI): void {
158
231
} )
159
232
160
233
buddy
161
- . command ( 'make:view [name]' , descriptions . page )
162
- . alias ( 'make:page [name]' )
234
+ . command ( 'make:function [name]' , descriptions . function )
235
+ . option ( '-n, --name [name]' , descriptions . name , { default : false } )
236
+ . option ( '-p, --project [project]' , descriptions . project , { default : false } )
237
+ . option ( '--verbose' , descriptions . verbose , { default : false } )
238
+ . action ( async ( options : MakeOptions ) => {
239
+ log . debug ( 'Running `buddy make:function` ...' , options )
240
+
241
+ await makeFunction ( options )
242
+ } )
243
+
244
+ buddy
245
+ . command ( 'make:lang [name]' , descriptions . language )
163
246
. option ( '-n, --name [name]' , descriptions . name , { default : false } )
164
247
. option ( '-p, --project [project]' , descriptions . project , { default : false } )
165
248
. option ( '--verbose' , descriptions . verbose , { default : false } )
166
249
. action ( async ( name : string , options : MakeOptions ) => {
167
- log . debug ( 'Running `buddy make:view ` ...' , options )
250
+ log . debug ( 'Running `buddy make:lang ` ...' , options )
168
251
169
252
name = name ?? options . name
170
253
options . name = name
@@ -174,37 +257,45 @@ export function make(buddy: CLI): void {
174
257
process . exit ( )
175
258
}
176
259
177
- await makePage ( options )
260
+ await makeLanguage ( options )
178
261
} )
179
262
180
263
buddy
181
- . command ( 'make:function [name]' , descriptions . function )
264
+ . command ( 'make:migration [name]' , descriptions . migration )
182
265
. option ( '-n, --name [name]' , descriptions . name , { default : false } )
183
266
. option ( '-p, --project [project]' , descriptions . project , { default : false } )
184
267
. option ( '--verbose' , descriptions . verbose , { default : false } )
185
- . action ( async ( options : MakeOptions ) => {
186
- log . debug ( 'Running `buddy make:function ` ...' , options )
268
+ . action ( ( name : string , options : MakeOptions ) => {
269
+ log . debug ( 'Running `buddy make:migration ` ...' , options )
187
270
188
- await makeFunction ( options )
271
+ name = name ?? options . name
272
+ options . name = name
273
+
274
+ if ( ! name ) {
275
+ log . error ( 'You need to specify a migration name' )
276
+ process . exit ( )
277
+ }
278
+
279
+ // log.info(path)
189
280
} )
190
281
191
282
buddy
192
- . command ( 'make:lang [name]' , descriptions . language )
283
+ . command ( 'make:model [name]' , descriptions . model )
193
284
. option ( '-n, --name [name]' , descriptions . name , { default : false } )
194
285
. option ( '-p, --project [project]' , descriptions . project , { default : false } )
195
286
. option ( '--verbose' , descriptions . verbose , { default : false } )
196
287
. action ( async ( name : string , options : MakeOptions ) => {
197
- log . debug ( 'Running `buddy make:lang ` ...' , options )
288
+ log . debug ( 'Running `buddy make:model ` ...' , options )
198
289
199
290
name = name ?? options . name
200
291
options . name = name
201
292
202
293
if ( ! name ) {
203
- log . error ( 'You need to specify a name. Read more about the documentation here. ' )
294
+ log . error ( 'You need to specify a model name ' )
204
295
process . exit ( )
205
296
}
206
297
207
- await makeLanguage ( options )
298
+ await createModel ( options )
208
299
} )
209
300
210
301
buddy
@@ -246,32 +337,22 @@ export function make(buddy: CLI): void {
246
337
} )
247
338
248
339
buddy
249
- . command ( 'make:stack [name]' , descriptions . stack )
250
- . option ( '-n, --name [name]' , descriptions . name , { default : false } )
340
+ . command ( 'make:queue-table' , descriptions . migration )
251
341
. option ( '-p, --project [project]' , descriptions . project , { default : false } )
252
342
. option ( '--verbose' , descriptions . verbose , { default : false } )
253
- . action ( ( name : string , options : MakeOptions ) => {
254
- log . debug ( 'Running `buddy make:stack` ...' , options )
255
-
256
- name = name ?? options . name
257
- options . name = name
258
-
259
- if ( ! name ) {
260
- log . error ( 'You need to specify a name. Read more about the documentation here.' )
261
- process . exit ( )
262
- }
343
+ . action ( async ( options : MakeOptions ) => {
344
+ log . debug ( 'Running `buddy make queue:table` ...' , options )
263
345
264
- makeStack ( options )
346
+ await makeQueueTable ( )
265
347
} )
266
348
267
349
buddy
268
- . command ( 'make:action [name]' , descriptions . action )
350
+ . command ( 'make:stack [name]' , descriptions . stack )
269
351
. option ( '-n, --name [name]' , descriptions . name , { default : false } )
270
352
. option ( '-p, --project [project]' , descriptions . project , { default : false } )
271
353
. option ( '--verbose' , descriptions . verbose , { default : false } )
272
- . action ( async ( name : string , options : MakeOptions ) => {
273
- log . info ( 'Running `buddy make:action` ...' )
274
- log . debug ( 'Running `buddy make:action` ...' , name , options )
354
+ . action ( ( name : string , options : MakeOptions ) => {
355
+ log . debug ( 'Running `buddy make:stack` ...' , options )
275
356
276
357
name = name ?? options . name
277
358
options . name = name
@@ -281,77 +362,27 @@ export function make(buddy: CLI): void {
281
362
process . exit ( )
282
363
}
283
364
284
- await makeAction ( options )
365
+ makeStack ( options )
285
366
} )
286
367
287
368
buddy
288
- . command ( 'make:model [name]' , descriptions . model )
369
+ . command ( 'make:view [name]' , descriptions . page )
370
+ . alias ( 'make:page [name]' )
289
371
. option ( '-n, --name [name]' , descriptions . name , { default : false } )
290
372
. option ( '-p, --project [project]' , descriptions . project , { default : false } )
291
373
. option ( '--verbose' , descriptions . verbose , { default : false } )
292
374
. action ( async ( name : string , options : MakeOptions ) => {
293
- log . debug ( 'Running `buddy make:model` ...' , options )
294
-
295
- name = name ?? options . name
296
- options . name = name
297
-
298
- if ( ! name ) {
299
- log . error ( 'You need to specify a model name' )
300
- process . exit ( )
301
- }
302
-
303
- await createModel ( options )
304
- } )
305
-
306
- buddy
307
- . command ( 'make:migration [name]' , descriptions . migration )
308
- . option ( '-n, --name [name]' , descriptions . name , { default : false } )
309
- . option ( '-p, --project [project]' , descriptions . project , { default : false } )
310
- . option ( '--verbose' , descriptions . verbose , { default : false } )
311
- . action ( ( name : string , options : MakeOptions ) => {
312
- log . debug ( 'Running `buddy make:migration` ...' , options )
375
+ log . debug ( 'Running `buddy make:view` ...' , options )
313
376
314
377
name = name ?? options . name
315
378
options . name = name
316
379
317
380
if ( ! name ) {
318
- log . error ( 'You need to specify a migration name' )
381
+ log . error ( 'You need to specify a name. Read more about the documentation here. ' )
319
382
process . exit ( )
320
383
}
321
384
322
- // log.info(path)
323
- } )
324
-
325
- buddy
326
- . command ( 'make:certificate' , descriptions . certificate )
327
- . alias ( 'make:cert' )
328
- . example ( 'buddy make:certificate' )
329
- . action ( async ( options : MakeOptions ) => {
330
- log . debug ( 'Running `buddy make:certificate` ...' , options )
331
-
332
- const domain = await localUrl ( )
333
-
334
- log . info ( `Creating SSL certificate...` )
335
- await runCommand ( `tlsx ${ domain } ` , {
336
- cwd : p . storagePath ( 'keys' ) ,
337
- } )
338
- log . success ( 'Certificate created' )
339
-
340
- log . info ( `Installing SSL certificate...` )
341
- await runCommand ( `tlsx -install` , {
342
- cwd : p . storagePath ( 'keys' ) ,
343
- } )
344
- log . success ( 'Certificate installed' )
345
- } )
346
-
347
- buddy
348
- . command ( 'make:queue-table' , descriptions . migration )
349
- . option ( '-p, --project [project]' , descriptions . project , { default : false } )
350
- . option ( '--verbose' , descriptions . verbose , { default : false } )
351
- . action ( async ( options : MakeOptions ) => {
352
- log . debug ( 'Running `buddy make queue:table` ...' , options )
353
-
354
- await makeQueueTable ( )
385
+ await makePage ( options )
355
386
} )
356
387
357
388
buddy . on ( 'make:*' , ( ) => {
0 commit comments