feat(@angular/cli): Add update cmd to update angular versions.

This commit is contained in:
Mike Brocchi 2018-01-10 21:27:59 -05:00 committed by Hans
parent f724722914
commit ac9c5995d2
8 changed files with 137 additions and 1 deletions

33
package-lock.json generated
View File

@ -114,6 +114,31 @@
}
}
},
"@schematics/package-update": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/@schematics/package-update/-/package-update-0.0.6.tgz",
"integrity": "sha512-H7xoVzBx8QQPNWQiitHD2D1nhVeQPj7UWOxtrLk4Ra2eOWQllKXb461VXcTpdGiABVHz3i4sp/Owq1TMRyE6Mg==",
"requires": {
"rxjs": "5.5.6",
"semver": "5.4.1",
"semver-intersect": "1.2.0"
},
"dependencies": {
"rxjs": {
"version": "5.5.6",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.5.6.tgz",
"integrity": "sha512-v4Q5HDC0FHAQ7zcBX7T2IL6O5ltl1a2GX4ENjPXg6SjDY69Cmx9v4113C99a4wGF16ClPv5Z8mghuYorVkg/kg==",
"requires": {
"symbol-observable": "1.0.1"
}
},
"symbol-observable": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.1.tgz",
"integrity": "sha1-g0D8RwLDEi310iKI+IKD9RPT/dQ="
}
}
},
"@types/common-tags": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@types/common-tags/-/common-tags-1.4.0.tgz",
@ -8564,6 +8589,14 @@
"resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz",
"integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg=="
},
"semver-intersect": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/semver-intersect/-/semver-intersect-1.2.0.tgz",
"integrity": "sha512-XwQtuo56XVJd4JDV90L9RWjBluxWcnKDlQivIlF+Jvdhqgvk7KAroAqs8aJ/hjQW0wNPSSWDxhJLzYX+dwb13A==",
"requires": {
"semver": "5.4.1"
}
},
"send": {
"version": "0.15.4",
"resolved": "https://registry.npmjs.org/send/-/send-0.15.4.tgz",

View File

@ -45,6 +45,7 @@
"@angular-devkit/core": "~0.0.28",
"@angular-devkit/schematics": "~0.0.51",
"@schematics/angular": "~0.1.16",
"@schematics/package-update": "0.0.6",
"autoprefixer": "^7.2.3",
"cache-loader": "^1.2.0",
"chalk": "~2.2.0",

View File

@ -0,0 +1,36 @@
const Command = require('../ember-cli/lib/models/command');
import { UpdateTask } from '../tasks/update';
export interface UpdateOptions {
schematic?: boolean;
}
const UpdateCommand = Command.extend({
name: 'update',
description: 'Updates your application.',
works: 'everywhere',
availableOptions: [
{
name: 'dry-run',
type: Boolean,
default: false,
aliases: ['d'],
description: 'Run through without making any changes.'
}
],
anonymousOptions: [],
run: function(commandOptions: any) {
const schematic = '@schematics/package-update:all';
const updateTask = new UpdateTask({
ui: this.ui,
project: this.project
});
return updateTask.run(schematic, commandOptions);
}
});
export default UpdateCommand;

View File

@ -20,6 +20,7 @@ function loadCommands() {
'completion': require('../../commands/completion').default,
'doc': require('../../commands/doc').default,
'xi18n': require('../../commands/xi18n').default,
'update': require('../../commands/update').default,
// Easter eggs.
'make-this-awesome': require('../../commands/easter-egg').default,

View File

@ -33,6 +33,7 @@
"@ngtools/json-schema": "1.1.0",
"@ngtools/webpack": "1.10.0-beta.1",
"@schematics/angular": "~0.1.16",
"@schematics/package-update": "0.0.6",
"autoprefixer": "^7.2.3",
"cache-loader": "^1.2.0",
"chalk": "~2.2.0",

View File

@ -0,0 +1,29 @@
const Task = require('../ember-cli/lib/models/task');
import SchematicRunTask from './schematic-run';
export interface UpdateTaskOptions {
dryRun: boolean;
force: boolean;
}
export const UpdateTask: any = Task.extend({
run: function(schematic: string, options: UpdateTaskOptions): Promise<any> {
const [collectionName, schematicName] = schematic.split(':');
const schematicRunTask = new SchematicRunTask({
ui: this.ui,
project: this.project
});
const schematicRunOptions = {
taskOptions: {
dryRun: options.dryRun
},
workingDir: this.project.root,
collectionName,
schematicName
};
return schematicRunTask.run(schematicRunOptions);
}
});

View File

@ -27,7 +27,8 @@ const NODE_PACKAGES = [
const ANGULAR_PACKAGES = [
'@angular/compiler',
'@angular/compiler-cli',
'@angular/core'
'@angular/core',
'@schematics/package-update'
];
const OPTIONAL_PACKAGES = [
'@angular/service-worker',

View File

@ -0,0 +1,34 @@
import { ng } from '../../utils/process';
import { readFile } from '../../utils/fs';
import { updateJsonFile } from '../../utils/project';
function updateVersions(obj: any) {
const keys = Object.keys(obj);
keys.forEach(key => {
if (key.startsWith('@angular/')) {
obj[key] = '2.0.0';
}
});
}
export default function () {
let origCoreVersion: string;
let origCliVersion: string;
return updateJsonFile('package.json', obj => {
origCoreVersion = obj.dependencies['@angular/core'];
origCliVersion = obj.devDependencies['@angular/cli'];
updateVersions(obj.dependencies);
updateVersions(obj.devDependencies);
obj.devDependencies['@angular/cli'] = '1.6.5';
})
.then(() => ng('update'))
.then(() => readFile('package.json'))
.then(s => {
const obj = JSON.parse(s);
const version = obj.dependencies['@angular/core'];
const cliVersion = obj.devDependencies['@angular/cli'];
if (origCoreVersion === version || origCliVersion === cliVersion) {
throw new Error('Versions not updated');
}
});
}