@openfn/cli 0.1.0 → 0.2.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/dist/index.js +28 -6
- package/dist/process/runner.js +79 -39
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -100,6 +100,16 @@ var configPath = {
|
|
|
100
100
|
default: "./.config.json"
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
|
+
var describe = {
|
|
104
|
+
name: "describe",
|
|
105
|
+
yargs: {
|
|
106
|
+
boolean: true,
|
|
107
|
+
description: "Downloads the project yaml from the specified instance"
|
|
108
|
+
},
|
|
109
|
+
ensure: (opts2) => {
|
|
110
|
+
setDefaultValue(opts2, "describe", true);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
103
113
|
var expandAdaptors = {
|
|
104
114
|
name: "no-expand-adaptors",
|
|
105
115
|
yargs: {
|
|
@@ -362,7 +372,7 @@ var compileCommand = {
|
|
|
362
372
|
var command_default = compileCommand;
|
|
363
373
|
|
|
364
374
|
// src/deploy/command.ts
|
|
365
|
-
var options2 = [statePath, projectPath, configPath, confirm];
|
|
375
|
+
var options2 = [statePath, projectPath, configPath, confirm, describe];
|
|
366
376
|
var deployCommand = {
|
|
367
377
|
command: "deploy",
|
|
368
378
|
desc: "Deploy a project's config to a remote Lightning instance",
|
|
@@ -469,6 +479,18 @@ var command_default6 = {
|
|
|
469
479
|
)
|
|
470
480
|
};
|
|
471
481
|
|
|
482
|
+
// src/pull/command.ts
|
|
483
|
+
var options5 = [statePath, projectPath, configPath];
|
|
484
|
+
var pullCommand = {
|
|
485
|
+
command: "pull",
|
|
486
|
+
desc: "Pull aproject's state and spec from a Lightning Instance to the local directory",
|
|
487
|
+
builder: (yargs2) => {
|
|
488
|
+
return build(options5, yargs2).example("pull", "Pull an updated copy of a project spec and state from a Lightning Instance");
|
|
489
|
+
},
|
|
490
|
+
handler: ensure("pull", options5)
|
|
491
|
+
};
|
|
492
|
+
var command_default7 = pullCommand;
|
|
493
|
+
|
|
472
494
|
// src/repo/command.ts
|
|
473
495
|
var repo = {
|
|
474
496
|
command: "repo [subcommand]",
|
|
@@ -525,17 +547,17 @@ var list = {
|
|
|
525
547
|
};
|
|
526
548
|
|
|
527
549
|
// src/test/command.ts
|
|
528
|
-
var
|
|
529
|
-
var
|
|
550
|
+
var options6 = [stateStdin];
|
|
551
|
+
var command_default8 = {
|
|
530
552
|
command: "test",
|
|
531
553
|
desc: "Compiles and runs a test job, printing the result to stdout",
|
|
532
|
-
handler: ensure("test",
|
|
533
|
-
builder: (yargs2) => build(
|
|
554
|
+
handler: ensure("test", options6),
|
|
555
|
+
builder: (yargs2) => build(options6, yargs2).example("test", "Run the test script")
|
|
534
556
|
};
|
|
535
557
|
|
|
536
558
|
// src/cli.ts
|
|
537
559
|
var y = yargs(hideBin(process.argv));
|
|
538
|
-
var cmd = y.command(command_default5).command(command_default).command(command_default2).command(install).command(repo).command(
|
|
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).option("log", {
|
|
539
561
|
alias: ["l"],
|
|
540
562
|
description: "Set the default log level to none, default, info or debug",
|
|
541
563
|
array: true
|
package/dist/process/runner.js
CHANGED
|
@@ -78,13 +78,13 @@ var execute_default = async (input, state, opts, logger) => {
|
|
|
78
78
|
};
|
|
79
79
|
function parseAdaptors(opts) {
|
|
80
80
|
const extractInfo = (specifier) => {
|
|
81
|
-
const [module,
|
|
81
|
+
const [module, path8] = specifier.split("=");
|
|
82
82
|
const { name, version } = getNameAndVersion(module);
|
|
83
83
|
const info = {
|
|
84
84
|
name
|
|
85
85
|
};
|
|
86
|
-
if (
|
|
87
|
-
info.path =
|
|
86
|
+
if (path8) {
|
|
87
|
+
info.path = path8;
|
|
88
88
|
}
|
|
89
89
|
if (version) {
|
|
90
90
|
info.version = version;
|
|
@@ -286,10 +286,10 @@ var stripVersionSpecifier = (specifier) => {
|
|
|
286
286
|
return specifier;
|
|
287
287
|
};
|
|
288
288
|
var resolveSpecifierPath = async (pattern, repoDir, log) => {
|
|
289
|
-
const [specifier,
|
|
290
|
-
if (
|
|
291
|
-
log.debug(`Resolved ${specifier} to path: ${
|
|
292
|
-
return
|
|
289
|
+
const [specifier, path8] = pattern.split("=");
|
|
290
|
+
if (path8) {
|
|
291
|
+
log.debug(`Resolved ${specifier} to path: ${path8}`);
|
|
292
|
+
return path8;
|
|
293
293
|
}
|
|
294
294
|
const repoPath = await getModulePath(specifier, repoDir, log);
|
|
295
295
|
if (repoPath) {
|
|
@@ -306,16 +306,16 @@ var loadTransformOptions = async (opts, log) => {
|
|
|
306
306
|
const [pattern] = opts.adaptors;
|
|
307
307
|
const [specifier] = pattern.split("=");
|
|
308
308
|
log.debug(`Attempting to preload types for ${specifier}`);
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
309
|
+
const path8 = await resolveSpecifierPath(pattern, opts.repoDir, log);
|
|
310
|
+
if (path8) {
|
|
311
311
|
try {
|
|
312
312
|
exports = await preloadAdaptorExports(
|
|
313
|
-
|
|
313
|
+
path8,
|
|
314
314
|
opts.useAdaptorsMonorepo,
|
|
315
315
|
log
|
|
316
316
|
);
|
|
317
317
|
} catch (e) {
|
|
318
|
-
log.error(`Failed to load adaptor typedefs from path ${
|
|
318
|
+
log.error(`Failed to load adaptor typedefs from path ${path8}`);
|
|
319
319
|
log.error(e);
|
|
320
320
|
}
|
|
321
321
|
}
|
|
@@ -754,20 +754,20 @@ var RETRY_COUNT = 20;
|
|
|
754
754
|
var TIMEOUT_MS = 1e3 * 60;
|
|
755
755
|
var actualDocGen = (specifier) => describePackage(specifier, {});
|
|
756
756
|
var ensurePath = (filePath) => mkdirSync(path3.dirname(filePath), { recursive: true });
|
|
757
|
-
var generatePlaceholder = (
|
|
758
|
-
writeFileSync(
|
|
757
|
+
var generatePlaceholder = (path8) => {
|
|
758
|
+
writeFileSync(path8, `{ "loading": true, "timestamp": ${Date.now()}}`);
|
|
759
759
|
};
|
|
760
760
|
var finish = (logger, resultPath) => {
|
|
761
761
|
logger.success("Done! Docs can be found at:\n");
|
|
762
762
|
logger.print(` ${path3.resolve(resultPath)}`);
|
|
763
763
|
};
|
|
764
|
-
var generateDocs = async (specifier,
|
|
764
|
+
var generateDocs = async (specifier, path8, docgen, logger) => {
|
|
765
765
|
const result = await docgen(specifier);
|
|
766
|
-
await writeFile3(
|
|
767
|
-
finish(logger,
|
|
768
|
-
return
|
|
766
|
+
await writeFile3(path8, JSON.stringify(result, null, 2));
|
|
767
|
+
finish(logger, path8);
|
|
768
|
+
return path8;
|
|
769
769
|
};
|
|
770
|
-
var waitForDocs = async (docs,
|
|
770
|
+
var waitForDocs = async (docs, path8, logger, retryDuration = RETRY_DURATION) => {
|
|
771
771
|
try {
|
|
772
772
|
if (docs.hasOwnProperty("loading")) {
|
|
773
773
|
logger.info("Docs are being loaded by another process. Waiting.");
|
|
@@ -779,19 +779,19 @@ var waitForDocs = async (docs, path7, logger, retryDuration = RETRY_DURATION) =>
|
|
|
779
779
|
clearInterval(i);
|
|
780
780
|
reject(new Error("Timed out waiting for docs to load"));
|
|
781
781
|
}
|
|
782
|
-
const updated = JSON.parse(readFileSync(
|
|
782
|
+
const updated = JSON.parse(readFileSync(path8, "utf8"));
|
|
783
783
|
if (!updated.hasOwnProperty("loading")) {
|
|
784
784
|
logger.info("Docs found!");
|
|
785
785
|
clearInterval(i);
|
|
786
|
-
resolve(
|
|
786
|
+
resolve(path8);
|
|
787
787
|
}
|
|
788
788
|
count++;
|
|
789
789
|
}, retryDuration);
|
|
790
790
|
});
|
|
791
791
|
} else {
|
|
792
|
-
logger.info(`Docs already written to cache at ${
|
|
793
|
-
finish(logger,
|
|
794
|
-
return
|
|
792
|
+
logger.info(`Docs already written to cache at ${path8}`);
|
|
793
|
+
finish(logger, path8);
|
|
794
|
+
return path8;
|
|
795
795
|
}
|
|
796
796
|
} catch (e) {
|
|
797
797
|
logger.error("Existing doc JSON corrupt. Aborting");
|
|
@@ -808,28 +808,28 @@ var docgenHandler = (options, logger, docgen = actualDocGen, retryDuration = RET
|
|
|
808
808
|
process.exit(9);
|
|
809
809
|
}
|
|
810
810
|
logger.success(`Generating docs for ${specifier}`);
|
|
811
|
-
const
|
|
812
|
-
ensurePath(
|
|
811
|
+
const path8 = `${repoDir}/docs/${specifier}.json`;
|
|
812
|
+
ensurePath(path8);
|
|
813
813
|
const handleError = () => {
|
|
814
814
|
logger.info("Removing placeholder");
|
|
815
|
-
rmSync(
|
|
815
|
+
rmSync(path8);
|
|
816
816
|
};
|
|
817
817
|
try {
|
|
818
|
-
const existing = readFileSync(
|
|
818
|
+
const existing = readFileSync(path8, "utf8");
|
|
819
819
|
const json = JSON.parse(existing);
|
|
820
820
|
if (json && json.timeout && Date.now() - json.timeout >= TIMEOUT_MS) {
|
|
821
821
|
logger.info(`Expired placeholder found. Removing.`);
|
|
822
|
-
rmSync(
|
|
822
|
+
rmSync(path8);
|
|
823
823
|
throw new Error("TIMEOUT");
|
|
824
824
|
}
|
|
825
|
-
return waitForDocs(json,
|
|
825
|
+
return waitForDocs(json, path8, logger, retryDuration);
|
|
826
826
|
} catch (e) {
|
|
827
827
|
if (e.message !== "TIMEOUT") {
|
|
828
|
-
logger.info(`Docs JSON not found at ${
|
|
828
|
+
logger.info(`Docs JSON not found at ${path8}`);
|
|
829
829
|
}
|
|
830
830
|
logger.debug("Generating placeholder");
|
|
831
|
-
generatePlaceholder(
|
|
832
|
-
return generateDocs(specifier,
|
|
831
|
+
generatePlaceholder(path8);
|
|
832
|
+
return generateDocs(specifier, path8, docgen, logger).catch((e2) => {
|
|
833
833
|
logger.error("Error generating documentation");
|
|
834
834
|
logger.error(e2);
|
|
835
835
|
handleError();
|
|
@@ -878,7 +878,7 @@ var docsHandler = async (options, logger) => {
|
|
|
878
878
|
logger.success(`Showing docs for ${adaptorName} v${version}`);
|
|
879
879
|
}
|
|
880
880
|
logger.info("Generating/loading documentation...");
|
|
881
|
-
const
|
|
881
|
+
const path8 = await handler_default5(
|
|
882
882
|
{
|
|
883
883
|
specifier: `${name}@${version}`,
|
|
884
884
|
repoDir
|
|
@@ -886,8 +886,8 @@ var docsHandler = async (options, logger) => {
|
|
|
886
886
|
createNullLogger()
|
|
887
887
|
);
|
|
888
888
|
let didError = false;
|
|
889
|
-
if (
|
|
890
|
-
const source = await readFile2(
|
|
889
|
+
if (path8) {
|
|
890
|
+
const source = await readFile2(path8, "utf8");
|
|
891
891
|
const data = JSON.parse(source);
|
|
892
892
|
let desc;
|
|
893
893
|
if (operation) {
|
|
@@ -1033,8 +1033,47 @@ var metadataHandler = async (options, logger) => {
|
|
|
1033
1033
|
};
|
|
1034
1034
|
var handler_default7 = metadataHandler;
|
|
1035
1035
|
|
|
1036
|
+
// src/pull/handler.ts
|
|
1037
|
+
import path5 from "path";
|
|
1038
|
+
import fs3 from "node:fs/promises";
|
|
1039
|
+
import {
|
|
1040
|
+
getProject,
|
|
1041
|
+
getConfig as getConfig2,
|
|
1042
|
+
getState
|
|
1043
|
+
} from "@openfn/deploy";
|
|
1044
|
+
async function pullHandler(options, logger) {
|
|
1045
|
+
try {
|
|
1046
|
+
const config = mergeOverrides2(await getConfig2(options.configPath), options);
|
|
1047
|
+
logger.always("Downloading project yaml and state from instance");
|
|
1048
|
+
const state = await getState(config.statePath);
|
|
1049
|
+
const { data: new_state } = await getProject(config, state.id);
|
|
1050
|
+
const url = new URL(`/download/yaml?id=${state.id}`, config.endpoint);
|
|
1051
|
+
const res = await fetch(url);
|
|
1052
|
+
await fs3.writeFile(path5.resolve(config.specPath), res.body);
|
|
1053
|
+
await fs3.writeFile(path5.resolve(config.statePath), new_state);
|
|
1054
|
+
logger.success("Project pulled successfully");
|
|
1055
|
+
process.exitCode = 0;
|
|
1056
|
+
return true;
|
|
1057
|
+
} catch (error) {
|
|
1058
|
+
throw error;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function mergeOverrides2(config, options) {
|
|
1062
|
+
return {
|
|
1063
|
+
...config,
|
|
1064
|
+
apiKey: pickFirst2(process.env["OPENFN_API_KEY"], config.apiKey),
|
|
1065
|
+
endpoint: pickFirst2(process.env["OPENFN_ENDPOINT"], config.endpoint),
|
|
1066
|
+
configPath: options.configPath,
|
|
1067
|
+
requireConfirmation: pickFirst2(options.confirm, config.requireConfirmation)
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
function pickFirst2(...args) {
|
|
1071
|
+
return args.find((arg) => arg !== void 0 && arg !== null);
|
|
1072
|
+
}
|
|
1073
|
+
var handler_default8 = pullHandler;
|
|
1074
|
+
|
|
1036
1075
|
// src/util/ensure-opts.ts
|
|
1037
|
-
import
|
|
1076
|
+
import path6 from "node:path";
|
|
1038
1077
|
var defaultLoggerOptions = {
|
|
1039
1078
|
default: "default",
|
|
1040
1079
|
job: "debug"
|
|
@@ -1112,7 +1151,7 @@ function ensureOpts(basePath = ".", opts) {
|
|
|
1112
1151
|
}
|
|
1113
1152
|
let baseDir = basePath;
|
|
1114
1153
|
if (basePath.endsWith(".js")) {
|
|
1115
|
-
baseDir =
|
|
1154
|
+
baseDir = path6.dirname(basePath);
|
|
1116
1155
|
set2("jobPath", basePath);
|
|
1117
1156
|
} else {
|
|
1118
1157
|
set2("jobPath", `${baseDir}/job.js`);
|
|
@@ -1130,7 +1169,7 @@ function ensureOpts(basePath = ".", opts) {
|
|
|
1130
1169
|
|
|
1131
1170
|
// src/util/print-versions.ts
|
|
1132
1171
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
1133
|
-
import
|
|
1172
|
+
import path7 from "node:path";
|
|
1134
1173
|
import { getNameAndVersion as getNameAndVersion6 } from "@openfn/runtime";
|
|
1135
1174
|
import { mainSymbols } from "figures";
|
|
1136
1175
|
var NODE = "node.js";
|
|
@@ -1140,7 +1179,7 @@ var COMPILER2 = "compiler";
|
|
|
1140
1179
|
var { triangleRightSmall: t } = mainSymbols;
|
|
1141
1180
|
var loadVersionFromPath = (adaptorPath) => {
|
|
1142
1181
|
try {
|
|
1143
|
-
const pkg = JSON.parse(readFileSync3(
|
|
1182
|
+
const pkg = JSON.parse(readFileSync3(path7.resolve(adaptorPath, "package.json"), "utf8"));
|
|
1144
1183
|
return pkg.version;
|
|
1145
1184
|
} catch (e) {
|
|
1146
1185
|
return "unknown";
|
|
@@ -1212,6 +1251,7 @@ var handlers = {
|
|
|
1212
1251
|
docgen: handler_default5,
|
|
1213
1252
|
docs: handler_default6,
|
|
1214
1253
|
metadata: handler_default7,
|
|
1254
|
+
pull: handler_default8,
|
|
1215
1255
|
["repo-clean"]: clean,
|
|
1216
1256
|
["repo-install"]: install,
|
|
1217
1257
|
["repo-pwd"]: pwd,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI devtools for the openfn toolchain.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"rimraf": "^3.0.2",
|
|
41
41
|
"treeify": "^1.1.0",
|
|
42
42
|
"yargs": "^17.5.1",
|
|
43
|
-
"@openfn/
|
|
44
|
-
"@openfn/
|
|
43
|
+
"@openfn/compiler": "0.0.32",
|
|
44
|
+
"@openfn/deploy": "0.2.0",
|
|
45
45
|
"@openfn/logger": "0.0.13",
|
|
46
46
|
"@openfn/describe-package": "0.0.16",
|
|
47
|
-
"@openfn/
|
|
47
|
+
"@openfn/runtime": "0.0.26"
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
50
50
|
"dist",
|