@openfn/cli 0.0.25 → 0.0.27
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 +24 -0
- package/dist/index.js +3 -0
- package/dist/process/runner.js +49 -8
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -68,6 +68,30 @@ If no command is specified, execute will run.
|
|
|
68
68
|
|
|
69
69
|
To get more information about a command, including usage examples, run `openfn <command> help`, ie, `openfn compile help`.
|
|
70
70
|
|
|
71
|
+
## Logging
|
|
72
|
+
|
|
73
|
+
The CLI is actually a collection of packages, each of which will log with slightly different rules. To help understand where logs are coming from, each package prints a namespace or prefix at the start of its log.
|
|
74
|
+
|
|
75
|
+
* [CLI] - the CLI itself, responsible for parsing and validating user input, reading and writing to disk, and executing the correct functionality.
|
|
76
|
+
* [CMP] - the Compiler will parse openfn jobs into executable Javascript, changing your code
|
|
77
|
+
* [R/T] - the Runtime executes your job code in a secure sandboxed environment, one operation at a time
|
|
78
|
+
* [JOB] - the actual job code that your wrote. Any console.log statements in your job will appear under this namespace.
|
|
79
|
+
|
|
80
|
+
The CLI will log information at three different levels of verbosity: `default`, `info` and `debug` (`none` is also supported).
|
|
81
|
+
|
|
82
|
+
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.
|
|
83
|
+
|
|
84
|
+
Note that, unless explicitly overriden, jobs will always report at debug verbosity (meaning job logging will always be shown).
|
|
85
|
+
|
|
86
|
+
If something unexpected happens during a command, your first step should be to re-run with info-level logging.
|
|
87
|
+
|
|
88
|
+
`default` logging is designed to give high-level feedback about what you absolutely need to know. It will show any errors or warnings, as well as high-level reporting about what the command has actually done.
|
|
89
|
+
|
|
90
|
+
`info` level logging is suitable for most developers. It is more verbose than default but still aims to provide high-level information about a command. It includes version numbers, key paths, and simple reporting about how the compiler changes your code (see below).
|
|
91
|
+
|
|
92
|
+
`debug` level logging is highly verbose and aims to tell you everything that's going on under-the hood. This is aimed mostly at CLI/runtime developers and can be very useful for debugging problems.
|
|
93
|
+
|
|
94
|
+
|
|
71
95
|
## Compilation
|
|
72
96
|
|
|
73
97
|
The CLI will attempt to compile your job code into normalized Javascript. It will do a number of things to make your code robust and portable:
|
package/dist/index.js
CHANGED
|
@@ -105,6 +105,9 @@ var executeCommand = {
|
|
|
105
105
|
}).option("state-stdin", {
|
|
106
106
|
alias: "S",
|
|
107
107
|
description: "Read state from stdin (instead of a file)"
|
|
108
|
+
}).option("skip-adaptor-validation", {
|
|
109
|
+
boolean: true,
|
|
110
|
+
description: "Skip adaptor validation warnings"
|
|
108
111
|
}).option("timeout", {
|
|
109
112
|
alias: "-t",
|
|
110
113
|
description: "Set the timeout duration in MS"
|
package/dist/process/runner.js
CHANGED
|
@@ -89,6 +89,7 @@ function ensureOpts(basePath = ".", opts) {
|
|
|
89
89
|
timeout: opts.timeout,
|
|
90
90
|
specifier: opts.specifier,
|
|
91
91
|
strictOutput: opts.strictOutput ?? true,
|
|
92
|
+
skipAdaptorValidation: opts.skipAdaptorValidation ?? false,
|
|
92
93
|
immutable: opts.immutable || false
|
|
93
94
|
};
|
|
94
95
|
const set = (key, value) => {
|
|
@@ -299,7 +300,7 @@ var expand_adaptors_default = (names, log = nullLogger) => names?.map((name) =>
|
|
|
299
300
|
return name;
|
|
300
301
|
}
|
|
301
302
|
const expanded = `@openfn/language-${name}`;
|
|
302
|
-
log.
|
|
303
|
+
log.debug(`Expanded adaptor ${name} to ${expanded}`);
|
|
303
304
|
return expanded;
|
|
304
305
|
});
|
|
305
306
|
|
|
@@ -370,6 +371,23 @@ var list = async (options, logger) => {
|
|
|
370
371
|
logger.success("Installed packages:\n\n" + treeify.asTree(output));
|
|
371
372
|
};
|
|
372
373
|
|
|
374
|
+
// src/util/validate-adaptors.ts
|
|
375
|
+
var validateAdaptors = async (options, logger) => {
|
|
376
|
+
if (options.skipAdaptorValidation) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (!options.adaptors || options.adaptors.length === 0) {
|
|
380
|
+
logger.warn("WARNING: No adaptor provided!");
|
|
381
|
+
logger.warn(
|
|
382
|
+
"This job will probably fail. Pass an adaptor with the -a flag, eg:"
|
|
383
|
+
);
|
|
384
|
+
logger.break();
|
|
385
|
+
logger.print(" openfn job.js -a common");
|
|
386
|
+
logger.break();
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
var validate_adaptors_default = validateAdaptors;
|
|
390
|
+
|
|
373
391
|
// src/execute/handler.ts
|
|
374
392
|
var getAutoinstallTargets = (options) => {
|
|
375
393
|
if (options.autoinstall && options.adaptors) {
|
|
@@ -379,6 +397,7 @@ var getAutoinstallTargets = (options) => {
|
|
|
379
397
|
};
|
|
380
398
|
var executeHandler = async (options, logger) => {
|
|
381
399
|
const start = new Date().getTime();
|
|
400
|
+
await validate_adaptors_default(options, logger);
|
|
382
401
|
const autoInstallTargets = getAutoinstallTargets(options);
|
|
383
402
|
if (autoInstallTargets.length) {
|
|
384
403
|
const { repoDir } = options;
|
|
@@ -601,17 +620,29 @@ var handler_default5 = docsHandler;
|
|
|
601
620
|
|
|
602
621
|
// src/util/print-versions.ts
|
|
603
622
|
import { mainSymbols } from "figures";
|
|
623
|
+
import { getNameAndVersion as getNameAndVersion4 } from "@openfn/runtime";
|
|
604
624
|
var { triangleRightSmall: t } = mainSymbols;
|
|
605
|
-
var printVersions = async (logger) => {
|
|
625
|
+
var printVersions = async (logger, options = {}) => {
|
|
626
|
+
const prefix = (str) => ` ${t} ${str.padEnd(options.adaptors ? 16 : 8, " ")}`;
|
|
606
627
|
const pkg = await import("../../package.json", { assert: { type: "json" } });
|
|
607
628
|
const { version, dependencies } = pkg.default;
|
|
608
629
|
const compilerVersion = dependencies["@openfn/compiler"];
|
|
609
630
|
const runtimeVersion = dependencies["@openfn/runtime"];
|
|
631
|
+
const { adaptors } = options;
|
|
632
|
+
let adaptorVersionString = "";
|
|
633
|
+
if (adaptors && adaptors.length === 1) {
|
|
634
|
+
const [a] = adaptors;
|
|
635
|
+
const { name, version: version2 } = getNameAndVersion4(a);
|
|
636
|
+
adaptorVersionString = `
|
|
637
|
+
${prefix(
|
|
638
|
+
"adaptor " + name.replace(/^@openfn\/language-/, "")
|
|
639
|
+
)}${version2 || "latest"}`;
|
|
640
|
+
}
|
|
610
641
|
logger.info(`Versions:
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
642
|
+
${prefix("node.js")}${process.version.substring(1)}
|
|
643
|
+
${prefix("cli")}${version}
|
|
644
|
+
${prefix("runtime")}${runtimeVersion}
|
|
645
|
+
${prefix("compiler")}${compilerVersion}${adaptorVersionString}`);
|
|
615
646
|
};
|
|
616
647
|
var print_versions_default = printVersions;
|
|
617
648
|
|
|
@@ -632,7 +663,7 @@ var parse = async (basePath, options, log) => {
|
|
|
632
663
|
const opts = ensureOpts(basePath, options);
|
|
633
664
|
const logger = log || logger_default(CLI, opts);
|
|
634
665
|
if (opts.command === "execute" || opts.command === "test") {
|
|
635
|
-
await print_versions_default(logger);
|
|
666
|
+
await print_versions_default(logger, opts);
|
|
636
667
|
}
|
|
637
668
|
if (opts.adaptors && opts.expand) {
|
|
638
669
|
opts.adaptors = expand_adaptors_default(opts.adaptors, logger);
|
|
@@ -653,7 +684,17 @@ var parse = async (basePath, options, log) => {
|
|
|
653
684
|
logger.error(`Unrecognise command: ${options.command}`);
|
|
654
685
|
process.exit(1);
|
|
655
686
|
}
|
|
656
|
-
|
|
687
|
+
try {
|
|
688
|
+
const result = await handler(opts, logger);
|
|
689
|
+
return result;
|
|
690
|
+
} catch (e) {
|
|
691
|
+
if (!process.exitCode) {
|
|
692
|
+
process.exitCode = e.exitCode || 1;
|
|
693
|
+
}
|
|
694
|
+
logger.break();
|
|
695
|
+
logger.error("Command failed!");
|
|
696
|
+
logger.error(e);
|
|
697
|
+
}
|
|
657
698
|
};
|
|
658
699
|
var commands_default = parse;
|
|
659
700
|
var assertPath = (basePath) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "CLI devtools for the openfn toolchain.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18",
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
"typescript": "^4.7.4"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@openfn/compiler": "0.0.22",
|
|
40
|
-
"@openfn/describe-package": "0.0.14",
|
|
41
|
-
"@openfn/logger": "0.0.8",
|
|
42
|
-
"@openfn/runtime": "0.0.15",
|
|
43
39
|
"fast-safe-stringify": "^2.1.1",
|
|
44
40
|
"figures": "^5.0.0",
|
|
45
41
|
"rimraf": "^3.0.2",
|
|
46
42
|
"treeify": "^1.1.0",
|
|
47
|
-
"yargs": "^17.5.1"
|
|
43
|
+
"yargs": "^17.5.1",
|
|
44
|
+
"@openfn/compiler": "0.0.23",
|
|
45
|
+
"@openfn/describe-package": "0.0.14",
|
|
46
|
+
"@openfn/logger": "0.0.8",
|
|
47
|
+
"@openfn/runtime": "0.0.17"
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
50
50
|
"dist",
|