Skip to content

Commit 94e3eda

Browse files
committed
Merge pull request #406 from eddiemonge/patch-2
feat(gen): add option to not add to index
2 parents fde8652 + 486ee14 commit 94e3eda

File tree

10 files changed

+64
-10
lines changed

10 files changed

+64
-10
lines changed

Diff for: constant/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() {
1010
util.inherits(Generator, ScriptBase);
1111

1212
Generator.prototype.createServiceFiles = function createServiceFiles() {
13-
this.generateSourceAndTest('service/constant', 'spec/service', 'services');
13+
this.generateSourceAndTest(
14+
'service/constant',
15+
'spec/service',
16+
'services',
17+
this.options['skip-add'] || false
18+
);
1419
};

Diff for: controller/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ var Generator = module.exports = function Generator() {
1616
util.inherits(Generator, ScriptBase);
1717

1818
Generator.prototype.createControllerFiles = function createControllerFiles() {
19-
this.generateSourceAndTest('controller', 'spec/controller', 'controllers');
19+
this.generateSourceAndTest(
20+
'controller',
21+
'spec/controller',
22+
'controllers',
23+
this.options['skip-add'] || false
24+
);
2025
};

Diff for: directive/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() {
1010
util.inherits(Generator, ScriptBase);
1111

1212
Generator.prototype.createDirectiveFiles = function createDirectiveFiles() {
13-
this.generateSourceAndTest('directive', 'spec/directive', 'directives');
13+
this.generateSourceAndTest(
14+
'directive',
15+
'spec/directive',
16+
'directives',
17+
this.options['skip-add'] || false
18+
);
1419
};

Diff for: factory/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() {
1010
util.inherits(Generator, ScriptBase);
1111

1212
Generator.prototype.createServiceFiles = function createServiceFiles() {
13-
this.generateSourceAndTest('service/factory', 'spec/service', 'services');
13+
this.generateSourceAndTest(
14+
'service/factory',
15+
'spec/service',
16+
'services',
17+
this.options['skip-add'] || false
18+
);
1419
};

Diff for: filter/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() {
1010
util.inherits(Generator, ScriptBase);
1111

1212
Generator.prototype.createFilterFiles = function createFilterFiles() {
13-
this.generateSourceAndTest('filter', 'spec/filter', 'filters');
13+
this.generateSourceAndTest(
14+
'filter',
15+
'spec/filter',
16+
'filters',
17+
this.options['skip-add'] || false
18+
);
1419
};

Diff for: provider/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() {
1010
util.inherits(Generator, ScriptBase);
1111

1212
Generator.prototype.createServiceFiles = function createServiceFiles() {
13-
this.generateSourceAndTest('service/provider', 'spec/service', 'services');
13+
this.generateSourceAndTest(
14+
'service/provider',
15+
'spec/service',
16+
'services',
17+
this.options['skip-add'] || false
18+
);
1419
};

Diff for: readme.md

+12
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ The annotations are important because minified code will rename variables, makin
227227

228228
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.
229229

230+
### Add to Index
231+
By default, new scripts are added to the index.html file. However, this may not always be suitable. Some use cases:
232+
233+
* Manually added to the file
234+
* Auto-added by a 3rd party plugin
235+
* Using this generator as a subgenerator
236+
237+
To skip adding them to the index, pass in the skip-add argument:
238+
```bash
239+
yo angular:service serviceName --skip-add
240+
```
241+
230242
## Bower Components
231243

232244
The following packages are always installed by the [app](#app) generator:

Diff for: script-base.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ Generator.prototype.addScriptToIndex = function (script) {
100100
}
101101
};
102102

103-
Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, targetDirectory) {
103+
Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, targetDirectory, skipAdd) {
104104
this.appTemplate(appTemplate, path.join('scripts', targetDirectory, this.name));
105105
this.testTemplate(testTemplate, path.join(targetDirectory, this.name));
106-
this.addScriptToIndex(path.join(targetDirectory, this.name));
106+
if (!skipAdd) {
107+
this.addScriptToIndex(path.join(targetDirectory, this.name));
108+
}
107109
};

Diff for: service/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() {
1010
util.inherits(Generator, ScriptBase);
1111

1212
Generator.prototype.createServiceFiles = function createServiceFiles() {
13-
this.generateSourceAndTest('service/service', 'spec/service', 'services');
13+
this.generateSourceAndTest(
14+
'service/service',
15+
'spec/service',
16+
'services',
17+
this.options['skip-add'] || false
18+
);
1419
};

Diff for: value/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ var Generator = module.exports = function Generator() {
1010
util.inherits(Generator, ScriptBase);
1111

1212
Generator.prototype.createServiceFiles = function createServiceFiles() {
13-
this.generateSourceAndTest('service/value', 'spec/service', 'services');
13+
this.generateSourceAndTest(
14+
'service/value',
15+
'spec/service',
16+
'services',
17+
this.options['skip-add'] || false
18+
);
1419
};

0 commit comments

Comments
 (0)