zorb 0.0.2 → 0.0.3
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/runners/run.cjs +59 -0
- package/dist/runners/run.mjs +61 -0
- package/dist/runners/run.py +31 -0
- package/dist/runners/run.ts +60 -0
- package/dist/zorb +0 -0
- package/package.json +9 -4
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file should not be bundled into Deno - it's a Javascript wrapper to load a file & run a function
|
|
3
|
+
*/
|
|
4
|
+
// deno-lint-ignore-file no-process-global
|
|
5
|
+
const { resolve } = require("node:path");
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
// node run.cjs <modulePath> <symbol> <inputsJson>
|
|
9
|
+
const [, , modulePath, symbol, inputsJson = "{}"] = process.argv;
|
|
10
|
+
|
|
11
|
+
if (!modulePath || !symbol) {
|
|
12
|
+
console.error(
|
|
13
|
+
"Usage: node run.cjs <modulePath> <symbol> <inputsJson> <ctxJson>",
|
|
14
|
+
);
|
|
15
|
+
process.exit(2);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let inputs;
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
inputs = JSON.parse(inputsJson);
|
|
22
|
+
} catch {
|
|
23
|
+
console.error("Invalid inputs JSON");
|
|
24
|
+
process.exit(2);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Resolve to absolute path so require() is deterministic
|
|
28
|
+
const absPath = resolve(modulePath);
|
|
29
|
+
|
|
30
|
+
let mod;
|
|
31
|
+
try {
|
|
32
|
+
mod = require(absPath);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error(`Failed to import ${absPath}`);
|
|
35
|
+
console.error(err);
|
|
36
|
+
process.exit(3);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const fn = mod[symbol];
|
|
40
|
+
if (typeof fn !== "function") {
|
|
41
|
+
console.error(`Export "${symbol}" is not a function in ${absPath}`);
|
|
42
|
+
process.exit(4);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const result = fn(inputs);
|
|
47
|
+
if (result && typeof result.then === "function") {
|
|
48
|
+
await result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
process.exit(0);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error(`Error running ${symbol} from ${absPath}`);
|
|
54
|
+
console.error(err);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
main();
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file should not be bundled into Deno - it's a Javascript wrapper to load a file & run a function
|
|
3
|
+
*/
|
|
4
|
+
// deno-lint-ignore-file no-process-global
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
// node run.mjs <modulePath> <symbol> <inputsJson>
|
|
10
|
+
const [, , modulePath, symbol, inputsJson = "{}"] = process.argv;
|
|
11
|
+
|
|
12
|
+
if (!modulePath || !symbol) {
|
|
13
|
+
console.error(
|
|
14
|
+
"Usage: node run.mjs <modulePath> <symbol> <inputsJson> <ctxJson>",
|
|
15
|
+
);
|
|
16
|
+
process.exit(2);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let inputs;
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
inputs = JSON.parse(inputsJson);
|
|
23
|
+
} catch {
|
|
24
|
+
console.error("Invalid inputs JSON");
|
|
25
|
+
process.exit(2);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Resolve to absolute path so import() is deterministic
|
|
29
|
+
const absPath = resolve(modulePath);
|
|
30
|
+
const { href: moduleUrl } = pathToFileURL(absPath);
|
|
31
|
+
|
|
32
|
+
let mod;
|
|
33
|
+
try {
|
|
34
|
+
mod = await import(moduleUrl);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error(`Failed to import ${absPath}`);
|
|
37
|
+
console.error(err);
|
|
38
|
+
process.exit(3);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const fn = mod[symbol];
|
|
42
|
+
if (typeof fn !== "function") {
|
|
43
|
+
console.error(`Export "${symbol}" is not a function in ${absPath}`);
|
|
44
|
+
process.exit(4);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const result = fn(inputs);
|
|
49
|
+
if (result && typeof result.then === "function") {
|
|
50
|
+
await result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
process.exit(0);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error(`Error running ${symbol} from ${absPath}`);
|
|
56
|
+
console.error(err);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
main();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Usage: python run.py <modulePath> <symbol> <inputsJson>
|
|
2
|
+
import importlib.util, json, sys, traceback
|
|
3
|
+
|
|
4
|
+
if len(sys.argv) < 3:
|
|
5
|
+
print("Usage: run.py <modulePath> <symbol> <inputsJson>", file=sys.stderr)
|
|
6
|
+
sys.exit(2)
|
|
7
|
+
|
|
8
|
+
module_path = sys.argv[1]
|
|
9
|
+
symbol = sys.argv[2]
|
|
10
|
+
inputs = json.loads(sys.argv[3]) if len(sys.argv) > 3 else {}
|
|
11
|
+
|
|
12
|
+
spec = importlib.util.spec_from_file_location("zorb_user_module", module_path)
|
|
13
|
+
if spec is None or spec.loader is None:
|
|
14
|
+
print(f"Failed to load module from {module_path}", file=sys.stderr)
|
|
15
|
+
sys.exit(3)
|
|
16
|
+
|
|
17
|
+
mod = importlib.util.module_from_spec(spec)
|
|
18
|
+
spec.loader.exec_module(mod)
|
|
19
|
+
|
|
20
|
+
fn = getattr(mod, symbol, None)
|
|
21
|
+
if not callable(fn):
|
|
22
|
+
print(f'Symbol "{symbol}" is not callable in {module_path}', file=sys.stderr)
|
|
23
|
+
sys.exit(4)
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
res = fn(inputs)
|
|
27
|
+
# If you want async python support, you can detect coroutine and run it.
|
|
28
|
+
sys.exit(0)
|
|
29
|
+
except Exception:
|
|
30
|
+
traceback.print_exc()
|
|
31
|
+
sys.exit(1)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file should not be bundled into Deno - it's a Typescript wrapper to load a file & run a function
|
|
3
|
+
*/
|
|
4
|
+
// deno-lint-ignore-file no-process-global
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
import { resolve } from 'node:path';
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
// tsx run.ts <modulePath> <symbol> <inputsJson>
|
|
10
|
+
const [, , modulePath, symbol, inputsJson = '{}'] = process.argv;
|
|
11
|
+
|
|
12
|
+
if (!modulePath || !symbol) {
|
|
13
|
+
console.error('Usage: tsx run.ts <modulePath> <symbol> <inputsJson> <ctxJson>');
|
|
14
|
+
process.exit(2);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let inputs: unknown;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
inputs = JSON.parse(inputsJson);
|
|
21
|
+
} catch {
|
|
22
|
+
console.error('Invalid inputs JSON');
|
|
23
|
+
process.exit(2);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Resolve to absolute path so import() is deterministic
|
|
27
|
+
const absPath = resolve(modulePath);
|
|
28
|
+
const { href: moduleUrl } = pathToFileURL(absPath);
|
|
29
|
+
|
|
30
|
+
let mod: Record<string, unknown>;
|
|
31
|
+
try {
|
|
32
|
+
mod = await import(moduleUrl);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error(`Failed to import ${absPath}`);
|
|
35
|
+
console.error(err);
|
|
36
|
+
process.exit(3);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const fn = mod![symbol];
|
|
40
|
+
if (typeof fn !== 'function') {
|
|
41
|
+
console.error(`Export "${symbol}" is not a function in ${absPath}`);
|
|
42
|
+
process.exit(4);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
// deno-lint-ignore no-explicit-any
|
|
47
|
+
const result = (fn as any)(inputs);
|
|
48
|
+
if (result && typeof result.then === 'function') {
|
|
49
|
+
await result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
process.exit(0);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error(`Error running ${symbol} from ${absPath}`);
|
|
55
|
+
console.error(err);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
main();
|
package/dist/zorb
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zorb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Standalone workflow runner",
|
|
5
|
-
"bin":
|
|
5
|
+
"bin": {
|
|
6
|
+
"zorb": "dist/zorb"
|
|
7
|
+
},
|
|
6
8
|
"author": "jdrydn <james@jdrydn.com> (https://jdrydn.com)",
|
|
7
9
|
"license": "MIT",
|
|
8
|
-
"repository":
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/jdrydn/zorb.git"
|
|
13
|
+
},
|
|
9
14
|
"bugs": "https://github.com/jdrydn/zorb/issues",
|
|
10
15
|
"homepage": "https://github.com/jdrydn/zorb",
|
|
11
16
|
"files": [
|
|
12
|
-
"./dist
|
|
17
|
+
"./dist"
|
|
13
18
|
]
|
|
14
19
|
}
|