-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.launch.scripts.mjs
More file actions
76 lines (72 loc) · 2.12 KB
/
.launch.scripts.mjs
File metadata and controls
76 lines (72 loc) · 2.12 KB
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
// @ts-check
import { homedir } from "node:os"
import { createHash } from "node:crypto"
/**
* @typedef {object} LaunchConfig
* @property {string} commandSeparator
* @property {number} othersCommandsToShow
* @property {RegExp} envRegexp
* @property {number} checkVersionTimeoutInMs
* @property {number} checkVersionIntervalInSeconds
*/
/** @type {Partial<LaunchConfig>} */
export const config = {
commandSeparator: "&&",
othersCommandsToShow: 3,
checkVersionTimeoutInMs: 1000,
checkVersionIntervalInSeconds: 12 * 60 * 60,
}
/**
* @typedef {{ path: string }} Context
* @typedef {(c: Context) => string} Builder
* @typedef {string | Builder} CmdArg
* @typedef {string | Builder} Cmd
* @typedef {Cmd[] | { args: string[], cmd: Cmd[] }} BuiltCmd
* @typedef {{ args: string[] }} CmdBuilderContext
* @typedef {(_: CmdBuilderContext) => BuiltCmd } CmdBuilder
* @typedef {{ dir?: string, cmd: Cmd[] | CmdBuilder, desc?: string }} Script
* @typedef {{ [_: string]: Script }} Scripts
* @typedef {(_0: TemplateStringsArray, ..._1: CmdArg[]) => Builder} CommandGenerator
* @type {(_: { cmd: CommandGenerator }) => Scripts}
*/
export default ({ cmd }) => ({
hello: {
cmd: [ "echo Hello world!" ],
desc: "Print Hello world!"
},
helloFn: {
dir: homedir() || "",
cmd: [
"echo Hello world from",
cmd`echo ${({ path }) => path}`
],
desc: "Print Hello world with home directory"
},
describeArgs: {
cmd: ({ args }) => [
`echo "count: ${args.length}"`,
...args.map((arg, i) => `echo "${i + 1}. ${arg}"`),
'echo input: '
],
desc: "Describes the arguments of command"
},
cryptoArgs: {
cmd({ args }) {
const input = args.join("-")
const algorithm = "sha256"
const resultArgs = createHash(algorithm)
.update(input)
.digest("hex")
.toString()
return {
args: [resultArgs],
cmd: [
`echo "hash algorithm: ${algorithm}"`,
`echo "input: ${input || "<empty>"}"`,
"echo result:" // will print resultArgs
]
}
},
desc: "Prints a hash of the arguments joined with '-'"
}
})