-
-
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(component-store): add ng-add and ng-update schematics (#2598)
Closes #2569
- Loading branch information
1 parent
60cd5cc
commit af7b2cc
Showing
34 changed files
with
2,373 additions
and
9 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,31 @@ | ||
load("//tools:defaults.bzl", "pkg_npm", "ts_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ts_library( | ||
name = "migrations", | ||
srcs = glob( | ||
[ | ||
"**/*.ts", | ||
], | ||
exclude = [ | ||
"**/testing/*.ts", | ||
"**/*.spec.ts", | ||
], | ||
), | ||
module_name = "@ngrx/component-store/migrations", | ||
deps = [ | ||
"//modules/component-store/schematics-core", | ||
"@npm//@angular-devkit/schematics", | ||
], | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_package", | ||
srcs = [ | ||
":migration.json", | ||
], | ||
deps = [ | ||
":migrations", | ||
], | ||
) |
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 @@ | ||
{ | ||
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json", | ||
"schematics": {} | ||
} |
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,92 @@ | ||
import { | ||
dasherize, | ||
decamelize, | ||
camelize, | ||
classify, | ||
underscore, | ||
group, | ||
capitalize, | ||
featurePath, | ||
pluralize, | ||
} from './utility/strings'; | ||
|
||
export { isIvyEnabled } from './utility/angular-utils'; | ||
|
||
export { | ||
findNodes, | ||
getSourceNodes, | ||
getDecoratorMetadata, | ||
getContentOfKeyLiteral, | ||
insertAfterLastOccurrence, | ||
insertImport, | ||
addBootstrapToModule, | ||
addDeclarationToModule, | ||
addExportToModule, | ||
addImportToModule, | ||
addProviderToModule, | ||
replaceImport, | ||
containsProperty, | ||
} from './utility/ast-utils'; | ||
|
||
export { | ||
Host, | ||
Change, | ||
NoopChange, | ||
InsertChange, | ||
RemoveChange, | ||
ReplaceChange, | ||
createReplaceChange, | ||
createChangeRecorder, | ||
commitChanges, | ||
} from './utility/change'; | ||
|
||
export { AppConfig, getWorkspace, getWorkspacePath } from './utility/config'; | ||
|
||
export { | ||
findModule, | ||
findModuleFromOptions, | ||
buildRelativePath, | ||
ModuleOptions, | ||
} from './utility/find-module'; | ||
|
||
export { findPropertyInAstObject } from './utility/json-utilts'; | ||
|
||
export { | ||
addReducerToState, | ||
addReducerToStateInterface, | ||
addReducerImportToNgModule, | ||
addReducerToActionReducerMap, | ||
omit, | ||
} from './utility/ngrx-utils'; | ||
|
||
export { getProjectPath, getProject, isLib } from './utility/project'; | ||
|
||
export const stringUtils = { | ||
dasherize, | ||
decamelize, | ||
camelize, | ||
classify, | ||
underscore, | ||
group, | ||
capitalize, | ||
featurePath, | ||
pluralize, | ||
}; | ||
|
||
export { updatePackage } from './utility/update'; | ||
|
||
export { parseName } from './utility/parse-name'; | ||
|
||
export { addPackageToPackageJson } from './utility/package'; | ||
|
||
export { platformVersion } from './utility/libs-version'; | ||
|
||
export { | ||
visitTSSourceFiles, | ||
visitNgModuleImports, | ||
visitNgModuleExports, | ||
visitComponents, | ||
visitDecorator, | ||
visitNgModules, | ||
visitTemplates, | ||
} from './utility/visitors'; |
50 changes: 50 additions & 0 deletions
50
modules/component-store/schematics-core/utility/angular-utils.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,50 @@ | ||
import { | ||
JsonParseMode, | ||
dirname, | ||
normalize, | ||
parseJsonAst, | ||
resolve, | ||
} from '@angular-devkit/core'; | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { findPropertyInAstObject } from './json-utilts'; | ||
|
||
// https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/migrations/update-9/utils.ts | ||
export function isIvyEnabled(tree: Tree, tsConfigPath: string): boolean { | ||
// In version 9, Ivy is turned on by default | ||
// Ivy is opted out only when 'enableIvy' is set to false. | ||
|
||
const buffer = tree.read(tsConfigPath); | ||
if (!buffer) { | ||
return true; | ||
} | ||
|
||
const tsCfgAst = parseJsonAst(buffer.toString(), JsonParseMode.Loose); | ||
|
||
if (tsCfgAst.kind !== 'object') { | ||
return true; | ||
} | ||
|
||
const ngCompilerOptions = findPropertyInAstObject( | ||
tsCfgAst, | ||
'angularCompilerOptions' | ||
); | ||
if (ngCompilerOptions && ngCompilerOptions.kind === 'object') { | ||
const enableIvy = findPropertyInAstObject(ngCompilerOptions, 'enableIvy'); | ||
|
||
if (enableIvy) { | ||
return !!enableIvy.value; | ||
} | ||
} | ||
|
||
const configExtends = findPropertyInAstObject(tsCfgAst, 'extends'); | ||
if (configExtends && configExtends.kind === 'string') { | ||
const extendedTsConfigPath = resolve( | ||
dirname(normalize(tsConfigPath)), | ||
normalize(configExtends.value) | ||
); | ||
|
||
return isIvyEnabled(tree, extendedTsConfigPath); | ||
} | ||
|
||
return true; | ||
} |
Oops, something went wrong.