Skip to content

Commit

Permalink
# This is a combination of 4 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

feat: Add ng update support to ngrx packages

# The commit message #2 will be skipped:

# Copy schematics-core into each package src directory
#
# Since Bazel builds from source, external consumers will be broken
# as they won't run the build step to copy the files

# The commit message #3 will be skipped:

# Run nyc tests without Bazel build

# The commit message #4 will be skipped:

# Remove build step from example app
  • Loading branch information
brandonroberts committed May 11, 2018
1 parent 92c13fd commit fb662c1
Show file tree
Hide file tree
Showing 143 changed files with 14,134 additions and 81 deletions.
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,4 @@ tmp

example-dist/

schematics-core
!modules/schematics-core
*.tgz
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 '../../src/schematics-core';

export default function(): Rule {
return updatePackage('effects');
}
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
}
72 changes: 72 additions & 0 deletions modules/effects/src/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';
60 changes: 60 additions & 0 deletions modules/effects/src/schematics-core/testing/create-app-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { UnitTestTree } from '@angular-devkit/schematics/testing';

export function createAppModule(
tree: UnitTestTree,
path?: string
): UnitTestTree {
tree.create(
path || '/src/app/app.module.ts',
`
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
`
);

return tree;
}

export function createAppModuleWithEffects(
tree: UnitTestTree,
path: string,
effects?: string
): UnitTestTree {
tree.create(
path || '/src/app/app.module.ts',
`
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { EffectsModule } from '@ngrx/effects';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
${effects}
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
`
);

return tree;
}
26 changes: 26 additions & 0 deletions modules/effects/src/schematics-core/testing/create-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Tree } from '@angular-devkit/schematics';
import {
UnitTestTree,
SchematicTestRunner,
} from '@angular-devkit/schematics/testing';

export const packagePath = '/package.json';

export function createPackageJson(
prefix: string,
pkg: string,
tree: UnitTestTree,
version = '5.2.0',
packagePath = '/package.json'
) {
tree.create(
packagePath,
`{
"dependencies": {
"@ngrx/${pkg}": "${prefix}5.2.0"
}
}`
);

return tree;
}
34 changes: 34 additions & 0 deletions modules/effects/src/schematics-core/testing/create-reducers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { UnitTestTree } from '@angular-devkit/schematics/testing';

export function createReducers(
tree: UnitTestTree,
path?: string,
project = 'bar'
) {
tree.create(
path || `/projects/${project}/src/app/reducers/index.ts`,
`
import {
ActionReducer,
ActionReducerMap,
createFeatureSelector,
createSelector,
MetaReducer
} from '@ngrx/store';
import { environment } from '../../environments/environment';
export interface State {
}
export const reducers: ActionReducerMap<State> = {
};
export const metaReducers: MetaReducer<State>[] = !environment.production ? [] : [];
`
);

return tree;
}
55 changes: 55 additions & 0 deletions modules/effects/src/schematics-core/testing/create-workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
UnitTestTree,
SchematicTestRunner,
} from '@angular-devkit/schematics/testing';

const defaultWorkspaceOptions = {
name: 'workspace',
newProjectRoot: 'projects',
version: '6.0.0',
};

const defaultAppOptions = {
name: 'bar',
inlineStyle: false,
inlineTemplate: false,
viewEncapsulation: 'Emulated',
routing: false,
style: 'css',
skipTests: false,
};

const defaultModuleOptions = {
name: 'foo',
spec: true,
module: undefined,
flat: false,
};

export function getTestProjectPath(
workspaceOptions: any = defaultWorkspaceOptions,
appOptions: any = defaultAppOptions
) {
return `/${workspaceOptions.newProjectRoot}/${appOptions.name}`;
}

export function createWorkspace(
schematicRunner: SchematicTestRunner,
appTree: UnitTestTree,
workspaceOptions = defaultWorkspaceOptions,
appOptions = defaultAppOptions
) {
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
'workspace',
workspaceOptions
);
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
'application',
appOptions,
appTree
);

return appTree;
}
11 changes: 11 additions & 0 deletions modules/effects/src/schematics-core/testing/get-file-content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Tree } from '@angular-devkit/schematics';

export function getFileContent(tree: Tree, path: string): string {
const fileEntry = tree.get(path);

if (!fileEntry) {
throw new Error(`The file (${path}) does not exist.`);
}

return fileEntry.content.toString();
}
4 changes: 4 additions & 0 deletions modules/effects/src/schematics-core/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './create-app-module';
export * from './create-reducers';
export * from './create-workspace';
export * from './get-file-content';
2 changes: 2 additions & 0 deletions modules/effects/src/schematics-core/testing/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const upgradeVersion = '6.0.0-beta.2';
export const versionPrefixes = ['~', '^', ''];
Loading

0 comments on commit fb662c1

Please sign in to comment.