Skip to content

Commit

Permalink
fix(cli): missing fileReplacements in Angular16
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Oct 17, 2023
1 parent d80f8fb commit 0a9dcc5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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'
});
});
}

0 comments on commit 0a9dcc5

Please sign in to comment.