@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/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/convert/camel-to-snake.d.ts +53 -0
- package/dist/convert/camel-to-snake.d.ts.map +1 -0
- package/dist/convert/snake-to-camel.d.ts +34 -0
- package/dist/convert/snake-to-camel.d.ts.map +1 -0
- package/dist/env.d.ts +27 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +7 -0
- package/dist/path.d.ts +12 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/shell.d.ts +33 -0
- package/dist/shell.d.ts.map +1 -0
- package/package.json +6 -5
- package/src/constants.spec.ts +16 -0
- package/src/constants.ts +21 -0
- package/src/convert/camel-to-snake.spec.ts +244 -0
- package/src/convert/camel-to-snake.ts +135 -0
- package/src/convert/snake-to-camel.spec.ts +221 -0
- package/src/convert/snake-to-camel.ts +101 -0
- package/src/env.spec.ts +468 -0
- package/src/env.ts +125 -0
- package/src/index.ts +11 -0
- package/src/path.spec.ts +34 -0
- package/src/path.ts +39 -0
- package/src/shell.ts +58 -0
- package/src/test/fixtures/repo/path/to/module/.dagger/src/index.ts +1 -0
- package/src/test/fixtures/repo/path/to/module/dagger.json +0 -0
- package/src/test/fixtures/repo/pnpm-lock.yaml +0 -0
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
|
|
File without changes
|