diff --git a/constant/index.js b/constant/index.js index d9ccb6789..aeed7d6ec 100644 --- a/constant/index.js +++ b/constant/index.js @@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() { util.inherits(Generator, ScriptBase); Generator.prototype.createServiceFiles = function createServiceFiles() { - this.generateSourceAndTest('service/constant', 'spec/service', 'services'); + this.generateSourceAndTest( + 'service/constant', + 'spec/service', + 'services', + this.options['skip-add'] || false + ); }; diff --git a/controller/index.js b/controller/index.js index b0c16dfd6..bd2efad4a 100644 --- a/controller/index.js +++ b/controller/index.js @@ -16,5 +16,10 @@ var Generator = module.exports = function Generator() { util.inherits(Generator, ScriptBase); Generator.prototype.createControllerFiles = function createControllerFiles() { - this.generateSourceAndTest('controller', 'spec/controller', 'controllers'); + this.generateSourceAndTest( + 'controller', + 'spec/controller', + 'controllers', + this.options['skip-add'] || false + ); }; diff --git a/directive/index.js b/directive/index.js index 6273dfccc..093ba5174 100644 --- a/directive/index.js +++ b/directive/index.js @@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() { util.inherits(Generator, ScriptBase); Generator.prototype.createDirectiveFiles = function createDirectiveFiles() { - this.generateSourceAndTest('directive', 'spec/directive', 'directives'); + this.generateSourceAndTest( + 'directive', + 'spec/directive', + 'directives', + this.options['skip-add'] || false + ); }; diff --git a/factory/index.js b/factory/index.js index 62032550f..71496e5bf 100644 --- a/factory/index.js +++ b/factory/index.js @@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() { util.inherits(Generator, ScriptBase); Generator.prototype.createServiceFiles = function createServiceFiles() { - this.generateSourceAndTest('service/factory', 'spec/service', 'services'); + this.generateSourceAndTest( + 'service/factory', + 'spec/service', + 'services', + this.options['skip-add'] || false + ); }; diff --git a/filter/index.js b/filter/index.js index 5d4f4dd6e..a69c30cf4 100644 --- a/filter/index.js +++ b/filter/index.js @@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() { util.inherits(Generator, ScriptBase); Generator.prototype.createFilterFiles = function createFilterFiles() { - this.generateSourceAndTest('filter', 'spec/filter', 'filters'); + this.generateSourceAndTest( + 'filter', + 'spec/filter', + 'filters', + this.options['skip-add'] || false + ); }; diff --git a/provider/index.js b/provider/index.js index 624bd7076..47fcb327d 100644 --- a/provider/index.js +++ b/provider/index.js @@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() { util.inherits(Generator, ScriptBase); Generator.prototype.createServiceFiles = function createServiceFiles() { - this.generateSourceAndTest('service/provider', 'spec/service', 'services'); + this.generateSourceAndTest( + 'service/provider', + 'spec/service', + 'services', + this.options['skip-add'] || false + ); }; diff --git a/readme.md b/readme.md index dfe72f7cc..ce229a241 100644 --- a/readme.md +++ b/readme.md @@ -224,6 +224,18 @@ The annotations are important because minified code will rename variables, makin The recommended build process uses `ngmin`, a tool that automatically adds these annotations. However, if you'd rather not use `ngmin`, you have to add these annotations manually yourself. +### Add to Index +By default, new scripts are added to the index.html file. However, this may not always be suitable. Some use cases: + +* Manually added to the file +* Auto-added by a 3rd party plugin +* Using this generator as a subgenerator + +To skip adding them to the index, pass in the skip-add argument: +```bash +yo angular:service serviceName --skip-add +``` + ## Bower Components The following packages are always installed by the [app](#app) generator: diff --git a/script-base.js b/script-base.js index 295155305..f9054ca58 100644 --- a/script-base.js +++ b/script-base.js @@ -100,8 +100,10 @@ Generator.prototype.addScriptToIndex = function (script) { } }; -Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, targetDirectory) { +Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, targetDirectory, skipAdd) { this.appTemplate(appTemplate, path.join('scripts', targetDirectory, this.name)); this.testTemplate(testTemplate, path.join(targetDirectory, this.name)); - this.addScriptToIndex(path.join(targetDirectory, this.name)); + if (!skipAdd) { + this.addScriptToIndex(path.join(targetDirectory, this.name)); + } }; diff --git a/service/index.js b/service/index.js index 7a18f4580..3aa5b55d9 100644 --- a/service/index.js +++ b/service/index.js @@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() { util.inherits(Generator, ScriptBase); Generator.prototype.createServiceFiles = function createServiceFiles() { - this.generateSourceAndTest('service/service', 'spec/service', 'services'); + this.generateSourceAndTest( + 'service/service', + 'spec/service', + 'services', + this.options['skip-add'] || false + ); }; diff --git a/value/index.js b/value/index.js index 271bcb5bc..6d16070ab 100644 --- a/value/index.js +++ b/value/index.js @@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() { util.inherits(Generator, ScriptBase); Generator.prototype.createServiceFiles = function createServiceFiles() { - this.generateSourceAndTest('service/value', 'spec/service', 'services'); + this.generateSourceAndTest( + 'service/value', + 'spec/service', + 'services', + this.options['skip-add'] || false + ); };