-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 4 commits.
# 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
1 parent
92c13fd
commit fb662c1
Showing
143 changed files
with
14,134 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,4 @@ tmp | |
|
||
example-dist/ | ||
|
||
schematics-core | ||
!modules/schematics-core | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
modules/effects/src/schematics-core/testing/create-app-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
modules/effects/src/schematics-core/testing/create-package.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
modules/effects/src/schematics-core/testing/create-reducers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
55
modules/effects/src/schematics-core/testing/create-workspace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
modules/effects/src/schematics-core/testing/get-file-content.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ['~', '^', '']; |
Oops, something went wrong.