This repository has been archived by the owner on Mar 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use grunt-bower-install for HTML dependency injection. #497
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var util = require('util'); | ||
var angularUtils = require('../util.js'); | ||
var spawn = require('child_process').spawn; | ||
var yeoman = require('yeoman-generator'); | ||
var chalk = require('chalk'); | ||
var wiredep = require('wiredep'); | ||
|
||
|
||
var Generator = module.exports = function Generator(args, options) { | ||
|
@@ -66,7 +68,10 @@ var Generator = module.exports = function Generator(args, options) { | |
}); | ||
|
||
this.on('end', function () { | ||
this.installDependencies({ skipInstall: this.options['skip-install'] }); | ||
this.installDependencies({ | ||
skipInstall: this.options['skip-install'], | ||
callback: this._injectDependencies.bind(this) | ||
}); | ||
|
||
var enabledComponents = []; | ||
|
||
|
@@ -97,9 +102,10 @@ var Generator = module.exports = function Generator(args, options) { | |
].concat(enabledComponents) | ||
} | ||
}); | ||
|
||
}); | ||
|
||
this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json'))); | ||
this.pkg = require(__dirname, '../package.json'); | ||
}; | ||
|
||
util.inherits(Generator, yeoman.generators.Base); | ||
|
@@ -213,78 +219,18 @@ Generator.prototype.readIndex = function readIndex() { | |
// Waiting a more flexible solution for #138 | ||
Generator.prototype.bootstrapFiles = function bootstrapFiles() { | ||
var sass = this.compassBootstrap; | ||
var files = []; | ||
var source = 'styles/' + ( sass ? 's' : '' ) + 'css/'; | ||
var dest = 'app/styles/'; | ||
var mainFile = 'main.' + (sass ? 's' : '') + 'css'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if (this.bootstrap && !sass) { | ||
files.push('bootstrap.css'); | ||
this.copy('fonts/glyphicons-halflings-regular.eot', 'app/fonts/glyphicons-halflings-regular.eot'); | ||
this.copy('fonts/glyphicons-halflings-regular.ttf', 'app/fonts/glyphicons-halflings-regular.ttf'); | ||
this.copy('fonts/glyphicons-halflings-regular.svg', 'app/fonts/glyphicons-halflings-regular.svg'); | ||
this.copy('fonts/glyphicons-halflings-regular.woff', 'app/fonts/glyphicons-halflings-regular.woff'); | ||
} | ||
|
||
files.push('main.' + (sass ? 's' : '') + 'css'); | ||
|
||
files.forEach(function (file) { | ||
this.copy(source + file, 'app/styles/' + file); | ||
}.bind(this)); | ||
|
||
this.indexFile = this.appendFiles({ | ||
html: this.indexFile, | ||
fileType: 'css', | ||
optimizedPath: 'styles/main.css', | ||
sourceFileList: files.map(function (file) { | ||
return 'styles/' + file.replace('.scss', '.css'); | ||
}), | ||
searchPath: ['.tmp', 'app'] | ||
}); | ||
}; | ||
|
||
Generator.prototype.bootstrapJS = function bootstrapJS() { | ||
if (!this.bootstrap) { | ||
return; // Skip if disabled. | ||
} | ||
|
||
// Wire Twitter Bootstrap plugins | ||
this.indexFile = this.appendScripts(this.indexFile, 'scripts/plugins.js', [ | ||
'bower_components/sass-bootstrap/js/affix.js', | ||
'bower_components/sass-bootstrap/js/alert.js', | ||
'bower_components/sass-bootstrap/js/button.js', | ||
'bower_components/sass-bootstrap/js/carousel.js', | ||
'bower_components/sass-bootstrap/js/transition.js', | ||
'bower_components/sass-bootstrap/js/collapse.js', | ||
'bower_components/sass-bootstrap/js/dropdown.js', | ||
'bower_components/sass-bootstrap/js/modal.js', | ||
'bower_components/sass-bootstrap/js/scrollspy.js', | ||
'bower_components/sass-bootstrap/js/tab.js', | ||
'bower_components/sass-bootstrap/js/tooltip.js', | ||
'bower_components/sass-bootstrap/js/popover.js' | ||
]); | ||
}; | ||
|
||
Generator.prototype.extraModules = function extraModules() { | ||
var modules = []; | ||
if (this.resourceModule) { | ||
modules.push('bower_components/angular-resource/angular-resource.js'); | ||
} | ||
|
||
if (this.cookiesModule) { | ||
modules.push('bower_components/angular-cookies/angular-cookies.js'); | ||
} | ||
|
||
if (this.sanitizeModule) { | ||
modules.push('bower_components/angular-sanitize/angular-sanitize.js'); | ||
} | ||
|
||
if (this.routeModule) { | ||
modules.push('bower_components/angular-route/angular-route.js'); | ||
} | ||
|
||
if (modules.length) { | ||
this.indexFile = this.appendScripts(this.indexFile, 'scripts/modules.js', | ||
modules); | ||
} | ||
this.copy(source + mainFile, dest + mainFile); | ||
}; | ||
|
||
Generator.prototype.appJs = function appJs() { | ||
|
@@ -313,3 +259,23 @@ Generator.prototype.imageFiles = function () { | |
this.sourceRoot(path.join(__dirname, 'templates')); | ||
this.directory('images', 'app/images', true); | ||
} | ||
|
||
Generator.prototype._injectDependencies = function _injectDependencies() { | ||
var howToInstall = | ||
'\nAfter running `npm install & bower install`, inject your front end dependencies into' + | ||
'\nyour HTML by running:' + | ||
'\n' + | ||
chalk.yellow.bold('\n grunt bower-install'); | ||
|
||
if (this.options['skip-install']) { | ||
console.log(howToInstall); | ||
} else { | ||
wiredep({ | ||
directory: 'app/bower_components', | ||
bowerJson: JSON.parse(fs.readFileSync('./bower.json')), | ||
ignorePath: 'app/', | ||
htmlFile: 'app/index.html', | ||
cssPattern: '<link rel="stylesheet" href="{{filePath}}">' | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.pkg = require('../package.json');