Skip to content

Commit

Permalink
gulp task updates.
Browse files Browse the repository at this point in the history
gulp should reload for gulpfile.js changes and grunt should reload for gruntfile.js changes.

update template cache

update template cache task flow

use asset variable.

indent
  • Loading branch information
rhutchison committed Jul 10, 2015
1 parent cff3efe commit cc02ecf
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"curly": false, // Require {} for every new block or scope.
"eqeqeq": true, // Require triple equals i.e. `===`.
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef": true, // Prohibit variable use before definition.
"latedef": "nofunc", // Prohibit variable use before definition.
"newcap": true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"quotmark": "single", // Define quotes to string values.
Expand Down
7 changes: 5 additions & 2 deletions config/assets/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ module.exports = {
'modules/*/client/*.js',
'modules/*/client/**/*.js'
],
views: ['modules/*/client/views/**/*.html']
views: ['modules/*/client/views/**/*.html'],
templates: ['build/templates.js']
},
server: {
allJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'modules/*/server/**/*.js'],
gruntConfig: 'gruntfile.js',
gulpConfig: 'gulpfile.js',
allJS: ['server.js', 'config/**/*.js', 'modules/*/server/**/*.js'],
models: 'modules/*/server/models/**/*.js',
routes: ['modules/!(core)/server/routes/**/*.js', 'modules/core/server/routes/**/*.js'],
sockets: 'modules/*/server/sockets/**/*.js',
Expand Down
4 changes: 2 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = function (grunt) {
options: {
nodeArgs: ['--debug'],
ext: 'js,html',
watch: _.union(defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
watch: _.union(defaultAssets.server.gruntConfig, defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
}
}
},
Expand All @@ -91,7 +91,7 @@ module.exports = function (grunt) {
},
jshint: {
all: {
src: _.union(defaultAssets.server.allJS, defaultAssets.client.js, testAssets.tests.server, testAssets.tests.client, testAssets.tests.e2e),
src: _.union(defaultAssets.server.gruntConfig, defaultAssets.server.allJS, defaultAssets.client.js, testAssets.tests.server, testAssets.tests.client, testAssets.tests.e2e),
options: {
jshintrc: true,
node: true,
Expand Down
96 changes: 75 additions & 21 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ var _ = require('lodash'),
gulp = require('gulp'),
gulpLoadPlugins = require('gulp-load-plugins'),
runSequence = require('run-sequence'),
plugins = gulpLoadPlugins();
plugins = gulpLoadPlugins({
rename: {
'gulp-angular-templatecache': 'templateCache'
}
}),
path = require('path'),
endOfLine = require('os').EOL;

// Set NODE_ENV to 'test'
gulp.task('env:test', function () {
Expand All @@ -32,23 +38,29 @@ gulp.task('nodemon', function () {
script: 'server.js',
nodeArgs: ['--debug'],
ext: 'js,html',
watch: _.union(defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
watch: _.union(defaultAssets.server.gulpConfig, defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
});
});

// Watch Files For Changes
gulp.task('watch', function() {
gulp.task('watch', function () {
// Start livereload
plugins.livereload.listen();

// Add watch rules
gulp.watch(defaultAssets.server.views).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.server.allJS, ['jshint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.views).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.js, ['jshint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.css, ['csslint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.sass, ['sass', 'csslint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.less, ['less', 'csslint']).on('change', plugins.livereload.changed);

if (process.env.NODE_ENV === 'production') {
gulp.watch(defaultAssets.client.views, ['templatecache', 'jshint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.server.gulpConfig, ['templatecache', 'lint']).on('change', plugins.livereload.changed);
} else {
gulp.watch(defaultAssets.server.gulpConfig, ['lint']).on('change', plugins.livereload.changed);
}
});

// CSS linting task
Expand All @@ -65,7 +77,16 @@ gulp.task('csslint', function (done) {

// JS linting task
gulp.task('jshint', function () {
return gulp.src(_.union(defaultAssets.server.allJS, defaultAssets.client.js, testAssets.tests.server, testAssets.tests.client, testAssets.tests.e2e))
var assets = _.union(
defaultAssets.server.gulpConfig,
defaultAssets.server.allJS,
defaultAssets.client.js,
testAssets.tests.server,
testAssets.tests.client,
testAssets.tests.e2e
);

return gulp.src(assets)
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('default'))
.pipe(plugins.jshint.reporter('fail'));
Expand All @@ -74,7 +95,12 @@ gulp.task('jshint', function () {

// JS minifying task
gulp.task('uglify', function () {
return gulp.src(defaultAssets.client.js)
var assets = _.union(
defaultAssets.client.js,
defaultAssets.client.templates
);

return gulp.src(assets)
.pipe(plugins.ngAnnotate())
.pipe(plugins.uglify({
mangle: false
Expand All @@ -95,8 +121,9 @@ gulp.task('cssmin', function () {
gulp.task('sass', function () {
return gulp.src(defaultAssets.client.sass)
.pipe(plugins.sass())
.pipe(plugins.rename(function (path) {
path.dirname = path.dirname.replace('/scss', '/css');
.pipe(plugins.autoprefixer())
.pipe(plugins.rename(function (file) {
file.dirname = file.dirname.replace(path.sep + 'scss', path.sep + 'css');
}))
.pipe(gulp.dest('./modules/'));
});
Expand All @@ -105,20 +132,39 @@ gulp.task('sass', function () {
gulp.task('less', function () {
return gulp.src(defaultAssets.client.less)
.pipe(plugins.less())
.pipe(plugins.rename(function (path) {
path.dirname = path.dirname.replace('/less', '/css');
.pipe(plugins.autoprefixer())
.pipe(plugins.rename(function (file) {
file.dirname = file.dirname.replace(path.sep + 'less', path.sep + 'css');
}))
.pipe(gulp.dest('./modules/'));
});

// Angular template cache task
gulp.task('templatecache', function () {
var re = new RegExp('\\' + path.sep + 'client\\' + path.sep, 'g');

return gulp.src(defaultAssets.client.views)
.pipe(plugins.templateCache('templates.js', {
root: 'modules/',
module: 'core',
templateHeader: '(function () {' + endOfLine + ' \'use strict\';' + endOfLine + endOfLine + ' angular' + endOfLine + ' .module(\'<%= module %>\'<%= standalone %>)' + endOfLine + ' .run(templates);' + endOfLine + endOfLine + ' templates.$inject = [\'$templateCache\'];' + endOfLine + endOfLine + ' function templates($templateCache) {' + endOfLine,
templateBody: ' $templateCache.put(\'<%= url %>\', \'<%= contents %>\');',
templateFooter: ' }' + endOfLine + '})();' + endOfLine,
transformUrl: function (url) {
return url.replace(re, path.sep);
}
}))
.pipe(gulp.dest('build'));
});

// Mocha tests task
gulp.task('mocha', function (done) {
// Open mongoose connections
var mongoose = require('./config/lib/mongoose.js');
var error;

// Connect mongoose
mongoose.connect(function() {
mongoose.connect(function () {
// Run the tests
gulp.src(testAssets.tests.server)
.pipe(plugins.mocha({
Expand All @@ -128,9 +174,9 @@ gulp.task('mocha', function (done) {
// If an error occurs, save it
error = err;
})
.on('end', function() {
.on('end', function () {
// When the tests are done, disconnect mongoose and pass the error state back to gulp
mongoose.disconnect(function() {
mongoose.disconnect(function () {
done(error);
});
});
Expand Down Expand Up @@ -163,31 +209,39 @@ gulp.task('protractor', function () {
});

// Lint CSS and JavaScript files.
gulp.task('lint', function(done) {
gulp.task('lint', function (done) {
runSequence('less', 'sass', ['csslint', 'jshint'], done);
});

// Lint project files and minify them into two production files.
gulp.task('build', function(done) {
runSequence('env:dev' ,'lint', ['uglify', 'cssmin'], done);
gulp.task('build', function (done) {
runSequence('env:dev', 'lint', ['uglify', 'cssmin'], done);
});

// Run the project tests
gulp.task('test', function(done) {
gulp.task('test', function (done) {
runSequence('env:test', ['karma', 'mocha'], done);
});

gulp.task('test:server', function (done) {
runSequence('env:test', ['mocha'], done);
});

gulp.task('test:client', function (done) {
runSequence('env:test', ['karma'], done);
});

// Run the project in development mode
gulp.task('default', function(done) {
gulp.task('default', function (done) {
runSequence('env:dev', 'lint', ['nodemon', 'watch'], done);
});

// Run the project in debug mode
gulp.task('debug', function(done) {
gulp.task('debug', function (done) {
runSequence('env:dev', 'lint', ['nodemon', 'watch'], done);
});

// Run the project in production mode
gulp.task('prod', function(done) {
runSequence('build', 'lint', ['nodemon', 'watch'], done);
gulp.task('prod', function (done) {
runSequence('templatecache', 'build', 'env:prod', ['nodemon', 'watch'], done);
});
2 changes: 1 addition & 1 deletion modules/core/server/views/layout.server.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</head>

<body class="ng-cloak">
<header data-ng-include="'/modules/core/views/header.client.view.html'" class="navbar navbar-fixed-top navbar-inverse"></header>
<header data-ng-include="'modules/core/views/header.client.view.html'" class="navbar navbar-fixed-top navbar-inverse"></header>
<section class="content">
<section class="container">
{% block content %}{% endblock %}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"grunt-nodemon": "~0.4.0",
"grunt-protractor-runner": "^2.0.0",
"gulp": "^3.9.0",
"gulp-angular-templatecache": "^1.7.0",
"gulp-autoprefixer": "^2.3.1",
"gulp-concat": "^2.6.0",
"gulp-csslint": "~0.1.5",
"gulp-cssmin": "~0.1.7",
Expand All @@ -84,6 +86,7 @@
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.0.3",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.6",
"karma": "~0.12.37",
"karma-chrome-launcher": "~0.2.0",
"karma-coverage": "~0.4.2",
Expand Down

0 comments on commit cc02ecf

Please sign in to comment.