@jahands/dagger-helpers 0.7.2 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/shell.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { match } from 'ts-pattern'
2
+
3
+ /**
4
+ * Shell options for a given command
5
+ */
6
+ export type ShellOptions = {
7
+ /**
8
+ * Prefix to add to all commands.
9
+ *
10
+ * @default
11
+ * ```sh
12
+ * # bash, zsh
13
+ * set -euo pipefail;
14
+ * # sh
15
+ * set -eu;
16
+ * ```
17
+ */
18
+ prefix?: string
19
+ }
20
+
21
+ /**
22
+ * Create a new shell helper with the given shell type
23
+ *
24
+ * @param shellName - The name of the shell to use
25
+ *
26
+ * @example
27
+ *
28
+ * ```ts
29
+ * const sh = shell('bash')
30
+ *
31
+ * const con = dag.container()
32
+ * .withExec(sh('echo hello world!'))
33
+ * ```
34
+ */
35
+ export function shell(shellName: 'sh' | 'bash' | 'zsh') {
36
+ return (input: string | string[], options?: ShellOptions): string[] => {
37
+ const inputAr = Array.isArray(input) ? input : [input]
38
+ const trimmedInput = inputAr.map((i) =>
39
+ i
40
+ .trim()
41
+ .split('\n')
42
+ .map((l) => l.trim())
43
+ .join('\n')
44
+ )
45
+
46
+ let prefix = match(shellName)
47
+ .with('bash', 'zsh', () => options?.prefix || 'set -euo pipefail')
48
+ .with('sh', () => options?.prefix || 'set -eu')
49
+ .exhaustive()
50
+ .trim()
51
+
52
+ if (!prefix.endsWith(';')) {
53
+ prefix += ';'
54
+ }
55
+
56
+ return [shellName, '-c', `${prefix} ${trimmedInput}`]
57
+ }
58
+ }
@@ -0,0 +1 @@
1
+ // fake dagger module
File without changes