Skip to content

Commit ba7b505

Browse files
stephenpluspluseddiemonge
authored andcommitted
feat(app): use grunt-bower-install for dep management
Closes #497
1 parent f2d5744 commit ba7b505

File tree

5 files changed

+62
-74
lines changed

5 files changed

+62
-74
lines changed

Diff for: app/index.js

+32-66
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use strict';
2+
var fs = require('fs');
23
var path = require('path');
34
var util = require('util');
45
var angularUtils = require('../util.js');
5-
var spawn = require('child_process').spawn;
66
var yeoman = require('yeoman-generator');
7+
var chalk = require('chalk');
8+
var wiredep = require('wiredep');
79

810

911
var Generator = module.exports = function Generator(args, options) {
@@ -66,7 +68,10 @@ var Generator = module.exports = function Generator(args, options) {
6668
});
6769

6870
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+
});
7075

7176
var enabledComponents = [];
7277

@@ -97,9 +102,10 @@ var Generator = module.exports = function Generator(args, options) {
97102
].concat(enabledComponents)
98103
}
99104
});
105+
100106
});
101107

102-
this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
108+
this.pkg = require('../package.json');
103109
};
104110

105111
util.inherits(Generator, yeoman.generators.Base);
@@ -213,78 +219,18 @@ Generator.prototype.readIndex = function readIndex() {
213219
// Waiting a more flexible solution for #138
214220
Generator.prototype.bootstrapFiles = function bootstrapFiles() {
215221
var sass = this.compassBootstrap;
216-
var files = [];
217222
var source = 'styles/' + ( sass ? 's' : '' ) + 'css/';
223+
var dest = 'app/styles/';
224+
var mainFile = 'main.' + (sass ? 's' : '') + 'css';
218225

219226
if (this.bootstrap && !sass) {
220-
files.push('bootstrap.css');
221227
this.copy('fonts/glyphicons-halflings-regular.eot', 'app/fonts/glyphicons-halflings-regular.eot');
222228
this.copy('fonts/glyphicons-halflings-regular.ttf', 'app/fonts/glyphicons-halflings-regular.ttf');
223229
this.copy('fonts/glyphicons-halflings-regular.svg', 'app/fonts/glyphicons-halflings-regular.svg');
224230
this.copy('fonts/glyphicons-halflings-regular.woff', 'app/fonts/glyphicons-halflings-regular.woff');
225231
}
226232

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);
288234
};
289235

290236
Generator.prototype.appJs = function appJs() {
@@ -313,3 +259,23 @@ Generator.prototype.imageFiles = function () {
313259
this.sourceRoot(path.join(__dirname, 'templates'));
314260
this.directory('images', 'app/images', true);
315261
}
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+
}

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"test": "mocha"
2323
},
2424
"dependencies": {
25-
"yeoman-generator": "~0.13.0"
25+
"yeoman-generator": "~0.13.0",
26+
"chalk": "~0.3.0",
27+
"wiredep": "~0.4.2"
2628
},
2729
"peerDependencies": {
2830
"generator-karma": "~0.6.0",

Diff for: templates/common/Gruntfile.js

+10
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ module.exports = function (grunt) {
152152
}
153153
},
154154

155+
// Automatically inject Bower components into the app
156+
'bower-install': {
157+
app: {
158+
html: '<%%= yeoman.app %>/index.html',
159+
ignorePath: '<%%= yeoman.app %>/'
160+
}
161+
},
162+
155163
<% if (coffee) { %>
156164
// Compiles CoffeeScript to JavaScript
157165
coffee: {
@@ -398,6 +406,7 @@ module.exports = function (grunt) {
398406

399407
grunt.task.run([
400408
'clean:server',
409+
'bower-install',
401410
'concurrent:server',
402411
'autoprefixer',
403412
'connect:livereload',
@@ -420,6 +429,7 @@ module.exports = function (grunt) {
420429

421430
grunt.registerTask('build', [
422431
'clean:dist',
432+
'bower-install',
423433
'useminPrepare',
424434
'concurrent:dist',
425435
'autoprefixer',

Diff for: templates/common/_package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"devDependencies": {
66
"grunt": "~0.4.1",
77
"grunt-autoprefixer": "~0.4.0",
8+
"grunt-bower-install": "~0.7.0",
89
"grunt-concurrent": "~0.4.1",
910
"grunt-contrib-clean": "~0.5.0",
1011
"grunt-contrib-coffee": "~0.7.0",

Diff for: templates/common/index.html

+16-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@
1010
<meta name="description" content="">
1111
<meta name="viewport" content="width=device-width">
1212
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
13+
<!-- build:css styles/vendor.css -->
14+
<!-- bower:css -->
15+
<!-- endbower -->
16+
<!-- endbuild -->
17+
<!-- build:css({.tmp,app}) styles/main.css -->
18+
<link rel="stylesheet" href="styles/main.css">
19+
<!-- endbuild -->
1320
</head>
1421
<body ng-app="<%= scriptAppName %>">
1522
<!--[if lt IE 7]>
1623
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
1724
<![endif]-->
1825

19-
<!--[if lt IE 9]>
20-
<script src="bower_components/es5-shim/es5-shim.js"></script>
21-
<script src="bower_components/json3/lib/json3.min.js"></script>
22-
<![endif]-->
23-
2426
<!-- Add your site or application content here -->
2527
<% if (ngRoute) {
2628
%><div class="container" ng-view></div><%
@@ -39,7 +41,14 @@
3941
ga('send', 'pageview');
4042
</script>
4143

42-
<% if (bootstrap) { %><script src="bower_components/jquery/jquery.js"></script><% } %>
43-
<script src="bower_components/angular/angular.js"></script>
44+
<!--[if lt IE 9]>
45+
<script src="bower_components/es5-shim/es5-shim.js"></script>
46+
<script src="bower_components/json3/lib/json3.min.js"></script>
47+
<![endif]-->
48+
49+
<!-- build:js scripts/vendor.js -->
50+
<!-- bower:js -->
51+
<!-- endbower -->
52+
<!-- endbuild -->
4453
</body>
4554
</html>

0 commit comments

Comments
 (0)