deno.land / x / denon@2.5.0 / src / scripts.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
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
// Copyright 2020-2021 the denosaurs team. All rights reserved. MIT license.
/** Map of declared scripts, * Used by `Runner`. */export interface Scripts { [key: string]: Script;}
/** A runnable script. * Can be as simple as a string: * ```json * { * "start": "deno run app.ts" * } * ``` * or as a complex `ScriptObject`: * ```json * { * "start": { * "cmd": "deno run app.ts", * "desc": "run main application", * "allow": [ "env", "read" ] * } * } * ``` */export type Script = string | ScriptObject | ScriptArray;
/** A collection of runnable scripts. * See Script */export type ScriptArray = (string | ScriptObject)[];
/** Most complete representation of a script. Can * be configured in details as it extends `ScriptOptions` * and can also contain a `desc` that is displayed along * script name when`denon` is run without any arguments . */export interface ScriptObject extends ScriptOptions { cmd: string; desc?: string;}
/** Deno CLI flags in a map. * `{ allow: { "write": "/tmp", "read": "/tmp" }}` * -> `[--allow-write=/tmp, --allow-read=/tmp]` */export interface FlagsObject { [key: string]: unknown;}
/** Environment variables in a map. * `{ TOKEN: "SECRET!" }` * -> `TOKEN=SECRET` */export interface EnvironmentVariables { [key: string]: string;}
/** Additional script options. * * These can be applied both in `ScriptObject`s and at top-level * in which case they're applied to all the scripts defined in the file */export interface ScriptOptions { /** A map of environment variables to be passed to the script */ env?: EnvironmentVariables; /** A list of boolean `--allow-*` deno cli options or * a map of option names to values */ allow?: string[] | FlagsObject | "all"; /** The path to an import map json file, * passed to deno cli's `--import-map` option. * * **Note** This currently requires the `--unstable` flag */ importMap?: string; /** The path to a tsconfig json file, * passed to deno cli's `--tsconfig` option. */ tsconfig?: string; /** If the code that has to be run is using unstable features * from deno standard library this option should be set to * `true` so that `--unstable` option is passed to deno cli's. */ unstable?: boolean; /** Skip Typescript type checking module */ noCheck?: boolean; /** The hostname and port where to start the inspector, * passed to deno cli's `--inspect` option. */ inspect?: string; /** Same as `inspect`, but breaks at start of user script. */ inspectBrk?: string; /** The path to an _existing_ lockfile, * passed to deno cli's `--lock` option. * * **Note** This doesn't create the lockfile, use `--lock-write` manually * when appropriate */ lock?: string; /** The path to a PEM certificate file, * passed to deno cli's `--cert` option. */ cert?: string; /** The log level, passed to deno cli's `--log-level` option. */ log?: string; /** Should watch. Enabled by default. Toggle file watching * for particular script. */ watch?: boolean; /** Standard i/o/err, to be passed directly to Deno.run. */ stdin?: "inherit" | "piped" | "null" | number; stdout?: "inherit" | "piped" | "null" | number; stderr?: "inherit" | "piped" | "null" | number;}
/** Build deno flags from ScriptOptions. * `{ allow: [ run, env ]}` -> `[--allow-run, --allow-env]` */export function buildFlags(options: ScriptOptions): string[] { const flags: string[] = []; if (options.allow) { if (Array.isArray(options.allow)) { options.allow.forEach((flag) => flags.push(`--allow-${flag}`)); } else if (options.allow === "all") { flags.push(`--allow-all`); } else if (typeof options.allow === "object") { Object.entries(options.allow).map(([flag, value]) => { if (!value || (typeof value === "boolean" && value)) { flags.push(`--allow-${flag}`); } else { flags.push(`--allow-${flag}=${value}`); } }); } } if (options.importMap) { flags.push("--import-map"); flags.push(options.importMap); } if (options.lock) { flags.push("--lock"); flags.push(options.lock); } if (options.log) { flags.push("--log-level"); flags.push(options.log); } if (options.tsconfig) { flags.push("--config"); flags.push(options.tsconfig); } if (options.cert) { flags.push("--cert"); flags.push(options.cert); } if (options.inspect) { flags.push(`--inspect=${options.inspect}`); } if (options.inspectBrk) { flags.push(`--inspect-brk=${options.inspectBrk}`); } if (options.noCheck) { flags.push("--no-check"); } if (options.unstable) { flags.push("--unstable"); } return flags;}
denon

Version Info

Tagged at
2 years ago

External Dependencies

No external dependencies 🎉