Skip to content

Commit

Permalink
fix(cli): add fixAngularJson option (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored Jul 26, 2021
1 parent c4fb7c2 commit dbe0642
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"eslint": "^7.26.0",
"eslint-config-prettier": "~8.3.0",
"eslint-plugin-import": "~2.23.4",
"eslint-plugin-jsdoc": "~35.1.3",
"eslint-plugin-jsdoc": "~36.0.2",
"eslint-plugin-prefer-arrow": "~1.2.2",
"eslint-plugin-prettier": "~3.4.0",
"lint-staged": "^10.5.3"
Expand Down
1 change: 1 addition & 0 deletions schematics/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"ng-update": {
"factory": "./ng-update/index#updateToV12",
"schema": "./ng-update/upgrade-rules/v12/schema.json",
"description": "Create an Alain workspace."
},
"application": {
Expand Down
5 changes: 3 additions & 2 deletions schematics/ng-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export function updateToV117(): Rule {
return chain([v117Rule]);
}

export function updateToV12(): Rule {
return chain([v12Rule, createMigrationSchematicRule(TargetVersion.V12, migrations, ruleUpgradeData, postUpdate)]);
export function updateToV12(schema: any): Rule {
const rule = v12Rule(schema);
return chain([rule, createMigrationSchematicRule(TargetVersion.V12, migrations, ruleUpgradeData, postUpdate)]);
}

/** Post-update schematic to be called when update is finished. */
Expand Down
206 changes: 206 additions & 0 deletions schematics/ng-update/upgrade-rules/v12/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,210 @@ describe('Schematic: ng-update: v12Rule', () => {
const content = tree.readContent(filePath);
expect(content).toContain(`@angular-eslint/builder:lint`);
});

it(`#2027: 'set' on proxy: trap returned falsish for property 'defaultConfiguration'`, async () => {
const filePath = `/angular.json`;
tree.overwrite(
filePath,
`{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"app-ui": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "less"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/app-ui",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets",
{
"glob": "**/*",
"input": "./node_modules/leaflet/dist/images",
"output": "assets/"
},
"src/manifest.webmanifest",
{
"glob": "**/*",
"input": "./node_modules/monaco-editor/min/vs",
"output": "/assets/vs/"
}
],
"styles": ["./src/styles.less", "./node_modules/leaflet/dist/leaflet.css"],
"scripts": ["node_modules/jszip/dist/jszip.min.js",
"node_modules/xlsx/dist/xlsx.mini.min.js"
],
"allowedCommonJsDependencies": [
"@angular/common/locales/zh",
"@ant-design/colors",
"@stomp/rx-stomp",
"babylonjs-gui",
"babylonjs-loaders",
"css-element-queries",
"fabric",
"file-saver",
"humanize-duration",
"sockjs-client",
"util",
"zrender/lib/svg/svg",
"zrender/lib/vml/vml",
"ajv",
"date-fns",
"ajv-formats",
"echarts/dist/extension/bmap.min"
],
"vendorChunk": true,
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": false,
"namedChunks": true
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "12mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "2mb"
}
],
"serviceWorker": true,
"ngswConfigPath": "ngsw-config.json"
}
},
"defaultConfiguration": ""
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "app-ui:build",
"proxyConfig": "proxy.conf.json"
},
"configurations": {
"production": {
"browserTarget": "app-ui:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "app-ui:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": ["src/favicon.ico", "src/assets", "src/manifest.webmanifest"],
"styles": ["src/styles.less"],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["tsconfig.app.json", "tsconfig.spec.json", "e2e/tsconfig.json"],
"exclude": ["**/node_modules/**"]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "app-ui:serve"
},
"configurations": {
"production": {
"devServerTarget": "app-ui:serve:production"
}
}
}
}
}
},
"defaultProject": "app-ui",
"cli": {
"analytics": false
},
"schematics": {
"ng-alain:module": {
"routing": true,
"spec": false
},
"ng-alain:list": {
"spec": false
},
"ng-alain:edit": {
"spec": false,
"modal": true
},
"ng-alain:view": {
"spec": false,
"modal": true
},
"ng-alain:curd": {
"spec": false
},
"@schematics/angular:module": {
"routing": true,
"spec": false
},
"@schematics/angular:component": {
"spec": false,
"flat": false,
"inlineStyle": true,
"inlineTemplate": false
},
"@schematics/angular:directive": {
"spec": false
},
"@schematics/angular:service": {
"spec": false
}
}
}
`
);
await runMigration();
const content = tree.readContent(filePath);
expect(content).toContain(`@angular-eslint/builder:lint`);
});
});
14 changes: 9 additions & 5 deletions schematics/ng-update/upgrade-rules/v12/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../../../utils';
import { LINT_STAGED, LINT_STAGED_CONFIG } from '../../../utils/code-style';
import { addESLintRule, UpgradeMainVersions } from '../../../utils/versions';
import { Schema } from './schema';

// 修正 angular.json 的格式
function fixAngularJson(context: SchematicContext): Rule {
Expand Down Expand Up @@ -170,19 +171,22 @@ function finished(): Rule {
};
}

export function v12Rule(): Rule {
export function v12Rule(options: Schema): Rule {
return async (tree: Tree, context: SchematicContext) => {
logStart(context, `Upgrade @delon/* version number`);
logStart(context, `Upgrade @delon/* version number ${JSON.stringify(options)}`);
UpgradeMainVersions(tree);
return chain([
fixAngularJson(context),
const rules = [
migrateESLint(tree, context),
addESLintRule(context),
upgradeThirdVersion(),
removeThird(),
upgradeHusky(),
formatJson(),
finished()
]);
];
if (options.fixAngularJson !== false) {
rules.splice(0, 0, fixAngularJson(context));
}
return chain(rules);
};
}
13 changes: 13 additions & 0 deletions schematics/ng-update/upgrade-rules/v12/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/schema",
"$id": "SchematicsNgUpdateV12",
"title": "Ng Alain Update V12",
"type": "object",
"properties": {
"fixAngularJson": {
"type": "boolean",
"default": true,
"description": "Automatically correct the Angular.json format, Default: true"
}
}
}
4 changes: 4 additions & 0 deletions schematics/ng-update/upgrade-rules/v12/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Schema {
/** Automatically correct the Angular.json format, Default: true */
fixAngularJson: Boolean;
}

0 comments on commit dbe0642

Please sign in to comment.