@openfn/cli 0.0.39 → 0.0.40
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/chunk-UBDWXKSG.js +33 -0
- package/dist/index.js +86 -78
- package/dist/process/runner.js +171 -59
- package/package.json +2 -2
- package/dist/chunk-LV5XDERP.js +0 -165
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/util/expand-adaptors.ts
|
|
2
|
+
var expand = (name) => {
|
|
3
|
+
if (typeof name === "string") {
|
|
4
|
+
const [left] = name.split("=");
|
|
5
|
+
if (left.match("/") || left.endsWith(".js")) {
|
|
6
|
+
return name;
|
|
7
|
+
}
|
|
8
|
+
return `@openfn/language-${name}`;
|
|
9
|
+
}
|
|
10
|
+
return name;
|
|
11
|
+
};
|
|
12
|
+
var expand_adaptors_default = (opts) => {
|
|
13
|
+
const { adaptors, workflow } = opts;
|
|
14
|
+
if (adaptors) {
|
|
15
|
+
opts.adaptors = adaptors?.map(expand);
|
|
16
|
+
}
|
|
17
|
+
if (workflow) {
|
|
18
|
+
Object.values(workflow.jobs).forEach((job) => {
|
|
19
|
+
if (job.adaptor) {
|
|
20
|
+
job.adaptor = expand(job.adaptor);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return opts;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/constants.ts
|
|
28
|
+
var DEFAULT_REPO_DIR = "/tmp/openfn/repo";
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
expand_adaptors_default,
|
|
32
|
+
DEFAULT_REPO_DIR
|
|
33
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
DEFAULT_REPO_DIR,
|
|
4
4
|
expand_adaptors_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-UBDWXKSG.js";
|
|
6
6
|
|
|
7
7
|
// src/process/spawn.ts
|
|
8
8
|
import path from "node:path";
|
|
@@ -34,77 +34,6 @@ function spawn_default(basePath, opts2) {
|
|
|
34
34
|
import yargs from "yargs";
|
|
35
35
|
import { hideBin } from "yargs/helpers";
|
|
36
36
|
|
|
37
|
-
// src/repo/command.ts
|
|
38
|
-
var repo = {
|
|
39
|
-
command: "repo [subcommand]",
|
|
40
|
-
desc: "Run commands on the module repo (install|clean)",
|
|
41
|
-
builder: (yargs2) => yargs2.command(clean).command(install).command(pwd).command(list).example("repo install -a http", "Install @openfn/language-http").example("repo clean", "Remove everything from the repo working dir").example("repo pwd", "Print the current repo working dir")
|
|
42
|
-
};
|
|
43
|
-
var install = {
|
|
44
|
-
command: "install [packages...]",
|
|
45
|
-
desc: "install one or more packages to the runtime repo",
|
|
46
|
-
handler: (argv) => {
|
|
47
|
-
argv.command = "repo-install";
|
|
48
|
-
},
|
|
49
|
-
builder: (yargs2) => {
|
|
50
|
-
return yargs2.option("adaptor", {
|
|
51
|
-
alias: ["a"],
|
|
52
|
-
description: "Install an adaptor by passing a shortened version of the name",
|
|
53
|
-
boolean: true
|
|
54
|
-
}).example("install axios", "Install the axios npm package to the repo").example(
|
|
55
|
-
"install -a http",
|
|
56
|
-
"Install @openfn/language-http adaptor to the repo"
|
|
57
|
-
).example(
|
|
58
|
-
"install @openfn/language-http",
|
|
59
|
-
"Install the language-http adaptor to the repo"
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
var clean = {
|
|
64
|
-
command: "clean",
|
|
65
|
-
desc: "Removes all modules from the runtime module repo",
|
|
66
|
-
handler: (argv) => {
|
|
67
|
-
argv.command = "repo-clean";
|
|
68
|
-
},
|
|
69
|
-
builder: (yargs2) => yargs2.option("force", {
|
|
70
|
-
alias: ["f"],
|
|
71
|
-
description: "Skip the prompt and force deletion",
|
|
72
|
-
boolean: true
|
|
73
|
-
})
|
|
74
|
-
};
|
|
75
|
-
var pwd = {
|
|
76
|
-
command: "pwd",
|
|
77
|
-
desc: "Print repo's current working directory",
|
|
78
|
-
handler: (argv) => {
|
|
79
|
-
argv.command = "repo-pwd";
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
var list = {
|
|
83
|
-
command: "list",
|
|
84
|
-
desc: "Show a report on what is installed in the repo",
|
|
85
|
-
handler: (argv) => {
|
|
86
|
-
argv.command = "repo-list";
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// src/util/command-builders.ts
|
|
91
|
-
var build = (opts2, yargs2) => opts2.reduce((_y, o) => yargs2.option(o.name, o.yargs), yargs2);
|
|
92
|
-
var ensure = (command, opts2) => (yargs2) => {
|
|
93
|
-
yargs2.command = command;
|
|
94
|
-
opts2.filter((opt) => opt.ensure).forEach((opt) => {
|
|
95
|
-
opt.ensure(yargs2);
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
var override = (command, yargs2) => {
|
|
99
|
-
return {
|
|
100
|
-
...command,
|
|
101
|
-
yargs: {
|
|
102
|
-
...command.yargs || {},
|
|
103
|
-
...yargs2
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
|
|
108
37
|
// src/options.ts
|
|
109
38
|
import path2 from "node:path";
|
|
110
39
|
var setDefaultValue = (opts2, key, value) => {
|
|
@@ -259,10 +188,10 @@ var outputPath = {
|
|
|
259
188
|
};
|
|
260
189
|
var repoDir = {
|
|
261
190
|
name: "repo-dir",
|
|
262
|
-
yargs: {
|
|
191
|
+
yargs: () => ({
|
|
263
192
|
description: "Provide a path to the repo root dir",
|
|
264
193
|
default: process.env.OPENFN_REPO_DIR || DEFAULT_REPO_DIR
|
|
265
|
-
}
|
|
194
|
+
})
|
|
266
195
|
};
|
|
267
196
|
var start = {
|
|
268
197
|
name: "start",
|
|
@@ -286,11 +215,11 @@ var strictOutput = {
|
|
|
286
215
|
}
|
|
287
216
|
};
|
|
288
217
|
var strict = {
|
|
289
|
-
name: "
|
|
218
|
+
name: "strict",
|
|
290
219
|
yargs: {
|
|
291
220
|
default: false,
|
|
292
221
|
boolean: true,
|
|
293
|
-
description: "
|
|
222
|
+
description: "Enables strict state handling, meaning only state.data is returned from a job."
|
|
294
223
|
},
|
|
295
224
|
ensure: (opts2) => {
|
|
296
225
|
if (!opts2.hasOwnProperty("strictOutput")) {
|
|
@@ -343,6 +272,85 @@ var useAdaptorsMonorepo = {
|
|
|
343
272
|
}
|
|
344
273
|
};
|
|
345
274
|
|
|
275
|
+
// src/util/command-builders.ts
|
|
276
|
+
var expandYargs = (y2) => {
|
|
277
|
+
if (typeof y2 === "function") {
|
|
278
|
+
return y2();
|
|
279
|
+
}
|
|
280
|
+
return y2;
|
|
281
|
+
};
|
|
282
|
+
var build = (opts2, yargs2) => opts2.reduce((_y, o) => yargs2.option(o.name, expandYargs(o.yargs)), yargs2);
|
|
283
|
+
var ensure = (command, opts2) => (yargs2) => {
|
|
284
|
+
yargs2.command = command;
|
|
285
|
+
opts2.filter((opt) => opt.ensure).forEach((opt) => {
|
|
286
|
+
opt.ensure(yargs2);
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
var override = (command, yargs2) => {
|
|
290
|
+
return {
|
|
291
|
+
...command,
|
|
292
|
+
yargs: {
|
|
293
|
+
...command.yargs || {},
|
|
294
|
+
...yargs2
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/repo/command.ts
|
|
300
|
+
var repo = {
|
|
301
|
+
command: "repo [subcommand]",
|
|
302
|
+
desc: "Run commands on the module repo (install|clean)",
|
|
303
|
+
builder: (yargs2) => yargs2.command(clean).command(install).command(list).example("repo install -a http", "Install @openfn/language-http").example("repo clean", "Remove everything from the repo working dir")
|
|
304
|
+
};
|
|
305
|
+
var installOptions = [
|
|
306
|
+
repoDir,
|
|
307
|
+
override(expandAdaptors, {
|
|
308
|
+
default: true,
|
|
309
|
+
hidden: true
|
|
310
|
+
}),
|
|
311
|
+
override(adaptors, {
|
|
312
|
+
description: "Specify which language-adaptor to install (allows short-form names to be used, eg, http)"
|
|
313
|
+
})
|
|
314
|
+
];
|
|
315
|
+
var install = {
|
|
316
|
+
command: "install [packages...]",
|
|
317
|
+
desc: "install one or more packages to the runtime repo. Use -a to pass shorthand adaptor names.",
|
|
318
|
+
handler: ensure("repo-install", installOptions),
|
|
319
|
+
builder: (yargs2) => build(installOptions, yargs2).example("install axios", "Install the axios npm package to the repo").example(
|
|
320
|
+
"install -a http",
|
|
321
|
+
"Install @openfn/language-http adaptor to the repo"
|
|
322
|
+
).example(
|
|
323
|
+
"install @openfn/language-http",
|
|
324
|
+
"Install the language-http adaptor to the repo"
|
|
325
|
+
)
|
|
326
|
+
};
|
|
327
|
+
var clean = {
|
|
328
|
+
command: "clean",
|
|
329
|
+
desc: "Removes all modules from the runtime module repo",
|
|
330
|
+
handler: ensure("repo-clean", [repoDir]),
|
|
331
|
+
builder: (yargs2) => build(
|
|
332
|
+
[
|
|
333
|
+
repoDir,
|
|
334
|
+
{
|
|
335
|
+
name: "force",
|
|
336
|
+
yargs: {
|
|
337
|
+
alias: ["f"],
|
|
338
|
+
description: "Skip the prompt and force deletion",
|
|
339
|
+
boolean: true
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
],
|
|
343
|
+
yargs2
|
|
344
|
+
)
|
|
345
|
+
};
|
|
346
|
+
var list = {
|
|
347
|
+
command: "list",
|
|
348
|
+
desc: "Show a report on what is installed in the repo",
|
|
349
|
+
aliases: ["$0"],
|
|
350
|
+
handler: ensure("repo-list", [repoDir]),
|
|
351
|
+
builder: (yargs2) => build([repoDir], yargs2)
|
|
352
|
+
};
|
|
353
|
+
|
|
346
354
|
// src/execute/command.ts
|
|
347
355
|
var options = [
|
|
348
356
|
expandAdaptors,
|
|
@@ -383,8 +391,8 @@ Remember to include the adaptor name with -a. Auto install adaptors with the -i
|
|
|
383
391
|
"openfn foo/job.js",
|
|
384
392
|
"Execute foo/job.js with no adaptor and write the final state to foo/job.json"
|
|
385
393
|
).example(
|
|
386
|
-
"openfn workflow.json -
|
|
387
|
-
"Execute workflow.json
|
|
394
|
+
"openfn workflow.json -i",
|
|
395
|
+
"Execute workflow.json with autoinstall enabled"
|
|
388
396
|
).example(
|
|
389
397
|
"openfn job.js -a common --log info",
|
|
390
398
|
"Execute job.js with common adaptor and info-level logging"
|
package/dist/process/runner.js
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
RUNTIME,
|
|
6
|
-
createNullLogger,
|
|
7
|
-
defaultLogger,
|
|
8
|
-
ensureLogOpts,
|
|
9
|
-
ensureOpts,
|
|
10
|
-
expand_adaptors_default,
|
|
11
|
-
logger_default,
|
|
12
|
-
printDuration
|
|
13
|
-
} from "../chunk-LV5XDERP.js";
|
|
2
|
+
DEFAULT_REPO_DIR,
|
|
3
|
+
expand_adaptors_default
|
|
4
|
+
} from "../chunk-UBDWXKSG.js";
|
|
14
5
|
|
|
15
6
|
// src/execute/execute.ts
|
|
16
7
|
import run, { getNameAndVersion } from "@openfn/runtime";
|
|
17
8
|
|
|
9
|
+
// src/util/logger.ts
|
|
10
|
+
import actualCreateLogger, { printDuration } from "@openfn/logger";
|
|
11
|
+
import { isValidLogLevel, defaultLogger } from "@openfn/logger";
|
|
12
|
+
var CLI = "cli";
|
|
13
|
+
var COMPILER = "compiler";
|
|
14
|
+
var RUNTIME = "runtime";
|
|
15
|
+
var JOB = "job";
|
|
16
|
+
var namespaces = {
|
|
17
|
+
[CLI]: "CLI",
|
|
18
|
+
[RUNTIME]: "R/T",
|
|
19
|
+
[COMPILER]: "CMP",
|
|
20
|
+
[JOB]: "JOB"
|
|
21
|
+
};
|
|
22
|
+
var createLogger = (name = "", options) => {
|
|
23
|
+
const logOptions = options.log || {};
|
|
24
|
+
let json = false;
|
|
25
|
+
let level = logOptions[name] || logOptions.default || "default";
|
|
26
|
+
if (options.logJson) {
|
|
27
|
+
json = true;
|
|
28
|
+
}
|
|
29
|
+
return actualCreateLogger(namespaces[name] || name, {
|
|
30
|
+
level,
|
|
31
|
+
json,
|
|
32
|
+
...logOptions
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
var logger_default = createLogger;
|
|
36
|
+
var createNullLogger = () => createLogger(void 0, { log: { default: "none" } });
|
|
37
|
+
|
|
18
38
|
// src/util/abort.ts
|
|
19
39
|
var AbortError = class extends Error {
|
|
20
40
|
constructor(reason) {
|
|
@@ -58,13 +78,13 @@ var execute_default = async (input, state, opts, logger) => {
|
|
|
58
78
|
};
|
|
59
79
|
function parseAdaptors(opts) {
|
|
60
80
|
const extractInfo = (specifier) => {
|
|
61
|
-
const [module,
|
|
81
|
+
const [module, path7] = specifier.split("=");
|
|
62
82
|
const { name, version } = getNameAndVersion(module);
|
|
63
83
|
const info = {
|
|
64
84
|
name
|
|
65
85
|
};
|
|
66
|
-
if (
|
|
67
|
-
info.path =
|
|
86
|
+
if (path7) {
|
|
87
|
+
info.path = path7;
|
|
68
88
|
}
|
|
69
89
|
if (version) {
|
|
70
90
|
info.version = version;
|
|
@@ -145,16 +165,13 @@ import { exec } from "node:child_process";
|
|
|
145
165
|
import treeify from "treeify";
|
|
146
166
|
import { install as rtInstall, loadRepoPkg } from "@openfn/runtime";
|
|
147
167
|
var install = async (opts, log = defaultLogger) => {
|
|
148
|
-
let { packages,
|
|
149
|
-
|
|
168
|
+
let { packages, adaptors, repoDir } = opts;
|
|
169
|
+
const targets = [].concat(packages ?? [], adaptors ?? []);
|
|
170
|
+
if (targets) {
|
|
150
171
|
log.timer("install");
|
|
151
172
|
log.success("Installing packages...");
|
|
152
173
|
log.debug("repoDir is set to:", repoDir);
|
|
153
|
-
|
|
154
|
-
const expanded = expand_adaptors_default({ adaptors: packages });
|
|
155
|
-
packages = expanded.adaptors;
|
|
156
|
-
}
|
|
157
|
-
await rtInstall(packages ?? [], repoDir, log);
|
|
174
|
+
await rtInstall(targets, repoDir, log);
|
|
158
175
|
const duration = log.timer("install");
|
|
159
176
|
log.success(`Installation complete in ${duration}`);
|
|
160
177
|
}
|
|
@@ -269,10 +286,10 @@ var stripVersionSpecifier = (specifier) => {
|
|
|
269
286
|
return specifier;
|
|
270
287
|
};
|
|
271
288
|
var resolveSpecifierPath = async (pattern, repoDir, log) => {
|
|
272
|
-
const [specifier,
|
|
273
|
-
if (
|
|
274
|
-
log.debug(`Resolved ${specifier} to path: ${
|
|
275
|
-
return
|
|
289
|
+
const [specifier, path7] = pattern.split("=");
|
|
290
|
+
if (path7) {
|
|
291
|
+
log.debug(`Resolved ${specifier} to path: ${path7}`);
|
|
292
|
+
return path7;
|
|
276
293
|
}
|
|
277
294
|
const repoPath = await getModulePath(specifier, repoDir, log);
|
|
278
295
|
if (repoPath) {
|
|
@@ -289,16 +306,16 @@ var loadTransformOptions = async (opts, log) => {
|
|
|
289
306
|
const [pattern] = opts.adaptors;
|
|
290
307
|
const [specifier] = pattern.split("=");
|
|
291
308
|
log.debug(`Attempting to preload types for ${specifier}`);
|
|
292
|
-
const
|
|
293
|
-
if (
|
|
309
|
+
const path7 = await resolveSpecifierPath(pattern, opts.repoDir, log);
|
|
310
|
+
if (path7) {
|
|
294
311
|
try {
|
|
295
312
|
exports = await preloadAdaptorExports(
|
|
296
|
-
|
|
313
|
+
path7,
|
|
297
314
|
opts.useAdaptorsMonorepo,
|
|
298
315
|
log
|
|
299
316
|
);
|
|
300
317
|
} catch (e) {
|
|
301
|
-
log.error(`Failed to load adaptor typedefs from path ${
|
|
318
|
+
log.error(`Failed to load adaptor typedefs from path ${path7}`);
|
|
302
319
|
log.error(e);
|
|
303
320
|
}
|
|
304
321
|
}
|
|
@@ -620,20 +637,20 @@ var RETRY_COUNT = 20;
|
|
|
620
637
|
var TIMEOUT_MS = 1e3 * 60;
|
|
621
638
|
var actualDocGen = (specifier) => describePackage(specifier, {});
|
|
622
639
|
var ensurePath = (filePath) => mkdirSync(path2.dirname(filePath), { recursive: true });
|
|
623
|
-
var generatePlaceholder = (
|
|
624
|
-
writeFileSync(
|
|
640
|
+
var generatePlaceholder = (path7) => {
|
|
641
|
+
writeFileSync(path7, `{ "loading": true, "timestamp": ${Date.now()}}`);
|
|
625
642
|
};
|
|
626
643
|
var finish = (logger, resultPath) => {
|
|
627
644
|
logger.success("Done! Docs can be found at:\n");
|
|
628
645
|
logger.print(` ${path2.resolve(resultPath)}`);
|
|
629
646
|
};
|
|
630
|
-
var generateDocs = async (specifier,
|
|
647
|
+
var generateDocs = async (specifier, path7, docgen, logger) => {
|
|
631
648
|
const result = await docgen(specifier);
|
|
632
|
-
await writeFile3(
|
|
633
|
-
finish(logger,
|
|
634
|
-
return
|
|
649
|
+
await writeFile3(path7, JSON.stringify(result, null, 2));
|
|
650
|
+
finish(logger, path7);
|
|
651
|
+
return path7;
|
|
635
652
|
};
|
|
636
|
-
var waitForDocs = async (docs,
|
|
653
|
+
var waitForDocs = async (docs, path7, logger, retryDuration = RETRY_DURATION) => {
|
|
637
654
|
try {
|
|
638
655
|
if (docs.hasOwnProperty("loading")) {
|
|
639
656
|
logger.info("Docs are being loaded by another process. Waiting.");
|
|
@@ -645,19 +662,19 @@ var waitForDocs = async (docs, path6, logger, retryDuration = RETRY_DURATION) =>
|
|
|
645
662
|
clearInterval(i);
|
|
646
663
|
reject(new Error("Timed out waiting for docs to load"));
|
|
647
664
|
}
|
|
648
|
-
const updated = JSON.parse(readFileSync(
|
|
665
|
+
const updated = JSON.parse(readFileSync(path7, "utf8"));
|
|
649
666
|
if (!updated.hasOwnProperty("loading")) {
|
|
650
667
|
logger.info("Docs found!");
|
|
651
668
|
clearInterval(i);
|
|
652
|
-
resolve(
|
|
669
|
+
resolve(path7);
|
|
653
670
|
}
|
|
654
671
|
count++;
|
|
655
672
|
}, retryDuration);
|
|
656
673
|
});
|
|
657
674
|
} else {
|
|
658
|
-
logger.info(`Docs already written to cache at ${
|
|
659
|
-
finish(logger,
|
|
660
|
-
return
|
|
675
|
+
logger.info(`Docs already written to cache at ${path7}`);
|
|
676
|
+
finish(logger, path7);
|
|
677
|
+
return path7;
|
|
661
678
|
}
|
|
662
679
|
} catch (e) {
|
|
663
680
|
logger.error("Existing doc JSON corrupt. Aborting");
|
|
@@ -674,28 +691,28 @@ var docgenHandler = (options, logger, docgen = actualDocGen, retryDuration = RET
|
|
|
674
691
|
process.exit(9);
|
|
675
692
|
}
|
|
676
693
|
logger.success(`Generating docs for ${specifier}`);
|
|
677
|
-
const
|
|
678
|
-
ensurePath(
|
|
694
|
+
const path7 = `${repoDir}/docs/${specifier}.json`;
|
|
695
|
+
ensurePath(path7);
|
|
679
696
|
const handleError = () => {
|
|
680
697
|
logger.info("Removing placeholder");
|
|
681
|
-
rmSync(
|
|
698
|
+
rmSync(path7);
|
|
682
699
|
};
|
|
683
700
|
try {
|
|
684
|
-
const existing = readFileSync(
|
|
701
|
+
const existing = readFileSync(path7, "utf8");
|
|
685
702
|
const json = JSON.parse(existing);
|
|
686
703
|
if (json && json.timeout && Date.now() - json.timeout >= TIMEOUT_MS) {
|
|
687
704
|
logger.info(`Expired placeholder found. Removing.`);
|
|
688
|
-
rmSync(
|
|
705
|
+
rmSync(path7);
|
|
689
706
|
throw new Error("TIMEOUT");
|
|
690
707
|
}
|
|
691
|
-
return waitForDocs(json,
|
|
708
|
+
return waitForDocs(json, path7, logger, retryDuration);
|
|
692
709
|
} catch (e) {
|
|
693
710
|
if (e.message !== "TIMEOUT") {
|
|
694
|
-
logger.info(`Docs JSON not found at ${
|
|
711
|
+
logger.info(`Docs JSON not found at ${path7}`);
|
|
695
712
|
}
|
|
696
713
|
logger.debug("Generating placeholder");
|
|
697
|
-
generatePlaceholder(
|
|
698
|
-
return generateDocs(specifier,
|
|
714
|
+
generatePlaceholder(path7);
|
|
715
|
+
return generateDocs(specifier, path7, docgen, logger).catch((e2) => {
|
|
699
716
|
logger.error("Error generating documentation");
|
|
700
717
|
logger.error(e2);
|
|
701
718
|
handleError();
|
|
@@ -744,7 +761,7 @@ var docsHandler = async (options, logger) => {
|
|
|
744
761
|
logger.success(`Showing docs for ${adaptorName} v${version}`);
|
|
745
762
|
}
|
|
746
763
|
logger.info("Generating/loading documentation...");
|
|
747
|
-
const
|
|
764
|
+
const path7 = await handler_default4(
|
|
748
765
|
{
|
|
749
766
|
specifier: `${name}@${version}`,
|
|
750
767
|
repoDir
|
|
@@ -752,8 +769,8 @@ var docsHandler = async (options, logger) => {
|
|
|
752
769
|
createNullLogger()
|
|
753
770
|
);
|
|
754
771
|
let didError = false;
|
|
755
|
-
if (
|
|
756
|
-
const source = await readFile(
|
|
772
|
+
if (path7) {
|
|
773
|
+
const source = await readFile(path7, "utf8");
|
|
757
774
|
const data = JSON.parse(source);
|
|
758
775
|
let desc;
|
|
759
776
|
if (operation) {
|
|
@@ -899,9 +916,104 @@ var metadataHandler = async (options, logger) => {
|
|
|
899
916
|
};
|
|
900
917
|
var handler_default6 = metadataHandler;
|
|
901
918
|
|
|
919
|
+
// src/util/ensure-opts.ts
|
|
920
|
+
import path4 from "node:path";
|
|
921
|
+
var defaultLoggerOptions = {
|
|
922
|
+
default: "default",
|
|
923
|
+
job: "debug"
|
|
924
|
+
};
|
|
925
|
+
var ERROR_MESSAGE_LOG_LEVEL = "Unknown log level. Valid levels are none, debug, info and default.";
|
|
926
|
+
var ERROR_MESSAGE_LOG_COMPONENT = "Unknown log component. Valid components are cli, compiler, runtime and job.";
|
|
927
|
+
var componentShorthands = {
|
|
928
|
+
cmp: "compiler",
|
|
929
|
+
rt: "runtime",
|
|
930
|
+
"r/t": "runtime"
|
|
931
|
+
};
|
|
932
|
+
var isValidComponent = (v) => /^(cli|runtime|compiler|job|default)$/i.test(v);
|
|
933
|
+
var ensureLogOpts = (opts) => {
|
|
934
|
+
const components = {};
|
|
935
|
+
if (!opts.log && /^(version|test)$/.test(opts.command)) {
|
|
936
|
+
opts.log = { default: "info" };
|
|
937
|
+
return opts;
|
|
938
|
+
} else if (opts.log) {
|
|
939
|
+
opts.log.forEach((l) => {
|
|
940
|
+
let component = "";
|
|
941
|
+
let level = "";
|
|
942
|
+
if (l.match(/=/)) {
|
|
943
|
+
const parts = l.split("=");
|
|
944
|
+
component = parts[0].toLowerCase();
|
|
945
|
+
if (componentShorthands[component]) {
|
|
946
|
+
component = componentShorthands[component];
|
|
947
|
+
}
|
|
948
|
+
level = parts[1].toLowerCase();
|
|
949
|
+
} else {
|
|
950
|
+
component = "default";
|
|
951
|
+
level = l.toLowerCase();
|
|
952
|
+
}
|
|
953
|
+
if (!isValidComponent(component)) {
|
|
954
|
+
throw new Error(ERROR_MESSAGE_LOG_COMPONENT);
|
|
955
|
+
}
|
|
956
|
+
level = level.toLowerCase();
|
|
957
|
+
if (!isValidLogLevel(level)) {
|
|
958
|
+
throw new Error(ERROR_MESSAGE_LOG_LEVEL);
|
|
959
|
+
}
|
|
960
|
+
components[component] = level;
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
opts.log = {
|
|
964
|
+
...defaultLoggerOptions,
|
|
965
|
+
...components
|
|
966
|
+
};
|
|
967
|
+
return opts;
|
|
968
|
+
};
|
|
969
|
+
function ensureOpts(basePath = ".", opts) {
|
|
970
|
+
const newOpts = {
|
|
971
|
+
adaptor: opts.adaptor,
|
|
972
|
+
adaptors: opts.adaptors || [],
|
|
973
|
+
autoinstall: opts.autoinstall,
|
|
974
|
+
command: opts.command,
|
|
975
|
+
expandAdaptors: opts.expandAdaptors !== false,
|
|
976
|
+
force: opts.force || false,
|
|
977
|
+
immutable: opts.immutable || false,
|
|
978
|
+
log: opts.log,
|
|
979
|
+
logJson: typeof opts.logJson == "boolean" ? opts.logJson : Boolean(process.env.OPENFN_LOG_JSON),
|
|
980
|
+
compile: Boolean(opts.compile),
|
|
981
|
+
operation: opts.operation,
|
|
982
|
+
outputStdout: Boolean(opts.outputStdout),
|
|
983
|
+
packages: opts.packages,
|
|
984
|
+
repoDir: opts.repoDir || process.env.OPENFN_REPO_DIR || DEFAULT_REPO_DIR,
|
|
985
|
+
skipAdaptorValidation: opts.skipAdaptorValidation ?? false,
|
|
986
|
+
specifier: opts.specifier,
|
|
987
|
+
stateStdin: opts.stateStdin,
|
|
988
|
+
timeout: opts.timeout
|
|
989
|
+
};
|
|
990
|
+
const set2 = (key, value) => {
|
|
991
|
+
newOpts[key] = opts.hasOwnProperty(key) ? opts[key] : value;
|
|
992
|
+
};
|
|
993
|
+
if (opts.useAdaptorsMonorepo) {
|
|
994
|
+
newOpts.monorepoPath = process.env.OPENFN_ADAPTORS_REPO || "ERR";
|
|
995
|
+
}
|
|
996
|
+
let baseDir = basePath;
|
|
997
|
+
if (basePath.endsWith(".js")) {
|
|
998
|
+
baseDir = path4.dirname(basePath);
|
|
999
|
+
set2("jobPath", basePath);
|
|
1000
|
+
} else {
|
|
1001
|
+
set2("jobPath", `${baseDir}/job.js`);
|
|
1002
|
+
}
|
|
1003
|
+
set2("statePath", `${baseDir}/state.json`);
|
|
1004
|
+
if (!opts.outputStdout) {
|
|
1005
|
+
set2(
|
|
1006
|
+
"outputPath",
|
|
1007
|
+
newOpts.command === "compile" ? `${baseDir}/output.js` : `${baseDir}/output.json`
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
ensureLogOpts(newOpts);
|
|
1011
|
+
return newOpts;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
902
1014
|
// src/util/use-adaptors-repo.ts
|
|
903
1015
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
904
|
-
import
|
|
1016
|
+
import path5 from "node:path";
|
|
905
1017
|
import assert from "node:assert";
|
|
906
1018
|
import { getNameAndVersion as getNameAndVersion5 } from "@openfn/runtime";
|
|
907
1019
|
var validateMonoRepo = async (repoPath, log) => {
|
|
@@ -925,7 +1037,7 @@ var updatePath = (adaptor, repoPath, log) => {
|
|
|
925
1037
|
);
|
|
926
1038
|
}
|
|
927
1039
|
const shortName = name.replace("@openfn/language-", "");
|
|
928
|
-
const abspath =
|
|
1040
|
+
const abspath = path5.resolve(repoPath, "packages", shortName);
|
|
929
1041
|
return `${name}=${abspath}`;
|
|
930
1042
|
};
|
|
931
1043
|
var useAdaptorsRepo = async (adaptors, repoPath, log) => {
|
|
@@ -942,7 +1054,7 @@ var use_adaptors_repo_default = useAdaptorsRepo;
|
|
|
942
1054
|
|
|
943
1055
|
// src/util/print-versions.ts
|
|
944
1056
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
945
|
-
import
|
|
1057
|
+
import path6 from "node:path";
|
|
946
1058
|
import { getNameAndVersion as getNameAndVersion6 } from "@openfn/runtime";
|
|
947
1059
|
import { mainSymbols } from "figures";
|
|
948
1060
|
var NODE = "node.js";
|
|
@@ -952,7 +1064,7 @@ var COMPILER2 = "compiler";
|
|
|
952
1064
|
var { triangleRightSmall: t } = mainSymbols;
|
|
953
1065
|
var loadVersionFromPath = (adaptorPath) => {
|
|
954
1066
|
try {
|
|
955
|
-
const pkg = JSON.parse(readFileSync3(
|
|
1067
|
+
const pkg = JSON.parse(readFileSync3(path6.resolve(adaptorPath, "package.json"), "utf8"));
|
|
956
1068
|
return pkg.version;
|
|
957
1069
|
} catch (e) {
|
|
958
1070
|
return "unknown";
|
|
@@ -1029,7 +1141,7 @@ var handlers = {
|
|
|
1029
1141
|
["repo-list"]: list,
|
|
1030
1142
|
version: async (opts, logger) => print_versions_default(logger, opts)
|
|
1031
1143
|
};
|
|
1032
|
-
var maybeEnsureOpts = (basePath, options) =>
|
|
1144
|
+
var maybeEnsureOpts = (basePath, options) => /(^(execute|compile|test)$)|(repo-)/.test(options.command) ? ensureLogOpts(options) : ensureOpts(basePath, options);
|
|
1033
1145
|
var parse = async (basePath, options, log) => {
|
|
1034
1146
|
const opts = maybeEnsureOpts(basePath, options);
|
|
1035
1147
|
const logger = log || logger_default(CLI, opts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
4
4
|
"description": "CLI devtools for the openfn toolchain.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@openfn/compiler": "0.0.32",
|
|
40
40
|
"@openfn/describe-package": "0.0.16",
|
|
41
41
|
"@openfn/logger": "0.0.13",
|
|
42
|
-
"@openfn/runtime": "0.0.
|
|
42
|
+
"@openfn/runtime": "0.0.25",
|
|
43
43
|
"figures": "^5.0.0",
|
|
44
44
|
"rimraf": "^3.0.2",
|
|
45
45
|
"treeify": "^1.1.0",
|
package/dist/chunk-LV5XDERP.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// src/util/expand-adaptors.ts
|
|
2
|
-
var expand = (name) => {
|
|
3
|
-
if (typeof name === "string") {
|
|
4
|
-
const [left] = name.split("=");
|
|
5
|
-
if (left.match("/") || left.endsWith(".js")) {
|
|
6
|
-
return name;
|
|
7
|
-
}
|
|
8
|
-
return `@openfn/language-${name}`;
|
|
9
|
-
}
|
|
10
|
-
return name;
|
|
11
|
-
};
|
|
12
|
-
var expand_adaptors_default = (opts) => {
|
|
13
|
-
const { adaptors, workflow } = opts;
|
|
14
|
-
if (adaptors) {
|
|
15
|
-
opts.adaptors = adaptors?.map(expand);
|
|
16
|
-
}
|
|
17
|
-
if (workflow) {
|
|
18
|
-
Object.values(workflow.jobs).forEach((job) => {
|
|
19
|
-
if (job.adaptor) {
|
|
20
|
-
job.adaptor = expand(job.adaptor);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
return opts;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// src/util/logger.ts
|
|
28
|
-
import actualCreateLogger, { printDuration } from "@openfn/logger";
|
|
29
|
-
import { isValidLogLevel, defaultLogger } from "@openfn/logger";
|
|
30
|
-
var CLI = "cli";
|
|
31
|
-
var COMPILER = "compiler";
|
|
32
|
-
var RUNTIME = "runtime";
|
|
33
|
-
var JOB = "job";
|
|
34
|
-
var namespaces = {
|
|
35
|
-
[CLI]: "CLI",
|
|
36
|
-
[RUNTIME]: "R/T",
|
|
37
|
-
[COMPILER]: "CMP",
|
|
38
|
-
[JOB]: "JOB"
|
|
39
|
-
};
|
|
40
|
-
var createLogger = (name = "", options) => {
|
|
41
|
-
const logOptions = options.log || {};
|
|
42
|
-
let json = false;
|
|
43
|
-
let level = logOptions[name] || logOptions.default || "default";
|
|
44
|
-
if (options.logJson) {
|
|
45
|
-
json = true;
|
|
46
|
-
}
|
|
47
|
-
return actualCreateLogger(namespaces[name] || name, {
|
|
48
|
-
level,
|
|
49
|
-
json,
|
|
50
|
-
...logOptions
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
var logger_default = createLogger;
|
|
54
|
-
var createNullLogger = () => createLogger(void 0, { log: { default: "none" } });
|
|
55
|
-
|
|
56
|
-
// src/util/ensure-opts.ts
|
|
57
|
-
import path from "node:path";
|
|
58
|
-
var defaultLoggerOptions = {
|
|
59
|
-
default: "default",
|
|
60
|
-
job: "debug"
|
|
61
|
-
};
|
|
62
|
-
var ERROR_MESSAGE_LOG_LEVEL = "Unknown log level. Valid levels are none, debug, info and default.";
|
|
63
|
-
var ERROR_MESSAGE_LOG_COMPONENT = "Unknown log component. Valid components are cli, compiler, runtime and job.";
|
|
64
|
-
var DEFAULT_REPO_DIR = "/tmp/openfn/repo";
|
|
65
|
-
var componentShorthands = {
|
|
66
|
-
cmp: "compiler",
|
|
67
|
-
rt: "runtime",
|
|
68
|
-
"r/t": "runtime"
|
|
69
|
-
};
|
|
70
|
-
var isValidComponent = (v) => /^(cli|runtime|compiler|job|default)$/i.test(v);
|
|
71
|
-
var ensureLogOpts = (opts) => {
|
|
72
|
-
const components = {};
|
|
73
|
-
if (!opts.log && /^(version|test)$/.test(opts.command)) {
|
|
74
|
-
opts.log = { default: "info" };
|
|
75
|
-
return opts;
|
|
76
|
-
} else if (opts.log) {
|
|
77
|
-
opts.log.forEach((l) => {
|
|
78
|
-
let component = "";
|
|
79
|
-
let level = "";
|
|
80
|
-
if (l.match(/=/)) {
|
|
81
|
-
const parts = l.split("=");
|
|
82
|
-
component = parts[0].toLowerCase();
|
|
83
|
-
if (componentShorthands[component]) {
|
|
84
|
-
component = componentShorthands[component];
|
|
85
|
-
}
|
|
86
|
-
level = parts[1].toLowerCase();
|
|
87
|
-
} else {
|
|
88
|
-
component = "default";
|
|
89
|
-
level = l.toLowerCase();
|
|
90
|
-
}
|
|
91
|
-
if (!isValidComponent(component)) {
|
|
92
|
-
throw new Error(ERROR_MESSAGE_LOG_COMPONENT);
|
|
93
|
-
}
|
|
94
|
-
level = level.toLowerCase();
|
|
95
|
-
if (!isValidLogLevel(level)) {
|
|
96
|
-
throw new Error(ERROR_MESSAGE_LOG_LEVEL);
|
|
97
|
-
}
|
|
98
|
-
components[component] = level;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
opts.log = {
|
|
102
|
-
...defaultLoggerOptions,
|
|
103
|
-
...components
|
|
104
|
-
};
|
|
105
|
-
return opts;
|
|
106
|
-
};
|
|
107
|
-
function ensureOpts(basePath = ".", opts) {
|
|
108
|
-
const newOpts = {
|
|
109
|
-
adaptor: opts.adaptor,
|
|
110
|
-
adaptors: opts.adaptors || [],
|
|
111
|
-
autoinstall: opts.autoinstall,
|
|
112
|
-
command: opts.command,
|
|
113
|
-
expandAdaptors: opts.expandAdaptors !== false,
|
|
114
|
-
force: opts.force || false,
|
|
115
|
-
immutable: opts.immutable || false,
|
|
116
|
-
log: opts.log,
|
|
117
|
-
logJson: typeof opts.logJson == "boolean" ? opts.logJson : Boolean(process.env.OPENFN_LOG_JSON),
|
|
118
|
-
compile: Boolean(opts.compile),
|
|
119
|
-
operation: opts.operation,
|
|
120
|
-
outputStdout: Boolean(opts.outputStdout),
|
|
121
|
-
packages: opts.packages,
|
|
122
|
-
repoDir: opts.repoDir || process.env.OPENFN_REPO_DIR || DEFAULT_REPO_DIR,
|
|
123
|
-
skipAdaptorValidation: opts.skipAdaptorValidation ?? false,
|
|
124
|
-
specifier: opts.specifier,
|
|
125
|
-
stateStdin: opts.stateStdin,
|
|
126
|
-
timeout: opts.timeout
|
|
127
|
-
};
|
|
128
|
-
const set = (key, value) => {
|
|
129
|
-
newOpts[key] = opts.hasOwnProperty(key) ? opts[key] : value;
|
|
130
|
-
};
|
|
131
|
-
if (opts.useAdaptorsMonorepo) {
|
|
132
|
-
newOpts.monorepoPath = process.env.OPENFN_ADAPTORS_REPO || "ERR";
|
|
133
|
-
}
|
|
134
|
-
let baseDir = basePath;
|
|
135
|
-
if (basePath.endsWith(".js")) {
|
|
136
|
-
baseDir = path.dirname(basePath);
|
|
137
|
-
set("jobPath", basePath);
|
|
138
|
-
} else {
|
|
139
|
-
set("jobPath", `${baseDir}/job.js`);
|
|
140
|
-
}
|
|
141
|
-
set("statePath", `${baseDir}/state.json`);
|
|
142
|
-
if (!opts.outputStdout) {
|
|
143
|
-
set(
|
|
144
|
-
"outputPath",
|
|
145
|
-
newOpts.command === "compile" ? `${baseDir}/output.js` : `${baseDir}/output.json`
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
ensureLogOpts(newOpts);
|
|
149
|
-
return newOpts;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export {
|
|
153
|
-
expand_adaptors_default,
|
|
154
|
-
printDuration,
|
|
155
|
-
CLI,
|
|
156
|
-
COMPILER,
|
|
157
|
-
RUNTIME,
|
|
158
|
-
JOB,
|
|
159
|
-
logger_default,
|
|
160
|
-
createNullLogger,
|
|
161
|
-
defaultLogger,
|
|
162
|
-
DEFAULT_REPO_DIR,
|
|
163
|
-
ensureLogOpts,
|
|
164
|
-
ensureOpts
|
|
165
|
-
};
|