omkit 0.1.0 → 0.1.2
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/actions/command.d.ts +16 -4
- package/dist/actions/command.js +23 -8
- package/package.json +1 -1
|
@@ -7,9 +7,21 @@ export interface CommandOptions {
|
|
|
7
7
|
/** Let this command inherit the orchestrator's debugger (default false). */
|
|
8
8
|
inheritDebugger?: boolean;
|
|
9
9
|
}
|
|
10
|
+
declare function build(name: string, cmdOrFile: string, argsOrOptions: readonly string[] | CommandOptions, maybeOptions: CommandOptions): import("../index.ts").ActionInstance<import("zx").ProcessOutput, import("../core/types.ts").NoEvents, void>;
|
|
10
11
|
/**
|
|
11
|
-
* Runs a
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Runs a shell command as an action instance. Two forms:
|
|
13
|
+
*
|
|
14
|
+
* - `command(name, cmd, options?)` — a full command **string**, run verbatim through the
|
|
15
|
+
* shell, so pipes, globs and `&&` work (quote anything yourself).
|
|
16
|
+
* - `command(name, file, args, options?)` — an executable **plus an args array**; each arg
|
|
17
|
+
* is quoted individually, so spaces and `=`/paths in args are safe without hand-quoting.
|
|
18
|
+
*
|
|
19
|
+
* Output streams into the run's log under `name`; a non-zero exit fails the action;
|
|
20
|
+
* teardown kills the child tree. For interpolated events or a daemon loop, drop to
|
|
21
|
+
* `action(...).run(...)`.
|
|
14
22
|
*/
|
|
15
|
-
export declare
|
|
23
|
+
export declare const command: {
|
|
24
|
+
(name: string, cmd: string, options?: CommandOptions): ReturnType<typeof build>;
|
|
25
|
+
(name: string, file: string, args: readonly string[], options?: CommandOptions): ReturnType<typeof build>;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
package/dist/actions/command.js
CHANGED
|
@@ -6,18 +6,33 @@ import { action } from "../core/action.js";
|
|
|
6
6
|
* `pieces` runs exactly as written (pipes, globs, `&&`).
|
|
7
7
|
*/
|
|
8
8
|
const verbatim = (cmd) => Object.assign([cmd], { raw: [cmd] });
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
export function command(name, cmd, options = {}) {
|
|
9
|
+
function build(name, cmdOrFile, argsOrOptions, maybeOptions) {
|
|
10
|
+
const hasArgs = Array.isArray(argsOrOptions);
|
|
11
|
+
const args = hasArgs ? argsOrOptions : undefined;
|
|
12
|
+
const options = (hasArgs ? maybeOptions : argsOrOptions) ?? {};
|
|
15
13
|
return action(name).run((ctx) => {
|
|
16
14
|
const cwd = path.resolve(options.cwd ?? ".");
|
|
17
|
-
|
|
15
|
+
const proc = ctx.proc(name, {
|
|
18
16
|
cwd,
|
|
19
17
|
...(options.env ? { env: options.env } : {}),
|
|
20
18
|
...(options.inheritDebugger ? { inheritDebugger: true } : {}),
|
|
21
|
-
})
|
|
19
|
+
});
|
|
20
|
+
// `file, args` form: zx quotes the file and every arg individually (arrays spread), so
|
|
21
|
+
// paths/values with spaces are safe and nothing is re-parsed by the shell. String form:
|
|
22
|
+
// run the whole command verbatim.
|
|
23
|
+
return args ? proc `${cmdOrFile} -- ${args}` : proc(verbatim(cmdOrFile));
|
|
22
24
|
})();
|
|
23
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Runs a shell command as an action instance. Two forms:
|
|
28
|
+
*
|
|
29
|
+
* - `command(name, cmd, options?)` — a full command **string**, run verbatim through the
|
|
30
|
+
* shell, so pipes, globs and `&&` work (quote anything yourself).
|
|
31
|
+
* - `command(name, file, args, options?)` — an executable **plus an args array**; each arg
|
|
32
|
+
* is quoted individually, so spaces and `=`/paths in args are safe without hand-quoting.
|
|
33
|
+
*
|
|
34
|
+
* Output streams into the run's log under `name`; a non-zero exit fails the action;
|
|
35
|
+
* teardown kills the child tree. For interpolated events or a daemon loop, drop to
|
|
36
|
+
* `action(...).run(...)`.
|
|
37
|
+
*/
|
|
38
|
+
export const command = (name, cmdOrFile, argsOrOptions = {}, maybeOptions = {}) => build(name, cmdOrFile, argsOrOptions, maybeOptions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A tiny runtime for developer workflows: typed actions that pass runtime capabilities and emit typed events, under one run and one shared log. The operational/runtime layer to tskb's knowledge layer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|