Skip to content

Commit ac9c599

Browse files
Broccohansl
authored andcommitted
feat(@angular/cli): Add update cmd to update angular versions.
1 parent f724722 commit ac9c599

File tree

8 files changed

+137
-1
lines changed

8 files changed

+137
-1
lines changed

Diff for: package-lock.json

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@angular-devkit/core": "~0.0.28",
4646
"@angular-devkit/schematics": "~0.0.51",
4747
"@schematics/angular": "~0.1.16",
48+
"@schematics/package-update": "0.0.6",
4849
"autoprefixer": "^7.2.3",
4950
"cache-loader": "^1.2.0",
5051
"chalk": "~2.2.0",

Diff for: packages/@angular/cli/commands/update.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const Command = require('../ember-cli/lib/models/command');
2+
import { UpdateTask } from '../tasks/update';
3+
4+
export interface UpdateOptions {
5+
schematic?: boolean;
6+
}
7+
8+
const UpdateCommand = Command.extend({
9+
name: 'update',
10+
description: 'Updates your application.',
11+
works: 'everywhere',
12+
availableOptions: [
13+
{
14+
name: 'dry-run',
15+
type: Boolean,
16+
default: false,
17+
aliases: ['d'],
18+
description: 'Run through without making any changes.'
19+
}
20+
],
21+
22+
anonymousOptions: [],
23+
24+
run: function(commandOptions: any) {
25+
const schematic = '@schematics/package-update:all';
26+
27+
const updateTask = new UpdateTask({
28+
ui: this.ui,
29+
project: this.project
30+
});
31+
32+
return updateTask.run(schematic, commandOptions);
33+
}
34+
});
35+
36+
export default UpdateCommand;

Diff for: packages/@angular/cli/lib/cli/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function loadCommands() {
2020
'completion': require('../../commands/completion').default,
2121
'doc': require('../../commands/doc').default,
2222
'xi18n': require('../../commands/xi18n').default,
23+
'update': require('../../commands/update').default,
2324

2425
// Easter eggs.
2526
'make-this-awesome': require('../../commands/easter-egg').default,

Diff for: packages/@angular/cli/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@ngtools/json-schema": "1.1.0",
3434
"@ngtools/webpack": "1.10.0-beta.1",
3535
"@schematics/angular": "~0.1.16",
36+
"@schematics/package-update": "0.0.6",
3637
"autoprefixer": "^7.2.3",
3738
"cache-loader": "^1.2.0",
3839
"chalk": "~2.2.0",

Diff for: packages/@angular/cli/tasks/update.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const Task = require('../ember-cli/lib/models/task');
2+
import SchematicRunTask from './schematic-run';
3+
4+
export interface UpdateTaskOptions {
5+
dryRun: boolean;
6+
force: boolean;
7+
}
8+
9+
export const UpdateTask: any = Task.extend({
10+
run: function(schematic: string, options: UpdateTaskOptions): Promise<any> {
11+
const [collectionName, schematicName] = schematic.split(':');
12+
13+
const schematicRunTask = new SchematicRunTask({
14+
ui: this.ui,
15+
project: this.project
16+
});
17+
18+
const schematicRunOptions = {
19+
taskOptions: {
20+
dryRun: options.dryRun
21+
},
22+
workingDir: this.project.root,
23+
collectionName,
24+
schematicName
25+
};
26+
27+
return schematicRunTask.run(schematicRunOptions);
28+
}
29+
});

Diff for: scripts/publish/validate_dependencies.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const NODE_PACKAGES = [
2727
const ANGULAR_PACKAGES = [
2828
'@angular/compiler',
2929
'@angular/compiler-cli',
30-
'@angular/core'
30+
'@angular/core',
31+
'@schematics/package-update'
3132
];
3233
const OPTIONAL_PACKAGES = [
3334
'@angular/service-worker',

Diff for: tests/e2e/tests/basic/update.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ng } from '../../utils/process';
2+
import { readFile } from '../../utils/fs';
3+
import { updateJsonFile } from '../../utils/project';
4+
5+
function updateVersions(obj: any) {
6+
const keys = Object.keys(obj);
7+
keys.forEach(key => {
8+
if (key.startsWith('@angular/')) {
9+
obj[key] = '2.0.0';
10+
}
11+
});
12+
}
13+
14+
export default function () {
15+
let origCoreVersion: string;
16+
let origCliVersion: string;
17+
return updateJsonFile('package.json', obj => {
18+
origCoreVersion = obj.dependencies['@angular/core'];
19+
origCliVersion = obj.devDependencies['@angular/cli'];
20+
updateVersions(obj.dependencies);
21+
updateVersions(obj.devDependencies);
22+
obj.devDependencies['@angular/cli'] = '1.6.5';
23+
})
24+
.then(() => ng('update'))
25+
.then(() => readFile('package.json'))
26+
.then(s => {
27+
const obj = JSON.parse(s);
28+
const version = obj.dependencies['@angular/core'];
29+
const cliVersion = obj.devDependencies['@angular/cli'];
30+
if (origCoreVersion === version || origCliVersion === cliVersion) {
31+
throw new Error('Versions not updated');
32+
}
33+
});
34+
}

0 commit comments

Comments
 (0)