Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 93e90a3

Browse filesBrowse files
committed
feat(@schematics/angular): add additional migrations
1 parent 8ce7c3c commit 93e90a3
Copy full SHA for 93e90a3

3 files changed

+97-44Lines changed: 97 additions & 44 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/schematics/angular/migrations/update-8/index.ts‎

Copy file name to clipboardExpand all lines: packages/schematics/angular/migrations/update-8/index.ts
+53-9Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { JsonParseMode, parseJsonAst, tags } from '@angular-devkit/core';
8+
import { JsonParseMode, Path, normalize, parseJson, parseJsonAst } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
12+
SchematicsException,
1213
Tree,
1314
chain,
1415
} from '@angular-devkit/schematics';
16+
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
17+
import { CliConfig } from '../../utility/config';
18+
import {
19+
NodeDependency,
20+
NodeDependencyType,
21+
addPackageJsonDependency,
22+
} from '../../utility/dependencies';
1523
import { findPropertyInAstObject } from '../../utility/json-utils';
1624

1725
const ruleMapping: {[key: string]: string} = {
@@ -33,6 +41,9 @@ const ruleMapping: {[key: string]: string} = {
3341
'no-template-call-expression': 'template-no-call-expression',
3442
'templates-no-negated-async': 'template-no-negated-async',
3543
'trackBy-function': 'template-use-track-by-function',
44+
'no-attribute-parameter-decorator': 'no-attribute-decorator',
45+
'component-change-detection': 'prefer-on-push-component-change-detection',
46+
'max-inline-declarations': 'component-max-inline-declarations',
3647
};
3748

3849
function updateTsLintConfig(): Rule {
@@ -69,17 +80,50 @@ function updateTsLintConfig(): Rule {
6980
};
7081
}
7182

83+
function updatePackageJson(config: CliConfig) {
84+
return (host: Tree, context: SchematicContext) => {
85+
const dependency: NodeDependency = {
86+
type: NodeDependencyType.Dev,
87+
name: 'codelyzer',
88+
version: '^5.0.0',
89+
overwrite: true,
90+
};
91+
92+
addPackageJsonDependency(host, dependency);
93+
94+
context.addTask(new NodePackageInstallTask({
95+
packageManager: config.packageManager === 'default' ? undefined : config.packageManager,
96+
}));
97+
98+
return host;
99+
};
100+
}
101+
102+
function getConfigPath(tree: Tree): Path {
103+
const possiblePath = normalize('angular-cli.json');
104+
if (tree.exists(possiblePath)) {
105+
return possiblePath;
106+
}
107+
108+
throw new SchematicsException('Could not find configuration file');
109+
}
110+
72111
export default function(): Rule {
73-
return () => {
112+
return (host: Tree) => {
113+
const configPath = getConfigPath(host);
114+
const configBuffer = host.read(normalize(configPath));
115+
if (configBuffer == null) {
116+
throw new SchematicsException(`Could not find configuration file (${configPath})`);
117+
}
118+
119+
const config = parseJson(configBuffer.toString(), JsonParseMode.Loose);
120+
if (typeof config != 'object' || Array.isArray(config) || config === null) {
121+
throw new SchematicsException('Invalid angular-cli.json configuration; expected an object.');
122+
}
123+
74124
return chain([
75125
updateTsLintConfig(),
76-
(host: Tree, context: SchematicContext) => {
77-
context.logger
78-
.warn(tags.oneLine`Some configuration options have been changed,
79-
please make sure to update any npm scripts which you may have modified.`);
80-
81-
return host;
82-
},
126+
updatePackageJson(config),
83127
]);
84128
};
85129
}
Collapse file

‎packages/schematics/angular/migrations/update-8/index_spec.ts‎

Copy file name to clipboardExpand all lines: packages/schematics/angular/migrations/update-8/index_spec.ts
+42-35Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,56 +23,63 @@ describe('Migration to version 8', () => {
2323
);
2424

2525
let tree: UnitTestTree;
26+
const tslintPath = '/tslint.json';
27+
const packageJsonPath = '/package.json';
2628
const baseConfig = {};
2729
const defaultOptions = {};
2830
const configPath = `/angular-cli.json`;
31+
const tslintConfig = {
32+
rules: {
33+
'directive-selector': [
34+
true,
35+
'attribute',
36+
'app',
37+
'camelCase',
38+
],
39+
'component-selector': [
40+
true,
41+
'element',
42+
'app',
43+
'kebab-case',
44+
],
45+
'no-output-on-prefix': true,
46+
'use-input-property-decorator': true,
47+
'use-output-property-decorator': true,
48+
'use-host-property-decorator': true,
49+
'no-input-rename': true,
50+
'no-output-rename': true,
51+
'use-life-cycle-interface': true,
52+
'use-pipe-transform-interface': true,
53+
'component-class-suffix': true,
54+
'directive-class-suffix': true,
55+
},
56+
};
57+
const packageJson = {
58+
devDependencies: {
59+
codelyzer: '^4.5.0',
60+
},
61+
};
2962

3063
describe('tslint.json', () => {
31-
const tslintPath = '/tslint.json';
32-
// tslint:disable-next-line:no-any
33-
let tslintConfig: any;
3464
beforeEach(() => {
35-
tslintConfig = {
36-
rules: {
37-
'directive-selector': [
38-
true,
39-
'attribute',
40-
'app',
41-
'camelCase',
42-
],
43-
'component-selector': [
44-
true,
45-
'element',
46-
'app',
47-
'kebab-case',
48-
],
49-
'no-output-on-prefix': true,
50-
'use-input-property-decorator': true,
51-
'use-output-property-decorator': true,
52-
'use-host-property-decorator': true,
53-
'no-input-rename': true,
54-
'no-output-rename': true,
55-
'use-life-cycle-interface': true,
56-
'use-pipe-transform-interface': true,
57-
'component-class-suffix': true,
58-
'directive-class-suffix': true,
59-
},
60-
};
6165
tree = new UnitTestTree(new EmptyTree());
62-
const packageJson = {
63-
devDependencies: {},
64-
};
65-
tree.create('/package.json', JSON.stringify(packageJson, null, 2));
66+
tree.create(configPath, JSON.stringify(baseConfig, null, 2));
67+
tree.create(packageJsonPath, JSON.stringify(packageJson, null, 2));
68+
tree.create(tslintPath, JSON.stringify(tslintConfig, null, 2));
6669
});
6770

6871
it('should rename all previous rules', () => {
69-
tree.create(configPath, JSON.stringify(baseConfig, null, 2));
70-
tree.create(tslintPath, JSON.stringify(tslintConfig, null, 2));
7172
tree = schematicRunner.runSchematic('migration-07', defaultOptions, tree);
7273
const tslint = JSON.parse(tree.readContent(tslintPath));
7374
for (const rule of renames) {
7475
expect(rule in tslint.rules).toBeTruthy(`Rule ${rule} not renamed`);
7576
}
7677
});
78+
79+
it('should update codelyzer\'s version', () => {
80+
tree = schematicRunner.runSchematic('migration-07', defaultOptions, tree);
81+
const packageJson = JSON.parse(tree.readContent(packageJsonPath));
82+
expect(packageJson.devDependencies.codelyzer).toBe('^5.0.0');
83+
});
7784
});
7885
});
Collapse file

‎scripts/test.ts‎

Copy file name to clipboardExpand all lines: scripts/test.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ export default function (args: ParsedArgs, logger: logging.Logger) {
213213
logger.info(`Found ${tests.length} spec files, out of ${allTests.length}.`);
214214
}
215215

216+
tests = tests.filter(e => e.endsWith('update-8/index_spec.ts'));
217+
216218
if (args.shard !== undefined) {
217219
// Remove tests that are not part of this shard.
218220
const shardId = args['shard'];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.