-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmod.ts
120 lines (113 loc) · 3.35 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
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
// deno-lint-ignore-file no-explicit-any
import { CLI } from './src/CLI.ts'
import yargs from 'https://deno.land/x/yargs@v17.7.2-deno/deno.ts'
import { parse as semverParse, compare as semverCompare } from 'jsr:@std/semver'
import { comMojangFolder } from './src/comMojangFolder.ts'
import { initRuntimes, swcVersion } from './src/deps.ts'
type YargsInstance = ReturnType<typeof yargs>
const CURRENT_VERSION = `1.0.0`
async function fetchLatestVersion(): Promise<string | null> {
try {
const response = await fetch('https://api.github.com/repos/bridge-core/deno-dash-compiler/releases/latest');
if (!response.ok) {
return null;
}
const data = await response.json();
return data.tag_name;
} catch (error) {
console.error('Error fetching the latest version:', error);
return null;
}
}
function compareVersions(current: string, latest: string): boolean {
const currentVersion = semverParse(current);
const latestVersion = semverParse(latest);
if (!currentVersion || !latestVersion) {
throw new Error('Invalid version format');
}
return semverCompare(currentVersion, latestVersion) < 0;
}
async function checkForUpdates() {
const latestVersion = await fetchLatestVersion();
if (latestVersion && compareVersions(CURRENT_VERSION, latestVersion)) {
console.log(`%cA new version (${latestVersion}) is available. You are currently using version v${CURRENT_VERSION}.`, 'color: red; font-weight:bold;');
}
}
initRuntimes(`https://esm.sh/@swc/wasm-web@${swcVersion}/wasm-web_bg.wasm`)
if (import.meta.main) {
await checkForUpdates();
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()
}