@openfn/cli 1.18.6 → 1.20.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 CHANGED
@@ -32,6 +32,18 @@ function spawn_default(opts2) {
32
32
  import yargs from "yargs";
33
33
  import { hideBin } from "yargs/helpers";
34
34
 
35
+ // src/env.ts
36
+ import { config } from "dotenv";
37
+ import { expand } from "dotenv-expand";
38
+ var env;
39
+ var env_default = (path3) => {
40
+ env = expand(config({ path: path3, override: true, debug: false, quiet: true }));
41
+ if (env.error) {
42
+ return null;
43
+ }
44
+ return env.parsed;
45
+ };
46
+
35
47
  // src/options.ts
36
48
  import nodePath from "node:path";
37
49
 
@@ -39,7 +51,7 @@ import nodePath from "node:path";
39
51
  var DEFAULT_REPO_DIR = "/tmp/openfn/repo";
40
52
 
41
53
  // src/util/expand-adaptors.ts
42
- var expand = (name) => {
54
+ var expand2 = (name) => {
43
55
  if (typeof name === "string") {
44
56
  const [left] = name.split("=");
45
57
  if (left.match("/") || left.endsWith(".js")) {
@@ -51,13 +63,13 @@ var expand = (name) => {
51
63
  };
52
64
  var expand_adaptors_default = (input) => {
53
65
  if (Array.isArray(input)) {
54
- return input?.map(expand);
66
+ return input?.map(expand2);
55
67
  }
56
68
  const plan = input;
57
69
  Object.values(plan.workflow.steps).forEach((step) => {
58
70
  const job = step;
59
71
  if (job.adaptors) {
60
- job.adaptors = job.adaptors.map(expand);
72
+ job.adaptors = job.adaptors.map(expand2);
61
73
  }
62
74
  });
63
75
  return plan;
@@ -224,14 +236,6 @@ var apolloUrl = {
224
236
  });
225
237
  }
226
238
  };
227
- var json = {
228
- name: "json",
229
- yargs: {
230
- boolean: true,
231
- description: "Output the result as a json object",
232
- default: false
233
- }
234
- };
235
239
  var beta = {
236
240
  name: "beta",
237
241
  yargs: {
@@ -307,7 +311,7 @@ var endpoint = {
307
311
  description: "[beta only] URL to Lightning endpoint"
308
312
  }
309
313
  };
310
- var env = {
314
+ var env2 = {
311
315
  name: "env",
312
316
  yargs: {
313
317
  description: "[beta only] Environment name (eg staging, prod, branch)"
@@ -589,6 +593,21 @@ var workflowMappings = {
589
593
  description: "A manual object mapping of which workflows in source and target should be matched for a merge."
590
594
  }
591
595
  };
596
+ var workspace = {
597
+ name: "workspace",
598
+ yargs: {
599
+ alias: ["w"],
600
+ description: "Path to the project workspace (ie, path to openfn.yaml)"
601
+ },
602
+ ensure: (opts2) => {
603
+ const ws = opts2.workspace ?? process.env.OPENFN_WORKSPACE;
604
+ if (!ws) {
605
+ opts2.workspace = process.cwd();
606
+ } else {
607
+ opts2.workspace = nodePath.resolve(ws);
608
+ }
609
+ }
610
+ };
592
611
 
593
612
  // src/util/command-builders.ts
594
613
  import c from "chalk";
@@ -604,15 +623,15 @@ function build(opts2, yargs2) {
604
623
  yargs2
605
624
  );
606
625
  }
607
- var ensure = (command, opts2) => (yargs2) => {
608
- yargs2.command = command;
626
+ var ensure = (command6, opts2) => (yargs2) => {
627
+ yargs2.command = command6;
609
628
  opts2.filter((opt) => opt.ensure).forEach((opt) => {
610
629
  try {
611
630
  opt.ensure(yargs2);
612
631
  } catch (e) {
613
632
  console.error(
614
633
  c.red(`
615
- Error parsing command arguments: ${command}.${opt.name}
634
+ Error parsing command arguments: ${command6}.${opt.name}
616
635
  `)
617
636
  );
618
637
  console.error(c.red("Aborting"));
@@ -621,11 +640,11 @@ Error parsing command arguments: ${command}.${opt.name}
621
640
  }
622
641
  });
623
642
  };
624
- var override = (command, yargs2) => {
643
+ var override = (command6, yargs2) => {
625
644
  return {
626
- ...command,
645
+ ...command6,
627
646
  yargs: {
628
- ...command.yargs || {},
647
+ ...command6.yargs || {},
629
648
  ...yargs2
630
649
  }
631
650
  };
@@ -1016,7 +1035,7 @@ var options7 = [
1016
1035
  beta,
1017
1036
  configPath,
1018
1037
  endpoint,
1019
- env,
1038
+ env2,
1020
1039
  log,
1021
1040
  override(path2, {
1022
1041
  description: "path to output the project to"
@@ -1025,7 +1044,11 @@ var options7 = [
1025
1044
  projectPath,
1026
1045
  snapshots,
1027
1046
  statePath,
1028
- path2
1047
+ path2,
1048
+ // These are hidden commands used only by beta
1049
+ // The need to be declared here to be initialised and defaulted properly
1050
+ override(force, { hidden: true }),
1051
+ override(workspace, { hidden: true })
1029
1052
  ];
1030
1053
  var pullCommand = {
1031
1054
  command: "pull [projectId]",
@@ -1108,34 +1131,51 @@ var command_default10 = {
1108
1131
  builder: (yargs2) => build(options8, yargs2).example("test", "Run the test script")
1109
1132
  };
1110
1133
 
1111
- // src/projects/command.ts
1112
- var options9 = [projectPath];
1113
- var projectsCommand = {
1114
- command: "projects [project-path]",
1134
+ // src/projects/list.ts
1135
+ import { Workspace } from "@openfn/project";
1136
+ var options9 = [log, workspace];
1137
+ var command = {
1138
+ command: "list [project-path]",
1115
1139
  describe: "List all the openfn projects available in the current directory",
1116
- aliases: ["project"],
1117
- handler: ensure("projects", options9),
1140
+ aliases: ["project", "$0"],
1141
+ handler: ensure("project-list", options9),
1118
1142
  builder: (yargs2) => build(options9, yargs2)
1119
1143
  };
1120
- var command_default11 = projectsCommand;
1144
+ var list_default = command;
1121
1145
 
1122
- // src/checkout/command.ts
1123
- var options10 = [projectId, projectPath, log];
1124
- var checkoutCommand = {
1125
- command: "checkout <project-id>",
1126
- describe: "Switch to a different openfn project in the same workspace",
1127
- handler: ensure("checkout", options10),
1146
+ // src/projects/version.ts
1147
+ import { Workspace as Workspace2 } from "@openfn/project";
1148
+ var options10 = [workflow, workspace, workflowMappings];
1149
+ var command2 = {
1150
+ command: "version [workflow]",
1151
+ describe: "Returns the version hash of a given workflow in a workspace",
1152
+ handler: ensure("project-version", options10),
1128
1153
  builder: (yargs2) => build(options10, yargs2)
1129
1154
  };
1130
- var command_default12 = checkoutCommand;
1155
+ var version_default = command2;
1156
+
1157
+ // src/projects/merge.ts
1158
+ import Project3, { Workspace as Workspace4 } from "@openfn/project";
1131
1159
 
1132
- // src/merge/command.ts
1133
- var options11 = [
1160
+ // src/projects/checkout.ts
1161
+ import Project2, { Workspace as Workspace3 } from "@openfn/project";
1162
+ import { rimraf } from "rimraf";
1163
+ var options11 = [projectId, workspace, log];
1164
+ var command3 = {
1165
+ command: "checkout <project-id>",
1166
+ describe: "Switch to a different OpenFn project in the same workspace",
1167
+ handler: ensure("project-checkout", options11),
1168
+ builder: (yargs2) => build(options11, yargs2)
1169
+ };
1170
+ var checkout_default = command3;
1171
+
1172
+ // src/projects/merge.ts
1173
+ var options12 = [
1134
1174
  projectId,
1135
- projectPath,
1136
1175
  removeUnmapped,
1137
1176
  workflowMappings,
1138
1177
  log,
1178
+ workspace,
1139
1179
  // custom output because we don't want defaults or anything
1140
1180
  {
1141
1181
  name: "output-path",
@@ -1155,27 +1195,71 @@ var options11 = [
1155
1195
  description: "Force a merge even when workflows are incompatible"
1156
1196
  })
1157
1197
  ];
1158
- var mergeCommand = {
1198
+ var command4 = {
1159
1199
  command: "merge <project-id>",
1160
- describe: "Merges the specified project into the checked out project",
1161
- handler: ensure("merge", options11),
1162
- builder: (yargs2) => build(options11, yargs2)
1200
+ describe: "Merges the specified project into the currently checked out project",
1201
+ handler: ensure("project-merge", options12),
1202
+ builder: (yargs2) => build(options12, yargs2)
1163
1203
  };
1164
- var command_default13 = mergeCommand;
1204
+ var merge_default = command4;
1165
1205
 
1166
- // src/version/command.ts
1167
- var options12 = [workflow, projectPath, workflowMappings, json];
1168
- var workflowVersionCommand = {
1169
- command: "project version [workflow]",
1170
- describe: "Returns the version has of a workflow",
1171
- handler: ensure("project", options12),
1172
- builder: (yargs2) => build(options12, yargs2)
1206
+ // src/projects/fetch.ts
1207
+ import Project4, { Workspace as Workspace5 } from "@openfn/project";
1208
+ var options13 = [
1209
+ apikey,
1210
+ configPath,
1211
+ endpoint,
1212
+ env2,
1213
+ log,
1214
+ override(outputPath, {
1215
+ description: "Path to output the fetched project to"
1216
+ }),
1217
+ logJson,
1218
+ workspace,
1219
+ snapshots,
1220
+ statePath,
1221
+ override(force, {
1222
+ description: "Overwrite local file contents with the fetched contents"
1223
+ })
1224
+ ];
1225
+ var command5 = {
1226
+ command: "fetch [projectId]",
1227
+ describe: `Fetch a project's state and spec from a Lightning Instance to the local state file without expanding to the filesystem.`,
1228
+ builder: (yargs2) => build(options13, yargs2).positional("projectId", {
1229
+ describe: "The id of the project that should be fetched, should be a UUID",
1230
+ demandOption: true
1231
+ }).example(
1232
+ "fetch 57862287-23e6-4650-8d79-e1dd88b24b1c",
1233
+ "Fetch an updated copy of a the above spec and state from a Lightning Instance"
1234
+ ),
1235
+ handler: ensure("project-fetch", options13)
1236
+ };
1237
+ var fetch_default = command5;
1238
+
1239
+ // src/projects/command.ts
1240
+ var projectsCommand = {
1241
+ command: "project [subcommand]",
1242
+ aliases: ["projects"],
1243
+ describe: "Sync and manage an OpenFn project",
1244
+ handler: () => {
1245
+ },
1246
+ builder: (yargs2) => yargs2.command(list_default).command(version_default).command(merge_default).command(checkout_default).command(fetch_default).example("project", "list all projects in the workspace").example("project list", "list all projects in the workspace").example(
1247
+ "project checkout staging",
1248
+ "Checkout the project with id staging"
1249
+ ).example(
1250
+ "project merge staging",
1251
+ "Merge staging into the checkout-out branch"
1252
+ )
1173
1253
  };
1174
- var command_default14 = workflowVersionCommand;
1254
+ var command_default11 = projectsCommand;
1175
1255
 
1176
1256
  // src/cli.ts
1257
+ var env3 = env_default();
1258
+ if (env3) {
1259
+ process.env.$DOT_ENV_OVERRIDES = Object.keys(env3).join(",");
1260
+ }
1177
1261
  var y = yargs(hideBin(process.argv));
1178
- var cmd = y.command(command_default7).command(command_default3).command(command_default2).command(command_default4).command(install).command(repo).command(command_default10).command(command_default6).command(command_default).command(command_default8).command(command_default5).command(command_default9).command(command_default11).command(command_default12).command(command_default13).command(command_default14).command({
1262
+ var cmd = y.command(command_default7).command(command_default3).command(command_default2).command(command_default4).command(install).command(repo).command(command_default10).command(command_default6).command(command_default).command(command_default8).command(command_default5).command(command_default9).command(command_default11).command(checkout_default).command(merge_default).command(fetch_default).command({
1179
1263
  command: "version",
1180
1264
  describe: "Show the currently installed version of the CLI, compiler and runtime.",
1181
1265
  handler: (argv) => {