-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schematics): add migration schematics for schematics users
- Loading branch information
Showing
5 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
{ | ||
"schematics": { | ||
"migration-01": { | ||
"version": "6", | ||
"factory": "./update-6_0_0/index#rxjsV6MigrationSchematic" | ||
} | ||
} | ||
} |
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,87 @@ | ||
import { Rule, SchematicContext, Tree, SchematicsException, chain, } from '@angular-devkit/schematics'; | ||
import { TsLintTask, NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; | ||
|
||
export function rxjsV6MigrationSchematic(_options: any): Rule { | ||
return chain([ | ||
addDependencies(), | ||
runTsLint(), | ||
]); | ||
} | ||
|
||
const rxjsCompatVersion = '^6.0.0-rc.0'; | ||
const rxjsTSLintVersion = '0.0.0'; | ||
|
||
function addDependencies() { | ||
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.devDependencies) { | ||
pkg.devDependencies = {}; | ||
} | ||
|
||
pkg.dependencies['rxjs-compat'] = rxjsCompatVersion; | ||
pkg.devDependencies['rxjs-tslint'] = rxjsTSLintVersion; | ||
|
||
tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2)); | ||
context.addTask(new NodePackageInstallTask()); | ||
|
||
return tree; | ||
}; | ||
} | ||
|
||
function runTsLint() { | ||
return (tree: Tree, context: SchematicContext) => { | ||
const workspace = getWorkspace(tree); | ||
const tsLintRules = { | ||
rulesDirectory: ['node_modules/rxjs-tslint'], | ||
rules: { | ||
'update-rxjs-imports': true, | ||
'migrate-to-pipeable-operators': true, | ||
'collapse-rxjs-imports': true | ||
} | ||
}; | ||
Object.keys(workspace.projects) | ||
.filter(prj => workspace.projects[prj].architect.build) | ||
.map(prj => workspace.projects[prj].architect.build.options.tsConfig) | ||
.forEach(tsConfigPath => { | ||
const options = { | ||
tsConfigPath: tsConfigPath, | ||
tslintConfig: tsLintRules | ||
}; | ||
|
||
context.addTask(new TslintFixTask(options)); | ||
}); | ||
|
||
}; | ||
} | ||
|
||
export function getWorkspacePath(tree: Tree): string { | ||
const possibleFiles = [ '/angular.json', '/.angular.json' ]; | ||
const path = possibleFiles.filter(path => tree.exists(path))[0]; | ||
|
||
return path; | ||
} | ||
|
||
export function getWorkspace(tree: Tree): any { | ||
const path = getWorkspacePath(tree); | ||
const configBuffer = tree.read(path); | ||
if (configBuffer === null) { | ||
throw new SchematicsException(`Could not find (${path})`); | ||
} | ||
const config = configBuffer.toString(); | ||
|
||
return JSON.parse(config); | ||
} |
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,5 @@ | ||
export const latestVersions = { | ||
'rxjs-compat': '^6.0.0-rc.0', | ||
'rxjs': '^6.0.0-rc.0', | ||
'rxjs-tslint': '*', | ||
}; |