forked from denoland/deployctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployctl.ts
84 lines (76 loc) · 2.07 KB
/
deployctl.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
// Copyright 2021 Deno Land Inc. All rights reserved. MIT license.
import { parseArgs, semverGreaterThanOrEquals } from "./deps.ts";
import { error } from "./src/error.ts";
import runSubcommand from "./src/subcommands/run.ts";
import typesSubcommand from "./src/subcommands/types.ts";
import checkSubcommand from "./src/subcommands/check.ts";
import upgradeSubcommand from "./src/subcommands/upgrade.ts";
import { MINIMUM_DENO_VERSION, VERSION } from "./src/version.ts";
const help = `deployctl ${VERSION}
Run Deno Deploy scripts locally.
To run a script locally:
deployctl run https://deno.land/x/deploy/examples/hello.js
To run a script locally and watch changes:
deployctl run --watch https://deno.land/x/deploy/examples/hello.js
SUBCOMMANDS:
run Run a script given a filename or url
check Perform type checking of the script without actually running it
types Print the Deno Deploy TypeScript declarations
upgrade Upgrade deployctl to the given version (defaults to latest)
`;
if (!semverGreaterThanOrEquals(Deno.version.deno, MINIMUM_DENO_VERSION)) {
error(
`The Deno version you are using is too old. Please update to Deno ${MINIMUM_DENO_VERSION} or later. To do this run \`deno upgrade\`.`,
);
}
const args = parseArgs(Deno.args, {
alias: {
"help": "h",
"reload": "r",
"version": "V",
},
boolean: [
"check",
"help",
"inspect",
"reload",
"version",
"watch",
],
string: [
"addr",
"libs",
"env",
],
default: {
addr: ":8080",
check: true,
libs: "ns,window,fetchevent",
},
});
const subcommand = args._.shift();
switch (subcommand) {
case "run":
await runSubcommand(args);
break;
case "types":
await typesSubcommand(args);
break;
case "check":
await checkSubcommand(args);
break;
case "upgrade":
await upgradeSubcommand(args);
break;
default:
if (args.version) {
console.log(`deployctl ${VERSION}`);
Deno.exit(0);
}
if (args.help) {
console.log(help);
Deno.exit(0);
}
console.error(help);
Deno.exit(1);
}