Skip to content

Commit

Permalink
bug(generate): skip-import flag not being respected (#3147)
Browse files Browse the repository at this point in the history
Fixes #2973
  • Loading branch information
Brocco authored and hansl committed Nov 16, 2016
1 parent 07e96ea commit 7c8b7f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
11 changes: 7 additions & 4 deletions packages/angular-cli/blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ module.exports = {
{ name: 'prefix', type: Boolean, default: true },
{ name: 'spec', type: Boolean },
{ name: 'view-encapsulation', type: String, aliases: ['ve'] },
{ name: 'change-detection', type: String, aliases: ['cd'] }
{ name: 'change-detection', type: String, aliases: ['cd'] },
{ name: 'skip-import', type: Boolean, default: false }
],

beforeInstall: function() {
beforeInstall: function(options) {
try {
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
} catch(e) {
throw `Error locating module for declaration\n\t${e}`;
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
}
}
},

Expand Down Expand Up @@ -139,7 +142,7 @@ module.exports = {
const componentDir = path.relative(path.dirname(this.pathToModule), this.generatePath);
const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`;

if (!options['skip-import']) {
if (!options.skipImport) {
returns.push(
astUtils.addDeclarationToModule(this.pathToModule, className, importPath)
.then(change => change.apply(NodeHost)));
Expand Down
11 changes: 7 additions & 4 deletions packages/angular-cli/blueprints/directive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ module.exports = {
availableOptions: [
{ name: 'flat', type: Boolean, default: true },
{ name: 'prefix', type: Boolean, default: true },
{ name: 'spec', type: Boolean }
{ name: 'spec', type: Boolean },
{ name: 'skip-import', type: Boolean, default: false }
],

beforeInstall: function() {
beforeInstall: function(options) {
try {
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
} catch(e) {
throw `Error locating module for declaration\n\t${e}`;
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
}
}
},

Expand Down Expand Up @@ -90,7 +93,7 @@ module.exports = {
const relativeDir = path.relative(moduleDir, fullGeneratePath);
const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`;

if (!options['skip-import']) {
if (!options.skipImport) {
returns.push(
astUtils.addDeclarationToModule(this.pathToModule, className, importPath)
.then(change => change.apply(NodeHost)));
Expand Down
11 changes: 7 additions & 4 deletions packages/angular-cli/blueprints/pipe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ module.exports = {

availableOptions: [
{ name: 'flat', type: Boolean, default: true },
{ name: 'spec', type: Boolean }
{ name: 'spec', type: Boolean },
{ name: 'skip-import', type: Boolean, default: false }
],

beforeInstall: function() {
beforeInstall: function(options) {
try {
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
} catch(e) {
throw `Error locating module for declaration\n\t${e}`;
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
}
}
},

Expand Down Expand Up @@ -78,7 +81,7 @@ module.exports = {
const relativeDir = path.relative(moduleDir, fullGeneratePath);
const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`;

if (!options['skip-import']) {
if (!options.skipImport) {
returns.push(
astUtils.addDeclarationToModule(this.pathToModule, className, importPath)
.then(change => change.apply(NodeHost)));
Expand Down

0 comments on commit 7c8b7f0

Please sign in to comment.