Skip to content

Commit

Permalink
fix(frontend): fix ngrx migration requiring angular cli 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored and vsavkin committed Jul 19, 2019
1 parent 297eca0 commit 98e5bbc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 13 deletions.
71 changes: 60 additions & 11 deletions packages/angular/src/migrations/update-8-3-0/upgrade-ngrx-8-0.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
import { chain, Tree, noop } from '@angular-devkit/schematics';
import { addUpdateTask, readJsonInTree, formatFiles } from '@nrwl/workspace';
import { chain, Tree, noop, TaskId } from '@angular-devkit/schematics';
import {
addUpdateTask,
readJsonInTree,
formatFiles,
updateJsonInTree
} from '@nrwl/workspace';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';

const runNgrxUpdate = addUpdateTask('@ngrx/store', '8.1.0');
function updateCLI() {
const tasks: TaskId[] = [];
const rule = chain([
updateJsonInTree('package.json', json => {
json.devDependencies = json.devDependencies || {};
const cliVersion = json.devDependencies['@angular/cli'];

const updateNgrx = (host: Tree) => {
const { dependencies } = readJsonInTree(host, 'package.json');
if (
cliVersion &&
(cliVersion.startsWith('8.1') ||
cliVersion.startsWith('~8.1') ||
cliVersion.startsWith('^8.1'))
) {
return json;
}

if (dependencies && dependencies['@ngrx/store']) {
return chain([runNgrxUpdate, formatFiles()]);
}
if (json['devDependencies']['@angular/cli']) {
json['devDependencies']['@angular/cli'] = '8.1.1';
}

return noop();
};
if (json['devDependencies']['@angular-devkit/build-angular']) {
json['devDependencies']['@angular-devkit/build-angular'] = '^0.801.1';
}

if (json['devDependencies']['@angular-devkit/build-ng-packagr']) {
json['devDependencies']['@angular-devkit/build-ng-packagr'] =
'~0.801.1';
}

return json;
}),
(host, context) => {
tasks.push(context.addTask(new NodePackageInstallTask()));
}
]);

return { rule, tasks };
}

function updateNgrx(updateDeps: TaskId[]) {
return (host: Tree) => {
const { dependencies } = readJsonInTree(host, 'package.json');

if (dependencies && dependencies['@ngrx/store']) {
return chain([
addUpdateTask('@ngrx/store', '8.1.0', updateDeps),
formatFiles()
]);
}

return noop();
};
}

export default function() {
return chain([updateNgrx]);
const { rule: updateCLIRule, tasks } = updateCLI();
return chain([updateCLIRule, updateNgrx(tasks)]);
}
11 changes: 9 additions & 2 deletions packages/workspace/src/utils/update-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
TaskConfiguration,
TaskConfigurationGenerator,
TaskExecutorFactory,
TaskId,
Tree
} from '@angular-devkit/schematics';
import { Observable } from 'rxjs';
Expand All @@ -12,7 +13,11 @@ import { join } from 'path';

let taskRegistered = false;

export function addUpdateTask(pkg: string, to: string): Rule {
export function addUpdateTask(
pkg: string,
to: string,
dependencies: TaskId[] = []
): Rule {
return (host: Tree, context: SchematicContext) => {
// Workflow should always be there during ng update but not during tests.
if (!context.engine.workflow) {
Expand All @@ -34,7 +39,9 @@ export function addUpdateTask(pkg: string, to: string): Rule {
}
});

context.addTask(new RunUpdateTask(pkg, to));
console.log(dependencies);

context.addTask(new RunUpdateTask(pkg, to), dependencies);
};
}

Expand Down

0 comments on commit 98e5bbc

Please sign in to comment.