Skip to content

Commit b18e8a6

Browse files
authored
Merge pull request #1111 from OpenFn/fix-project-stuff
Fix project stuff
2 parents f34b281 + 03643db commit b18e8a6

File tree

14 files changed

+134
-146
lines changed

14 files changed

+134
-146
lines changed

packages/cli/src/checkout/command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ 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' | 'projectId' | 'projectPath'>
88
> &
99
Pick<Opts, 'log'>;
1010

11-
const options = [o.projectName, o.projectPath, o.log];
11+
const options = [o.projectId, o.projectPath, o.log];
1212

1313
const checkoutCommand: yargs.CommandModule = {
14-
command: 'checkout <project-name>',
14+
command: 'checkout <project-id>',
1515
describe: 'Switch to a different openfn project in the same workspace',
1616
handler: ensure('checkout', options),
1717
builder: (yargs) => build(options, yargs),

packages/cli/src/checkout/handler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ const checkoutHandler = async (options: CheckoutOptions, logger: Logger) => {
1919

2020
// get the project
2121
let switchProject;
22-
if (/\.(yaml|json)$/.test(options.projectName)) {
22+
if (/\.(yaml|json)$/.test(options.projectId)) {
2323
// TODO: should we allow checkout into an arbitrary folder?
24-
const filePath = path.join(commandPath, options.projectName);
24+
const filePath = path.join(commandPath, options.projectId);
2525
logger.debug('Loading project from path ', filePath);
2626
switchProject = await Project.from('path', filePath, {
2727
config,
2828
});
2929
} else {
30-
switchProject = workspace.get(options.projectName);
30+
switchProject = workspace.get(options.projectId);
3131
}
3232

3333
if (!switchProject) {
3434
logger.error(
35-
`Project with id/name ${options.projectName} not found in the workspace`
35+
`Project with id/name ${options.projectId} not found in the workspace`
3636
);
3737
return;
3838
}

packages/cli/src/merge/command.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ export type MergeOptions = Required<
77
Pick<
88
Opts,
99
| 'command'
10-
| 'projectName'
10+
| 'projectId'
1111
| 'projectPath'
1212
| 'removeUnmapped'
1313
| 'workflowMappings'
14-
| 'log'
15-
| 'force'
1614
>
17-
>;
15+
> &
16+
Pick<Opts, 'log' | 'force'>;
1817

1918
const options = [
20-
o.projectName,
19+
o.projectId,
2120
o.projectPath,
2221
o.removeUnmapped,
2322
o.workflowMappings,
@@ -28,7 +27,7 @@ const options = [
2827
];
2928

3029
const mergeCommand: yargs.CommandModule = {
31-
command: 'merge [project-name]',
30+
command: 'merge <project-id>',
3231
describe: 'Merges the specified project into the checked out project',
3332
handler: ensure('merge', options),
3433
builder: (yargs) => build(options, yargs),

packages/cli/src/merge/handler.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,29 @@ const mergeHandler = async (options: MergeOptions, logger: Logger) => {
2323

2424
// Lookup the source project - the thing we are getting changes from
2525
let sourceProject;
26-
if (/\.(yaml|json)$/.test(options.projectName)) {
27-
const filePath = path.join(commandPath, options.projectName);
26+
if (/\.(yaml|json)$/.test(options.projectId)) {
27+
const filePath = path.join(commandPath, options.projectId);
2828
logger.debug('Loading source project from path ', filePath);
2929
sourceProject = await Project.from('path', filePath);
3030
} else {
31-
sourceProject = workspace.get(options.projectName);
31+
sourceProject = workspace.get(options.projectId);
3232
}
3333
if (!sourceProject) {
34-
logger.error(`Project "${options.projectName}" not found in the workspace`);
34+
logger.error(`Project "${options.projectId}" not found in the workspace`);
3535
return;
3636
}
3737

38-
if (targetProject.name === sourceProject.name) {
38+
if (targetProject.id === sourceProject.id) {
3939
logger.error('Merging into the same project not allowed');
4040
return;
4141
}
4242

43-
if (!targetProject.name) {
44-
logger.error('The checked out project has no name/id');
43+
if (!targetProject.id) {
44+
logger.error('The checked out project has no id');
4545
return;
4646
}
4747

48-
const finalPath = workspace.getProjectPath(targetProject.name);
48+
const finalPath = workspace.getProjectPath(targetProject.id);
4949
if (!finalPath) {
5050
logger.error('Path to checked out project not found.');
5151
return;
@@ -64,13 +64,13 @@ const mergeHandler = async (options: MergeOptions, logger: Logger) => {
6464
{
6565
command: 'checkout',
6666
projectPath: commandPath,
67-
projectName: final.name || '',
67+
projectId: final.id,
6868
log: options.log,
6969
},
7070
logger
7171
);
7272
logger.success(
73-
`Project ${sourceProject.name} has been merged into Project ${targetProject.name} successfully`
73+
`Project ${sourceProject.id} has been merged into Project ${targetProject.id} successfully`
7474
);
7575
};
7676

packages/cli/src/options.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,7 @@ const getBaseDir = (opts: { path?: string }) => {
336336
export const projectId: CLIOption = {
337337
name: 'project-id',
338338
yargs: {
339-
hidden: true,
340-
},
341-
ensure: (opts) => {
342-
const projectId = opts.projectId;
343-
//check that this is a uuid
344-
return projectId;
345-
},
346-
};
347-
348-
export const projectName: CLIOption = {
349-
name: 'project-name',
350-
yargs: {
351-
description: 'The name of an openfn project',
339+
description: 'The id or UUID of an openfn project',
352340
string: true,
353341
},
354342
ensure: (opts) => {

packages/cli/src/projects/handler.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ const projectsHandler = async (options: ProjectsOptions, logger: Logger) => {
1313

1414
logger.success(`Available openfn projects\n\n${workspace
1515
.list()
16-
.map((p) => describeProject(p, p.name === workspace.activeProjectId))
16+
.map((p) => describeProject(p, p.id === workspace.activeProjectId))
1717
.join('\n\n')}
1818
`);
1919
};
2020

2121
function describeProject(project: Project, active = false) {
2222
// @ts-ignore
23-
const pId = project.openfn?.uuid;
24-
return `${project.name} ${active ? '(active)' : ''}\n ${
25-
pId || '<project-id>'
26-
}\n workflows:\n${project.workflows
27-
.map((w) => ' - ' + w.name)
28-
.join('\n')}`;
23+
const uuid = project.openfn?.uuid;
24+
return `${project.id} ${active ? '(active)' : ''}\n ${
25+
uuid || '<project-id>'
26+
}\n workflows:\n${project.workflows.map((w) => ' - ' + w.id).join('\n')}`;
2927
}
3028

3129
export default projectsHandler;

packages/cli/src/version/command.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,11 @@ import * as o from '../options';
66
export type VersionOptions = Required<
77
Pick<
88
Opts,
9-
| 'command'
10-
| 'workflow'
11-
| 'projectName'
12-
| 'projectPath'
13-
| 'workflowMappings'
14-
| 'json'
9+
'command' | 'workflow' | 'projectPath' | 'workflowMappings' | 'json'
1510
>
1611
>;
1712

18-
const options = [
19-
o.workflow,
20-
o.projectName,
21-
o.projectPath,
22-
o.workflowMappings,
23-
o.json,
24-
];
13+
const options = [o.workflow, o.projectPath, o.workflowMappings, o.json];
2514

2615
const workflowVersionCommand: yargs.CommandModule = {
2716
command: 'project version [workflow]',

packages/cli/test/checkout/handler.test.ts

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ test.beforeEach(() => {
99
mock({
1010
'/ws/workflows': {},
1111
'/ws/openfn.yaml': jsonToYaml({
12-
name: 'some-project-name',
13-
workflowRoot: 'workflows',
14-
formats: {
15-
openfn: 'yaml',
16-
project: 'yaml',
17-
workflow: 'yaml',
12+
project: {
13+
id: 'my-project',
14+
},
15+
workspace: {
16+
workflowRoot: 'workflows',
17+
formats: {
18+
openfn: 'yaml',
19+
project: 'yaml',
20+
workflow: 'yaml',
21+
},
1822
},
1923
}),
2024
'/ws/.projects/staging@app.openfn.org.yaml': jsonToYaml({
21-
id: 'some-id',
22-
name: 'some-project-name',
25+
id: '<uuid:staging>>',
26+
name: 'My Staging',
2327
workflows: [
2428
{
2529
name: 'simple-workflow',
@@ -80,8 +84,8 @@ test.beforeEach(() => {
8084
],
8185
}),
8286
'/ws/.projects/project@app.openfn.org.yaml': jsonToYaml({
83-
id: 'main-id',
84-
name: 'main-project-id',
87+
id: '<uuid:main>',
88+
name: 'My Project',
8589
workflows: [
8690
{
8791
name: 'simple-workflow-main',
@@ -149,35 +153,33 @@ const logger = createMockLogger('', { level: 'debug' });
149153
test.serial('get active project', (t) => {
150154
const workspace = new Workspace('/ws');
151155
t.is(workspace.valid, true);
152-
t.is(workspace.activeProjectId, 'some-project-name');
156+
t.is(workspace.activeProjectId, 'my-project');
153157
});
154158

155159
test.serial('checkout: invalid project id', (t) => {
156160
checkoutHandler(
157-
{ command: 'checkout', projectName: 'not-known', projectPath: '/ws' },
161+
{ command: 'checkout', projectId: 'not-known', projectPath: '/ws' },
158162
logger
159163
);
160164
const { message } = logger._parse(logger._last);
161165
t.is(message, 'Project with id/name not-known not found in the workspace');
162166
});
163167

164168
test.serial('checkout: to a different valid project', async (t) => {
165-
// before checkout. some-project-name is active and expanded
169+
// before checkout. my-project is active and expanded
166170
const bcheckout = new Workspace('/ws');
167-
t.is(bcheckout.projectMeta.name, 'some-project-name');
168-
t.is(bcheckout.getActiveProject()?.name, 'some-project-name');
171+
t.is(bcheckout.activeProject.id, 'my-project');
169172

170173
await checkoutHandler(
171-
{ command: 'checkout', projectName: 'main-project-id', projectPath: '/ws' },
174+
{ command: 'checkout', projectId: 'my-project', projectPath: '/ws' },
172175
logger
173176
);
174177
const { message } = logger._parse(logger._last);
175178
t.is(message, 'Expanded project to /ws');
176179

177-
// after checkout. main-project-id is active and expanded
180+
// after checkout. my-project is active and expanded
178181
const acheckout = new Workspace('/ws');
179-
t.is(acheckout.projectMeta.name, 'main-project-id');
180-
t.is(acheckout.getActiveProject()?.name, 'main-project-id');
182+
t.is(acheckout.activeProject.id, 'my-project');
181183

182184
// check if files where well expanded
183185
t.deepEqual(
@@ -187,79 +189,74 @@ test.serial('checkout: to a different valid project', async (t) => {
187189
});
188190

189191
test.serial('checkout: same id as active', async (t) => {
190-
// before checkout. some-project-name is active and expanded
192+
// before checkout. my-project is active and expanded
191193
const bcheckout = new Workspace('/ws');
192-
t.is(bcheckout.projectMeta.name, 'some-project-name');
193-
t.is(bcheckout.getActiveProject()?.name, 'some-project-name');
194+
t.is(bcheckout.activeProject.id, 'my-project');
194195

195196
await checkoutHandler(
196197
{
197198
command: 'checkout',
198-
projectName: 'some-project-name',
199+
projectId: 'my-project',
199200
projectPath: '/ws',
200201
},
201202
logger
202203
);
203204
const { message } = logger._parse(logger._last);
204205
t.is(message, 'Expanded project to /ws');
205206

206-
// after checkout. main-project-id is active and expanded
207+
// after checkout. my-project is active and expanded
207208
const acheckout = new Workspace('/ws');
208-
t.is(acheckout.projectMeta.name, 'some-project-name');
209-
t.is(acheckout.getActiveProject()?.name, 'some-project-name');
209+
t.is(acheckout.activeProject.id, 'my-project');
210210

211211
// check if files where well expanded
212212
t.deepEqual(
213213
fs.readdirSync('/ws/workflows').sort(),
214-
['simple-workflow', 'another-workflow'].sort()
214+
['simple-workflow-main', 'another-workflow-main'].sort()
215215
);
216216
});
217217

218218
test.serial('checkout: switching to and back between projects', async (t) => {
219-
// before checkout. some-project-name is active and expanded
219+
// before checkout. my-project is active and expanded
220220
const bcheckout = new Workspace('/ws');
221-
t.is(bcheckout.projectMeta.name, 'some-project-name');
222-
t.is(bcheckout.getActiveProject()?.name, 'some-project-name');
221+
t.is(bcheckout.activeProject.id, 'my-project');
223222

224-
// 1. switch from some-project-name to main-project-id
223+
// 1. switch from my-project to my-staging
225224
await checkoutHandler(
226-
{ command: 'checkout', projectName: 'main-project-id', projectPath: '/ws' },
225+
{ command: 'checkout', projectId: 'my-staging', projectPath: '/ws' },
227226
logger
228227
);
229228
const { message } = logger._parse(logger._last);
230229
t.is(message, 'Expanded project to /ws');
231230

232-
// after checkout. main-project-id is active and expanded
231+
// after checkout. my-staging is active and expanded
233232
const acheckout = new Workspace('/ws');
234-
t.is(acheckout.projectMeta.name, 'main-project-id');
235-
t.is(acheckout.getActiveProject()?.name, 'main-project-id');
233+
t.is(acheckout.activeProject.id, 'my-staging');
236234

237235
// check if files where well expanded
238236
t.deepEqual(
239237
fs.readdirSync('/ws/workflows').sort(),
240-
['simple-workflow-main', 'another-workflow-main'].sort()
238+
['simple-workflow', 'another-workflow'].sort()
241239
);
242240

243-
// 2. switch back from main-project-id to some-project-name
241+
// 2. switch back from my-project to my-project
244242
await checkoutHandler(
245243
{
246244
command: 'checkout',
247-
projectName: 'some-project-name',
245+
projectId: 'my-project',
248246
projectPath: '/ws',
249247
},
250248
logger
251249
);
252250
const { message: lastMsg } = logger._parse(logger._last);
253251
t.is(lastMsg, 'Expanded project to /ws');
254252

255-
// after checkout. main-project-id is active and expanded
253+
// after checkout. my-project is active and expanded
256254
const fcheckout = new Workspace('/ws');
257-
t.is(fcheckout.projectMeta.name, 'some-project-name');
258-
t.is(fcheckout.getActiveProject()?.name, 'some-project-name');
255+
t.is(fcheckout.activeProject.id, 'my-project');
259256

260257
// check if files where well expanded
261258
t.deepEqual(
262259
fs.readdirSync('/ws/workflows').sort(),
263-
['simple-workflow', 'another-workflow'].sort()
260+
['simple-workflow-main', 'another-workflow-main'].sort()
264261
);
265262
});

0 commit comments

Comments
 (0)