forked from bridge-core/deno-dash-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
95 lines (90 loc) · 2.32 KB
/
mod.ts
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
// deno-lint-ignore-file no-explicit-any
import { CLI } from './src/CLI.ts'
import yargs from 'https://deno.land/x/[email protected]/deno.ts'
import { comMojangFolder } from './src/comMojangFolder.ts'
import { initRuntimes, swcVersion } from './src/deps.ts'
// @ts-ignore: Required by some of our dependencies
window.global = window
// @ts-ignore: Required by some of our dependencies
window.process = {
cwd: () => '',
env: {},
}
type YargsInstance = ReturnType<typeof yargs>
initRuntimes(`https://esm.sh/@swc/wasm-web@${swcVersion}/wasm-web_bg.wasm`)
if (import.meta.main) {
const cli = new CLI()
yargs(Deno.args)
.command(
'build',
'Build the current project',
(yargs: YargsInstance) => {
return yargs
.option('out', {
alias: 'o',
description: 'The output directory',
type: 'string',
})
.option('mode', {
alias: 'm',
description: 'The mode to build for',
type: 'string',
default: 'production',
choices: ['development', 'production'],
})
.option('compilerConfig', {
alias: 'c',
description: 'The compiler config file',
type: 'string',
})
},
async (argv: any) => {
await cli.build(argv)
}
)
.command(
'watch',
'Build the current project and watch for future changes',
(yargs: YargsInstance) => {
return (
yargs
.option('out', {
alias: 'o',
description: 'The output directory',
type: 'string',
default: comMojangFolder,
})
.option('mode', {
alias: 'm',
description: 'The mode to build for',
type: 'string',
default: 'development',
choices: ['development', 'production'],
})
.option('compilerConfig', {
alias: 'c',
description: 'The compiler config file',
type: 'string',
})
.option('reload', {
alias: 'r',
description:
'Quick reload for functions and scripts',
type: 'number',
})
// Need to use coerce rather than "default" so we can differentiate between when the option isn't used or is used without an argument
.coerce('reload', (arg: any) => {
if (!arg) return 8080
else return arg
})
)
},
async (argv: any) => {
await cli.watch(argv)
}
)
.strictCommands(true)
.demandCommand(1)
.help()
.parse()
}