Skip to content

Commit 5addae9

Browse files
committed
project: serialize id and uuid to config properly
1 parent f34b281 commit 5addae9

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

packages/project/src/Workspace.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class Workspace {
5454
const stateFilePath = path.join(projectsPath, file);
5555
const data = fs.readFileSync(stateFilePath, 'utf-8');
5656
const project = fromAppState(data, { format: 'yaml' });
57-
this.projectPaths.set(project.name, stateFilePath);
57+
this.projectPaths.set(project.id, stateFilePath);
5858
return project;
5959
})
6060
.filter((s) => s);
@@ -85,8 +85,10 @@ export class Workspace {
8585
}
8686

8787
getActiveProject() {
88-
// TODO should use id, not name
89-
return this.projects.find((p) => p.id === this.activeProject?.id);
88+
return (
89+
this.projects.find((p) => p.id === this.activeProject?.id) ??
90+
this.projects.find((p) => p.openfn?.uuid === this.activeProject?.id)
91+
);
9092
}
9193

9294
// TODO this needs to return default values

packages/project/src/util/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const buildConfig = (config: WorkspaceConfig = {}) => ({
8181
export const extractConfig = (source: Project) => {
8282
const project = {
8383
...(source.openfn || {}),
84+
id: source.id,
8485
};
8586
const workspace = {
8687
...source.config,

packages/project/test/serialize/to-fs.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ test('extractWorkflow: single simple workflow with custom root', (t) => {
187187
test('toFs: extract a project with 1 workflow and 1 step', (t) => {
188188
const project = new Project(
189189
{
190+
name: 'My Project',
190191
workflows: [
191192
{
192193
id: 'my-workflow',
@@ -219,7 +220,9 @@ test('toFs: extract a project with 1 workflow and 1 step', (t) => {
219220
formats: { openfn: 'json', project: 'yaml', workflow: 'json' },
220221
dirs: { projects: '.projects', workflows: 'workflows' },
221222
},
222-
project: {},
223+
project: {
224+
id: 'my-project',
225+
},
223226
});
224227

225228
const workflow = JSON.parse(files['workflows/my-workflow/my-workflow.json']);

packages/project/test/util/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ test('generate openfn.yaml', (t) => {
167167
result.content,
168168
`project:
169169
uuid: 1234
170+
id: my-project
170171
workspace:
171172
formats:
172173
openfn: yaml

0 commit comments

Comments
 (0)