Skip to content

refactor(@angular/schematics): Add an extra option to not use dasheri… #12500

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
Oct 9, 2018
Merged
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
4 changes: 3 additions & 1 deletion packages/schematics/angular/utility/find-module.ts
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ export interface ModuleOptions {
skipImport?: boolean;
moduleExt?: string;
routingModuleExt?: string;
nameFormatter?: (str: string) => string;
}

const MODULE_EXT = '.module.ts';
@@ -42,8 +43,9 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
const routingModuleExt = options.routingModuleExt || ROUTING_MODULE_EXT;

if (!options.module) {
options.nameFormatter = options.nameFormatter || strings.dasherize;
const pathToCheck = (options.path || '')
+ (options.flat ? '' : '/' + strings.dasherize(options.name));
+ (options.flat ? '' : '/' + options.nameFormatter(options.name));

return normalize(findModule(host, pathToCheck, moduleExt, routingModuleExt));
} else {
10 changes: 9 additions & 1 deletion packages/schematics/angular/utility/find-module_spec.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Path } from '@angular-devkit/core';
import { Path, strings } from '@angular-devkit/core';
import { EmptyTree, Tree } from '@angular-devkit/schematics';
import { ModuleOptions, findModule, findModuleFromOptions } from './find-module';

@@ -111,6 +111,14 @@ describe('find-module', () => {
expect(modPath).toEqual('/projects/my-proj/src/app.module.ts' as Path);
});

it('should find a module if nameFormatter is provided', () => {
tree.create('/projects/my-proj/src/app_test.module.ts', '');
options.path = '/projects/my-proj/src';
options.nameFormatter = strings.underscore;
const modPath = findModuleFromOptions(tree, options);
expect(modPath).toEqual('/projects/my-proj/src/app_test.module.ts' as Path);
});

it('should find a module in a sub dir', () => {
tree.create('/projects/my-proj/src/admin/foo.module.ts', '');
options.name = 'other/test';