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