From 1652aa3fdc279b986c6f0b2389b61005f6b91665 Mon Sep 17 00:00:00 2001 From: Mike Brocchi Date: Tue, 5 Sep 2017 19:32:24 +0200 Subject: [PATCH] fix(@angular/cli): Use the app default prefix when generating fixes #7522 --- packages/@angular/cli/commands/generate.ts | 6 ++++++ .../generate/component/component-prefix.ts | 21 +++++++++++++++++++ .../generate/directive/directive-prefix.ts | 21 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/e2e/tests/generate/component/component-prefix.ts create mode 100644 tests/e2e/tests/generate/directive/directive-prefix.ts diff --git a/packages/@angular/cli/commands/generate.ts b/packages/@angular/cli/commands/generate.ts index 9d44cedbbd70..1434c224e6cd 100644 --- a/packages/@angular/cli/commands/generate.ts +++ b/packages/@angular/cli/commands/generate.ts @@ -145,6 +145,12 @@ export default Command.extend({ const cwd = this.project.root; const schematicName = rawArgs[0]; + if (schematicName === 'component' || schematicName === 'directive') { + if (commandOptions.prefix === undefined) { + commandOptions.prefix = appConfig.prefix; + } + } + const SchematicRunTask = require('../tasks/schematic-run').default; const schematicRunTask = new SchematicRunTask({ ui: this.ui, diff --git a/tests/e2e/tests/generate/component/component-prefix.ts b/tests/e2e/tests/generate/component/component-prefix.ts new file mode 100644 index 000000000000..2530e778bbfd --- /dev/null +++ b/tests/e2e/tests/generate/component/component-prefix.ts @@ -0,0 +1,21 @@ +import {join} from 'path'; +import {ng} from '../../../utils/process'; +import {expectFileToMatch} from '../../../utils/fs'; +import { updateJsonFile } from '../../../utils/project'; + + +export default function() { + const componentDir = join('src', 'app', 'test-component'); + + return Promise.resolve() + .then(() => updateJsonFile('.angular-cli.json', configJson => { + const app = configJson['apps'][0]; + app['prefix'] = 'pre'; + })) + .then(() => ng('generate', 'component', 'test-component')) + .then(() => expectFileToMatch(join(componentDir, 'test-component.component.ts'), + /selector: 'pre-/)) + + // Try to run the unit tests. + .then(() => ng('test', '--single-run')); +} diff --git a/tests/e2e/tests/generate/directive/directive-prefix.ts b/tests/e2e/tests/generate/directive/directive-prefix.ts new file mode 100644 index 000000000000..43380458c7b0 --- /dev/null +++ b/tests/e2e/tests/generate/directive/directive-prefix.ts @@ -0,0 +1,21 @@ +import {join} from 'path'; +import {ng} from '../../../utils/process'; +import {expectFileToMatch} from '../../../utils/fs'; +import { updateJsonFile } from '../../../utils/project'; + + +export default function() { + const directiveDir = join('src', 'app'); + + return Promise.resolve() + .then(() => updateJsonFile('.angular-cli.json', configJson => { + const app = configJson['apps'][0]; + app['prefix'] = 'pre'; + })) + .then(() => ng('generate', 'directive', 'test-directive')) + .then(() => expectFileToMatch(join(directiveDir, 'test-directive.directive.ts'), + /selector: '\[pre/)) + + // Try to run the unit tests. + .then(() => ng('test', '--single-run')); +}