Skip to content

Commit

Permalink
perf(cli:update): automatically add @_mock path (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Nov 3, 2023
1 parent b7dbc68 commit d014b54
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions schematics/application/index.ts
Expand Up @@ -160,6 +160,7 @@ function addPathsToTsConfig(): Rule {
paths['@shared'] = ['src/app/shared/index'];
paths['@core'] = ['src/app/core/index'];
paths['@env/*'] = ['src/environments/*'];
paths['@_mock'] = ['_mock/index'];
writeJSON(tree, 'tsconfig.json', json);
return tree;
};
Expand Down
16 changes: 16 additions & 0 deletions schematics/ng-update/upgrade-rules/base.ts
@@ -0,0 +1,16 @@
import { Rule, Tree } from '@angular-devkit/schematics';

import { readJSON, writeJSON } from '../../utils';

export function updateMockPath(): Rule {
return (tree: Tree) => {
const json = readJSON(tree, 'tsconfig.json', 'compilerOptions');
if (json == null) return tree;
if (!json.compilerOptions) json.compilerOptions = {};
if (!json.compilerOptions.paths) json.compilerOptions.paths = {};
const paths = json.compilerOptions.paths;
paths[`@_mock`] = [`_mock/index`];
writeJSON(tree, 'tsconfig.json', json);
return tree;
};
}
3 changes: 2 additions & 1 deletion schematics/ng-update/upgrade-rules/v16/index.ts
Expand Up @@ -4,6 +4,7 @@ import * as colors from 'ansi-colors';

import { logStart, readJSON, readPackage, writeJSON, writePackage } from '../../../utils';
import { UpgradeMainVersions } from '../../../utils/versions';
import { updateMockPath } from '../base';

function removeStylelintConfigPrettier(): Rule {
return (tree: Tree, context: SchematicContext) => {
Expand Down Expand Up @@ -47,6 +48,6 @@ export function v16Rule(): Rule {
return async (tree: Tree, context: SchematicContext) => {
logStart(context, `Upgrade @delon/* version number`);
UpgradeMainVersions(tree);
return chain([removeStylelintConfigPrettier(), finished()]);
return chain([removeStylelintConfigPrettier(), updateMockPath(), finished()]);
};
}

0 comments on commit d014b54

Please sign in to comment.