@openfn/cli 1.18.2 → 1.18.4

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
@@ -1136,6 +1136,21 @@ var options11 = [
1136
1136
  removeUnmapped,
1137
1137
  workflowMappings,
1138
1138
  log,
1139
+ // custom output because we don't want defaults or anything
1140
+ {
1141
+ name: "output-path",
1142
+ yargs: {
1143
+ alias: "o",
1144
+ description: "Optionally write the merged project file to a custom location"
1145
+ }
1146
+ },
1147
+ {
1148
+ name: "base",
1149
+ yargs: {
1150
+ alias: "target",
1151
+ description: "Path to the base (target) state file to merge into (ie, what main should be)"
1152
+ }
1153
+ },
1139
1154
  override(force, {
1140
1155
  description: "Force a merge even when workflows are incompatible"
1141
1156
  })
@@ -2127,12 +2127,16 @@ async function handler2(options, logger) {
2127
2127
  const config = workspace.getConfig();
2128
2128
  const { data } = await getProject(cfg, options.projectId);
2129
2129
  const name = options.env || "project";
2130
- const project = Project3.from("state", data, {
2131
- config,
2132
- endpoint: cfg.endpoint,
2133
- env: name,
2134
- fetched_at: (/* @__PURE__ */ new Date()).toISOString()
2135
- });
2130
+ const project = await Project3.from(
2131
+ "state",
2132
+ data,
2133
+ {
2134
+ endpoint: cfg.endpoint,
2135
+ env: name,
2136
+ fetched_at: (/* @__PURE__ */ new Date()).toISOString()
2137
+ },
2138
+ config
2139
+ );
2136
2140
  const projectFileName = project.getIdentifier();
2137
2141
  await fs4.mkdir(`${outputRoot}/.projects`, { recursive: true });
2138
2142
  let stateOutputPath = `${outputRoot}/.projects/${projectFileName}`;
@@ -2312,7 +2316,7 @@ var workflowVersionHandler = async (options, logger) => {
2312
2316
  if (options.workflow) {
2313
2317
  const workflow = activeProject?.getWorkflow(options.workflow);
2314
2318
  if (!workflow) {
2315
- logger.error(`No workflow found with id/name ${options.workflow}`);
2319
+ logger.error(`No workflow found with id ${options.workflow}`);
2316
2320
  return;
2317
2321
  }
2318
2322
  output.set(workflow.name || workflow.id, workflow.getVersionHash());
@@ -2352,19 +2356,16 @@ var checkoutHandler = async (options, logger) => {
2352
2356
  const { project: _, ...config } = workspace.getConfig();
2353
2357
  let switchProject;
2354
2358
  if (/\.(yaml|json)$/.test(options.projectId)) {
2355
- const filePath = path13.join(commandPath, options.projectId);
2359
+ const filePath = options.projectId.startsWith("/") ? options.projectId : path13.join(commandPath, options.projectId);
2356
2360
  logger.debug("Loading project from path ", filePath);
2357
- switchProject = await Project5.from("path", filePath, {
2358
- config
2359
- });
2361
+ switchProject = await Project5.from("path", filePath, config);
2360
2362
  } else {
2361
2363
  switchProject = workspace.get(options.projectId);
2362
2364
  }
2363
2365
  if (!switchProject) {
2364
- logger.error(
2365
- `Project with id/name ${options.projectId} not found in the workspace`
2366
+ throw new Error(
2367
+ `Project with id ${options.projectId} not found in the workspace`
2366
2368
  );
2367
- return;
2368
2369
  }
2369
2370
  await rimraf2(path13.join(commandPath, config.workflowRoot ?? "workflows"));
2370
2371
  const files = switchProject.serialize("fs");
@@ -2393,10 +2394,18 @@ var mergeHandler = async (options, logger) => {
2393
2394
  logger.error("Command was run in an invalid openfn workspace");
2394
2395
  return;
2395
2396
  }
2396
- const targetProject = workspace.getActiveProject();
2397
- if (!targetProject) {
2398
- logger.error(`No project currently checked out`);
2399
- return;
2397
+ let targetProject;
2398
+ if (options.base) {
2399
+ const basePath = path14.resolve(options.base);
2400
+ logger.debug("Loading target project from path", basePath);
2401
+ targetProject = await Project6.from("path", basePath);
2402
+ } else {
2403
+ targetProject = workspace.getActiveProject();
2404
+ if (!targetProject) {
2405
+ logger.error(`No project currently checked out`);
2406
+ return;
2407
+ }
2408
+ logger.debug(`Loading target project from workspace (${targetProject.id})`);
2400
2409
  }
2401
2410
  let sourceProject;
2402
2411
  if (/\.(yaml|json)$/.test(options.projectId)) {
@@ -2404,6 +2413,7 @@ var mergeHandler = async (options, logger) => {
2404
2413
  logger.debug("Loading source project from path ", filePath);
2405
2414
  sourceProject = await Project6.from("path", filePath);
2406
2415
  } else {
2416
+ logger.debug(`Loading source project from workspace ${options.projectId}`);
2407
2417
  sourceProject = workspace.get(options.projectId);
2408
2418
  }
2409
2419
  if (!sourceProject) {
@@ -2418,7 +2428,7 @@ var mergeHandler = async (options, logger) => {
2418
2428
  logger.error("The checked out project has no id");
2419
2429
  return;
2420
2430
  }
2421
- const finalPath = workspace.getProjectPath(targetProject.id);
2431
+ const finalPath = options.outputPath ?? workspace.getProjectPath(targetProject.id);
2422
2432
  if (!finalPath) {
2423
2433
  logger.error("Path to checked out project not found.");
2424
2434
  return;
@@ -2428,13 +2438,26 @@ var mergeHandler = async (options, logger) => {
2428
2438
  workflowMappings: options.workflowMappings,
2429
2439
  force: options.force
2430
2440
  });
2431
- const yaml = final.serialize("state", { format: "yaml" });
2432
- await fs7.writeFile(finalPath, yaml);
2441
+ let outputFormat = workspace.config.formats.project;
2442
+ if (options.outputPath?.endsWith(".json")) {
2443
+ outputFormat = "json";
2444
+ } else if (options.outputPath?.endsWith(".yaml")) {
2445
+ outputFormat = "yaml";
2446
+ }
2447
+ let finalState = final.serialize("state", {
2448
+ format: outputFormat
2449
+ });
2450
+ if (outputFormat === "json") {
2451
+ finalState = JSON.stringify(finalState, null, 2);
2452
+ }
2453
+ await fs7.writeFile(finalPath, finalState);
2454
+ logger.info(`Updated statefile at `, finalPath);
2455
+ logger.info("Checking out merged project to filesystem");
2433
2456
  await handler_default13(
2434
2457
  {
2435
2458
  command: "checkout",
2436
2459
  projectPath: commandPath,
2437
- projectId: final.id,
2460
+ projectId: options.outputPath ? finalPath : final.id,
2438
2461
  log: options.log
2439
2462
  },
2440
2463
  logger
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/cli",
3
- "version": "1.18.2",
3
+ "version": "1.18.4",
4
4
  "description": "CLI devtools for the OpenFn toolchain",
5
5
  "engines": {
6
6
  "node": ">=18",
@@ -48,12 +48,12 @@
48
48
  "ws": "^8.18.3",
49
49
  "yargs": "^17.7.2",
50
50
  "@openfn/compiler": "1.1.5",
51
- "@openfn/deploy": "0.11.3",
52
51
  "@openfn/describe-package": "0.1.5",
53
- "@openfn/lexicon": "^1.2.5",
52
+ "@openfn/deploy": "0.11.3",
53
+ "@openfn/lexicon": "^1.2.6",
54
54
  "@openfn/runtime": "1.7.5",
55
- "@openfn/logger": "1.0.6",
56
- "@openfn/project": "^0.7.1"
55
+ "@openfn/project": "^0.8.0",
56
+ "@openfn/logger": "1.0.6"
57
57
  },
58
58
  "files": [
59
59
  "dist",