|
1 | 1 | 'use strict';
|
| 2 | +var fs = require('fs'); |
2 | 3 | var path = require('path');
|
3 | 4 | var util = require('util');
|
4 | 5 | var angularUtils = require('../util.js');
|
5 |
| -var spawn = require('child_process').spawn; |
6 | 6 | var yeoman = require('yeoman-generator');
|
| 7 | +var chalk = require('chalk'); |
| 8 | +var wiredep = require('wiredep'); |
7 | 9 |
|
8 | 10 |
|
9 | 11 | var Generator = module.exports = function Generator(args, options) {
|
@@ -66,7 +68,10 @@ var Generator = module.exports = function Generator(args, options) {
|
66 | 68 | });
|
67 | 69 |
|
68 | 70 | this.on('end', function () {
|
69 |
| - this.installDependencies({ skipInstall: this.options['skip-install'] }); |
| 71 | + this.installDependencies({ |
| 72 | + skipInstall: this.options['skip-install'], |
| 73 | + callback: this._injectDependencies.bind(this) |
| 74 | + }); |
70 | 75 |
|
71 | 76 | var enabledComponents = [];
|
72 | 77 |
|
@@ -97,9 +102,10 @@ var Generator = module.exports = function Generator(args, options) {
|
97 | 102 | ].concat(enabledComponents)
|
98 | 103 | }
|
99 | 104 | });
|
| 105 | + |
100 | 106 | });
|
101 | 107 |
|
102 |
| - this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json'))); |
| 108 | + this.pkg = require('../package.json'); |
103 | 109 | };
|
104 | 110 |
|
105 | 111 | util.inherits(Generator, yeoman.generators.Base);
|
@@ -213,78 +219,18 @@ Generator.prototype.readIndex = function readIndex() {
|
213 | 219 | // Waiting a more flexible solution for #138
|
214 | 220 | Generator.prototype.bootstrapFiles = function bootstrapFiles() {
|
215 | 221 | var sass = this.compassBootstrap;
|
216 |
| - var files = []; |
217 | 222 | var source = 'styles/' + ( sass ? 's' : '' ) + 'css/';
|
| 223 | + var dest = 'app/styles/'; |
| 224 | + var mainFile = 'main.' + (sass ? 's' : '') + 'css'; |
218 | 225 |
|
219 | 226 | if (this.bootstrap && !sass) {
|
220 |
| - files.push('bootstrap.css'); |
221 | 227 | this.copy('fonts/glyphicons-halflings-regular.eot', 'app/fonts/glyphicons-halflings-regular.eot');
|
222 | 228 | this.copy('fonts/glyphicons-halflings-regular.ttf', 'app/fonts/glyphicons-halflings-regular.ttf');
|
223 | 229 | this.copy('fonts/glyphicons-halflings-regular.svg', 'app/fonts/glyphicons-halflings-regular.svg');
|
224 | 230 | this.copy('fonts/glyphicons-halflings-regular.woff', 'app/fonts/glyphicons-halflings-regular.woff');
|
225 | 231 | }
|
226 | 232 |
|
227 |
| - files.push('main.' + (sass ? 's' : '') + 'css'); |
228 |
| - |
229 |
| - files.forEach(function (file) { |
230 |
| - this.copy(source + file, 'app/styles/' + file); |
231 |
| - }.bind(this)); |
232 |
| - |
233 |
| - this.indexFile = this.appendFiles({ |
234 |
| - html: this.indexFile, |
235 |
| - fileType: 'css', |
236 |
| - optimizedPath: 'styles/main.css', |
237 |
| - sourceFileList: files.map(function (file) { |
238 |
| - return 'styles/' + file.replace('.scss', '.css'); |
239 |
| - }), |
240 |
| - searchPath: ['.tmp', 'app'] |
241 |
| - }); |
242 |
| -}; |
243 |
| - |
244 |
| -Generator.prototype.bootstrapJS = function bootstrapJS() { |
245 |
| - if (!this.bootstrap) { |
246 |
| - return; // Skip if disabled. |
247 |
| - } |
248 |
| - |
249 |
| - // Wire Twitter Bootstrap plugins |
250 |
| - this.indexFile = this.appendScripts(this.indexFile, 'scripts/plugins.js', [ |
251 |
| - 'bower_components/sass-bootstrap/js/affix.js', |
252 |
| - 'bower_components/sass-bootstrap/js/alert.js', |
253 |
| - 'bower_components/sass-bootstrap/js/button.js', |
254 |
| - 'bower_components/sass-bootstrap/js/carousel.js', |
255 |
| - 'bower_components/sass-bootstrap/js/transition.js', |
256 |
| - 'bower_components/sass-bootstrap/js/collapse.js', |
257 |
| - 'bower_components/sass-bootstrap/js/dropdown.js', |
258 |
| - 'bower_components/sass-bootstrap/js/modal.js', |
259 |
| - 'bower_components/sass-bootstrap/js/scrollspy.js', |
260 |
| - 'bower_components/sass-bootstrap/js/tab.js', |
261 |
| - 'bower_components/sass-bootstrap/js/tooltip.js', |
262 |
| - 'bower_components/sass-bootstrap/js/popover.js' |
263 |
| - ]); |
264 |
| -}; |
265 |
| - |
266 |
| -Generator.prototype.extraModules = function extraModules() { |
267 |
| - var modules = []; |
268 |
| - if (this.resourceModule) { |
269 |
| - modules.push('bower_components/angular-resource/angular-resource.js'); |
270 |
| - } |
271 |
| - |
272 |
| - if (this.cookiesModule) { |
273 |
| - modules.push('bower_components/angular-cookies/angular-cookies.js'); |
274 |
| - } |
275 |
| - |
276 |
| - if (this.sanitizeModule) { |
277 |
| - modules.push('bower_components/angular-sanitize/angular-sanitize.js'); |
278 |
| - } |
279 |
| - |
280 |
| - if (this.routeModule) { |
281 |
| - modules.push('bower_components/angular-route/angular-route.js'); |
282 |
| - } |
283 |
| - |
284 |
| - if (modules.length) { |
285 |
| - this.indexFile = this.appendScripts(this.indexFile, 'scripts/modules.js', |
286 |
| - modules); |
287 |
| - } |
| 233 | + this.copy(source + mainFile, dest + mainFile); |
288 | 234 | };
|
289 | 235 |
|
290 | 236 | Generator.prototype.appJs = function appJs() {
|
@@ -313,3 +259,23 @@ Generator.prototype.imageFiles = function () {
|
313 | 259 | this.sourceRoot(path.join(__dirname, 'templates'));
|
314 | 260 | this.directory('images', 'app/images', true);
|
315 | 261 | }
|
| 262 | + |
| 263 | +Generator.prototype._injectDependencies = function _injectDependencies() { |
| 264 | + var howToInstall = |
| 265 | + '\nAfter running `npm install & bower install`, inject your front end dependencies into' + |
| 266 | + '\nyour HTML by running:' + |
| 267 | + '\n' + |
| 268 | + chalk.yellow.bold('\n grunt bower-install'); |
| 269 | + |
| 270 | + if (this.options['skip-install']) { |
| 271 | + console.log(howToInstall); |
| 272 | + } else { |
| 273 | + wiredep({ |
| 274 | + directory: 'app/bower_components', |
| 275 | + bowerJson: JSON.parse(fs.readFileSync('./bower.json')), |
| 276 | + ignorePath: 'app/', |
| 277 | + htmlFile: 'app/index.html', |
| 278 | + cssPattern: '<link rel="stylesheet" href="{{filePath}}">' |
| 279 | + }); |
| 280 | + } |
| 281 | +} |
0 commit comments