Skip to content

Commit aaca7f3

Browse files
committed
hook schematic into daff cli flow
1 parent 6dc5046 commit aaca7f3

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

tools/schematics/ng-add/generators/daff-config/daff-config.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ import {
66
import { updateWorkspace } from '@schematics/angular/utility/workspace';
77
import chalk from 'chalk';
88

9+
import {
10+
daffJson,
11+
syncProjects,
12+
} from '../../../bin/daff';
13+
import packagesJson from '../../../versioning/packages.json';
14+
import {
15+
DAFF_JSON_DEFAULT,
16+
isSupportedPlatform,
17+
} from '../../../versioning/public_api';
918
import { NgAddOptions } from '../../schema';
1019

11-
export const DEFAULT_MAGENTO_VERSION = '2.4.3';
12-
1320
const DAFF_JSON_PATH = 'daff.json';
1421

1522
const shouldScaffoldDaffConfig = (options: NgAddOptions): boolean =>
@@ -29,14 +36,18 @@ export const createDaffJson = (options: NgAddOptions, projectName: string): Rule
2936
}
3037

3138
const body = {
32-
projects: {
39+
...DAFF_JSON_DEFAULT,
40+
};
41+
42+
if (isSupportedPlatform(options.driver) && options.driverVersion) {
43+
body.projects = {
3344
[projectName]: {
3445
drivers: {
35-
magento: DEFAULT_MAGENTO_VERSION,
46+
[options.driver]: options.driverVersion,
3647
},
3748
},
38-
},
39-
};
49+
};
50+
}
4051

4152
tree.create(DAFF_JSON_PATH, JSON.stringify(body, null, 2) + '\n');
4253
return tree;
@@ -47,18 +58,7 @@ export const addBuildCondition = (options: NgAddOptions, projectName: string): R
4758
return (tree: Tree) => tree;
4859
}
4960

50-
const workspaceRule = updateWorkspace((workspace) => {
51-
const project = workspace.projects.get(projectName);
52-
const build = project?.targets.get('build');
53-
if (!build) {
54-
return;
55-
}
56-
57-
build.configurations ??= {};
58-
const production = <{ conditions?: string[] }>(build.configurations.production ??= {});
59-
const cond = `magento-${DEFAULT_MAGENTO_VERSION}`;
60-
production.conditions = Array.from(new Set([...(production.conditions ?? []), cond]));
61+
return updateWorkspace(async (workspace) => {
62+
syncProjects(await daffJson(DAFF_JSON_PATH).read(), workspace, <any>packagesJson);
6163
});
62-
63-
return <Rule><unknown>workspaceRule;
6464
};

tools/schematics/ng-add/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export interface NgAddOptions {
33
skipPackageJson?: boolean;
44
isNewProject?: boolean;
55
driver?: 'magento' | 'shopify' | 'in-memory' | 'demo';
6+
driverVersion?: string;
67
}

0 commit comments

Comments
 (0)