Skip to content

Commit

Permalink
fix(@angular/cli): fix package name fetching from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitarora authored and Brocco committed May 24, 2017
1 parent 7bd4074 commit 169dc9e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ export default Command.extend({
const blueprint = this.blueprints.find((bp: any) => bp.name === name
|| (bp.aliases && bp.aliases.includes(name)));

const projectName = CliConfig.getValue('project.name');
const blueprintOptions = {
target: this.project.root,
entity: {
name: rawArgs[1],
options: parseOptions(rawArgs.slice(2))
},
projectName,
ui: this.ui,
project: this.project,
settings: this.settings,
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/ember-cli/lib/models/blueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ Blueprint.prototype._generateFileMapVariables = function(moduleName, locals, opt
@return {Object}
*/
Blueprint.prototype._locals = function(options) {
var packageName = options.project.name();
var packageName = options.project.name() || options.projectName;
var moduleName = options.entity && options.entity.name || packageName;
var sanitizedModuleName = moduleName.replace(/\//g, '-');

Expand Down
24 changes: 24 additions & 0 deletions tests/e2e/tests/generate/generate-name-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {join} from 'path';
import {ng} from '../../utils/process';
import {expectFileToExist} from '../../utils/fs';
import {updateJsonFile} from '../../utils/project';


export default function() {
const compDir = join('src', 'app', 'test-component');

return Promise.resolve()
.then(() => updateJsonFile('package.json', configJson => {
delete configJson.name;
return configJson;
}))
.then(() => ng('generate', 'component', 'test-component'))
.then(() => expectFileToExist(compDir))
.then(() => expectFileToExist(join(compDir, 'test-component.component.ts')))
.then(() => expectFileToExist(join(compDir, 'test-component.component.spec.ts')))
.then(() => expectFileToExist(join(compDir, 'test-component.component.html')))
.then(() => expectFileToExist(join(compDir, 'test-component.component.css')))

// Try to run the unit tests.
.then(() => ng('test', '--single-run'));
}

0 comments on commit 169dc9e

Please sign in to comment.