Skip to content

Commit cf48e7d

Browse files
committed
Merge branch 'main' into send_final_state
2 parents 4db376a + a860081 commit cf48e7d

43 files changed

Lines changed: 972 additions & 191 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/cli/CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
# @openfn/cli
22

3+
## 1.17.1
4+
5+
### Patch Changes
6+
7+
- a0a1cb7: Add log option for checkout and merge
8+
9+
## 1.17.0
10+
11+
### Minor Changes
12+
13+
- New command: openfn project version
14+
15+
### Patch Changes
16+
17+
- Updated dependencies
18+
- @openfn/project@0.6.0
19+
20+
## 1.16.2
21+
22+
### Patch Changes
23+
24+
- 8a50703: Allow a project to be checked out from a direct path to a project file
25+
- 7d16875: When merging, allow the source project to specified as a path to a project file
26+
- Updated dependencies [81b97c3]
27+
- Updated dependencies [43be979]
28+
- Updated dependencies [1f8d65e]
29+
- Updated dependencies [25c7a2b]
30+
- Updated dependencies [04a89e2]
31+
- Updated dependencies [7d16875]
32+
- @openfn/project@0.5.1
33+
- @openfn/lexicon@1.2.4
34+
335
## 1.16.1
436

537
### Patch Changes

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/cli",
3-
"version": "1.16.1",
3+
"version": "1.17.1",
44
"description": "CLI devtools for the OpenFn toolchain",
55
"engines": {
66
"node": ">=18",

packages/cli/src/checkout/command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { ensure, build } from '../util/command-builders';
44
import * as o from '../options';
55

66
export type CheckoutOptions = Required<
7-
Pick<Opts, 'command' | 'projectName' | 'projectPath'>
7+
Pick<Opts, 'command' | 'projectName' | 'projectPath' | 'log'>
88
>;
99

10-
const options = [o.projectName, o.projectPath];
10+
const options = [o.projectName, o.projectPath, o.log];
1111

1212
const checkoutCommand: yargs.CommandModule = {
1313
command: 'checkout <project-name>',

packages/cli/src/checkout/handler.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Workspace } from '@openfn/project';
1+
import Project, { Workspace } from '@openfn/project';
22
import path from 'path';
33
import type { Logger } from '../util/logger';
44
import type { CheckoutOptions } from './command';
@@ -13,20 +13,32 @@ const checkoutHandler = async (options: CheckoutOptions, logger: Logger) => {
1313
return;
1414
}
1515

16+
// get the config
17+
// TODO: try to retain the endpoint for the projects
18+
const { project: _, ...config } = workspace.getConfig() ?? {};
19+
1620
// get the project
17-
const switchProject = workspace.get(options.projectName);
21+
let switchProject;
22+
if (/\.(yaml|json)$/.test(options.projectName)) {
23+
// TODO: should we allow checkout into an arbitrary folder?
24+
const filePath = path.join(commandPath, options.projectName);
25+
logger.debug('Loading project from path ', filePath);
26+
switchProject = await Project.from('path', filePath, {
27+
config,
28+
});
29+
} else {
30+
switchProject = workspace.get(options.projectName);
31+
}
32+
1833
if (!switchProject) {
1934
logger.error(
2035
`Project with id/name ${options.projectName} not found in the workspace`
2136
);
2237
return;
2338
}
24-
// get the config
25-
// TODO: try to retain the endpoint for the projects
26-
const config = workspace.getConfig();
2739

2840
// delete workflow dir before expanding project
29-
await rimraf(path.join(commandPath, config?.workflowRoot || 'workflows'));
41+
await rimraf(path.join(commandPath, config.workflowRoot ?? 'workflows'));
3042

3143
// expand project into directory
3244
const files = switchProject.serialize('fs');

packages/cli/src/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import testCommand from './test/command';
1616
import projectsCommand from './projects/command';
1717
import checkoutCommand from './checkout/command';
1818
import mergeCommand from './merge/command';
19+
import workflowVersionCommand from './version/command';
1920

2021
const y = yargs(hideBin(process.argv));
2122

@@ -36,6 +37,7 @@ export const cmd = y
3637
.command(projectsCommand)
3738
.command(checkoutCommand)
3839
.command(mergeCommand)
40+
.command(workflowVersionCommand)
3941
.command({
4042
command: 'version',
4143
describe:

packages/cli/src/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import docs from './docs/handler';
1010
import metadata from './metadata/handler';
1111
import pull from './pull/handler';
1212
import projects from './projects/handler';
13+
import workflowVersion from './version/handler';
1314
import checkout from './checkout/handler';
1415
import merge from './merge/handler';
1516
import { clean, install, pwd, list } from './repo/handler';
@@ -36,6 +37,7 @@ export type CommandList =
3637
| 'projects'
3738
| 'checkout'
3839
| 'merge'
40+
| 'project'
3941
| 'repo-clean'
4042
| 'repo-install'
4143
| 'repo-list'
@@ -56,6 +58,7 @@ const handlers = {
5658
projects,
5759
checkout,
5860
merge,
61+
project: workflowVersion,
5962
['collections-get']: collections.get,
6063
['collections-set']: collections.set,
6164
['collections-remove']: collections.remove,

packages/cli/src/merge/command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type MergeOptions = Required<
1111
| 'projectPath'
1212
| 'removeUnmapped'
1313
| 'workflowMappings'
14+
| 'log'
1415
>
1516
>;
1617

@@ -19,6 +20,7 @@ const options = [
1920
o.projectPath,
2021
o.removeUnmapped,
2122
o.workflowMappings,
23+
o.log,
2224
];
2325

2426
const mergeCommand: yargs.CommandModule = {

packages/cli/src/merge/handler.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,46 @@ const mergeHandler = async (options: MergeOptions, logger: Logger) => {
1313
return;
1414
}
1515

16-
const checkedProject = workspace.getActiveProject();
17-
if (!checkedProject) {
16+
// The target project - the think we apply changes to - is
17+
// whatever is checked out
18+
const targetProject = workspace.getActiveProject();
19+
if (!targetProject) {
1820
logger.error(`No project currently checked out`);
1921
return;
2022
}
2123

22-
const mProject = workspace.get(options.projectName);
23-
if (!mProject) {
24-
logger.error(
25-
`Project with id/name ${options.projectName} not found in the workspace`
26-
);
24+
// Lookup the source project - the thing we are getting changes from
25+
let sourceProject;
26+
if (/\.(yaml|json)$/.test(options.projectName)) {
27+
const filePath = path.join(commandPath, options.projectName);
28+
logger.debug('Loading source project from path ', filePath);
29+
sourceProject = await Project.from('path', filePath);
30+
} else {
31+
sourceProject = workspace.get(options.projectName);
32+
}
33+
if (!sourceProject) {
34+
logger.error(`Project "${options.projectName}" not found in the workspace`);
2735
return;
2836
}
2937

30-
if (checkedProject.name === mProject.name) {
38+
if (targetProject.name === sourceProject.name) {
3139
logger.error('Merging into the same project not allowed');
3240
return;
3341
}
3442

35-
if (!checkedProject.name) {
43+
if (!targetProject.name) {
3644
logger.error('The checked out project has no name/id');
3745
return;
3846
}
3947

40-
const finalPath = workspace.getProjectPath(checkedProject.name);
48+
const finalPath = workspace.getProjectPath(targetProject.name);
4149
if (!finalPath) {
4250
logger.error('Path to checked out project not found.');
4351
return;
4452
}
4553

4654
// TODO pick options from the terminal
47-
const final = Project.merge(mProject, checkedProject, {
55+
const final = Project.merge(sourceProject, targetProject, {
4856
removeUnmapped: options.removeUnmapped,
4957
workflowMappings: options.workflowMappings,
5058
});
@@ -61,7 +69,7 @@ const mergeHandler = async (options: MergeOptions, logger: Logger) => {
6169
logger
6270
);
6371
logger.success(
64-
`Project ${mProject.name} has been merged into Project ${checkedProject.name} successfully`
72+
`Project ${sourceProject.name} has been merged into Project ${targetProject.name} successfully`
6573
);
6674
};
6775

packages/cli/src/options.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type Opts = {
2525
apolloUrl?: string;
2626
apiKey?: string;
2727
autoinstall?: boolean;
28+
json?: boolean;
2829
beta?: boolean;
2930
cacheSteps?: boolean;
3031
compile?: boolean;
@@ -176,6 +177,15 @@ export const apolloUrl: CLIOption = {
176177
},
177178
};
178179

180+
export const json: CLIOption = {
181+
name: 'json',
182+
yargs: {
183+
boolean: true,
184+
description: 'Output the result as a json object',
185+
default: false,
186+
},
187+
};
188+
179189
export const beta: CLIOption = {
180190
name: 'beta',
181191
yargs: {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import yargs from 'yargs';
2+
import { Opts } from '../options';
3+
import { ensure, build } from '../util/command-builders';
4+
import * as o from '../options';
5+
6+
export type VersionOptions = Required<
7+
Pick<
8+
Opts,
9+
| 'command'
10+
| 'workflow'
11+
| 'projectName'
12+
| 'projectPath'
13+
| 'workflowMappings'
14+
| 'json'
15+
>
16+
>;
17+
18+
const options = [
19+
o.workflow,
20+
o.projectName,
21+
o.projectPath,
22+
o.workflowMappings,
23+
o.json,
24+
];
25+
26+
const workflowVersionCommand: yargs.CommandModule = {
27+
command: 'project version [workflow]',
28+
describe: 'Returns the version has of a workflow',
29+
handler: ensure('project', options),
30+
builder: (yargs) => build(options, yargs),
31+
};
32+
33+
export default workflowVersionCommand;

0 commit comments

Comments
 (0)