@openfn/cli 0.2.4 → 0.4.0
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/README.md +1 -1
- package/dist/index.js +227 -78
- package/dist/process/runner.d.ts +1 -0
- package/dist/process/runner.js +162 -203
- package/package.json +14 -10
- package/dist/chunk-UBDWXKSG.js +0 -33
package/README.md
CHANGED
|
@@ -225,7 +225,7 @@ The CLI is actually a collection of packages, each of which will log with slight
|
|
|
225
225
|
|
|
226
226
|
The CLI will log information at three different levels of verbosity: `default`, `info` and `debug` (`none` is also supported).
|
|
227
227
|
|
|
228
|
-
To set the log level, pass `--log info` into your command. You can configure this for individual packages, ie `--log cmp=debug` will run the compiler with debug logging but leave everything else at default.
|
|
228
|
+
To set the log level, pass `--log info` into your command. You can configure this for individual packages, ie `--log cmp=debug` will run the compiler with debug logging but leave everything else at default. To control multiple components, use comma-seperated values, ie, `--log debug,r/t=none,job=info`
|
|
229
229
|
|
|
230
230
|
Note that, unless explicitly overriden, jobs will always report at debug verbosity (meaning job logging will always be shown).
|
|
231
231
|
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_REPO_DIR,
|
|
4
|
-
expand_adaptors_default
|
|
5
|
-
} from "./chunk-UBDWXKSG.js";
|
|
6
2
|
|
|
7
3
|
// src/process/spawn.ts
|
|
8
4
|
import path from "node:path";
|
|
9
5
|
import * as url from "url";
|
|
10
6
|
import { fork } from "node:child_process";
|
|
11
7
|
import process2 from "node:process";
|
|
12
|
-
function spawn_default(
|
|
8
|
+
function spawn_default(opts2) {
|
|
13
9
|
const execArgv = [
|
|
10
|
+
// Suppress experimental argument warnings
|
|
14
11
|
"--no-warnings",
|
|
12
|
+
// Allows us to load an ESM module from a text string
|
|
15
13
|
"--experimental-vm-modules"
|
|
16
14
|
];
|
|
17
15
|
const dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
18
16
|
const child = fork(`${dirname}/process/runner.js`, [], { execArgv });
|
|
19
17
|
child.on("message", ({ done, init, exitCode }) => {
|
|
20
18
|
if (init) {
|
|
21
|
-
child.send({ init: true,
|
|
19
|
+
child.send({ init: true, opts: opts2 });
|
|
22
20
|
}
|
|
23
21
|
if (done) {
|
|
24
22
|
child.kill();
|
|
@@ -36,6 +34,108 @@ import { hideBin } from "yargs/helpers";
|
|
|
36
34
|
|
|
37
35
|
// src/options.ts
|
|
38
36
|
import path2 from "node:path";
|
|
37
|
+
|
|
38
|
+
// src/constants.ts
|
|
39
|
+
var DEFAULT_REPO_DIR = "/tmp/openfn/repo";
|
|
40
|
+
|
|
41
|
+
// src/util/expand-adaptors.ts
|
|
42
|
+
var expand = (name) => {
|
|
43
|
+
if (typeof name === "string") {
|
|
44
|
+
const [left] = name.split("=");
|
|
45
|
+
if (left.match("/") || left.endsWith(".js")) {
|
|
46
|
+
return name;
|
|
47
|
+
}
|
|
48
|
+
return `@openfn/language-${name}`;
|
|
49
|
+
}
|
|
50
|
+
return name;
|
|
51
|
+
};
|
|
52
|
+
var expand_adaptors_default = (opts2) => {
|
|
53
|
+
const { adaptors: adaptors2, workflow } = opts2;
|
|
54
|
+
if (adaptors2) {
|
|
55
|
+
opts2.adaptors = adaptors2?.map(expand);
|
|
56
|
+
}
|
|
57
|
+
if (workflow) {
|
|
58
|
+
Object.values(workflow.jobs).forEach((job) => {
|
|
59
|
+
if (job.adaptor) {
|
|
60
|
+
job.adaptor = expand(job.adaptor);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return opts2;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/util/logger.ts
|
|
68
|
+
import actualCreateLogger, { printDuration } from "@openfn/logger";
|
|
69
|
+
import { isValidLogLevel, defaultLogger } from "@openfn/logger";
|
|
70
|
+
var CLI = "cli";
|
|
71
|
+
var COMPILER = "compiler";
|
|
72
|
+
var RUNTIME = "runtime";
|
|
73
|
+
var JOB = "job";
|
|
74
|
+
var namespaces = {
|
|
75
|
+
[CLI]: "CLI",
|
|
76
|
+
[RUNTIME]: "R/T",
|
|
77
|
+
[COMPILER]: "CMP",
|
|
78
|
+
[JOB]: "JOB"
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/util/ensure-log-opts.ts
|
|
82
|
+
var defaultLoggerOptions = {
|
|
83
|
+
default: "default",
|
|
84
|
+
// TODO fix to lower case
|
|
85
|
+
job: "debug"
|
|
86
|
+
};
|
|
87
|
+
var ERROR_MESSAGE_LOG_LEVEL = "Unknown log level. Valid levels are none, debug, info and default.";
|
|
88
|
+
var ERROR_MESSAGE_LOG_COMPONENT = "Unknown log component. Valid components are cli, compiler, runtime and job.";
|
|
89
|
+
var componentShorthands = {
|
|
90
|
+
cmp: "compiler",
|
|
91
|
+
rt: "runtime",
|
|
92
|
+
"r/t": "runtime"
|
|
93
|
+
};
|
|
94
|
+
var ensureLogOpts = (opts2) => {
|
|
95
|
+
const components = {};
|
|
96
|
+
const outgoingOpts = opts2;
|
|
97
|
+
if (!opts2.log && /^(version|test)$/.test(opts2.command)) {
|
|
98
|
+
outgoingOpts.log = { default: "info" };
|
|
99
|
+
return outgoingOpts;
|
|
100
|
+
}
|
|
101
|
+
if (opts2.log) {
|
|
102
|
+
const parts = opts2.log.split(",");
|
|
103
|
+
parts.forEach((l) => {
|
|
104
|
+
let component = "";
|
|
105
|
+
let level = "";
|
|
106
|
+
if (l.match(/=/)) {
|
|
107
|
+
const parts2 = l.split("=");
|
|
108
|
+
component = parts2[0].toLowerCase();
|
|
109
|
+
if (componentShorthands[component]) {
|
|
110
|
+
component = componentShorthands[component];
|
|
111
|
+
}
|
|
112
|
+
level = parts2[1].toLowerCase();
|
|
113
|
+
} else {
|
|
114
|
+
component = "default";
|
|
115
|
+
level = l.toLowerCase();
|
|
116
|
+
if (level === "none" && !parts.find((p) => p.startsWith("job"))) {
|
|
117
|
+
components["job"] = "none";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (!/^(cli|runtime|compiler|job|default)$/i.test(component)) {
|
|
121
|
+
throw new Error(ERROR_MESSAGE_LOG_COMPONENT);
|
|
122
|
+
}
|
|
123
|
+
level = level.toLowerCase();
|
|
124
|
+
if (!isValidLogLevel(level)) {
|
|
125
|
+
throw new Error(ERROR_MESSAGE_LOG_LEVEL);
|
|
126
|
+
}
|
|
127
|
+
components[component] = level;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
outgoingOpts.log = {
|
|
131
|
+
...defaultLoggerOptions,
|
|
132
|
+
...components
|
|
133
|
+
};
|
|
134
|
+
return outgoingOpts;
|
|
135
|
+
};
|
|
136
|
+
var ensure_log_opts_default = ensureLogOpts;
|
|
137
|
+
|
|
138
|
+
// src/options.ts
|
|
39
139
|
var setDefaultValue = (opts2, key, value) => {
|
|
40
140
|
const v = opts2[key];
|
|
41
141
|
if (isNaN(v) && !v) {
|
|
@@ -172,13 +272,22 @@ var inputPath = {
|
|
|
172
272
|
}
|
|
173
273
|
}
|
|
174
274
|
};
|
|
275
|
+
var log = {
|
|
276
|
+
name: "log",
|
|
277
|
+
yargs: {
|
|
278
|
+
alias: ["l"],
|
|
279
|
+
description: "Set the log level",
|
|
280
|
+
string: true
|
|
281
|
+
},
|
|
282
|
+
ensure: (opts2) => {
|
|
283
|
+
ensure_log_opts_default(opts2);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
175
286
|
var logJson = {
|
|
176
287
|
name: "log-json",
|
|
177
288
|
yargs: {
|
|
178
289
|
description: "Output all logs as JSON objects",
|
|
179
290
|
boolean: true
|
|
180
|
-
},
|
|
181
|
-
ensure: () => {
|
|
182
291
|
}
|
|
183
292
|
};
|
|
184
293
|
var outputStdout = {
|
|
@@ -310,8 +419,26 @@ var useAdaptorsMonorepo = {
|
|
|
310
419
|
}
|
|
311
420
|
}
|
|
312
421
|
};
|
|
422
|
+
var sanitize = {
|
|
423
|
+
name: "sanitize",
|
|
424
|
+
yargs: {
|
|
425
|
+
string: true,
|
|
426
|
+
alias: ["sanitise"],
|
|
427
|
+
description: "Sanitize logging of objects and arrays: none (default), remove, summarize, obfuscate.",
|
|
428
|
+
default: "none"
|
|
429
|
+
},
|
|
430
|
+
ensure: (opts2) => {
|
|
431
|
+
if (!opts2.sanitize || opts2.sanitize?.match(/^(none|summarize|remove|obfuscate)$/)) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const err = "Unknown sanitize value provided: " + opts2.sanitize;
|
|
435
|
+
console.error(err);
|
|
436
|
+
throw new Error(err);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
313
439
|
|
|
314
440
|
// src/util/command-builders.ts
|
|
441
|
+
import c from "chalk";
|
|
315
442
|
var expandYargs = (y2) => {
|
|
316
443
|
if (typeof y2 === "function") {
|
|
317
444
|
return y2();
|
|
@@ -327,7 +454,18 @@ function build(opts2, yargs2) {
|
|
|
327
454
|
var ensure = (command, opts2) => (yargs2) => {
|
|
328
455
|
yargs2.command = command;
|
|
329
456
|
opts2.filter((opt) => opt.ensure).forEach((opt) => {
|
|
330
|
-
|
|
457
|
+
try {
|
|
458
|
+
opt.ensure(yargs2);
|
|
459
|
+
} catch (e) {
|
|
460
|
+
console.error(
|
|
461
|
+
c.red(`
|
|
462
|
+
Error parsing command arguments: ${command}.${opt.name}
|
|
463
|
+
`)
|
|
464
|
+
);
|
|
465
|
+
console.error(c.red("Aborting"));
|
|
466
|
+
console.error();
|
|
467
|
+
process.exit(9);
|
|
468
|
+
}
|
|
331
469
|
});
|
|
332
470
|
};
|
|
333
471
|
var override = (command, yargs2) => {
|
|
@@ -346,6 +484,7 @@ var options = [
|
|
|
346
484
|
adaptors,
|
|
347
485
|
ignoreImports,
|
|
348
486
|
inputPath,
|
|
487
|
+
log,
|
|
349
488
|
logJson,
|
|
350
489
|
override(outputStdout, {
|
|
351
490
|
default: true
|
|
@@ -356,7 +495,7 @@ var options = [
|
|
|
356
495
|
];
|
|
357
496
|
var compileCommand = {
|
|
358
497
|
command: "compile [path]",
|
|
359
|
-
|
|
498
|
+
describe: "Compile an openfn job or workflow and print or save the resulting JavaScript.",
|
|
360
499
|
handler: ensure("compile", options),
|
|
361
500
|
builder: (yargs2) => build(options, yargs2).positional("path", {
|
|
362
501
|
describe: "The path to load the job or workflow from (a .js or .json file or a dir containing a job.js file)",
|
|
@@ -372,42 +511,51 @@ var compileCommand = {
|
|
|
372
511
|
var command_default = compileCommand;
|
|
373
512
|
|
|
374
513
|
// src/deploy/command.ts
|
|
375
|
-
var options2 = [
|
|
514
|
+
var options2 = [
|
|
515
|
+
configPath,
|
|
516
|
+
confirm,
|
|
517
|
+
describe,
|
|
518
|
+
log,
|
|
519
|
+
logJson,
|
|
520
|
+
projectPath,
|
|
521
|
+
statePath
|
|
522
|
+
];
|
|
376
523
|
var deployCommand = {
|
|
377
524
|
command: "deploy",
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
},
|
|
382
|
-
handler: ensure("deploy", options2)
|
|
525
|
+
describe: "Deploy a project's config to a remote Lightning instance",
|
|
526
|
+
handler: ensure("deploy", options2),
|
|
527
|
+
builder: (yargs2) => build(options2, yargs2)
|
|
383
528
|
};
|
|
384
529
|
var command_default2 = deployCommand;
|
|
385
530
|
|
|
386
531
|
// src/docgen/command.ts
|
|
387
532
|
var docgenCommand = {
|
|
388
533
|
command: "docgen <specifier>",
|
|
389
|
-
|
|
534
|
+
// Hide this command as it's not really for public usage
|
|
535
|
+
describe: false,
|
|
536
|
+
// 'Generate documentation into the repo. Specifier must include a version number.'
|
|
390
537
|
handler: (argv) => {
|
|
391
538
|
argv.command = "docgen";
|
|
392
539
|
},
|
|
393
|
-
builder: (yargs2) =>
|
|
394
|
-
return yargs2.example("docgen @openfn/language-common@1.7.5", "");
|
|
395
|
-
}
|
|
540
|
+
builder: (yargs2) => yargs2.example("docgen @openfn/language-common@1.7.5", "")
|
|
396
541
|
};
|
|
397
542
|
var command_default3 = docgenCommand;
|
|
398
543
|
|
|
399
544
|
// src/docs/command.ts
|
|
400
|
-
var
|
|
545
|
+
var options3 = [log, logJson, repoDir];
|
|
546
|
+
var docsCommand = {
|
|
401
547
|
command: "docs <adaptor> [operation]",
|
|
402
|
-
|
|
403
|
-
handler: (
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
548
|
+
describe: "Print help for an adaptor function. You can use short-hand for adaptor names (ie, common instead of @openfn/language-common)",
|
|
549
|
+
handler: ensure("docs", options3),
|
|
550
|
+
builder: (yargs2) => build(options3, yargs2).example(
|
|
551
|
+
"docs common fn",
|
|
552
|
+
"Print help for the common fn operation"
|
|
553
|
+
)
|
|
407
554
|
};
|
|
555
|
+
var command_default4 = docsCommand;
|
|
408
556
|
|
|
409
557
|
// src/execute/command.ts
|
|
410
|
-
var
|
|
558
|
+
var options4 = [
|
|
411
559
|
expandAdaptors,
|
|
412
560
|
adaptors,
|
|
413
561
|
autoinstall,
|
|
@@ -415,11 +563,13 @@ var options3 = [
|
|
|
415
563
|
immutable,
|
|
416
564
|
ignoreImports,
|
|
417
565
|
inputPath,
|
|
566
|
+
log,
|
|
418
567
|
logJson,
|
|
419
568
|
outputPath,
|
|
420
569
|
outputStdout,
|
|
421
570
|
repoDir,
|
|
422
571
|
skipAdaptorValidation,
|
|
572
|
+
sanitize,
|
|
423
573
|
start,
|
|
424
574
|
statePath,
|
|
425
575
|
stateStdin,
|
|
@@ -430,7 +580,7 @@ var options3 = [
|
|
|
430
580
|
];
|
|
431
581
|
var executeCommand = {
|
|
432
582
|
command: "execute [path]",
|
|
433
|
-
|
|
583
|
+
describe: `Run an openfn job or workflow. Get more help by running openfn <command> help.
|
|
434
584
|
|
|
435
585
|
Execute will run a job/workflow at the path and write the output state to disk (to ./state.json unless otherwise specified)
|
|
436
586
|
|
|
@@ -438,8 +588,8 @@ By default only state.data will be returned fron a job. Include --no-strict to w
|
|
|
438
588
|
|
|
439
589
|
Remember to include the adaptor name with -a. Auto install adaptors with the -i flag.`,
|
|
440
590
|
aliases: ["$0"],
|
|
441
|
-
handler: ensure("execute",
|
|
442
|
-
builder: (yargs2) => build(
|
|
591
|
+
handler: ensure("execute", options4),
|
|
592
|
+
builder: (yargs2) => build(options4, yargs2).positional("path", {
|
|
443
593
|
describe: "The path to load the job or workflow from (a .js or .json file or a dir containing a job.js file)",
|
|
444
594
|
demandOption: true
|
|
445
595
|
}).example(
|
|
@@ -459,10 +609,11 @@ Remember to include the adaptor name with -a. Auto install adaptors with the -i
|
|
|
459
609
|
var command_default5 = executeCommand;
|
|
460
610
|
|
|
461
611
|
// src/metadata/command.ts
|
|
462
|
-
var
|
|
612
|
+
var options5 = [
|
|
463
613
|
expandAdaptors,
|
|
464
614
|
adaptors,
|
|
465
615
|
force,
|
|
616
|
+
log,
|
|
466
617
|
logJson,
|
|
467
618
|
repoDir,
|
|
468
619
|
statePath,
|
|
@@ -471,33 +622,39 @@ var options4 = [
|
|
|
471
622
|
];
|
|
472
623
|
var command_default6 = {
|
|
473
624
|
command: "metadata",
|
|
474
|
-
|
|
475
|
-
handler: ensure("metadata",
|
|
476
|
-
builder: (yargs2) => build(
|
|
625
|
+
describe: "Generate metadata for an adaptor config",
|
|
626
|
+
handler: ensure("metadata", options5),
|
|
627
|
+
builder: (yargs2) => build(options5, yargs2).example(
|
|
477
628
|
"metadata -a salesforce -s tmp/state.json",
|
|
478
629
|
"Generate salesforce metadata from config in state.json"
|
|
479
630
|
)
|
|
480
631
|
};
|
|
481
632
|
|
|
482
633
|
// src/pull/command.ts
|
|
483
|
-
var
|
|
634
|
+
var options6 = [statePath, projectPath, configPath, log, logJson];
|
|
484
635
|
var pullCommand = {
|
|
485
|
-
command: "pull",
|
|
486
|
-
|
|
487
|
-
builder: (yargs2) => {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
636
|
+
command: "pull [projectId]",
|
|
637
|
+
describe: "Pull a project's state and spec from a Lightning Instance to the local directory",
|
|
638
|
+
builder: (yargs2) => build(options6, yargs2).positional("projectId", {
|
|
639
|
+
describe: "The id of the project that should be pulled shouled be a UUID",
|
|
640
|
+
demandOption: true
|
|
641
|
+
}).example(
|
|
642
|
+
"pull 57862287-23e6-4650-8d79-e1dd88b24b1c",
|
|
643
|
+
"Pull an updated copy of a the above spec and state from a Lightning Instance"
|
|
644
|
+
),
|
|
645
|
+
handler: ensure("pull", options6)
|
|
491
646
|
};
|
|
492
647
|
var command_default7 = pullCommand;
|
|
493
648
|
|
|
494
649
|
// src/repo/command.ts
|
|
495
650
|
var repo = {
|
|
496
651
|
command: "repo [subcommand]",
|
|
497
|
-
|
|
652
|
+
describe: "Run commands on the module repo (install|clean)",
|
|
498
653
|
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")
|
|
499
654
|
};
|
|
500
655
|
var installOptions = [
|
|
656
|
+
log,
|
|
657
|
+
logJson,
|
|
501
658
|
repoDir,
|
|
502
659
|
override(expandAdaptors, {
|
|
503
660
|
default: true,
|
|
@@ -509,7 +666,7 @@ var installOptions = [
|
|
|
509
666
|
];
|
|
510
667
|
var install = {
|
|
511
668
|
command: "install [packages...]",
|
|
512
|
-
|
|
669
|
+
describe: "install one or more packages to the runtime repo. Use -a to pass shorthand adaptor names.",
|
|
513
670
|
handler: ensure("repo-install", installOptions),
|
|
514
671
|
builder: (yargs2) => build(installOptions, yargs2).example("install axios", "Install the axios npm package to the repo").example(
|
|
515
672
|
"install -a http",
|
|
@@ -519,61 +676,53 @@ var install = {
|
|
|
519
676
|
"Install the language-http adaptor to the repo"
|
|
520
677
|
)
|
|
521
678
|
};
|
|
679
|
+
var cleanOptions = [
|
|
680
|
+
log,
|
|
681
|
+
logJson,
|
|
682
|
+
repoDir,
|
|
683
|
+
{
|
|
684
|
+
name: "force",
|
|
685
|
+
yargs: {
|
|
686
|
+
alias: ["f"],
|
|
687
|
+
description: "Skip the prompt and force deletion",
|
|
688
|
+
boolean: true
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
];
|
|
522
692
|
var clean = {
|
|
523
693
|
command: "clean",
|
|
524
|
-
|
|
525
|
-
handler: ensure("repo-clean",
|
|
526
|
-
builder: (yargs2) => build(
|
|
527
|
-
[
|
|
528
|
-
repoDir,
|
|
529
|
-
{
|
|
530
|
-
name: "force",
|
|
531
|
-
yargs: {
|
|
532
|
-
alias: ["f"],
|
|
533
|
-
description: "Skip the prompt and force deletion",
|
|
534
|
-
boolean: true
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
],
|
|
538
|
-
yargs2
|
|
539
|
-
)
|
|
694
|
+
describe: "Removes all modules from the runtime module repo",
|
|
695
|
+
handler: ensure("repo-clean", cleanOptions),
|
|
696
|
+
builder: (yargs2) => build(cleanOptions, yargs2)
|
|
540
697
|
};
|
|
698
|
+
var listOptions = [repoDir, log, logJson];
|
|
541
699
|
var list = {
|
|
542
700
|
command: "list",
|
|
543
|
-
|
|
701
|
+
describe: "Show a report on what is installed in the repo",
|
|
544
702
|
aliases: ["$0"],
|
|
545
|
-
handler: ensure("repo-list",
|
|
546
|
-
builder: (yargs2) => build(
|
|
703
|
+
handler: ensure("repo-list", listOptions),
|
|
704
|
+
builder: (yargs2) => build(listOptions, yargs2)
|
|
547
705
|
};
|
|
548
706
|
|
|
549
707
|
// src/test/command.ts
|
|
550
|
-
var
|
|
708
|
+
var options7 = [stateStdin, log, logJson];
|
|
551
709
|
var command_default8 = {
|
|
552
710
|
command: "test",
|
|
553
711
|
desc: "Compiles and runs a test job, printing the result to stdout",
|
|
554
|
-
handler: ensure("test",
|
|
555
|
-
builder: (yargs2) => build(
|
|
712
|
+
handler: ensure("test", options7),
|
|
713
|
+
builder: (yargs2) => build(options7, yargs2).example("test", "Run the test script")
|
|
556
714
|
};
|
|
557
715
|
|
|
558
716
|
// src/cli.ts
|
|
559
717
|
var y = yargs(hideBin(process.argv));
|
|
560
|
-
var cmd = y.command(command_default5).command(command_default).command(command_default2).command(install).command(repo).command(command_default8).command(command_default4).command(command_default6).command(command_default3).command(command_default7).
|
|
561
|
-
alias: ["l"],
|
|
562
|
-
description: "Set the default log level to none, default, info or debug",
|
|
563
|
-
array: true
|
|
564
|
-
}).option("log-json", {
|
|
565
|
-
description: "Output all logs as JSON objects",
|
|
566
|
-
boolean: true
|
|
567
|
-
}).example("openfn execute help", "Show documentation for the execute command").example(
|
|
568
|
-
"openfn docs @openfn/language-common each",
|
|
569
|
-
"Get more help on the common.each command"
|
|
570
|
-
).command({
|
|
718
|
+
var cmd = y.command(command_default5).command(command_default).command(command_default2).command(install).command(repo).command(command_default8).command(command_default4).command(command_default6).command(command_default3).command(command_default7).command({
|
|
571
719
|
command: "version",
|
|
720
|
+
describe: "Show the currently installed version of the CLI, compiler and runtime.",
|
|
572
721
|
handler: (argv) => {
|
|
573
722
|
argv.command = "version";
|
|
574
723
|
}
|
|
575
724
|
}).wrap(y.terminalWidth()).help();
|
|
576
725
|
|
|
577
726
|
// src/index.ts
|
|
578
|
-
var opts = cmd.
|
|
579
|
-
spawn_default(opts
|
|
727
|
+
var opts = cmd.parseSync();
|
|
728
|
+
spawn_default(opts);
|
package/dist/process/runner.d.ts
CHANGED
package/dist/process/runner.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_REPO_DIR,
|
|
3
|
-
expand_adaptors_default
|
|
4
|
-
} from "../chunk-UBDWXKSG.js";
|
|
5
|
-
|
|
6
1
|
// src/execute/execute.ts
|
|
7
2
|
import run, { getNameAndVersion } from "@openfn/runtime";
|
|
8
3
|
|
|
@@ -29,6 +24,7 @@ var createLogger = (name = "", options) => {
|
|
|
29
24
|
return actualCreateLogger(namespaces[name] || name, {
|
|
30
25
|
level,
|
|
31
26
|
json,
|
|
27
|
+
sanitize: options.sanitize || "none",
|
|
32
28
|
...logOptions
|
|
33
29
|
});
|
|
34
30
|
};
|
|
@@ -39,8 +35,8 @@ var createNullLogger = () => createLogger(void 0, { log: { default: "none" } });
|
|
|
39
35
|
var AbortError = class extends Error {
|
|
40
36
|
constructor(reason) {
|
|
41
37
|
super(reason);
|
|
42
|
-
this.handled = true;
|
|
43
38
|
}
|
|
39
|
+
handled = true;
|
|
44
40
|
};
|
|
45
41
|
var abort_default = (logger, reason, error, help) => {
|
|
46
42
|
const e = new AbortError(reason);
|
|
@@ -78,13 +74,13 @@ var execute_default = async (input, state, opts, logger) => {
|
|
|
78
74
|
};
|
|
79
75
|
function parseAdaptors(opts) {
|
|
80
76
|
const extractInfo = (specifier) => {
|
|
81
|
-
const [module,
|
|
77
|
+
const [module, path7] = specifier.split("=");
|
|
82
78
|
const { name, version } = getNameAndVersion(module);
|
|
83
79
|
const info = {
|
|
84
80
|
name
|
|
85
81
|
};
|
|
86
|
-
if (
|
|
87
|
-
info.path =
|
|
82
|
+
if (path7) {
|
|
83
|
+
info.path = path7;
|
|
88
84
|
}
|
|
89
85
|
if (version) {
|
|
90
86
|
info.version = version;
|
|
@@ -225,7 +221,9 @@ var list = async (options, logger) => {
|
|
|
225
221
|
output[key][v] = null;
|
|
226
222
|
});
|
|
227
223
|
});
|
|
228
|
-
logger.success(
|
|
224
|
+
logger.success(
|
|
225
|
+
"Installed packages:\n\n" + treeify.asTree(output, false, false)
|
|
226
|
+
);
|
|
229
227
|
};
|
|
230
228
|
|
|
231
229
|
// src/compile/compile.ts
|
|
@@ -286,10 +284,10 @@ var stripVersionSpecifier = (specifier) => {
|
|
|
286
284
|
return specifier;
|
|
287
285
|
};
|
|
288
286
|
var resolveSpecifierPath = async (pattern, repoDir, log) => {
|
|
289
|
-
const [specifier,
|
|
290
|
-
if (
|
|
291
|
-
log.debug(`Resolved ${specifier} to path: ${
|
|
292
|
-
return
|
|
287
|
+
const [specifier, path7] = pattern.split("=");
|
|
288
|
+
if (path7) {
|
|
289
|
+
log.debug(`Resolved ${specifier} to path: ${path7}`);
|
|
290
|
+
return path7;
|
|
293
291
|
}
|
|
294
292
|
const repoPath = await getModulePath(specifier, repoDir, log);
|
|
295
293
|
if (repoPath) {
|
|
@@ -306,16 +304,16 @@ var loadTransformOptions = async (opts, log) => {
|
|
|
306
304
|
const [pattern] = opts.adaptors;
|
|
307
305
|
const [specifier] = pattern.split("=");
|
|
308
306
|
log.debug(`Attempting to preload types for ${specifier}`);
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
307
|
+
const path7 = await resolveSpecifierPath(pattern, opts.repoDir, log);
|
|
308
|
+
if (path7) {
|
|
311
309
|
try {
|
|
312
310
|
exports = await preloadAdaptorExports(
|
|
313
|
-
|
|
311
|
+
path7,
|
|
314
312
|
opts.useAdaptorsMonorepo,
|
|
315
313
|
log
|
|
316
314
|
);
|
|
317
315
|
} catch (e) {
|
|
318
|
-
log.error(`Failed to load adaptor typedefs from path ${
|
|
316
|
+
log.error(`Failed to load adaptor typedefs from path ${path7}`);
|
|
319
317
|
log.error(e);
|
|
320
318
|
}
|
|
321
319
|
}
|
|
@@ -511,6 +509,32 @@ Paths inside the workflow are relative to the workflow.json`
|
|
|
511
509
|
}
|
|
512
510
|
};
|
|
513
511
|
|
|
512
|
+
// src/util/expand-adaptors.ts
|
|
513
|
+
var expand = (name) => {
|
|
514
|
+
if (typeof name === "string") {
|
|
515
|
+
const [left] = name.split("=");
|
|
516
|
+
if (left.match("/") || left.endsWith(".js")) {
|
|
517
|
+
return name;
|
|
518
|
+
}
|
|
519
|
+
return `@openfn/language-${name}`;
|
|
520
|
+
}
|
|
521
|
+
return name;
|
|
522
|
+
};
|
|
523
|
+
var expand_adaptors_default = (opts) => {
|
|
524
|
+
const { adaptors, workflow } = opts;
|
|
525
|
+
if (adaptors) {
|
|
526
|
+
opts.adaptors = adaptors?.map(expand);
|
|
527
|
+
}
|
|
528
|
+
if (workflow) {
|
|
529
|
+
Object.values(workflow.jobs).forEach((job) => {
|
|
530
|
+
if (job.adaptor) {
|
|
531
|
+
job.adaptor = expand(job.adaptor);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
return opts;
|
|
536
|
+
};
|
|
537
|
+
|
|
514
538
|
// src/util/map-adaptors-to-monorepo.ts
|
|
515
539
|
import { readFile } from "node:fs/promises";
|
|
516
540
|
import path2 from "node:path";
|
|
@@ -564,9 +588,22 @@ var mapAdaptorsToMonorepo = async (options, log) => {
|
|
|
564
588
|
};
|
|
565
589
|
var map_adaptors_to_monorepo_default = mapAdaptorsToMonorepo;
|
|
566
590
|
|
|
591
|
+
// src/util/assert-path.ts
|
|
592
|
+
var assert_path_default = (path7) => {
|
|
593
|
+
if (!path7) {
|
|
594
|
+
console.error("ERROR: no path provided!");
|
|
595
|
+
console.error("\nUsage:");
|
|
596
|
+
console.error(" open path/to/job");
|
|
597
|
+
console.error("\nFor more help do:");
|
|
598
|
+
console.error(" openfn --help ");
|
|
599
|
+
process.exit(1);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
567
603
|
// src/execute/handler.ts
|
|
568
604
|
var executeHandler = async (options, logger) => {
|
|
569
|
-
const start = new Date().getTime();
|
|
605
|
+
const start = (/* @__PURE__ */ new Date()).getTime();
|
|
606
|
+
assert_path_default(options.path);
|
|
570
607
|
await validate_adaptors_default(options, logger);
|
|
571
608
|
let input = await load_input_default(options, logger);
|
|
572
609
|
if (options.workflow) {
|
|
@@ -597,7 +634,7 @@ var executeHandler = async (options, logger) => {
|
|
|
597
634
|
try {
|
|
598
635
|
const result = await execute_default(input, state, options, logger);
|
|
599
636
|
await serialize_output_default(options, result, logger);
|
|
600
|
-
const duration = printDuration(new Date().getTime() - start);
|
|
637
|
+
const duration = printDuration((/* @__PURE__ */ new Date()).getTime() - start);
|
|
601
638
|
if (result.errors) {
|
|
602
639
|
logger.warn(
|
|
603
640
|
`Errors reported in ${Object.keys(result.errors).length} jobs`
|
|
@@ -610,7 +647,7 @@ var executeHandler = async (options, logger) => {
|
|
|
610
647
|
logger.error("Unexpected error in execution");
|
|
611
648
|
logger.error(err);
|
|
612
649
|
}
|
|
613
|
-
const duration = printDuration(new Date().getTime() - start);
|
|
650
|
+
const duration = printDuration((/* @__PURE__ */ new Date()).getTime() - start);
|
|
614
651
|
logger.always(`Workflow failed in ${duration}.`);
|
|
615
652
|
process.exitCode = 1;
|
|
616
653
|
}
|
|
@@ -620,6 +657,7 @@ var handler_default = executeHandler;
|
|
|
620
657
|
// src/compile/handler.ts
|
|
621
658
|
import { writeFile as writeFile2 } from "node:fs/promises";
|
|
622
659
|
var compileHandler = async (options, logger) => {
|
|
660
|
+
assert_path_default(options.path);
|
|
623
661
|
await load_input_default(options, logger);
|
|
624
662
|
if (options.workflow) {
|
|
625
663
|
expand_adaptors_default(options);
|
|
@@ -645,9 +683,10 @@ var handler_default2 = compileHandler;
|
|
|
645
683
|
// src/test/handler.ts
|
|
646
684
|
var testHandler = async (options, logger) => {
|
|
647
685
|
logger.log("Running test job...");
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
686
|
+
const opts = { ...options };
|
|
687
|
+
opts.compile = true;
|
|
688
|
+
opts.adaptors = [];
|
|
689
|
+
opts.workflow = {
|
|
651
690
|
start: "start",
|
|
652
691
|
jobs: [
|
|
653
692
|
{
|
|
@@ -673,18 +712,23 @@ var testHandler = async (options, logger) => {
|
|
|
673
712
|
};
|
|
674
713
|
logger.break();
|
|
675
714
|
logger.info("Workflow object:");
|
|
676
|
-
logger.info(JSON.stringify(
|
|
715
|
+
logger.info(JSON.stringify(opts.workflow, null, 2));
|
|
677
716
|
logger.break();
|
|
678
|
-
if (!
|
|
717
|
+
if (!opts.stateStdin) {
|
|
679
718
|
logger.debug(
|
|
680
719
|
"No state provided: pass an object with state.data.answer to provide custom input"
|
|
681
720
|
);
|
|
682
721
|
logger.debug('eg: -S "{ "data": { "answer": 33 } }"');
|
|
683
722
|
}
|
|
684
723
|
const silentLogger = createNullLogger();
|
|
685
|
-
const state = await load_state_default(
|
|
686
|
-
const code = await compile_default(
|
|
687
|
-
const result = await execute_default(
|
|
724
|
+
const state = await load_state_default(opts, silentLogger);
|
|
725
|
+
const code = await compile_default(opts, logger);
|
|
726
|
+
const result = await execute_default(
|
|
727
|
+
code,
|
|
728
|
+
state,
|
|
729
|
+
opts,
|
|
730
|
+
silentLogger
|
|
731
|
+
);
|
|
688
732
|
logger.success(`Result: ${result.data.answer}`);
|
|
689
733
|
return result;
|
|
690
734
|
};
|
|
@@ -754,20 +798,20 @@ var RETRY_COUNT = 20;
|
|
|
754
798
|
var TIMEOUT_MS = 1e3 * 60;
|
|
755
799
|
var actualDocGen = (specifier) => describePackage(specifier, {});
|
|
756
800
|
var ensurePath = (filePath) => mkdirSync(path3.dirname(filePath), { recursive: true });
|
|
757
|
-
var generatePlaceholder = (
|
|
758
|
-
writeFileSync(
|
|
801
|
+
var generatePlaceholder = (path7) => {
|
|
802
|
+
writeFileSync(path7, `{ "loading": true, "timestamp": ${Date.now()}}`);
|
|
759
803
|
};
|
|
760
804
|
var finish = (logger, resultPath) => {
|
|
761
805
|
logger.success("Done! Docs can be found at:\n");
|
|
762
806
|
logger.print(` ${path3.resolve(resultPath)}`);
|
|
763
807
|
};
|
|
764
|
-
var generateDocs = async (specifier,
|
|
808
|
+
var generateDocs = async (specifier, path7, docgen, logger) => {
|
|
765
809
|
const result = await docgen(specifier);
|
|
766
|
-
await writeFile3(
|
|
767
|
-
finish(logger,
|
|
768
|
-
return
|
|
810
|
+
await writeFile3(path7, JSON.stringify(result, null, 2));
|
|
811
|
+
finish(logger, path7);
|
|
812
|
+
return path7;
|
|
769
813
|
};
|
|
770
|
-
var waitForDocs = async (docs,
|
|
814
|
+
var waitForDocs = async (docs, path7, logger, retryDuration = RETRY_DURATION) => {
|
|
771
815
|
try {
|
|
772
816
|
if (docs.hasOwnProperty("loading")) {
|
|
773
817
|
logger.info("Docs are being loaded by another process. Waiting.");
|
|
@@ -779,19 +823,19 @@ var waitForDocs = async (docs, path8, logger, retryDuration = RETRY_DURATION) =>
|
|
|
779
823
|
clearInterval(i);
|
|
780
824
|
reject(new Error("Timed out waiting for docs to load"));
|
|
781
825
|
}
|
|
782
|
-
const updated = JSON.parse(readFileSync(
|
|
826
|
+
const updated = JSON.parse(readFileSync(path7, "utf8"));
|
|
783
827
|
if (!updated.hasOwnProperty("loading")) {
|
|
784
828
|
logger.info("Docs found!");
|
|
785
829
|
clearInterval(i);
|
|
786
|
-
resolve(
|
|
830
|
+
resolve(path7);
|
|
787
831
|
}
|
|
788
832
|
count++;
|
|
789
833
|
}, retryDuration);
|
|
790
834
|
});
|
|
791
835
|
} else {
|
|
792
|
-
logger.info(`Docs already written to cache at ${
|
|
793
|
-
finish(logger,
|
|
794
|
-
return
|
|
836
|
+
logger.info(`Docs already written to cache at ${path7}`);
|
|
837
|
+
finish(logger, path7);
|
|
838
|
+
return path7;
|
|
795
839
|
}
|
|
796
840
|
} catch (e) {
|
|
797
841
|
logger.error("Existing doc JSON corrupt. Aborting");
|
|
@@ -808,28 +852,28 @@ var docgenHandler = (options, logger, docgen = actualDocGen, retryDuration = RET
|
|
|
808
852
|
process.exit(9);
|
|
809
853
|
}
|
|
810
854
|
logger.success(`Generating docs for ${specifier}`);
|
|
811
|
-
const
|
|
812
|
-
ensurePath(
|
|
855
|
+
const path7 = `${repoDir}/docs/${specifier}.json`;
|
|
856
|
+
ensurePath(path7);
|
|
813
857
|
const handleError = () => {
|
|
814
858
|
logger.info("Removing placeholder");
|
|
815
|
-
rmSync(
|
|
859
|
+
rmSync(path7);
|
|
816
860
|
};
|
|
817
861
|
try {
|
|
818
|
-
const existing = readFileSync(
|
|
862
|
+
const existing = readFileSync(path7, "utf8");
|
|
819
863
|
const json = JSON.parse(existing);
|
|
820
864
|
if (json && json.timeout && Date.now() - json.timeout >= TIMEOUT_MS) {
|
|
821
865
|
logger.info(`Expired placeholder found. Removing.`);
|
|
822
|
-
rmSync(
|
|
866
|
+
rmSync(path7);
|
|
823
867
|
throw new Error("TIMEOUT");
|
|
824
868
|
}
|
|
825
|
-
return waitForDocs(json,
|
|
869
|
+
return waitForDocs(json, path7, logger, retryDuration);
|
|
826
870
|
} catch (e) {
|
|
827
871
|
if (e.message !== "TIMEOUT") {
|
|
828
|
-
logger.info(`Docs JSON not found at ${
|
|
872
|
+
logger.info(`Docs JSON not found at ${path7}`);
|
|
829
873
|
}
|
|
830
874
|
logger.debug("Generating placeholder");
|
|
831
|
-
generatePlaceholder(
|
|
832
|
-
return generateDocs(specifier,
|
|
875
|
+
generatePlaceholder(path7);
|
|
876
|
+
return generateDocs(specifier, path7, docgen, logger).catch((e2) => {
|
|
833
877
|
logger.error("Error generating documentation");
|
|
834
878
|
logger.error(e2);
|
|
835
879
|
handleError();
|
|
@@ -878,16 +922,17 @@ var docsHandler = async (options, logger) => {
|
|
|
878
922
|
logger.success(`Showing docs for ${adaptorName} v${version}`);
|
|
879
923
|
}
|
|
880
924
|
logger.info("Generating/loading documentation...");
|
|
881
|
-
const
|
|
925
|
+
const path7 = await handler_default5(
|
|
882
926
|
{
|
|
883
927
|
specifier: `${name}@${version}`,
|
|
884
928
|
repoDir
|
|
885
929
|
},
|
|
930
|
+
// TODO I'm not sure how to handle logging here - we ought to feedback SOMETHING though
|
|
886
931
|
createNullLogger()
|
|
887
932
|
);
|
|
888
933
|
let didError = false;
|
|
889
|
-
if (
|
|
890
|
-
const source = await readFile2(
|
|
934
|
+
if (path7) {
|
|
935
|
+
const source = await readFile2(path7, "utf8");
|
|
891
936
|
const data = JSON.parse(source);
|
|
892
937
|
let desc;
|
|
893
938
|
if (operation) {
|
|
@@ -958,7 +1003,7 @@ var cache_default = { get, set, generateKey, getPath, sortKeys };
|
|
|
958
1003
|
// src/metadata/handler.ts
|
|
959
1004
|
import { getModuleEntryPoint } from "@openfn/runtime";
|
|
960
1005
|
var decorateMetadata = (metadata) => {
|
|
961
|
-
metadata.created = new Date().toISOString();
|
|
1006
|
+
metadata.created = (/* @__PURE__ */ new Date()).toISOString();
|
|
962
1007
|
};
|
|
963
1008
|
var getAdaptorPath = async (adaptor, logger, repoDir) => {
|
|
964
1009
|
let adaptorPath;
|
|
@@ -1037,20 +1082,44 @@ var handler_default7 = metadataHandler;
|
|
|
1037
1082
|
import path5 from "path";
|
|
1038
1083
|
import fs3 from "node:fs/promises";
|
|
1039
1084
|
import {
|
|
1040
|
-
getProject,
|
|
1041
1085
|
getConfig as getConfig2,
|
|
1042
|
-
getState
|
|
1086
|
+
getState,
|
|
1087
|
+
mergeSpecIntoState,
|
|
1088
|
+
getSpec
|
|
1043
1089
|
} from "@openfn/deploy";
|
|
1044
1090
|
async function pullHandler(options, logger) {
|
|
1045
1091
|
try {
|
|
1092
|
+
assert_path_default(options.projectId);
|
|
1046
1093
|
const config = mergeOverrides2(await getConfig2(options.configPath), options);
|
|
1047
|
-
logger.always("Downloading project yaml and
|
|
1094
|
+
logger.always("Downloading project yaml and state from instance");
|
|
1048
1095
|
const state = await getState(config.statePath);
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1096
|
+
const url2 = new URL(
|
|
1097
|
+
`api/provision/yaml?id=${options.projectId}`,
|
|
1098
|
+
config.endpoint
|
|
1099
|
+
);
|
|
1100
|
+
logger.debug("Fetching project spec from", url2);
|
|
1101
|
+
const res = await fetch(url2, {
|
|
1102
|
+
headers: {
|
|
1103
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
1104
|
+
Accept: "application/json"
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
const resolvedPath = path5.resolve(config.specPath);
|
|
1108
|
+
logger.debug("reading spec from", resolvedPath);
|
|
1109
|
+
await fs3.writeFile(resolvedPath, res.body);
|
|
1110
|
+
const spec = await getSpec(config.specPath);
|
|
1111
|
+
logger.debug("validated spec: ", spec);
|
|
1112
|
+
if (spec.errors.length > 0) {
|
|
1113
|
+
logger.error("ERROR: invalid spec");
|
|
1114
|
+
logger.error(spec.errors);
|
|
1115
|
+
process.exitCode = 1;
|
|
1116
|
+
process.exit(1);
|
|
1117
|
+
}
|
|
1118
|
+
const nextState = mergeSpecIntoState(state, spec.doc);
|
|
1119
|
+
await fs3.writeFile(
|
|
1120
|
+
path5.resolve(config.statePath),
|
|
1121
|
+
JSON.stringify(nextState, null, 2)
|
|
1122
|
+
);
|
|
1054
1123
|
logger.success("Project pulled successfully");
|
|
1055
1124
|
process.exitCode = 0;
|
|
1056
1125
|
return true;
|
|
@@ -1072,105 +1141,11 @@ function pickFirst2(...args) {
|
|
|
1072
1141
|
}
|
|
1073
1142
|
var handler_default8 = pullHandler;
|
|
1074
1143
|
|
|
1075
|
-
// src/util/ensure-opts.ts
|
|
1076
|
-
import path6 from "node:path";
|
|
1077
|
-
var defaultLoggerOptions = {
|
|
1078
|
-
default: "default",
|
|
1079
|
-
job: "debug"
|
|
1080
|
-
};
|
|
1081
|
-
var ERROR_MESSAGE_LOG_LEVEL = "Unknown log level. Valid levels are none, debug, info and default.";
|
|
1082
|
-
var ERROR_MESSAGE_LOG_COMPONENT = "Unknown log component. Valid components are cli, compiler, runtime and job.";
|
|
1083
|
-
var componentShorthands = {
|
|
1084
|
-
cmp: "compiler",
|
|
1085
|
-
rt: "runtime",
|
|
1086
|
-
"r/t": "runtime"
|
|
1087
|
-
};
|
|
1088
|
-
var isValidComponent = (v) => /^(cli|runtime|compiler|job|default)$/i.test(v);
|
|
1089
|
-
var ensureLogOpts = (opts) => {
|
|
1090
|
-
const components = {};
|
|
1091
|
-
if (!opts.log && /^(version|test)$/.test(opts.command)) {
|
|
1092
|
-
opts.log = { default: "info" };
|
|
1093
|
-
return opts;
|
|
1094
|
-
} else if (opts.log) {
|
|
1095
|
-
opts.log.forEach((l) => {
|
|
1096
|
-
let component = "";
|
|
1097
|
-
let level = "";
|
|
1098
|
-
if (l.match(/=/)) {
|
|
1099
|
-
const parts = l.split("=");
|
|
1100
|
-
component = parts[0].toLowerCase();
|
|
1101
|
-
if (componentShorthands[component]) {
|
|
1102
|
-
component = componentShorthands[component];
|
|
1103
|
-
}
|
|
1104
|
-
level = parts[1].toLowerCase();
|
|
1105
|
-
} else {
|
|
1106
|
-
component = "default";
|
|
1107
|
-
level = l.toLowerCase();
|
|
1108
|
-
}
|
|
1109
|
-
if (!isValidComponent(component)) {
|
|
1110
|
-
throw new Error(ERROR_MESSAGE_LOG_COMPONENT);
|
|
1111
|
-
}
|
|
1112
|
-
level = level.toLowerCase();
|
|
1113
|
-
if (!isValidLogLevel(level)) {
|
|
1114
|
-
throw new Error(ERROR_MESSAGE_LOG_LEVEL);
|
|
1115
|
-
}
|
|
1116
|
-
components[component] = level;
|
|
1117
|
-
});
|
|
1118
|
-
}
|
|
1119
|
-
opts.log = {
|
|
1120
|
-
...defaultLoggerOptions,
|
|
1121
|
-
...components
|
|
1122
|
-
};
|
|
1123
|
-
return opts;
|
|
1124
|
-
};
|
|
1125
|
-
function ensureOpts(basePath = ".", opts) {
|
|
1126
|
-
const newOpts = {
|
|
1127
|
-
adaptor: opts.adaptor,
|
|
1128
|
-
adaptors: opts.adaptors || [],
|
|
1129
|
-
autoinstall: opts.autoinstall,
|
|
1130
|
-
command: opts.command,
|
|
1131
|
-
expandAdaptors: opts.expandAdaptors !== false,
|
|
1132
|
-
force: opts.force || false,
|
|
1133
|
-
immutable: opts.immutable || false,
|
|
1134
|
-
log: opts.log,
|
|
1135
|
-
logJson: typeof opts.logJson == "boolean" ? opts.logJson : Boolean(process.env.OPENFN_LOG_JSON),
|
|
1136
|
-
compile: Boolean(opts.compile),
|
|
1137
|
-
operation: opts.operation,
|
|
1138
|
-
outputStdout: Boolean(opts.outputStdout),
|
|
1139
|
-
packages: opts.packages,
|
|
1140
|
-
repoDir: opts.repoDir || process.env.OPENFN_REPO_DIR || DEFAULT_REPO_DIR,
|
|
1141
|
-
skipAdaptorValidation: opts.skipAdaptorValidation ?? false,
|
|
1142
|
-
specifier: opts.specifier,
|
|
1143
|
-
stateStdin: opts.stateStdin,
|
|
1144
|
-
timeout: opts.timeout
|
|
1145
|
-
};
|
|
1146
|
-
const set2 = (key, value) => {
|
|
1147
|
-
newOpts[key] = opts.hasOwnProperty(key) ? opts[key] : value;
|
|
1148
|
-
};
|
|
1149
|
-
if (opts.useAdaptorsMonorepo) {
|
|
1150
|
-
newOpts.monorepoPath = process.env.OPENFN_ADAPTORS_REPO || "ERR";
|
|
1151
|
-
}
|
|
1152
|
-
let baseDir = basePath;
|
|
1153
|
-
if (basePath.endsWith(".js")) {
|
|
1154
|
-
baseDir = path6.dirname(basePath);
|
|
1155
|
-
set2("jobPath", basePath);
|
|
1156
|
-
} else {
|
|
1157
|
-
set2("jobPath", `${baseDir}/job.js`);
|
|
1158
|
-
}
|
|
1159
|
-
set2("statePath", `${baseDir}/state.json`);
|
|
1160
|
-
if (!opts.outputStdout) {
|
|
1161
|
-
set2(
|
|
1162
|
-
"outputPath",
|
|
1163
|
-
newOpts.command === "compile" ? `${baseDir}/output.js` : `${baseDir}/output.json`
|
|
1164
|
-
);
|
|
1165
|
-
}
|
|
1166
|
-
ensureLogOpts(newOpts);
|
|
1167
|
-
return newOpts;
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
1144
|
// src/util/print-versions.ts
|
|
1171
1145
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
1172
|
-
import
|
|
1173
|
-
import
|
|
1146
|
+
import path6 from "node:path";
|
|
1147
|
+
import url from "node:url";
|
|
1148
|
+
import { getNameAndVersion as getNameAndVersion5 } from "@openfn/runtime";
|
|
1174
1149
|
import { mainSymbols } from "figures";
|
|
1175
1150
|
var NODE = "node.js";
|
|
1176
1151
|
var CLI2 = "cli";
|
|
@@ -1179,7 +1154,9 @@ var COMPILER2 = "compiler";
|
|
|
1179
1154
|
var { triangleRightSmall: t } = mainSymbols;
|
|
1180
1155
|
var loadVersionFromPath = (adaptorPath) => {
|
|
1181
1156
|
try {
|
|
1182
|
-
const pkg = JSON.parse(
|
|
1157
|
+
const pkg = JSON.parse(
|
|
1158
|
+
readFileSync3(path6.resolve(adaptorPath, "package.json"), "utf8")
|
|
1159
|
+
);
|
|
1183
1160
|
return pkg.version;
|
|
1184
1161
|
} catch (e) {
|
|
1185
1162
|
return "unknown";
|
|
@@ -1197,23 +1174,20 @@ var printVersions = async (logger, options = {}) => {
|
|
|
1197
1174
|
if (adaptor.match("=")) {
|
|
1198
1175
|
const [namePart, pathPart] = adaptor.split("=");
|
|
1199
1176
|
adaptorVersion = loadVersionFromPath(pathPart);
|
|
1200
|
-
adaptorName =
|
|
1177
|
+
adaptorName = getNameAndVersion5(namePart).name;
|
|
1201
1178
|
} else {
|
|
1202
|
-
const { name, version: version2 } =
|
|
1179
|
+
const { name, version: version2 } = getNameAndVersion5(adaptor);
|
|
1203
1180
|
adaptorName = name;
|
|
1204
1181
|
adaptorVersion = version2 || "latest";
|
|
1205
1182
|
}
|
|
1206
1183
|
}
|
|
1207
|
-
const longest = Math.max(
|
|
1208
|
-
NODE,
|
|
1209
|
-
|
|
1210
|
-
RUNTIME2,
|
|
1211
|
-
COMPILER2,
|
|
1212
|
-
adaptorName
|
|
1213
|
-
].map((s) => s.length));
|
|
1184
|
+
const longest = Math.max(
|
|
1185
|
+
...[NODE, CLI2, RUNTIME2, COMPILER2, adaptorName].map((s) => s.length)
|
|
1186
|
+
);
|
|
1214
1187
|
const prefix = (str) => ` ${t} ${str.padEnd(longest + 4, " ")}`;
|
|
1215
|
-
const
|
|
1216
|
-
const
|
|
1188
|
+
const dirname = path6.dirname(url.fileURLToPath(import.meta.url));
|
|
1189
|
+
const pkg = JSON.parse(readFileSync3(`${dirname}/../../package.json`, "utf8"));
|
|
1190
|
+
const { version, dependencies } = pkg;
|
|
1217
1191
|
const compilerVersion = dependencies["@openfn/compiler"];
|
|
1218
1192
|
const runtimeVersion = dependencies["@openfn/runtime"];
|
|
1219
1193
|
let output;
|
|
@@ -1238,7 +1212,7 @@ ${prefix(CLI2)}${version}
|
|
|
1238
1212
|
${prefix(RUNTIME2)}${runtimeVersion}
|
|
1239
1213
|
${prefix(COMPILER2)}${compilerVersion}${adaptorVersionString}`;
|
|
1240
1214
|
}
|
|
1241
|
-
logger.
|
|
1215
|
+
logger.always(output);
|
|
1242
1216
|
};
|
|
1243
1217
|
var print_versions_default = printVersions;
|
|
1244
1218
|
|
|
@@ -1258,26 +1232,25 @@ var handlers = {
|
|
|
1258
1232
|
["repo-list"]: list,
|
|
1259
1233
|
version: async (opts, logger) => print_versions_default(logger, opts)
|
|
1260
1234
|
};
|
|
1261
|
-
var
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
if (opts.monorepoPath) {
|
|
1269
|
-
if (opts.monorepoPath === "ERR") {
|
|
1235
|
+
var parse = async (options, log) => {
|
|
1236
|
+
const logger = log || logger_default(CLI, options);
|
|
1237
|
+
if (options.command === "execute" || options.command === "test") {
|
|
1238
|
+
await print_versions_default(logger, options);
|
|
1239
|
+
}
|
|
1240
|
+
if (options.monorepoPath) {
|
|
1241
|
+
if (options.monorepoPath === "ERR") {
|
|
1270
1242
|
logger.error(
|
|
1271
1243
|
"ERROR: --use-adaptors-monorepo was passed, but OPENFN_ADAPTORS_REPO env var is undefined"
|
|
1272
1244
|
);
|
|
1273
1245
|
logger.error("Set OPENFN_ADAPTORS_REPO to a path pointing to the repo");
|
|
1274
1246
|
process.exit(9);
|
|
1275
1247
|
}
|
|
1276
|
-
await map_adaptors_to_monorepo_default(
|
|
1277
|
-
|
|
1278
|
-
|
|
1248
|
+
await map_adaptors_to_monorepo_default(
|
|
1249
|
+
options,
|
|
1250
|
+
logger
|
|
1251
|
+
);
|
|
1279
1252
|
}
|
|
1280
|
-
if (!/^(deploy|test|version)$/.test(
|
|
1253
|
+
if (!/^(pull|deploy|test|version)$/.test(options.command) && !options.repoDir) {
|
|
1281
1254
|
logger.warn(
|
|
1282
1255
|
"WARNING: no repo module dir found! Using the default (/tmp/repo)"
|
|
1283
1256
|
);
|
|
@@ -1285,17 +1258,13 @@ var parse = async (basePath, options, log) => {
|
|
|
1285
1258
|
"You should set OPENFN_REPO_DIR or pass --repoDir=some/path in to the CLI"
|
|
1286
1259
|
);
|
|
1287
1260
|
}
|
|
1288
|
-
const handler =
|
|
1289
|
-
if (!opts.command || /^(compile|execute)$/.test(opts.command)) {
|
|
1290
|
-
assertPath(basePath);
|
|
1291
|
-
}
|
|
1261
|
+
const handler = handlers[options.command];
|
|
1292
1262
|
if (!handler) {
|
|
1293
1263
|
logger.error(`Unrecognised command: ${options.command}`);
|
|
1294
1264
|
process.exit(1);
|
|
1295
1265
|
}
|
|
1296
1266
|
try {
|
|
1297
|
-
|
|
1298
|
-
return result;
|
|
1267
|
+
return await handler(options, logger);
|
|
1299
1268
|
} catch (e) {
|
|
1300
1269
|
if (!process.exitCode) {
|
|
1301
1270
|
process.exitCode = e.exitCode || 1;
|
|
@@ -1309,21 +1278,11 @@ var parse = async (basePath, options, log) => {
|
|
|
1309
1278
|
}
|
|
1310
1279
|
};
|
|
1311
1280
|
var commands_default = parse;
|
|
1312
|
-
var assertPath = (basePath) => {
|
|
1313
|
-
if (!basePath) {
|
|
1314
|
-
console.error("ERROR: no path provided!");
|
|
1315
|
-
console.error("\nUsage:");
|
|
1316
|
-
console.error(" open path/to/job");
|
|
1317
|
-
console.error("\nFor more help do:");
|
|
1318
|
-
console.error(" openfn --help ");
|
|
1319
|
-
process.exit(1);
|
|
1320
|
-
}
|
|
1321
|
-
};
|
|
1322
1281
|
|
|
1323
1282
|
// src/process/runner.ts
|
|
1324
|
-
process.on("message", ({ init,
|
|
1283
|
+
process.on("message", ({ init, opts }) => {
|
|
1325
1284
|
if (init) {
|
|
1326
|
-
commands_default(
|
|
1285
|
+
commands_default(opts).then(() => {
|
|
1327
1286
|
process.send({ done: true, exitCode: process.exitCode });
|
|
1328
1287
|
});
|
|
1329
1288
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "CLI devtools for the openfn toolchain.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18",
|
|
@@ -26,25 +26,29 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@openfn/language-common": "2.0.0-rc3",
|
|
28
28
|
"@types/mock-fs": "^4.13.1",
|
|
29
|
-
"@types/node": "^
|
|
29
|
+
"@types/node": "^18.15.13",
|
|
30
|
+
"@types/rimraf": "^3.0.2",
|
|
31
|
+
"@types/treeify": "^1.0.0",
|
|
30
32
|
"@types/yargs": "^17.0.24",
|
|
31
|
-
"ava": "5.1
|
|
33
|
+
"ava": "5.3.1",
|
|
32
34
|
"mock-fs": "^5.1.4",
|
|
33
35
|
"ts-node": "^10.9.1",
|
|
34
36
|
"tslib": "^2.4.0",
|
|
35
|
-
"tsup": "^
|
|
36
|
-
"typescript": "^
|
|
37
|
+
"tsup": "^7.2.0",
|
|
38
|
+
"typescript": "^5.1.6"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
41
|
+
"@inquirer/prompts": "^1.1.4",
|
|
42
|
+
"chalk": "^5.1.2",
|
|
39
43
|
"figures": "^5.0.0",
|
|
40
44
|
"rimraf": "^3.0.2",
|
|
41
45
|
"treeify": "^1.1.0",
|
|
42
46
|
"yargs": "^17.7.2",
|
|
43
|
-
"@openfn/compiler": "0.0.
|
|
44
|
-
"@openfn/deploy": "0.2.
|
|
47
|
+
"@openfn/compiler": "0.0.36",
|
|
48
|
+
"@openfn/deploy": "0.2.6",
|
|
45
49
|
"@openfn/describe-package": "0.0.18",
|
|
46
|
-
"@openfn/logger": "0.0.
|
|
47
|
-
"@openfn/runtime": "0.0.
|
|
50
|
+
"@openfn/logger": "0.0.17",
|
|
51
|
+
"@openfn/runtime": "0.0.30"
|
|
48
52
|
},
|
|
49
53
|
"files": [
|
|
50
54
|
"dist",
|
|
@@ -53,7 +57,7 @@
|
|
|
53
57
|
"scripts": {
|
|
54
58
|
"test": "pnpm ava",
|
|
55
59
|
"test:watch": "pnpm ava -w",
|
|
56
|
-
"test:types": "pnpm tsc --
|
|
60
|
+
"test:types": "pnpm tsc --project tsconfig.test.json",
|
|
57
61
|
"build": "tsup --config ./tsup.config.js",
|
|
58
62
|
"build:watch": "pnpm build --watch",
|
|
59
63
|
"openfn": "node --no-warnings dist/index.js",
|
package/dist/chunk-UBDWXKSG.js
DELETED
|
@@ -1,33 +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/constants.ts
|
|
28
|
-
var DEFAULT_REPO_DIR = "/tmp/openfn/repo";
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
expand_adaptors_default,
|
|
32
|
-
DEFAULT_REPO_DIR
|
|
33
|
-
};
|