Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): missing fileReplacements in Angular16 #1658

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions schematics/application/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ describe('NgAlainSchematic: application', () => {
expect(json != null).toBe(true);
expect(json.recommendations[0]).toBe('cipchk.ng-alain-extension-pack');
});
it('should be add addFileReplacements', () => {
const angualrJson = tree.readContent('angular.json');
expect(angualrJson).toContain(`fileReplacements`);
});
});

describe('#i18n', () => {
Expand Down
2 changes: 2 additions & 0 deletions schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
addAllowedCommonJsDependencies,
addAllowSyntheticDefaultImports,
addAssetsToTarget,
addFileReplacements,
addHeadStyle,
addHtmlToBody,
addPackage,
Expand Down Expand Up @@ -94,6 +95,7 @@ function fixAngularJson(options: ApplicationOptions): Rule {

addStylePreprocessorOptionsToAllProject(workspace);
addSchematicCollections(workspace);
addFileReplacements(workspace);
});
}

Expand Down
15 changes: 15 additions & 0 deletions schematics/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,18 @@ export function addSchematicCollections(workspace: WorkspaceDefinition): void {
if (!schematicCollections.includes(`ng-alain`)) schematicCollections.push(`ng-alain`);
workspace.extensions.cli['schematicCollections'] = schematicCollections;
}

export function addFileReplacements(workspace: WorkspaceDefinition): void {
workspace.projects.forEach(project => {
const build = project.targets.get(BUILD_TARGET_BUILD);
if (build == null || build.options == null) return;
if (build.configurations == null) build.configurations = {};
if (build.configurations.production == null) build.configurations.production = {};
if (!Array.isArray(build.configurations.production.fileReplacements))
build.configurations.production.fileReplacements = [];
build.configurations.production.fileReplacements.push({
replace: 'src/environments/environment.ts',
with: 'src/environments/environment.prod.ts'
});
});
}
Loading