Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ng update support to ngrx packages #1053

Merged
merged 4 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,20 @@ jobs:
# Install the dependencies from NPM, using the node and yarn binaries managed by Bazel
- run: bazel run @yarn//:yarn

# Copy shared schematics-core into schematics/src directory
- run: yarn copy:schematics

# Build and Test
# Use bazel query so that we explicitly ask for all buildable targets to
# be built even though we run `bazel test`
# See https://github.com/bazelbuild/bazel/issues/4257
- run: bazel query --output=label //... | xargs bazel test

test:
<<: *run_in_ngcontainer
docker:
- image: circleci/node:latest-browsers
steps:
- checkout
- restore_cache:
key: *cache_key
- run: yarn
- run: yarn copy:schematics
- run: yarn run ci
- run: yarn run example:build:prod
- run: yarn run example:test --watch=false
Expand All @@ -89,7 +86,6 @@ jobs:
- restore_cache:
key: *cache_key
- run: yarn
- run: yarn copy:schematics
- run: yarn run build
- run: yarn run deploy:builds

Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ tmp

example-dist/

schematics-core
!modules/schematics-core
*.tgz
*.tgz
modules/*/schematics-core/testing
!modules/schematics-core/testing
2 changes: 1 addition & 1 deletion build/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Config {
scope: string;
}

const modulesDir = './modules/';
export const modulesDir = './modules/';
export const packages: PackageDescription[] = fs
.readdirSync(modulesDir)
.filter(path => {
Expand Down
15 changes: 15 additions & 0 deletions build/copy-schematics-core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as tasks from './tasks';
import { createBuilder } from './util';
import { packages } from './config';

const copySchematics = createBuilder([
['Copy Schematics Core Files', tasks.copySchematicsCore],
]);

copySchematics({
scope: '@ngrx',
packages,
}).catch(err => {
console.error(err);
process.exit(1);
});
31 changes: 30 additions & 1 deletion build/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
import { Config } from './config';
import { Config, modulesDir } from './config';
import * as util from './util';
import * as fs from 'fs';
import { ncp } from 'ncp';

/**
*
* Copies the schematics-core package into any package that provides
* schematics or migrations
*/
export async function copySchematicsCore(config: Config) {
(ncp as any).limit = 1;
for (let pkg of util.getTopLevelPackages(config)) {
const packageJson = fs
.readFileSync(`${modulesDir}${pkg}/package.json`)
.toString('utf-8');
const pkgConfig = JSON.parse(packageJson);

if (pkgConfig.schematics || pkgConfig['ng-update'].migrations) {
ncp(
`${modulesDir}/schematics-core`,
`${modulesDir}/${pkg}/schematics-core`,
function(err: any) {
if (err) {
return console.error(err);
}
}
);
}
}
}

/**
* Deploy build artifacts to repos
Expand Down
4 changes: 4 additions & 0 deletions modules/effects/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ ng_package(
"//modules/effects/testing:package.json",
],
entry_point = "modules/effects/index.js",
packages = [
"//modules/effects/migrations:npm_package",
"//modules/effects/schematics-core:npm_package",
],
deps = [
":effects",
"//modules/effects/testing",
Expand Down
39 changes: 39 additions & 0 deletions modules/effects/migrations/6_0_0/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Tree } from '@angular-devkit/schematics';
import {
SchematicTestRunner,
UnitTestTree,
} from '@angular-devkit/schematics/testing';
import * as path from 'path';
import {
createPackageJson,
packagePath,
} from '../../../schematics-core/testing/create-package';
import {
upgradeVersion,
versionPrefixes,
} from '../../../schematics-core/testing/update';

const collectionPath = path.join(__dirname, '../migration.json');

describe('Effects Migration 6_0_0', () => {
let appTree;
const pkgName = 'effects';

versionPrefixes.forEach(prefix => {
it(`should install version ${prefix}6.0.0`, () => {
appTree = new UnitTestTree(Tree.empty());
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = createPackageJson(prefix, pkgName, appTree);

const newTree = runner.runSchematic(
`ngrx-${pkgName}-migration-01`,
{},
tree
);
const pkg = JSON.parse(newTree.readContent(packagePath));
expect(pkg.dependencies[`@ngrx/${pkgName}`]).toBe(
`${prefix}${upgradeVersion}`
);
});
});
});
6 changes: 6 additions & 0 deletions modules/effects/migrations/6_0_0/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Rule } from '@angular-devkit/schematics';
import { updatePackage } from '@ngrx/effects/schematics-core';

export default function(): Rule {
return updatePackage('effects');
}
31 changes: 31 additions & 0 deletions modules/effects/migrations/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package(default_visibility = ["//visibility:public"])

load("//tools:defaults.bzl", "ts_library")
load("//tools:defaults.bzl", "npm_package")

ts_library(
name = "migrations",
srcs = glob(
[
"**/*.ts",
],
exclude = [
"**/testing/*.ts",
"**/*.spec.ts",
],
),
module_name = "@ngrx/effects/migrations",
deps = [
"//modules/effects/schematics-core",
],
)

npm_package(
name = "npm_package",
srcs = [
":migration.json",
],
deps = [
":migrations",
],
)
11 changes: 11 additions & 0 deletions modules/effects/migrations/migration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema":
"../../../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"ngrx-effects-migration-01": {
"description": "The road to v6",
"version": "5.2",
"factory": "./6_0_0/index"
}
}
}
3 changes: 2 additions & 1 deletion modules/effects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"rxjs": "RXJS_VERSION"
},
"ng-update": {
"packageGroup": "NG_UPDATE_PACKAGE_GROUP"
"packageGroup": "NG_UPDATE_PACKAGE_GROUP",
"migrations": "NG_UPDATE_MIGRATIONS"
},
"sideEffects": false
}
26 changes: 26 additions & 0 deletions modules/effects/schematics-core/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package(default_visibility = ["//visibility:public"])

load("//tools:defaults.bzl", "ts_library")
load("//tools:defaults.bzl", "npm_package")

ts_library(
name = "schematics-core",
srcs = glob(
[
"**/*.ts",
],
exclude = [
"**/testing/**/*.ts",
"**/*spec.ts",
],
),
module_name = "@ngrx/effects/schematics-core",
)

npm_package(
name = "npm_package",
srcs = [],
deps = [
":schematics-core",
],
)
72 changes: 72 additions & 0 deletions modules/effects/schematics-core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
dasherize,
decamelize,
camelize,
classify,
underscore,
group,
capitalize,
featurePath,
} from './utility/strings';

export {
findNodes,
getSourceNodes,
getDecoratorMetadata,
getContentOfKeyLiteral,
insertAfterLastOccurrence,
addBootstrapToModule,
addDeclarationToModule,
addExportToModule,
addImportToModule,
addProviderToModule,
} from './utility/ast-utils';

export {
Host,
Change,
NoopChange,
InsertChange,
RemoveChange,
ReplaceChange,
} from './utility/change';

export {
AppConfig,
CliConfig,
getAppFromConfig,
getConfig,
getWorkspace,
getWorkspacePath,
} from './utility/config';

export {
findModule,
findModuleFromOptions,
buildRelativePath,
ModuleOptions,
} from './utility/find-module';

export {
addReducerToState,
addReducerToStateInferface,
addReducerImportToNgModule,
addReducerToActionReducerMap,
omit,
} from './utility/ngrx-utils';

export { getProjectPath } from './utility/project';
export { insertImport } from './utility/route-utils';

export const stringUtils = {
dasherize,
decamelize,
camelize,
classify,
underscore,
group,
capitalize,
featurePath,
};

export { updatePackage } from './utility/update';
Loading