Skip to content

Commit

Permalink
fix(@angular/cli): show a simpler command for ng update
Browse files Browse the repository at this point in the history
And use validate instead of run() ot change the options which is more correct.
  • Loading branch information
hansl committed Apr 28, 2018
1 parent 9274ca7 commit 2d34128
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/@angular/cli/bin/ng-update-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (found) {
The Angular CLI configuration format has been changed, and your existing configuration can
be updated automatically by running the following command:
ng update @angular/cli --migrate-only --from=1
ng update @angular/cli
${'='.repeat(80)}
\u001b[39m`.replace(/^ {4}/gm, ''));
}
33 changes: 25 additions & 8 deletions packages/@angular/cli/commands/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { normalize } from '@angular-devkit/core';
import { CommandScope, Option } from '../models/command';
import { SchematicCommand, CoreSchematicOptions } from '../models/schematic-command';
import { findUp } from '../utilities/find-up';

export interface UpdateOptions extends CoreSchematicOptions {
next: boolean;
Expand Down Expand Up @@ -38,19 +40,34 @@ export default class UpdateCommand extends SchematicCommand {
this.arguments = this.arguments.concat(schematicOptions.arguments.map(a => a.name));
}

public async run(options: UpdateOptions) {
const schematicOptions: any = { ...options };
if (schematicOptions._[0] == '@angular/cli'
&& !schematicOptions.migrateOnly
&& !schematicOptions.from) {
schematicOptions.migrateOnly = true;
schematicOptions.from = '1.0.0';
async validate(options: any) {
if (options._[0] == '@angular/cli'
&& options.migrateOnly === undefined
&& options.from === undefined) {
// Check for a 1.7 angular-cli.json file.
const oldConfigFileNames = [
normalize('.angular-cli.json'),
normalize('angular-cli.json'),
];
const oldConfigFilePath =
findUp(oldConfigFileNames, process.cwd())
|| findUp(oldConfigFileNames, __dirname);

if (oldConfigFilePath) {
options.migrateOnly = true;
options.from = '1.0.0';
}
}

return super.validate(options);
}


public async run(options: UpdateOptions) {
return this.runSchematic({
collectionName: this.collectionName,
schematicName: this.schematicName,
schematicOptions,
schematicOptions: options,
dryRun: options.dryRun,
force: false,
showNothingDone: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/models/command-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function verifyWorkspace(
The Angular CLI configuration format has been changed, and your existing configuration can
be updated automatically by running the following command:
ng update @angular/cli --migrate-only --from=1
ng update @angular/cli
`;

if (!logger) {
Expand Down

0 comments on commit 2d34128

Please sign in to comment.