Skip to content

refactor(Schematics): remove unused imports #914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion modules/schematics/src/action/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path';
import { getFileContent } from '../utility/test';
import { Schema as ActionOptions } from './schema';

describe('Action Schematic', () => {
Expand Down
12 changes: 4 additions & 8 deletions modules/schematics/src/container/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { normalize } from '@angular-devkit/core';
import {
Rule,
SchematicContext,
Expand All @@ -12,20 +11,17 @@ import {
filter,
template,
move,
branchAndMerge,
mergeWith,
} from '@angular-devkit/schematics';
import * as ts from 'typescript';
import * as fs from 'fs';
import * as path from 'path';
import * as stringUtils from '../strings';
import { Schema as FeatureOptions } from './schema';
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';

function addStateToComponent(options: FeatureOptions) {
function addStateToComponent(options: ContainerOptions) {
return (host: Tree) => {
if (!options.state && !options.stateInterface) {
return host;
Expand Down Expand Up @@ -118,7 +114,7 @@ function addStateToComponent(options: FeatureOptions) {
};
}

export default function(options: FeatureOptions): Rule {
export default function(options: ContainerOptions): Rule {
return (host: Tree, context: SchematicContext) => {
const sourceDir = options.sourceDir;

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

const opts = ['state', 'stateInterface'].reduce(
(current: Partial<FeatureOptions>, key) => {
(current: Partial<ContainerOptions>, key) => {
return omit(current, key as any);
},
options
Expand Down
14 changes: 6 additions & 8 deletions modules/schematics/src/effect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import {
template,
url,
} from '@angular-devkit/schematics';
import 'rxjs/add/operator/merge';
import * as ts from 'typescript';
import * as stringUtils from '../strings';
import { addProviderToModule, addImportToModule } from '../utility/ast-utils';
import { addImportToModule } from '../utility/ast-utils';
import { InsertChange } from '../utility/change';
import {
buildRelativePath,
Expand All @@ -28,12 +27,13 @@ import { insertImport } from '../utility/route-utils';

function addImportToNgModule(options: EffectOptions): Rule {
return (host: Tree) => {
if (!options.module) {
const modulePath = options.module;

if (!modulePath) {
return host;
}

const modulePath = options.module;
if (!host.exists(options.module)) {
if (!host.exists(modulePath)) {
throw new Error('Specified module does not exist');
}

Expand Down Expand Up @@ -75,9 +75,7 @@ function addImportToNgModule(options: EffectOptions): Rule {
const [effectsNgModuleImport] = addImportToModule(
source,
modulePath,
options.root
? `EffectsModule.forRoot([${effectsName}])`
: `EffectsModule.forFeature([${effectsName}])`,
`EffectsModule.for${options.root ? 'Root' : 'Feature'}([${effectsName}])`,
relativePath
);
const changes = [effectsModuleImport, effectsImport, effectsNgModuleImport];
Expand Down
6 changes: 1 addition & 5 deletions modules/schematics/src/feature/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
SchematicTestRunner,
UnitTestTree,
} from '@angular-devkit/schematics/testing';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path';
import { getFileContent } from '../utility/test';
import { Schema as FeatureOptions } from './schema';

describe('Feature Schematic', () => {
Expand Down
15 changes: 0 additions & 15 deletions modules/schematics/src/feature/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import {
MergeStrategy,
Rule,
SchematicContext,
SchematicsException,
Tree,
apply,
chain,
filter,
mergeWith,
move,
noop,
schematic,
template,
url,
} from '@angular-devkit/schematics';
import * as ts from 'typescript';
import * as stringUtils from '../strings';
import { addBootstrapToModule, addImportToModule } from '../utility/ast-utils';
import { InsertChange } from '../utility/change';
import { Schema as FeatureOptions } from './schema';
import { insertImport } from '../utility/route-utils';
import { buildRelativePath } from '../utility/find-module';

export default function(options: FeatureOptions): Rule {
return (host: Tree, context: SchematicContext) => {
Expand Down
10 changes: 1 addition & 9 deletions modules/schematics/src/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@ import {
template,
url,
} from '@angular-devkit/schematics';
import 'rxjs/add/operator/merge';
import * as ts from 'typescript';
import * as stringUtils from '../strings';
import { addProviderToModule, addImportToModule } from '../utility/ast-utils';
import { InsertChange, Change } from '../utility/change';
import {
buildRelativePath,
findModuleFromOptions,
} from '../utility/find-module';
import { findModuleFromOptions } from '../utility/find-module';
import { Schema as ReducerOptions } from './schema';
import { insertImport } from '../utility/route-utils';
import * as path from 'path';
import {
addReducerToStateInferface,
addReducerToActionReducerMap,
Expand Down
17 changes: 8 additions & 9 deletions modules/schematics/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,29 @@ import {
filter,
mergeWith,
move,
noop,
template,
url,
} from '@angular-devkit/schematics';
import 'rxjs/add/operator/merge';
import * as ts from 'typescript';
import * as stringUtils from '../strings';
import { addProviderToModule, addImportToModule } from '../utility/ast-utils';
import { addImportToModule } from '../utility/ast-utils';
import { InsertChange, Change } from '../utility/change';
import {
buildRelativePath,
findModuleFromOptions,
} from '../utility/find-module';
import { Schema as ServiceOptions } from './schema';
import { Schema as StoreOptions } from './schema';
import { insertImport } from '../utility/route-utils';

function addImportToNgModule(options: ServiceOptions): Rule {
function addImportToNgModule(options: StoreOptions): Rule {
return (host: Tree) => {
if (!options.module) {
const modulePath = options.module;

if (!modulePath) {
return host;
}

const modulePath = options.module;
if (!host.exists(options.module)) {
if (!host.exists(modulePath)) {
throw new Error('Specified module does not exist');
}

Expand Down Expand Up @@ -127,7 +126,7 @@ function addImportToNgModule(options: ServiceOptions): Rule {
};
}

export default function(options: ServiceOptions): Rule {
export default function(options: StoreOptions): Rule {
options.path = options.path ? normalize(options.path) : options.path;
const sourceDir = options.sourceDir;
const statePath = `/${options.sourceDir}/${options.path}/${
Expand Down