|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {FileEntry, Rule, SchematicContext, Tree} from '@angular-devkit/schematics'; |
10 |
| -import { |
11 |
| - NodePackageInstallTask, |
12 |
| - RunSchematicTask, |
13 |
| - TslintFixTask, |
14 |
| -} from '@angular-devkit/schematics/tasks'; |
| 9 | +import {Rule, SchematicContext, TaskId, Tree} from '@angular-devkit/schematics'; |
| 10 | +import {RunSchematicTask, TslintFixTask} from '@angular-devkit/schematics/tasks'; |
15 | 11 | import {getWorkspace} from '@schematics/angular/utility/config';
|
16 |
| -import {existsSync, mkdtempSync} from 'fs'; |
17 | 12 | import * as path from 'path';
|
18 | 13 |
|
19 |
| -const schematicsSrcPath = 'node_modules/@angular/material/schematics'; |
20 |
| -const schematicsTmpPath = mkdtempSync('angular_material_temp_schematics'); |
21 |
| - |
22 | 14 | /** Entry point for `ng update` from Angular CLI. */
|
23 | 15 | export default function(): Rule {
|
24 | 16 | return (tree: Tree, context: SchematicContext) => {
|
25 |
| - // If this script failed in an earlier run, clear out the temporary files from that failed |
26 |
| - // run before doing anything else. |
27 |
| - tree.getDir(schematicsTmpPath).visit((_, entry) => tree.delete(entry.path)); |
28 |
| - |
29 |
| - // Copy the update schematics to a temporary directory. |
30 |
| - const updateSrcs: FileEntry[] = []; |
31 |
| - tree.getDir(schematicsSrcPath).visit((_, entry) => updateSrcs.push(entry)); |
32 |
| - for (let src of updateSrcs) { |
33 |
| - tree.create(src.path.replace(schematicsSrcPath, schematicsTmpPath), src.content); |
34 |
| - } |
35 |
| - |
36 |
| - // Downgrade @angular/cdk and @angular/material to 5.x. This allows us to use the 5.x type |
37 |
| - // information in the update script. |
38 |
| - const downgradeTask = context.addTask(new NodePackageInstallTask({ |
39 |
| - packageName: '@angular/cdk@">=5 <6" @angular/material@">=5 <6"' |
40 |
| - })); |
41 | 17 |
|
42 | 18 | const allTsConfigPaths = getTsConfigPaths(tree);
|
43 |
| - const allUpdateTasks = []; |
| 19 | + const tslintFixTasks: TaskId[] = []; |
| 20 | + |
| 21 | + if (!allTsConfigPaths.length) { |
| 22 | + throw new Error('Could not find any tsconfig file. Please submit an issue on the Angular ' + |
| 23 | + 'Material repository that includes the name of your TypeScript configuration.'); |
| 24 | + } |
44 | 25 |
|
45 | 26 | for (const tsconfig of allTsConfigPaths) {
|
46 | 27 | // Run the update tslint rules.
|
47 |
| - allUpdateTasks.push(context.addTask(new TslintFixTask({ |
48 |
| - rulesDirectory: path.join(schematicsTmpPath, 'update/rules'), |
| 28 | + tslintFixTasks.push(context.addTask(new TslintFixTask({ |
| 29 | + rulesDirectory: path.join(__dirname, 'rules/'), |
49 | 30 | rules: {
|
50 | 31 | // Automatic fixes.
|
51 | 32 | 'switch-identifiers': true,
|
@@ -78,38 +59,25 @@ export default function(): Rule {
|
78 | 59 | silent: false,
|
79 | 60 | ignoreErrors: true,
|
80 | 61 | tsConfigPath: tsconfig,
|
81 |
| - }), [downgradeTask])); |
| 62 | + }))); |
82 | 63 | }
|
83 | 64 |
|
84 |
| - // Upgrade @angular/material back to 6.x. |
85 |
| - const upgradeTask = context.addTask(new NodePackageInstallTask({ |
86 |
| - // TODO(mmalerba): Change "next" to ">=6 <7". |
87 |
| - packageName: '@angular/cdk@next @angular/material@next' |
88 |
| - }), allUpdateTasks); |
89 |
| - |
90 | 65 | // Delete the temporary schematics directory.
|
91 |
| - context.addTask(new RunSchematicTask('ng-post-update', { |
92 |
| - deletePath: schematicsTmpPath |
93 |
| - }), [upgradeTask]); |
| 66 | + context.addTask(new RunSchematicTask('ng-post-update', {}), tslintFixTasks); |
94 | 67 | };
|
95 | 68 | }
|
96 | 69 |
|
97 |
| -/** Post-update schematic to be called when ng update is finished. */ |
98 |
| -export function postUpdate(options: {deletePath: string}): Rule { |
99 |
| - return (tree: Tree, context: SchematicContext) => { |
100 |
| - tree.delete(options.deletePath); |
101 |
| - context.addTask(new RunSchematicTask('ng-post-post-update', {})); |
102 |
| - }; |
103 |
| -} |
104 |
| - |
105 |
| -/** Post-post-update schematic to be called when post-update is finished. */ |
106 |
| -export function postPostUpdate(): Rule { |
| 70 | +/** Post-update schematic to be called when update is finished. */ |
| 71 | +export function postUpdate(): Rule { |
107 | 72 | return () => console.log(
|
108 | 73 | '\nComplete! Please check the output above for any issues that were detected but could not' +
|
109 | 74 | ' be automatically fixed.');
|
110 | 75 | }
|
111 | 76 |
|
112 |
| -/** Gets the first tsconfig path from possibile locations based on the history of the CLI. */ |
| 77 | +/** |
| 78 | + * Gets all tsconfig paths from a CLI project by reading the workspace configuration |
| 79 | + * and looking for common tsconfig locations. |
| 80 | + */ |
113 | 81 | function getTsConfigPaths(tree: Tree): string[] {
|
114 | 82 | // Start with some tsconfig paths that are generally used.
|
115 | 83 | const tsconfigPaths = [
|
@@ -139,6 +107,6 @@ function getTsConfigPaths(tree: Tree): string[] {
|
139 | 107 |
|
140 | 108 | // Filter out tsconfig files that don't exist and remove any duplicates.
|
141 | 109 | return tsconfigPaths
|
142 |
| - .filter(p => existsSync(p)) |
| 110 | + .filter(p => tree.exists(p)) |
143 | 111 | .filter((value, index, self) => self.indexOf(value) === index);
|
144 | 112 | }
|
0 commit comments