Skip to content

Commit d1fbd35

Browse files
vitaliy-bobrovbrandonroberts
authored andcommitted
refactor(Schematics): Clean up and remove unused imports (#914)
1 parent 6c27182 commit d1fbd35

File tree

7 files changed

+20
-55
lines changed

7 files changed

+20
-55
lines changed

modules/schematics/src/action/index.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
22
import * as path from 'path';
3-
import { getFileContent } from '../utility/test';
43
import { Schema as ActionOptions } from './schema';
54

65
describe('Action Schematic', () => {

modules/schematics/src/container/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { normalize } from '@angular-devkit/core';
21
import {
32
Rule,
43
SchematicContext,
@@ -12,20 +11,17 @@ import {
1211
filter,
1312
template,
1413
move,
15-
branchAndMerge,
1614
mergeWith,
1715
} from '@angular-devkit/schematics';
1816
import * as ts from 'typescript';
19-
import * as fs from 'fs';
20-
import * as path from 'path';
2117
import * as stringUtils from '../strings';
22-
import { Schema as FeatureOptions } from './schema';
18+
import { Schema as ContainerOptions } from './schema';
2319
import { buildRelativePath } from '../utility/find-module';
2420
import { NoopChange, InsertChange, ReplaceChange } from '../utility/change';
2521
import { insertImport } from '../utility/route-utils';
2622
import { omit } from '../utility/ngrx-utils';
2723

28-
function addStateToComponent(options: FeatureOptions) {
24+
function addStateToComponent(options: ContainerOptions) {
2925
return (host: Tree) => {
3026
if (!options.state && !options.stateInterface) {
3127
return host;
@@ -118,7 +114,7 @@ function addStateToComponent(options: FeatureOptions) {
118114
};
119115
}
120116

121-
export default function(options: FeatureOptions): Rule {
117+
export default function(options: ContainerOptions): Rule {
122118
return (host: Tree, context: SchematicContext) => {
123119
const sourceDir = options.sourceDir;
124120

@@ -127,7 +123,7 @@ export default function(options: FeatureOptions): Rule {
127123
}
128124

129125
const opts = ['state', 'stateInterface'].reduce(
130-
(current: Partial<FeatureOptions>, key) => {
126+
(current: Partial<ContainerOptions>, key) => {
131127
return omit(current, key as any);
132128
},
133129
options

modules/schematics/src/effect/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import {
1414
template,
1515
url,
1616
} from '@angular-devkit/schematics';
17-
import 'rxjs/add/operator/merge';
1817
import * as ts from 'typescript';
1918
import * as stringUtils from '../strings';
20-
import { addProviderToModule, addImportToModule } from '../utility/ast-utils';
19+
import { addImportToModule } from '../utility/ast-utils';
2120
import { InsertChange } from '../utility/change';
2221
import {
2322
buildRelativePath,
@@ -28,12 +27,13 @@ import { insertImport } from '../utility/route-utils';
2827

2928
function addImportToNgModule(options: EffectOptions): Rule {
3029
return (host: Tree) => {
31-
if (!options.module) {
30+
const modulePath = options.module;
31+
32+
if (!modulePath) {
3233
return host;
3334
}
3435

35-
const modulePath = options.module;
36-
if (!host.exists(options.module)) {
36+
if (!host.exists(modulePath)) {
3737
throw new Error('Specified module does not exist');
3838
}
3939

@@ -75,9 +75,7 @@ function addImportToNgModule(options: EffectOptions): Rule {
7575
const [effectsNgModuleImport] = addImportToModule(
7676
source,
7777
modulePath,
78-
options.root
79-
? `EffectsModule.forRoot([${effectsName}])`
80-
: `EffectsModule.forFeature([${effectsName}])`,
78+
`EffectsModule.for${options.root ? 'Root' : 'Feature'}([${effectsName}])`,
8179
relativePath
8280
);
8381
const changes = [effectsModuleImport, effectsImport, effectsNgModuleImport];

modules/schematics/src/feature/index.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import {
2-
SchematicTestRunner,
3-
UnitTestTree,
4-
} from '@angular-devkit/schematics/testing';
1+
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
52
import * as path from 'path';
6-
import { getFileContent } from '../utility/test';
73
import { Schema as FeatureOptions } from './schema';
84

95
describe('Feature Schematic', () => {

modules/schematics/src/feature/index.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
import {
2-
MergeStrategy,
32
Rule,
43
SchematicContext,
5-
SchematicsException,
64
Tree,
7-
apply,
85
chain,
9-
filter,
10-
mergeWith,
11-
move,
12-
noop,
136
schematic,
14-
template,
15-
url,
167
} from '@angular-devkit/schematics';
17-
import * as ts from 'typescript';
18-
import * as stringUtils from '../strings';
19-
import { addBootstrapToModule, addImportToModule } from '../utility/ast-utils';
20-
import { InsertChange } from '../utility/change';
218
import { Schema as FeatureOptions } from './schema';
22-
import { insertImport } from '../utility/route-utils';
23-
import { buildRelativePath } from '../utility/find-module';
249

2510
export default function(options: FeatureOptions): Rule {
2611
return (host: Tree, context: SchematicContext) => {

modules/schematics/src/reducer/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@ import {
1414
template,
1515
url,
1616
} from '@angular-devkit/schematics';
17-
import 'rxjs/add/operator/merge';
1817
import * as ts from 'typescript';
1918
import * as stringUtils from '../strings';
20-
import { addProviderToModule, addImportToModule } from '../utility/ast-utils';
21-
import { InsertChange, Change } from '../utility/change';
22-
import {
23-
buildRelativePath,
24-
findModuleFromOptions,
25-
} from '../utility/find-module';
19+
import { findModuleFromOptions } from '../utility/find-module';
2620
import { Schema as ReducerOptions } from './schema';
27-
import { insertImport } from '../utility/route-utils';
28-
import * as path from 'path';
2921
import {
3022
addReducerToStateInferface,
3123
addReducerToActionReducerMap,

modules/schematics/src/store/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,29 @@ import {
1010
filter,
1111
mergeWith,
1212
move,
13-
noop,
1413
template,
1514
url,
1615
} from '@angular-devkit/schematics';
17-
import 'rxjs/add/operator/merge';
1816
import * as ts from 'typescript';
1917
import * as stringUtils from '../strings';
20-
import { addProviderToModule, addImportToModule } from '../utility/ast-utils';
18+
import { addImportToModule } from '../utility/ast-utils';
2119
import { InsertChange, Change } from '../utility/change';
2220
import {
2321
buildRelativePath,
2422
findModuleFromOptions,
2523
} from '../utility/find-module';
26-
import { Schema as ServiceOptions } from './schema';
24+
import { Schema as StoreOptions } from './schema';
2725
import { insertImport } from '../utility/route-utils';
2826

29-
function addImportToNgModule(options: ServiceOptions): Rule {
27+
function addImportToNgModule(options: StoreOptions): Rule {
3028
return (host: Tree) => {
31-
if (!options.module) {
29+
const modulePath = options.module;
30+
31+
if (!modulePath) {
3232
return host;
3333
}
3434

35-
const modulePath = options.module;
36-
if (!host.exists(options.module)) {
35+
if (!host.exists(modulePath)) {
3736
throw new Error('Specified module does not exist');
3837
}
3938

@@ -127,7 +126,7 @@ function addImportToNgModule(options: ServiceOptions): Rule {
127126
};
128127
}
129128

130-
export default function(options: ServiceOptions): Rule {
129+
export default function(options: StoreOptions): Rule {
131130
options.path = options.path ? normalize(options.path) : options.path;
132131
const sourceDir = options.sourceDir;
133132
const statePath = `/${options.sourceDir}/${options.path}/${

0 commit comments

Comments
 (0)