From 6d4ec0db79b778e30eddb38fad7221a86c0c7907 Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 9 May 2018 21:25:32 -0500 Subject: [PATCH] refactor(Schematics): Move schematics utilities to modules/schematics-core (#1044) --- .circleci/config.yml | 3 + .gitignore | 6 +- BUILD.bazel | 1 + build/config.ts | 5 -- example-app/app/shared/utils.ts | 5 +- modules/schematics-core/index.ts | 70 +++++++++++++++++++ .../testing}/create-app-module.ts | 0 .../testing}/create-reducers.ts | 0 .../testing}/create-workspace.ts | 2 +- .../testing}/get-file-content.ts | 0 .../test => schematics-core/testing}/index.ts | 2 + .../utility/ast-utils.ts | 0 .../utility/ast-utils_spec.ts | 4 +- .../src => schematics-core}/utility/change.ts | 0 .../src => schematics-core}/utility/config.ts | 0 .../utility/find-module.ts | 0 .../utility/find-module_spec.ts | 0 .../utility/ngrx-utils.ts | 7 +- .../utility/project.ts | 2 +- .../utility/route-utils.ts | 0 .../utility}/strings.ts | 0 modules/schematics/BUILD | 35 ++++++++++ modules/schematics/package.json | 5 +- modules/schematics/src/action/index.spec.ts | 6 +- modules/schematics/src/action/index.ts | 4 +- .../src/action/{schema.d.ts => schema.ts} | 0 modules/schematics/src/cli.spec.ts | 6 +- .../schematics/src/container/index.spec.ts | 7 +- modules/schematics/src/container/index.ts | 16 +++-- .../src/container/{schema.d.ts => schema.ts} | 0 modules/schematics/src/effect/index.spec.ts | 13 ++-- modules/schematics/src/effect/index.ts | 13 ++-- .../src/effect/{schema.d.ts => schema.ts} | 0 modules/schematics/src/entity/index.spec.ts | 7 +- modules/schematics/src/entity/index.ts | 11 ++- .../src/entity/{schema.d.ts => schema.ts} | 0 modules/schematics/src/feature/index.spec.ts | 7 +- .../src/feature/{schema.d.ts => schema.ts} | 0 modules/schematics/src/reducer/index.spec.ts | 9 +-- modules/schematics/src/reducer/index.ts | 13 ++-- .../src/reducer/{schema.d.ts => schema.ts} | 0 modules/schematics/src/store/index.spec.ts | 7 +- modules/schematics/src/store/index.ts | 14 ++-- .../src/store/{schema.d.ts => schema.ts} | 0 modules/schematics/tsconfig-build.json | 16 ----- package.json | 5 +- 46 files changed, 200 insertions(+), 101 deletions(-) create mode 100644 modules/schematics-core/index.ts rename modules/{schematics/src/utility/test => schematics-core/testing}/create-app-module.ts (100%) rename modules/{schematics/src/utility/test => schematics-core/testing}/create-reducers.ts (100%) rename modules/{schematics/src/utility/test => schematics-core/testing}/create-workspace.ts (96%) rename modules/{schematics/src/utility/test => schematics-core/testing}/get-file-content.ts (100%) rename modules/{schematics/src/utility/test => schematics-core/testing}/index.ts (50%) rename modules/{schematics/src => schematics-core}/utility/ast-utils.ts (100%) rename modules/{schematics/src => schematics-core}/utility/ast-utils_spec.ts (95%) rename modules/{schematics/src => schematics-core}/utility/change.ts (100%) rename modules/{schematics/src => schematics-core}/utility/config.ts (100%) rename modules/{schematics/src => schematics-core}/utility/find-module.ts (100%) rename modules/{schematics/src => schematics-core}/utility/find-module_spec.ts (100%) rename modules/{schematics/src => schematics-core}/utility/ngrx-utils.ts (96%) rename modules/{schematics/src => schematics-core}/utility/project.ts (93%) rename modules/{schematics/src => schematics-core}/utility/route-utils.ts (100%) rename modules/{schematics/src => schematics-core/utility}/strings.ts (100%) create mode 100644 modules/schematics/BUILD rename modules/schematics/src/action/{schema.d.ts => schema.ts} (100%) rename modules/schematics/src/container/{schema.d.ts => schema.ts} (100%) rename modules/schematics/src/effect/{schema.d.ts => schema.ts} (100%) rename modules/schematics/src/entity/{schema.d.ts => schema.ts} (100%) rename modules/schematics/src/feature/{schema.d.ts => schema.ts} (100%) rename modules/schematics/src/reducer/{schema.d.ts => schema.ts} (100%) rename modules/schematics/src/store/{schema.d.ts => schema.ts} (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index d992916552..e9a5d8e56c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -54,6 +54,9 @@ 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` diff --git a/.gitignore b/.gitignore index 3d0baf4a0f..40a4674c46 100644 --- a/.gitignore +++ b/.gitignore @@ -69,4 +69,8 @@ output *.ngfactory.ts tmp -example-dist/ \ No newline at end of file +example-dist/ + +schematics-core +!modules/schematics-core +*.tgz \ No newline at end of file diff --git a/BUILD.bazel b/BUILD.bazel index a901735e70..fab213f686 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -17,6 +17,7 @@ filegroup( ext, ]) for pkg in [ "@angular", + "@angular-devkit", "jasmine", "jasmine-marbles", "typescript", diff --git a/build/config.ts b/build/config.ts index 3518ad8d56..1b652b6333 100644 --- a/build/config.ts +++ b/build/config.ts @@ -35,9 +35,4 @@ export const packages: PackageDescription[] = [ hasTestingModule: false, bundle: true, }, - { - name: 'schematics', - hasTestingModule: false, - bundle: false, - }, ]; diff --git a/example-app/app/shared/utils.ts b/example-app/app/shared/utils.ts index 45bd19ae6c..8370fdda34 100644 --- a/example-app/app/shared/utils.ts +++ b/example-app/app/shared/utils.ts @@ -25,7 +25,10 @@ export class CustomRouterStateSerializer route = route.firstChild; } - const { url, root: { queryParams } } = routerState; + const { + url, + root: { queryParams }, + } = routerState; const { params } = route; // Only return an object including the URL, params and query params diff --git a/modules/schematics-core/index.ts b/modules/schematics-core/index.ts new file mode 100644 index 0000000000..8c37240cfb --- /dev/null +++ b/modules/schematics-core/index.ts @@ -0,0 +1,70 @@ +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, +}; diff --git a/modules/schematics/src/utility/test/create-app-module.ts b/modules/schematics-core/testing/create-app-module.ts similarity index 100% rename from modules/schematics/src/utility/test/create-app-module.ts rename to modules/schematics-core/testing/create-app-module.ts diff --git a/modules/schematics/src/utility/test/create-reducers.ts b/modules/schematics-core/testing/create-reducers.ts similarity index 100% rename from modules/schematics/src/utility/test/create-reducers.ts rename to modules/schematics-core/testing/create-reducers.ts diff --git a/modules/schematics/src/utility/test/create-workspace.ts b/modules/schematics-core/testing/create-workspace.ts similarity index 96% rename from modules/schematics/src/utility/test/create-workspace.ts rename to modules/schematics-core/testing/create-workspace.ts index 8076f67b02..cc6e357255 100644 --- a/modules/schematics/src/utility/test/create-workspace.ts +++ b/modules/schematics-core/testing/create-workspace.ts @@ -26,7 +26,7 @@ const defaultModuleOptions = { flat: false, }; -export function getProjectPath( +export function getTestProjectPath( workspaceOptions: any = defaultWorkspaceOptions, appOptions: any = defaultAppOptions ) { diff --git a/modules/schematics/src/utility/test/get-file-content.ts b/modules/schematics-core/testing/get-file-content.ts similarity index 100% rename from modules/schematics/src/utility/test/get-file-content.ts rename to modules/schematics-core/testing/get-file-content.ts diff --git a/modules/schematics/src/utility/test/index.ts b/modules/schematics-core/testing/index.ts similarity index 50% rename from modules/schematics/src/utility/test/index.ts rename to modules/schematics-core/testing/index.ts index 9b653dcab2..894bca7d98 100644 --- a/modules/schematics/src/utility/test/index.ts +++ b/modules/schematics-core/testing/index.ts @@ -1,2 +1,4 @@ export * from './create-app-module'; +export * from './create-reducers'; +export * from './create-workspace'; export * from './get-file-content'; diff --git a/modules/schematics/src/utility/ast-utils.ts b/modules/schematics-core/utility/ast-utils.ts similarity index 100% rename from modules/schematics/src/utility/ast-utils.ts rename to modules/schematics-core/utility/ast-utils.ts diff --git a/modules/schematics/src/utility/ast-utils_spec.ts b/modules/schematics-core/utility/ast-utils_spec.ts similarity index 95% rename from modules/schematics/src/utility/ast-utils_spec.ts rename to modules/schematics-core/utility/ast-utils_spec.ts index ec4a56c902..4290558148 100644 --- a/modules/schematics/src/utility/ast-utils_spec.ts +++ b/modules/schematics-core/utility/ast-utils_spec.ts @@ -8,8 +8,8 @@ import { tags } from '@angular-devkit/core'; import { VirtualTree } from '@angular-devkit/schematics'; import * as ts from 'typescript'; -import { Change, InsertChange } from '../utility/change'; -import { getFileContent } from '../utility/test'; +import { Change, InsertChange } from './change'; +import { getFileContent } from '../testing'; import { addExportToModule } from './ast-utils'; function getTsSource(path: string, content: string): ts.SourceFile { diff --git a/modules/schematics/src/utility/change.ts b/modules/schematics-core/utility/change.ts similarity index 100% rename from modules/schematics/src/utility/change.ts rename to modules/schematics-core/utility/change.ts diff --git a/modules/schematics/src/utility/config.ts b/modules/schematics-core/utility/config.ts similarity index 100% rename from modules/schematics/src/utility/config.ts rename to modules/schematics-core/utility/config.ts diff --git a/modules/schematics/src/utility/find-module.ts b/modules/schematics-core/utility/find-module.ts similarity index 100% rename from modules/schematics/src/utility/find-module.ts rename to modules/schematics-core/utility/find-module.ts diff --git a/modules/schematics/src/utility/find-module_spec.ts b/modules/schematics-core/utility/find-module_spec.ts similarity index 100% rename from modules/schematics/src/utility/find-module_spec.ts rename to modules/schematics-core/utility/find-module_spec.ts diff --git a/modules/schematics/src/utility/ngrx-utils.ts b/modules/schematics-core/utility/ngrx-utils.ts similarity index 96% rename from modules/schematics/src/utility/ngrx-utils.ts rename to modules/schematics-core/utility/ngrx-utils.ts index 24a3df4ae8..1873ad0446 100644 --- a/modules/schematics/src/utility/ngrx-utils.ts +++ b/modules/schematics-core/utility/ngrx-utils.ts @@ -1,14 +1,13 @@ import * as ts from 'typescript'; -import * as stringUtils from '../strings'; +import * as stringUtils from './strings'; import { InsertChange, Change, NoopChange } from './change'; import { Tree, SchematicsException, Rule } from '@angular-devkit/schematics'; import { normalize } from '@angular-devkit/core'; import { buildRelativePath } from './find-module'; import { insertImport } from './route-utils'; -import { Schema as ReducerOptions } from '../reducer/schema'; import { addImportToModule } from './ast-utils'; -export function addReducerToState(options: ReducerOptions): Rule { +export function addReducerToState(options: any): Rule { return (host: Tree) => { if (!options.reducers) { return host; @@ -185,7 +184,7 @@ export function addReducerToActionReducerMap( /** * Add reducer feature to NgModule */ -export function addReducerImportToNgModule(options: ReducerOptions): Rule { +export function addReducerImportToNgModule(options: any): Rule { return (host: Tree) => { if (!options.module) { return host; diff --git a/modules/schematics/src/utility/project.ts b/modules/schematics-core/utility/project.ts similarity index 93% rename from modules/schematics/src/utility/project.ts rename to modules/schematics-core/utility/project.ts index 3998881a4b..c9aeda34a8 100644 --- a/modules/schematics/src/utility/project.ts +++ b/modules/schematics-core/utility/project.ts @@ -1,4 +1,4 @@ -import { getWorkspace } from '../utility/config'; +import { getWorkspace } from './config'; import { Tree } from '@angular-devkit/schematics'; export function getProjectPath( diff --git a/modules/schematics/src/utility/route-utils.ts b/modules/schematics-core/utility/route-utils.ts similarity index 100% rename from modules/schematics/src/utility/route-utils.ts rename to modules/schematics-core/utility/route-utils.ts diff --git a/modules/schematics/src/strings.ts b/modules/schematics-core/utility/strings.ts similarity index 100% rename from modules/schematics/src/strings.ts rename to modules/schematics-core/utility/strings.ts diff --git a/modules/schematics/BUILD b/modules/schematics/BUILD new file mode 100644 index 0000000000..aabb1e8c25 --- /dev/null +++ b/modules/schematics/BUILD @@ -0,0 +1,35 @@ +package(default_visibility = ["//visibility:public"]) + +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") +load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package") + +ts_library( + name = "schematics", + srcs = glob( + [ + "**/src/**/*.ts", + ], + exclude = [ + "**/src/**/*.spec.ts", + "**/src/**/files/**/*", + ], + ), + module_name = "@ngrx/schematics", + tsconfig = ":tsconfig-build.json", +) + +npm_package( + name = "npm_package", + srcs = [ + ":collection.json", + ":package.json", + ":README.md", + ] + glob([ + "**/src/*/files/**/*", + "**/schema.json", + "**/migration.json", + ]), + deps = [ + ":schematics", + ], +) diff --git a/modules/schematics/package.json b/modules/schematics/package.json index e01b27b7f9..8598bfd634 100644 --- a/modules/schematics/package.json +++ b/modules/schematics/package.json @@ -1,6 +1,6 @@ { "name": "@ngrx/schematics", - "version": "5.2.0", + "version": "0.0.0-PLACEHOLDER", "description": "NgRx Schematics for Angular", "repository": { "type": "git", @@ -21,6 +21,9 @@ }, "homepage": "https://github.com/ngrx/platform#readme", "schematics": "./collection.json", + "ng-update": { + "packageGroup": "NG_UPDATE_PACKAGE_GROUP" + }, "peerDependencies": { "@angular-devkit/core": "^0.5.0", "@angular-devkit/schematics": "^0.5.0" diff --git a/modules/schematics/src/action/index.spec.ts b/modules/schematics/src/action/index.spec.ts index 72631fa548..3e77c1a44a 100644 --- a/modules/schematics/src/action/index.spec.ts +++ b/modules/schematics/src/action/index.spec.ts @@ -5,9 +5,9 @@ import { import * as path from 'path'; import { Schema as ActionOptions } from './schema'; import { - getProjectPath, + getTestProjectPath, createWorkspace, -} from '../utility/test/create-workspace'; +} from '../../../schematics-core/testing'; describe('Action Schematic', () => { const schematicRunner = new SchematicTestRunner( @@ -23,7 +23,7 @@ describe('Action Schematic', () => { flat: true, }; - const projectPath = getProjectPath(); + const projectPath = getTestProjectPath(); let appTree: UnitTestTree; diff --git a/modules/schematics/src/action/index.ts b/modules/schematics/src/action/index.ts index add9f86f7c..9c7c2b39fa 100644 --- a/modules/schematics/src/action/index.ts +++ b/modules/schematics/src/action/index.ts @@ -1,4 +1,3 @@ -import { normalize } from '@angular-devkit/core'; import { Rule, SchematicsException, @@ -14,9 +13,8 @@ import { Tree, SchematicContext, } from '@angular-devkit/schematics'; -import * as stringUtils from '../strings'; import { Schema as ActionOptions } from './schema'; -import { getProjectPath } from '../utility/project'; +import { getProjectPath, stringUtils } from '../schematics-core'; export default function(options: ActionOptions): Rule { return (host: Tree, context: SchematicContext) => { diff --git a/modules/schematics/src/action/schema.d.ts b/modules/schematics/src/action/schema.ts similarity index 100% rename from modules/schematics/src/action/schema.d.ts rename to modules/schematics/src/action/schema.ts diff --git a/modules/schematics/src/cli.spec.ts b/modules/schematics/src/cli.spec.ts index a266d45a59..9c29b468cd 100644 --- a/modules/schematics/src/cli.spec.ts +++ b/modules/schematics/src/cli.spec.ts @@ -5,9 +5,9 @@ import { } from '@angular-devkit/schematics/testing'; import * as path from 'path'; import { + getTestProjectPath, createWorkspace, - getProjectPath, -} from './utility/test/create-workspace'; +} from '../../schematics-core/testing'; describe('CLI Schematic', () => { const schematicRunner = new SchematicTestRunner( @@ -20,7 +20,7 @@ describe('CLI Schematic', () => { project: 'bar', }; - const projectPath = getProjectPath(); + const projectPath = getTestProjectPath(); let appTree: UnitTestTree; diff --git a/modules/schematics/src/container/index.spec.ts b/modules/schematics/src/container/index.spec.ts index ece90a93ca..712b3ce0a4 100644 --- a/modules/schematics/src/container/index.spec.ts +++ b/modules/schematics/src/container/index.spec.ts @@ -4,10 +4,11 @@ import { } from '@angular-devkit/schematics/testing'; import * as path from 'path'; import { Schema as ContainerOptions } from './schema'; +import {} from '../../schematics-core'; import { + getTestProjectPath, createWorkspace, - getProjectPath, -} from '../utility/test/create-workspace'; +} from '../../../schematics-core/testing'; describe('Container Schematic', () => { const schematicRunner = new SchematicTestRunner( @@ -29,7 +30,7 @@ describe('Container Schematic', () => { prefix: 'app', }; - const projectPath = getProjectPath(); + const projectPath = getTestProjectPath(); let appTree: UnitTestTree; diff --git a/modules/schematics/src/container/index.ts b/modules/schematics/src/container/index.ts index a6fd29ce79..3054baf430 100644 --- a/modules/schematics/src/container/index.ts +++ b/modules/schematics/src/container/index.ts @@ -14,13 +14,17 @@ import { mergeWith, } from '@angular-devkit/schematics'; import * as ts from 'typescript'; -import * as stringUtils from '../strings'; +import { + stringUtils, + buildRelativePath, + insertImport, + NoopChange, + ReplaceChange, + InsertChange, + getProjectPath, + omit, +} from '../schematics-core'; import { Schema as ContainerOptions } from './schema'; -import { buildRelativePath } from '../utility/find-module'; -import { NoopChange, InsertChange, ReplaceChange } from '../utility/change'; -import { insertImport } from '../utility/route-utils'; -import { omit } from '../utility/ngrx-utils'; -import { getProjectPath } from '../utility/project'; function addStateToComponent(options: ContainerOptions) { return (host: Tree) => { diff --git a/modules/schematics/src/container/schema.d.ts b/modules/schematics/src/container/schema.ts similarity index 100% rename from modules/schematics/src/container/schema.d.ts rename to modules/schematics/src/container/schema.ts diff --git a/modules/schematics/src/effect/index.spec.ts b/modules/schematics/src/effect/index.spec.ts index b3ddb28651..18233cd363 100644 --- a/modules/schematics/src/effect/index.spec.ts +++ b/modules/schematics/src/effect/index.spec.ts @@ -3,16 +3,13 @@ import { UnitTestTree, } from '@angular-devkit/schematics/testing'; import * as path from 'path'; -import { - createAppModule, - getFileContent, - createAppModuleWithEffects, -} from '../utility/test'; +import {} from '../../schematics-core'; import { Schema as EffectOptions } from './schema'; import { - getProjectPath, + getTestProjectPath, createWorkspace, -} from '../utility/test/create-workspace'; + createAppModuleWithEffects, +} from '../../../schematics-core/testing'; describe('Effect Schematic', () => { const schematicRunner = new SchematicTestRunner( @@ -32,7 +29,7 @@ describe('Effect Schematic', () => { group: false, }; - const projectPath = getProjectPath(); + const projectPath = getTestProjectPath(); let appTree: UnitTestTree; diff --git a/modules/schematics/src/effect/index.ts b/modules/schematics/src/effect/index.ts index 57d6079a4c..688fc42458 100644 --- a/modules/schematics/src/effect/index.ts +++ b/modules/schematics/src/effect/index.ts @@ -1,4 +1,3 @@ -import { normalize } from '@angular-devkit/core'; import { Rule, SchematicContext, @@ -15,16 +14,16 @@ import { url, } from '@angular-devkit/schematics'; import * as ts from 'typescript'; -import * as stringUtils from '../strings'; -import { addImportToModule } from '../utility/ast-utils'; -import { InsertChange } from '../utility/change'; import { + stringUtils, + insertImport, buildRelativePath, + addImportToModule, + InsertChange, + getProjectPath, findModuleFromOptions, -} from '../utility/find-module'; +} from '../schematics-core'; import { Schema as EffectOptions } from './schema'; -import { insertImport } from '../utility/route-utils'; -import { getProjectPath } from '../utility/project'; function addImportToNgModule(options: EffectOptions): Rule { return (host: Tree) => { diff --git a/modules/schematics/src/effect/schema.d.ts b/modules/schematics/src/effect/schema.ts similarity index 100% rename from modules/schematics/src/effect/schema.d.ts rename to modules/schematics/src/effect/schema.ts diff --git a/modules/schematics/src/entity/index.spec.ts b/modules/schematics/src/entity/index.spec.ts index e1ba7636f0..b9f95ed87f 100644 --- a/modules/schematics/src/entity/index.spec.ts +++ b/modules/schematics/src/entity/index.spec.ts @@ -4,10 +4,11 @@ import { } from '@angular-devkit/schematics/testing'; import * as path from 'path'; import { Schema as EntityOptions } from './schema'; +import {} from '../../schematics-core'; import { - getProjectPath, + getTestProjectPath, createWorkspace, -} from '../utility/test/create-workspace'; +} from '../../../schematics-core/testing'; describe('Entity Schematic', () => { const schematicRunner = new SchematicTestRunner( @@ -21,7 +22,7 @@ describe('Entity Schematic', () => { spec: false, }; - const projectPath = getProjectPath(); + const projectPath = getTestProjectPath(); let appTree: UnitTestTree; diff --git a/modules/schematics/src/entity/index.ts b/modules/schematics/src/entity/index.ts index 0efdb27365..b52ff98721 100644 --- a/modules/schematics/src/entity/index.ts +++ b/modules/schematics/src/entity/index.ts @@ -1,4 +1,3 @@ -import { normalize } from '@angular-devkit/core'; import { Rule, SchematicsException, @@ -14,14 +13,14 @@ import { Tree, SchematicContext, } from '@angular-devkit/schematics'; -import * as stringUtils from '../strings'; -import { Schema as EntityOptions } from './schema'; import { + stringUtils, addReducerToState, addReducerImportToNgModule, -} from '../utility/ngrx-utils'; -import { findModuleFromOptions } from '../utility/find-module'; -import { getProjectPath } from '../utility/project'; + getProjectPath, + findModuleFromOptions, +} from '../schematics-core'; +import { Schema as EntityOptions } from './schema'; export default function(options: EntityOptions): Rule { return (host: Tree, context: SchematicContext) => { diff --git a/modules/schematics/src/entity/schema.d.ts b/modules/schematics/src/entity/schema.ts similarity index 100% rename from modules/schematics/src/entity/schema.d.ts rename to modules/schematics/src/entity/schema.ts diff --git a/modules/schematics/src/feature/index.spec.ts b/modules/schematics/src/feature/index.spec.ts index 2e8d0ded3e..2b4267f4a7 100644 --- a/modules/schematics/src/feature/index.spec.ts +++ b/modules/schematics/src/feature/index.spec.ts @@ -4,10 +4,11 @@ import { } from '@angular-devkit/schematics/testing'; import * as path from 'path'; import { Schema as FeatureOptions } from './schema'; +import {} from '../../schematics-core'; import { - getProjectPath, + getTestProjectPath, createWorkspace, -} from '../utility/test/create-workspace'; +} from '../../../schematics-core/testing'; describe('Feature Schematic', () => { const schematicRunner = new SchematicTestRunner( @@ -23,7 +24,7 @@ describe('Feature Schematic', () => { group: false, }; - const projectPath = getProjectPath(); + const projectPath = getTestProjectPath(); let appTree: UnitTestTree; diff --git a/modules/schematics/src/feature/schema.d.ts b/modules/schematics/src/feature/schema.ts similarity index 100% rename from modules/schematics/src/feature/schema.d.ts rename to modules/schematics/src/feature/schema.ts diff --git a/modules/schematics/src/reducer/index.spec.ts b/modules/schematics/src/reducer/index.spec.ts index a83eb56a94..fbade280c7 100644 --- a/modules/schematics/src/reducer/index.spec.ts +++ b/modules/schematics/src/reducer/index.spec.ts @@ -4,11 +4,12 @@ import { } from '@angular-devkit/schematics/testing'; import * as path from 'path'; import { Schema as ReducerOptions } from './schema'; -import { createReducers } from '../utility/test/create-reducers'; +import {} from '../../schematics-core'; import { - getProjectPath, + getTestProjectPath, + createReducers, createWorkspace, -} from '../utility/test/create-workspace'; +} from '../../../schematics-core/testing'; describe('Reducer Schematic', () => { const schematicRunner = new SchematicTestRunner( @@ -22,7 +23,7 @@ describe('Reducer Schematic', () => { spec: false, }; - const projectPath = getProjectPath(); + const projectPath = getTestProjectPath(); let appTree: UnitTestTree; diff --git a/modules/schematics/src/reducer/index.ts b/modules/schematics/src/reducer/index.ts index 0777adc52f..d49f6035b2 100644 --- a/modules/schematics/src/reducer/index.ts +++ b/modules/schematics/src/reducer/index.ts @@ -1,4 +1,3 @@ -import { normalize } from '@angular-devkit/core'; import { Rule, SchematicContext, @@ -15,16 +14,14 @@ import { url, } from '@angular-devkit/schematics'; import * as ts from 'typescript'; -import * as stringUtils from '../strings'; -import { findModuleFromOptions } from '../utility/find-module'; -import { Schema as ReducerOptions } from './schema'; import { - addReducerToStateInferface, - addReducerToActionReducerMap, + getProjectPath, + findModuleFromOptions, + stringUtils, addReducerToState, addReducerImportToNgModule, -} from '../utility/ngrx-utils'; -import { getProjectPath } from '../utility/project'; +} from '../schematics-core'; +import { Schema as ReducerOptions } from './schema'; export default function(options: ReducerOptions): Rule { return (host: Tree, context: SchematicContext) => { diff --git a/modules/schematics/src/reducer/schema.d.ts b/modules/schematics/src/reducer/schema.ts similarity index 100% rename from modules/schematics/src/reducer/schema.d.ts rename to modules/schematics/src/reducer/schema.ts diff --git a/modules/schematics/src/store/index.spec.ts b/modules/schematics/src/store/index.spec.ts index 497d700397..b00713bb18 100644 --- a/modules/schematics/src/store/index.spec.ts +++ b/modules/schematics/src/store/index.spec.ts @@ -4,10 +4,11 @@ import { } from '@angular-devkit/schematics/testing'; import * as path from 'path'; import { Schema as StoreOptions } from './schema'; +import {} from '../../schematics-core'; import { - getProjectPath, + getTestProjectPath, createWorkspace, -} from '../utility/test/create-workspace'; +} from '../../../schematics-core/testing'; describe('Store Schematic', () => { const schematicRunner = new SchematicTestRunner( @@ -24,7 +25,7 @@ describe('Store Schematic', () => { root: true, }; - const projectPath = getProjectPath(); + const projectPath = getTestProjectPath(); let appTree: UnitTestTree; diff --git a/modules/schematics/src/store/index.ts b/modules/schematics/src/store/index.ts index e5648b00d2..61c1707b31 100644 --- a/modules/schematics/src/store/index.ts +++ b/modules/schematics/src/store/index.ts @@ -1,4 +1,3 @@ -import { normalize } from '@angular-devkit/core'; import { Rule, SchematicContext, @@ -14,16 +13,17 @@ import { url, } from '@angular-devkit/schematics'; import * as ts from 'typescript'; -import * as stringUtils from '../strings'; -import { addImportToModule } from '../utility/ast-utils'; -import { InsertChange, Change } from '../utility/change'; import { + stringUtils, buildRelativePath, + insertImport, + Change, + InsertChange, + getProjectPath, findModuleFromOptions, -} from '../utility/find-module'; + addImportToModule, +} from '../schematics-core'; import { Schema as StoreOptions } from './schema'; -import { insertImport } from '../utility/route-utils'; -import { getProjectPath } from '../utility/project'; function addImportToNgModule(options: StoreOptions): Rule { return (host: Tree) => { diff --git a/modules/schematics/src/store/schema.d.ts b/modules/schematics/src/store/schema.ts similarity index 100% rename from modules/schematics/src/store/schema.d.ts rename to modules/schematics/src/store/schema.ts diff --git a/modules/schematics/tsconfig-build.json b/modules/schematics/tsconfig-build.json index 2489c55ed7..385f00bde4 100644 --- a/modules/schematics/tsconfig-build.json +++ b/modules/schematics/tsconfig-build.json @@ -1,32 +1,16 @@ { "compilerOptions": { - "baseUrl": ".", - "declaration": true, "stripInternal": true, "experimentalDecorators": true, "strictPropertyInitialization": false, - "module": "commonjs", "moduleResolution": "node", "outDir": "../../dist/packages/schematics", - "paths": {}, - "rootDir": ".", "sourceMap": true, "inlineSources": true, - "target": "es5", "lib": ["es2017", "dom"], "skipLibCheck": true, "strict": true }, - "files": [ - "src/action/index.ts", - "src/container/index.ts", - "src/effect/index.ts", - "src/entity/index.ts", - "src/feature/index.ts", - "src/reducer/index.ts", - "src/store/index.ts" - ], - "exclude": ["src/*/files/**/*"], "angularCompilerOptions": { "skipMetadataEmit": true, "enableSummariesForJit": false diff --git a/package.json b/package.json index 553e5909ab..86d904bf99 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "ts-node ./build/index.ts", "deploy:builds": "ts-node ./build/deploy-build.ts", "test:unit": "node ./tests.js", - "test": "nyc yarn run test:unit", + "test": "yarn copy:schematics && nyc yarn run test:unit", "clean": "git clean -xdf && yarn && yarn run bootstrap", "cli": "ng", "coverage:html": "nyc report --reporter=html", @@ -25,7 +25,8 @@ "release": "lerna publish --skip-npm --conventional-commits && npm run build", "codegen": "ts-node modules/codegen/src/index.ts", "prebuildifier": "bazel build --noshow_progress @com_github_bazelbuild_buildtools//buildifier", - "buildifier": "find . -type f \\( -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" | xargs $(bazel info bazel-bin)/external/com_github_bazelbuild_buildtools/buildifier/*/buildifier" + "buildifier": "find . -type f \\( -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" | xargs $(bazel info bazel-bin)/external/com_github_bazelbuild_buildtools/buildifier/buildifier", + "copy:schematics": "ncp modules/schematics-core/ modules/schematics/src/schematics-core/" }, "engines": { "node": ">=8.9.0",