-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathcli.ts
More file actions
2156 lines (2070 loc) · 58.3 KB
/
cli.ts
File metadata and controls
2156 lines (2070 loc) · 58.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
import path from 'node:path'
import '@epic-web/workshop-utils/init-env'
import chalk from 'chalk'
import { matchSorter } from 'match-sorter'
import yargs, { type ArgumentsCamelCase, type Argv } from 'yargs'
import { hideBin } from 'yargs/helpers'
import { assertCanPrompt } from './utils/cli-runtime.js'
import { initCliSentry } from './utils/sentry-cli.js'
// Check for --help on start command before yargs parses
// (yargs exits before command handler when help is requested)
const args = hideBin(process.argv)
const cliSentry = initCliSentry(args)
if (
(args.includes('--help') || args.includes('-h')) &&
(args.length === 0 || args[0] === 'start')
) {
const { displayHelp } = await import('./commands/start.js')
displayHelp()
process.exit(0)
}
// Helper function to colorize help output
function formatHelp(helpText: string): string {
return helpText
.replace(/^(Commands:)/gm, chalk.cyan.bold('$1'))
.replace(/^(Options:)/gm, chalk.cyan.bold('$1'))
.replace(/^(Examples:)/gm, chalk.cyan.bold('$1'))
.replace(/^\s{2}(\S+)\s{2,}/gm, (match, cmd) => {
return match.replace(cmd, chalk.green(cmd))
})
.replace(/--[\w-]+/g, (match) => chalk.yellow(match))
.replace(/-\w(?=\s|,)/g, (match) => chalk.yellow(match))
}
function resolveWorkshopContextCwd(
explicitWorkshopDir?: string,
): string | undefined {
const fromFlag = explicitWorkshopDir?.trim()
? explicitWorkshopDir.trim()
: undefined
if (fromFlag) return fromFlag
const fromEnv = process.env.EPICSHOP_CONTEXT_CWD
return fromEnv?.trim() ? fromEnv.trim() : undefined
}
// Set up yargs CLI
const cli = yargs(args)
.scriptName('epicshop')
.usage(chalk.bold('$0 <command> [options]'))
.help('help')
.alias('h', 'help')
.version(false)
.showHelpOnFail(true)
.middleware((argv) => {
cliSentry.setCommandContextFromArgv(argv)
})
.command(
'start [workshop]',
'Start a workshop (auto-detects if inside a workshop directory)',
(yargs: Argv) => {
return yargs
.positional('workshop', {
describe: 'Workshop name to start (optional if inside a workshop)',
type: 'string',
})
.option('verbose', {
alias: 'v',
type: 'boolean',
description: 'Show verbose output',
default: false,
})
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.option('app-location', {
type: 'string',
description: 'Path to the workshop app directory',
})
.example('$0 start', 'Start the current workshop or select one')
.example('$0 start full-stack-foundations', 'Start a specific workshop')
.example(
'$0 start --app-location /path/to/workshop-app',
'Start with custom app location',
)
},
async (
argv: ArgumentsCamelCase<{
workshop?: string
verbose?: boolean
silent?: boolean
appLocation?: string
}>,
) => {
// If a specific workshop is requested, start it from managed workshops
if (argv.workshop) {
const { startWorkshop } = await import('./commands/workshops.js')
const result = await startWorkshop({
workshop: argv.workshop,
silent: argv.silent,
})
if (!result.success) {
process.exit(1)
}
return
}
// Check if we're inside any workshop directory (walk up to find package.json with epicshop)
const { findWorkshopRoot } = await import('./commands/workshops.js')
const workshopRoot = await findWorkshopRoot()
if (workshopRoot) {
// We're inside a workshop directory, start from that root
const originalCwd = process.cwd()
process.chdir(workshopRoot)
try {
// run migrations before starting
await import('./commands/migrate.js')
.then(({ migrate }) => migrate())
.catch((error) => {
if (!argv.silent) {
console.error(chalk.yellow('⚠️ Migration failed:'), error)
}
})
// kick off a warmup while we start the server
import('./commands/warm.js')
.then(({ warm }) => warm({ silent: true }))
.catch((error) => {
if (!argv.silent) {
console.error(chalk.yellow('⚠️ Warmup failed:'), error)
}
})
const { start } = await import('./commands/start.js')
const result = await start({
appLocation: argv.appLocation,
verbose: argv.verbose,
silent: argv.silent,
})
if (!result.success) {
if (!argv.silent) {
const message =
result.message || 'Failed to start workshop application'
console.error(chalk.red(`❌ ${message}`))
if (result.error?.message && result.error.message !== message) {
console.error(chalk.red(result.error.message))
}
}
process.exit(1)
}
} finally {
process.chdir(originalCwd)
}
} else {
// Not inside a workshop, show selection from managed workshops
const { startWorkshop } = await import('./commands/workshops.js')
const result = await startWorkshop({ silent: argv.silent })
if (!result.success) {
process.exit(1)
}
}
},
)
.command(
'init',
'Initialize epicshop and start the tutorial (first-time setup)',
(yargs: Argv) => {
return yargs.example('$0 init', 'Run the first-time setup wizard')
},
async () => {
const { onboarding } = await import('./commands/workshops.js')
const result = await onboarding()
if (!result.success) {
process.exit(1)
}
},
)
.command(
'setup',
'Install workshop dependencies (uses configured package manager)',
(yargs: Argv) => {
return yargs
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 setup', 'Install workshop dependencies')
},
async (argv: ArgumentsCamelCase<{ silent?: boolean }>) => {
const { setup } = await import('./commands/setup.js')
const result = await setup({ silent: argv.silent })
if (!result.success) {
process.exit(1)
}
},
)
.command(
'add [repo-name] [destination]',
'Add a workshop by cloning from epicweb-dev GitHub org',
(yargs: Argv) => {
return yargs
.positional('repo-name', {
describe:
'Repository name from epicweb-dev org (optional, shows list if omitted). Use <repo>#<tag|branch|commit> to pin a ref.',
type: 'string',
})
.positional('destination', {
describe:
'Optional directory to clone into (full path). If provided, this bypasses the configured repos directory.',
type: 'string',
})
.option('directory', {
alias: 'd',
type: 'string',
description:
'Directory to clone into (defaults to configured repos directory)',
})
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 add', 'Show available workshops to add')
.example(
'$0 add full-stack-foundations',
'Clone and set up the full-stack-foundations workshop',
)
.example(
'$0 add web-forms --directory ~/my-workshops',
'Clone workshop to a custom directory',
)
.example(
'$0 add react-fundamentals ~/Desktop/react-fundamentals',
'Clone workshop to a specific destination directory',
)
.example(
'$0 add react-fundamentals#v1.2.0',
'Clone a workshop at a specific tag, branch, or commit',
)
},
async (
argv: ArgumentsCamelCase<{
repoName?: string
destination?: string
directory?: string
silent?: boolean
}>,
) => {
const { add } = await import('./commands/workshops.js')
const result = await add({
repoName: argv.repoName,
destination: argv.destination,
directory: argv.directory,
silent: argv.silent,
})
if (!result.success) {
process.exit(1)
}
},
)
.command(
'list',
'List all added workshops',
(yargs: Argv) => {
return yargs
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 list', 'List all added workshops')
},
async (argv: ArgumentsCamelCase<{ silent?: boolean }>) => {
const { list } = await import('./commands/workshops.js')
const result = await list({ silent: argv.silent })
if (!result.success) {
process.exit(1)
}
},
)
.command(
'remove [workshop]',
'Remove a workshop (deletes the directory)',
(yargs: Argv) => {
return yargs
.positional('workshop', {
describe:
'Workshop to remove (auto-detects if inside a workshop directory)',
type: 'string',
})
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 remove', 'Remove current workshop or select one')
.example(
'$0 remove full-stack-foundations',
'Remove a specific workshop',
)
},
async (
argv: ArgumentsCamelCase<{
workshop?: string
silent?: boolean
}>,
) => {
const { findWorkshopRoot, remove } =
await import('./commands/workshops.ts')
let workshopToRemove = argv.workshop
// If no workshop specified, check if we're inside a workshop directory
if (!workshopToRemove) {
const workshopRoot = await findWorkshopRoot()
if (workshopRoot) {
// Pass the path directly - remove will handle it
workshopToRemove = workshopRoot
}
}
const result = await remove({
workshop: workshopToRemove,
silent: argv.silent,
})
if (!result.success) {
process.exit(1)
}
},
)
.command(
'open [workshop]',
'Open a workshop in your editor',
(yargs: Argv) => {
return yargs
.positional('workshop', {
describe:
'Workshop to open (auto-detects if inside a workshop directory)',
type: 'string',
})
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 open', 'Open current workshop or select one')
.example('$0 open full-stack-foundations', 'Open a specific workshop')
},
async (
argv: ArgumentsCamelCase<{
workshop?: string
silent?: boolean
}>,
) => {
const { findWorkshopRoot, openWorkshop } =
await import('./commands/workshops.ts')
let workshopToOpen = argv.workshop
// If no workshop specified, check if we're inside a workshop directory
if (!workshopToOpen) {
const workshopRoot = await findWorkshopRoot()
if (workshopRoot) {
// Pass the path directly - openWorkshop will handle it
workshopToOpen = workshopRoot
}
}
const result = await openWorkshop({
workshop: workshopToOpen,
silent: argv.silent,
})
if (!result.success) {
process.exit(1)
}
},
)
.command(
'config [subcommand]',
'View or update workshop configuration',
(yargs: Argv) => {
return yargs
.positional('subcommand', {
describe: 'Config subcommand (reset)',
type: 'string',
choices: ['reset', 'editor'],
})
.option('repos-dir', {
type: 'string',
description: 'Set the default directory for workshop repos',
})
.option('editor', {
type: 'string',
description: 'Set the preferred editor command',
})
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 config', 'View current configuration')
.example('$0 config reset', 'Delete config file and reset to defaults')
.example('$0 config --repos-dir ~/epicweb', 'Set the repos directory')
.example('$0 config editor', 'Choose a preferred editor')
.example('$0 config --editor code', 'Set preferred editor to VS Code')
},
async (
argv: ArgumentsCamelCase<{
subcommand?: string
reposDir?: string
editor?: string
silent?: boolean
}>,
) => {
const { config } = await import('./commands/workshops.js')
const result = await config({
subcommand:
argv.subcommand === 'reset'
? 'reset'
: argv.subcommand === 'editor'
? 'editor'
: undefined,
reposDir: argv.reposDir,
preferredEditor: argv.editor,
silent: argv.silent,
})
if (!result.success) {
process.exit(1)
}
},
)
.command(
['update', 'upgrade'],
'Update the current workshop or select one to update',
(yargs: Argv) => {
return yargs
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 update', 'Update workshop to latest version')
.example(
'$0 update --silent',
'Update workshop to latest version silently',
)
},
async (argv: ArgumentsCamelCase<{ silent?: boolean }>) => {
// Check if we're inside any workshop directory
const { findWorkshopRoot } = await import('./commands/workshops.js')
const workshopRoot = await findWorkshopRoot()
if (workshopRoot) {
// Inside a workshop, run update on it
const originalCwd = process.cwd()
process.chdir(workshopRoot)
try {
const { update } = await import('./commands/update.js')
const result = await update({ silent: argv.silent })
if (!result.success) {
if (!argv.silent) {
console.error(
chalk.red(
`❌ ${result.message || 'Failed to update workshop'}`,
),
)
if (result.error) {
console.error(chalk.red(result.error.message))
}
}
process.exit(1)
}
} catch (error) {
if (!argv.silent) {
console.error(chalk.red('❌ Update failed:'), error)
}
process.exit(1)
} finally {
process.chdir(originalCwd)
}
} else {
// Not inside a workshop, prompt user to select one
const { listWorkshops, getWorkshop } =
await import('@epic-web/workshop-utils/workshops.server')
const workshops = await listWorkshops()
if (workshops.length === 0) {
if (!argv.silent) {
console.log(
chalk.yellow(
`No workshops found. Use 'epicshop add <repo-name>' to add one.`,
),
)
}
process.exit(1)
}
assertCanPrompt({
reason: 'select a workshop to update',
hints: [
'Run from inside a workshop directory: (cd <workshop> && npx epicshop update)',
'Or run in a TTY to select interactively.',
],
})
const { search } = await import('@inquirer/prompts')
const allChoices = workshops.map(
(w: { title: string; repoName: string; path: string }) => ({
name: `${w.title} (${w.repoName})`,
value: w.repoName,
description: w.path,
}),
)
try {
const selectedWorkshop = await search({
message: 'Select a workshop to update:',
source: async (input) => {
if (!input) {
return allChoices
}
return matchSorter(allChoices, input, {
keys: ['name', 'value', 'description'],
})
},
})
const workshop = await getWorkshop(selectedWorkshop)
if (!workshop) {
if (!argv.silent) {
console.error(
chalk.red(`❌ Workshop "${selectedWorkshop}" not found`),
)
}
process.exit(1)
}
// Change to workshop directory and run update
const originalCwd = process.cwd()
process.chdir(workshop.path)
try {
const { update } = await import('./commands/update.js')
const result = await update({ silent: argv.silent })
if (!result.success) {
if (!argv.silent) {
console.error(
chalk.red(
`❌ ${result.message || 'Failed to update workshop'}`,
),
)
if (result.error) {
console.error(chalk.red(result.error.message))
}
}
process.exit(1)
}
} finally {
process.chdir(originalCwd)
}
} catch (error) {
if ((error as Error).message === 'USER_QUIT') {
process.exit(0)
}
throw error
}
}
},
)
.command(
'warm',
'Warm up the workshop application caches (apps, diffs)',
(yargs: Argv) => {
return yargs
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 warm', 'Warm up workshop caches')
.example('$0 warm --silent', 'Warm up workshop caches silently')
},
async (argv: ArgumentsCamelCase<{ silent?: boolean }>) => {
// Check if we're inside any workshop directory
const { findWorkshopRoot } = await import('./commands/workshops.js')
const workshopRoot = await findWorkshopRoot()
if (workshopRoot) {
// Inside a workshop, warm it
const originalCwd = process.cwd()
process.chdir(workshopRoot)
try {
const { warm } = await import('./commands/warm.js')
const result = await warm({ silent: argv.silent })
if (!result.success) {
if (!argv.silent) {
console.error(
chalk.red(
`❌ ${result.message || 'Failed to warm up workshop'}`,
),
)
if (result.error) {
console.error(chalk.red(result.error.message))
}
}
process.exit(1)
}
} catch (error) {
if (!argv.silent) {
console.error(chalk.red('❌ Warmup failed:'), error)
}
process.exit(1)
} finally {
process.chdir(originalCwd)
}
} else {
// Not inside a workshop, prompt user to select one
const { listWorkshops, getWorkshop } =
await import('@epic-web/workshop-utils/workshops.server')
const workshops = await listWorkshops()
if (workshops.length === 0) {
if (!argv.silent) {
console.log(
chalk.yellow(
`No workshops found. Use 'epicshop add <repo-name>' to add one.`,
),
)
}
process.exit(1)
}
assertCanPrompt({
reason: 'select a workshop to warm',
hints: [
'Run from inside a workshop directory: (cd <workshop> && npx epicshop warm)',
'Or run in a TTY to select interactively.',
],
})
const { search } = await import('@inquirer/prompts')
const allChoices = workshops.map(
(w: { title: string; repoName: string; path: string }) => ({
name: `${w.title} (${w.repoName})`,
value: w.repoName,
description: w.path,
}),
)
try {
const selectedWorkshop = await search({
message: 'Select a workshop to warm:',
source: async (input) => {
if (!input) {
return allChoices
}
return matchSorter(allChoices, input, {
keys: ['name', 'value', 'description'],
})
},
})
const workshop = await getWorkshop(selectedWorkshop)
if (!workshop) {
if (!argv.silent) {
console.error(
chalk.red(`❌ Workshop "${selectedWorkshop}" not found`),
)
}
process.exit(1)
}
// Change to workshop directory and run warm
const originalCwd = process.cwd()
process.chdir(workshop.path)
try {
const { warm } = await import('./commands/warm.js')
const result = await warm({ silent: argv.silent })
if (!result.success) {
if (!argv.silent) {
console.error(
chalk.red(
`❌ ${result.message || 'Failed to warm up workshop'}`,
),
)
if (result.error) {
console.error(chalk.red(result.error.message))
}
}
process.exit(1)
}
} finally {
process.chdir(originalCwd)
}
} catch (error) {
if ((error as Error).message === 'USER_QUIT') {
process.exit(0)
}
throw error
}
}
},
)
.command(
'cleanup',
'Clean up local epicshop data',
(yargs: Argv) => {
return yargs
.option('targets', {
alias: 't',
type: 'array',
choices: [
'caches',
'offline-videos',
'preferences',
'auth',
'config',
],
description:
'Cleanup targets (repeatable): caches, offline-videos, preferences, auth, config',
})
.option('workshops', {
type: 'array',
description: 'Workshops to clean (repeatable, by repo name or path)',
})
.option('workshop-actions', {
type: 'array',
choices: ['files', 'caches', 'offline-videos'],
description: 'Cleanup actions for selected workshops (repeatable)',
})
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.option('force', {
alias: 'f',
type: 'boolean',
description: 'Skip the confirmation prompt',
default: false,
})
.example(
'$0 cleanup',
'Pick cleanup targets interactively (multi-select)',
)
.example(
'$0 cleanup --targets caches --targets preferences --force',
'Clean selected targets without prompting',
)
.example(
'$0 cleanup --workshops full-stack-foundations --workshop-actions caches --force',
'Clean caches for a specific workshop',
)
},
async (
argv: ArgumentsCamelCase<{
silent?: boolean
force?: boolean
targets?: Array<string>
workshops?: Array<string>
workshopActions?: Array<string>
}>,
) => {
const { cleanup } = await import('./commands/cleanup.js')
const result = await cleanup({
silent: argv.silent,
force: argv.force,
targets: argv.targets as Array<
'caches' | 'offline-videos' | 'preferences' | 'auth' | 'config'
>,
workshops: argv.workshops,
workshopTargets: argv.workshopActions as Array<
'files' | 'caches' | 'offline-videos'
>,
})
if (!result.success) {
process.exit(1)
}
},
)
.command(
'migrate',
'Run any necessary migrations for workshop data',
(yargs: Argv) => {
return yargs
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 migrate', 'Run necessary migrations')
.example('$0 migrate --silent', 'Run migrations silently')
},
async (argv: ArgumentsCamelCase<{ silent?: boolean }>) => {
try {
const { migrate } = await import('./commands/migrate.js')
const result = await migrate()
if (argv.silent) return
if (result === null) {
console.log(chalk.green('✅ No migrations needed'))
return
}
if (result.success) {
console.log(
chalk.green(
result.message || '✅ Migrations completed successfully',
),
)
} else {
console.error(
chalk.red(`❌ ${result.message || 'Failed to run migrations'}`),
)
if (result.error) {
console.error(chalk.red(result.error.message))
}
process.exit(1)
}
} catch (error) {
if (!argv.silent) {
console.error(chalk.red('❌ Migration failed:'), error)
}
process.exit(1)
}
},
)
.command(
'auth [subcommand] [domain]',
'Manage authentication for Epic domains (epicweb.dev, epicreact.dev, epicai.pro)',
(yargs: Argv) => {
return yargs
.positional('subcommand', {
describe: 'Auth subcommand (status, login, logout)',
type: 'string',
choices: ['status', 'login', 'logout'],
})
.positional('domain', {
describe:
'Domain to authenticate with (e.g., epicweb.dev, epicreact, epicai)',
type: 'string',
})
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.example('$0 auth', 'Show auth subcommand menu')
.example('$0 auth status', 'Show login status for all domains')
.example('$0 auth login', 'Login to a domain (interactive)')
.example('$0 auth login epicweb.dev', 'Login to EpicWeb.dev')
.example('$0 auth logout epicreact', 'Logout from EpicReact.dev')
},
async (
argv: ArgumentsCamelCase<{
subcommand?: string
domain?: string
silent?: boolean
}>,
) => {
const { status, login, logout } = await import('./commands/auth.js')
let subcommand = argv.subcommand
if (!subcommand) {
if (argv.silent) {
console.error(
chalk.red(
'❌ Subcommand required in silent mode (status, login, logout)',
),
)
process.exit(1)
}
assertCanPrompt({
reason: 'choose an auth subcommand',
hints: [
'Provide the subcommand: npx epicshop auth status|login|logout',
'Examples: npx epicshop auth status, npx epicshop auth login epicweb.dev, npx epicshop auth logout epicreact',
],
})
const { search } = await import('@inquirer/prompts')
const authChoices = [
{
name: `${chalk.green('status')} - Show login status`,
value: 'status' as const,
description: 'Show login status for all Epic domains',
},
{
name: `${chalk.green('login')} - Log in to a domain`,
value: 'login' as const,
description: 'Log in to EpicWeb.dev, EpicReact.dev, or EpicAI.pro',
},
{
name: `${chalk.green('logout')} - Log out from a domain`,
value: 'logout' as const,
description: 'Log out from an Epic domain',
},
]
try {
subcommand = await search({
message: 'What would you like to do?',
source: async (input) => {
if (!input) return authChoices
return matchSorter(authChoices, input, {
keys: ['name', 'value', 'description'],
})
},
})
} catch (error) {
if ((error as Error).message === 'USER_QUIT') {
process.exit(0)
}
throw error
}
}
if (!argv.subcommand) {
cliSentry.setCommandContext({
command: 'auth',
subcommand,
})
}
let result: { success: boolean }
switch (subcommand) {
case 'status':
result = await status({ silent: argv.silent })
break
case 'login':
result = await login({ domain: argv.domain, silent: argv.silent })
break
case 'logout':
result = await logout({ domain: argv.domain, silent: argv.silent })
break
default:
console.error(chalk.red(`❌ Unknown auth subcommand: ${subcommand}`))
process.exit(1)
}
if (!result.success) {
process.exit(1)
}
},
)
.command(
'admin <subcommand>',
false,
(yargs: Argv) => {
return yargs
.positional('subcommand', {
describe: 'Admin subcommand',
type: 'string',
choices: ['launch-readiness', 'set-videos'],
})
.option('workshop-dir', {
alias: 'w',
type: 'string',
description:
'Path to a workshop directory to use as context (instead of the current working directory)',
})
.option('silent', {
alias: 's',
type: 'boolean',
description: 'Run without output logs',
default: false,
})
.option('skip-remote', {
type: 'boolean',
description:
'Skip the remote "product lessons" check (only run local checks)',
default: false,
})
.option('skip-head', {