|
| 1 | +import { normalize } from '@angular-devkit/core'; |
1 | 2 | import { CommandScope, Option } from '../models/command';
|
2 | 3 | import { SchematicCommand, CoreSchematicOptions } from '../models/schematic-command';
|
| 4 | +import { findUp } from '../utilities/find-up'; |
3 | 5 |
|
4 | 6 | export interface UpdateOptions extends CoreSchematicOptions {
|
5 | 7 | next: boolean;
|
@@ -38,19 +40,34 @@ export default class UpdateCommand extends SchematicCommand {
|
38 | 40 | this.arguments = this.arguments.concat(schematicOptions.arguments.map(a => a.name));
|
39 | 41 | }
|
40 | 42 |
|
41 |
| - public async run(options: UpdateOptions) { |
42 |
| - const schematicOptions: any = { ...options }; |
43 |
| - if (schematicOptions._[0] == '@angular/cli' |
44 |
| - && !schematicOptions.migrateOnly |
45 |
| - && !schematicOptions.from) { |
46 |
| - schematicOptions.migrateOnly = true; |
47 |
| - schematicOptions.from = '1.0.0'; |
| 43 | + async validate(options: any) { |
| 44 | + if (options._[0] == '@angular/cli' |
| 45 | + && options.migrateOnly === undefined |
| 46 | + && options.from === undefined) { |
| 47 | + // Check for a 1.7 angular-cli.json file. |
| 48 | + const oldConfigFileNames = [ |
| 49 | + normalize('.angular-cli.json'), |
| 50 | + normalize('angular-cli.json'), |
| 51 | + ]; |
| 52 | + const oldConfigFilePath = |
| 53 | + findUp(oldConfigFileNames, process.cwd()) |
| 54 | + || findUp(oldConfigFileNames, __dirname); |
| 55 | + |
| 56 | + if (oldConfigFilePath) { |
| 57 | + options.migrateOnly = true; |
| 58 | + options.from = '1.0.0'; |
| 59 | + } |
48 | 60 | }
|
49 | 61 |
|
| 62 | + return super.validate(options); |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + public async run(options: UpdateOptions) { |
50 | 67 | return this.runSchematic({
|
51 | 68 | collectionName: this.collectionName,
|
52 | 69 | schematicName: this.schematicName,
|
53 |
| - schematicOptions, |
| 70 | + schematicOptions: options, |
54 | 71 | dryRun: options.dryRun,
|
55 | 72 | force: false,
|
56 | 73 | showNothingDone: false,
|
|
0 commit comments