From e000de0fc8264318c3b834ece1cd55dd2c4c9c93 Mon Sep 17 00:00:00 2001 From: cipchk Date: Mon, 30 Oct 2023 15:34:18 +0800 Subject: [PATCH] perf(cli:update): automatically add @_mock path --- schematics/application/index.ts | 1 + schematics/ng-update/upgrade-rules/base.ts | 16 ++++++++++++++++ schematics/ng-update/upgrade-rules/v16/index.ts | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 schematics/ng-update/upgrade-rules/base.ts diff --git a/schematics/application/index.ts b/schematics/application/index.ts index 205bba54c..31140e5e1 100644 --- a/schematics/application/index.ts +++ b/schematics/application/index.ts @@ -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; }; diff --git a/schematics/ng-update/upgrade-rules/base.ts b/schematics/ng-update/upgrade-rules/base.ts new file mode 100644 index 000000000..1ab06eae6 --- /dev/null +++ b/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; + }; +} diff --git a/schematics/ng-update/upgrade-rules/v16/index.ts b/schematics/ng-update/upgrade-rules/v16/index.ts index f7c97cbdc..12cb6bc5b 100644 --- a/schematics/ng-update/upgrade-rules/v16/index.ts +++ b/schematics/ng-update/upgrade-rules/v16/index.ts @@ -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) => { @@ -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()]); }; }