-
-
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.
feat(Store): Add support ng update (#1032)
- Loading branch information
1 parent
4c4e6a9
commit 5b4f067
Showing
6 changed files
with
102 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { | ||
SchematicTestRunner, | ||
UnitTestTree, | ||
} from '@angular-devkit/schematics/testing'; | ||
import * as path from 'path'; | ||
|
||
const packagePath = '/package.json'; | ||
const collectionPath = path.join(__dirname, '../migration.json'); | ||
|
||
describe('Migration 6_0_0', () => { | ||
function setup(prefix: string) { | ||
const tree = Tree.empty() as UnitTestTree; | ||
tree.create( | ||
packagePath, | ||
`{ | ||
"dependencies": { | ||
"@ngrx/store": "${prefix}5.2.0" | ||
} | ||
}` | ||
); | ||
|
||
return { | ||
tree, | ||
runner: new SchematicTestRunner('schematics', collectionPath), | ||
}; | ||
} | ||
|
||
const prefixes = ['~', '^', '']; | ||
prefixes.forEach(prefix => { | ||
it(`should install version ${prefix}6.0.0`, () => { | ||
const { runner, tree } = setup(prefix); | ||
const newTree = runner.runSchematic('ngrx-store-migration-01', {}, tree); | ||
const pkg = JSON.parse(newTree.readContent(packagePath)); | ||
expect(pkg.dependencies['@ngrx/store']).toBe(`${prefix}6.0.0-beta.2`); | ||
}); | ||
}); | ||
}); |
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,44 @@ | ||
import { | ||
Rule, | ||
SchematicContext, | ||
Tree, | ||
SchematicsException, | ||
chain, | ||
} from '@angular-devkit/schematics'; | ||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; | ||
|
||
export default function(): Rule { | ||
return (tree: Tree, context: SchematicContext) => { | ||
const pkgPath = '/package.json'; | ||
const buffer = tree.read(pkgPath); | ||
if (buffer == null) { | ||
throw new SchematicsException('Could not read package.json'); | ||
} | ||
const content = buffer.toString(); | ||
const pkg = JSON.parse(content); | ||
|
||
if (pkg === null || typeof pkg !== 'object' || Array.isArray(pkg)) { | ||
throw new SchematicsException('Error reading package.json'); | ||
} | ||
|
||
if (!pkg.dependencies) { | ||
pkg.dependencies = {}; | ||
} | ||
|
||
if (pkg.dependencies['@ngrx/store']) { | ||
const firstChar = pkg.dependencies['@ngrx/store'][0]; | ||
const suffix = match(firstChar, '^') || match(firstChar, '~'); | ||
|
||
// TODO: remove beta | ||
pkg.dependencies['@ngrx/store'] = `${suffix}6.0.0-beta.2`; | ||
tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2)); | ||
context.addTask(new NodePackageInstallTask()); | ||
} | ||
|
||
return tree; | ||
}; | ||
} | ||
|
||
function match(value: string, test: string) { | ||
return value === test ? test : ''; | ||
} |
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-store-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