From cabc9dcafe1d5a45aba79e335de74a561308fdaf Mon Sep 17 00:00:00 2001 From: Mike Brocchi Date: Tue, 1 Nov 2016 13:58:30 -0400 Subject: [PATCH] bug(generate): ensure classes and imports are in lower case (#2920) Fixes #2833 --- .../angular-cli/blueprints/component/index.js | 2 +- .../angular-cli/blueprints/directive/index.js | 2 +- packages/angular-cli/blueprints/pipe/index.js | 2 +- .../component-basic.ts} | 4 ++-- .../generate/component/component-path-case.ts | 20 +++++++++++++++++++ 5 files changed, 25 insertions(+), 5 deletions(-) rename tests/e2e/tests/generate/{component.ts => component/component-basic.ts} (87%) create mode 100644 tests/e2e/tests/generate/component/component-path-case.ts diff --git a/packages/angular-cli/blueprints/component/index.js b/packages/angular-cli/blueprints/component/index.js index 1770fdce9b07..f67a4801358b 100644 --- a/packages/angular-cli/blueprints/component/index.js +++ b/packages/angular-cli/blueprints/component/index.js @@ -124,7 +124,7 @@ module.exports = { const returns = []; const className = stringUtils.classify(`${options.entity.name}Component`); const fileName = stringUtils.dasherize(`${options.entity.name}.component`); - const componentDir = path.relative(path.dirname(this.pathToModule), this.generatePath); + const componentDir = path.relative(path.dirname(this.pathToModule), this.generatePath).toLowerCase(); const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`; if (!options['skip-import']) { diff --git a/packages/angular-cli/blueprints/directive/index.js b/packages/angular-cli/blueprints/directive/index.js index ba53e7e95442..2e568e4959fc 100644 --- a/packages/angular-cli/blueprints/directive/index.js +++ b/packages/angular-cli/blueprints/directive/index.js @@ -87,7 +87,7 @@ module.exports = { const fileName = stringUtils.dasherize(`${options.entity.name}.directive`); const fullGeneratePath = path.join(this.project.root, this.generatePath); const moduleDir = path.parse(this.pathToModule).dir; - const relativeDir = path.relative(moduleDir, fullGeneratePath); + const relativeDir = path.relative(moduleDir, fullGeneratePath).toLowerCase(); const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`; if (!options['skip-import']) { diff --git a/packages/angular-cli/blueprints/pipe/index.js b/packages/angular-cli/blueprints/pipe/index.js index 12f957add718..7fbdf9e2ca63 100644 --- a/packages/angular-cli/blueprints/pipe/index.js +++ b/packages/angular-cli/blueprints/pipe/index.js @@ -75,7 +75,7 @@ module.exports = { const fileName = stringUtils.dasherize(`${options.entity.name}.pipe`); const fullGeneratePath = path.join(this.project.root, this.generatePath); const moduleDir = path.parse(this.pathToModule).dir; - const relativeDir = path.relative(moduleDir, fullGeneratePath); + const relativeDir = path.relative(moduleDir, fullGeneratePath).toLowerCase(); const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`; if (!options['skip-import']) { diff --git a/tests/e2e/tests/generate/component.ts b/tests/e2e/tests/generate/component/component-basic.ts similarity index 87% rename from tests/e2e/tests/generate/component.ts rename to tests/e2e/tests/generate/component/component-basic.ts index 251c14ebcc4e..e974f400cd6a 100644 --- a/tests/e2e/tests/generate/component.ts +++ b/tests/e2e/tests/generate/component/component-basic.ts @@ -1,6 +1,6 @@ import {join} from 'path'; -import {ng} from '../../utils/process'; -import {expectFileToExist} from '../../utils/fs'; +import {ng} from '../../../utils/process'; +import {expectFileToExist} from '../../../utils/fs'; export default function() { diff --git a/tests/e2e/tests/generate/component/component-path-case.ts b/tests/e2e/tests/generate/component/component-path-case.ts new file mode 100644 index 000000000000..942e2459a7c6 --- /dev/null +++ b/tests/e2e/tests/generate/component/component-path-case.ts @@ -0,0 +1,20 @@ +import {join} from 'path'; +import {ng} from '../../../utils/process'; +import {expectFileToExist, createDir} from '../../../utils/fs'; + + +export default function() { + const rootDir = join('src', 'app', 'upper-dir'); + const componentDir = join(rootDir.toLowerCase(), 'test-component'); + createDir(rootDir); + + return ng('generate', 'component', 'Upper-Dir', 'test-component') + .then(() => expectFileToExist(componentDir)) + .then(() => expectFileToExist(join(componentDir, 'test-component.component.ts'))) + .then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts'))) + .then(() => expectFileToExist(join(componentDir, 'test-component.component.html'))) + .then(() => expectFileToExist(join(componentDir, 'test-component.component.css'))) + + // Try to run the unit tests. + .then(() => ng('test', '--watch=false')); +}