From 486ee14660ac51b7cfcb4b7de50135833954f193 Mon Sep 17 00:00:00 2001 From: Eddie Monge Date: Wed, 23 Oct 2013 11:07:27 -0700 Subject: [PATCH] feat(gen): add option to not add to index Allow skipping of adding script to index file with default being to add --- constant/index.js | 7 ++++++- controller/index.js | 7 ++++++- directive/index.js | 7 ++++++- factory/index.js | 7 ++++++- filter/index.js | 7 ++++++- provider/index.js | 7 ++++++- readme.md | 12 ++++++++++++ script-base.js | 6 ++++-- service/index.js | 7 ++++++- value/index.js | 7 ++++++- 10 files changed, 64 insertions(+), 10 deletions(-) diff --git a/constant/index.js b/constant/index.js index d9ccb67..aeed7d6 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 b0c16df..bd2efad 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 6273dfc..093ba51 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 6203255..71496e5 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 5d4f4dd..a69c30c 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 624bd70..47fcb32 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 dfe72f7..ce229a2 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 2951553..f9054ca 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 7a18f45..3aa5b55 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 271bcb5..6d16070 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 + ); };