generated from denorg/starter
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.ts
48 lines (44 loc) · 1.03 KB
/
cli.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
import { dpx } from "./mod.ts";
import { parse } from "https://deno.land/std/flags/mod.ts";
const DENO_FLAGS = [
"-A",
"--allow-all",
"--allow-env",
"--allow-hrtime",
"--allow-net=",
"--allow-plugin",
"--allow-read=",
"--allow-run",
"--allow-write=",
"--reload",
"-r",
"--lock=",
"--importmap=",
"--unstable",
"--inspect",
"--inspect-brk",
"--root",
];
// https://deno.land/manual/tools/script_installer
if (import.meta.main) {
const flags: string[] = [];
const args: string[] = [];
let packageName = "";
let registry: string | undefined = undefined;
let argsv = parse(Deno.args);
registry = argsv.registry
Deno.args.forEach((arg, index) => {
if (index === 0) packageName = arg;
let isDenoFlag = false;
DENO_FLAGS.forEach((flag) => {
if (
flag === arg ||
(flag.endsWith("=") && arg.startsWith(flag.slice(0, -1)))
)
isDenoFlag = true;
});
if (isDenoFlag) flags.push(arg);
else args.push(arg);
});
dpx(packageName, flags, args, registry);
}