deno.land / x / velociraptor@1.5.0 / src / normalize_script.ts

normalize_script.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
import { ParallelScripts, ScriptDefinition, ScriptOptions,} from "./scripts_config.ts";import { Command, isParallel, ParallelCommands } from "./command.ts";import { mergeParams } from "./merge_params.ts";import { isParallelScripts, isScriptObject } from "./util.ts";
/** * Normalizes a script definition to a list of `Command` objects */export function normalizeScript( script: ScriptDefinition, rootParams: ScriptOptions,): Array<Command | ParallelCommands | null> { const res = _normalizeScript(script, rootParams); return Array.isArray(res) ? res : [res];}
function _normalizeScript( node: ScriptDefinition | ParallelScripts, parentParams: ScriptOptions,): Command | ParallelCommands | Array<Command | ParallelCommands> | null { if (typeof node === "string") { return { cmd: node.trim(), ...mergeParams({}, parentParams), } as Command; } if (Array.isArray(node)) { return node.map((s) => _normalizeScript(s, parentParams)) as Array< Command | ParallelCommands >; } if (isParallelScripts(node)) { return { pll: node.pll.flatMap((s) => _normalizeScript(s, parentParams)), } as ParallelCommands; } if (isScriptObject(node)) { const { cmd, ...nodeParams } = node; return _normalizeScript( node.cmd, mergeParams(nodeParams, parentParams), ) as Command; } return null;}
export function flattenCommands( commands: (Command | ParallelCommands | null)[],): Command[] { return commands .filter((c) => c !== null) .flatMap((c) => c instanceof Object && isParallel(c) ? flattenCommands(c.pll) : c ) as Command[];}
velociraptor

Version Info

Tagged at
2 years ago