Skip to content

Commit

Permalink
feat(gen): add option to not add to index
Browse files Browse the repository at this point in the history
Allow skipping of adding script to index file with default being to add
  • Loading branch information
eddiemonge committed Oct 23, 2013
1 parent bb2fe60 commit 486ee14
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 10 deletions.
7 changes: 6 additions & 1 deletion constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
7 changes: 6 additions & 1 deletion controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
7 changes: 6 additions & 1 deletion directive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
7 changes: 6 additions & 1 deletion factory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
7 changes: 6 additions & 1 deletion filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
7 changes: 6 additions & 1 deletion provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions script-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};
7 changes: 6 additions & 1 deletion service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};
7 changes: 6 additions & 1 deletion value/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};

0 comments on commit 486ee14

Please sign in to comment.