Closed pford68 closed 8 years ago
Add the dev tasks
/**
* Gulp tasks specific to development.
*
*
* NOTES:
* (1) The livereload module works best with Chrome's Livereload extension:
* See https://www.npmjs.org/package/gulp-livereload
*/
var gulp = require('gulp'),
gutil = require('gulp-util'),
jshint = require('gulp-jshint'),
csslint = require('gulp-csslint'),
async = require("async"),
seedData = require("./users.json"),
livereload = require('gulp-livereload'), // See Note 1 above
MongoDriver = require('mongodb'),
config = require("config"),
conn = config.connection,
entanglement = require("./entanglement"),
components = require("./components");
/*
Build/rebuild the dev database
*/
gulp.task('rebuild-dev', function(){
var DB = new MongoDriver.Db(conn.database, new MongoDriver.Server(conn.host, conn.port), { w: 1 });
var userCollection = DB.collection("users");
async.series([
function(cmd){
DB.open(function (err, db){
if (err) throw err;
cmd(null, "Connected to the database " + config.database);
});
},
function(cmd) {
userCollection.drop(function(err, result){
cmd(null, "User collection cleared");
});
},
function(cmd) {
userCollection.insert(seedData, { w: 1 }, function (err, result) {
DB.close();
cmd(err, result);
});
}
]);
});
/*
Linting all sub-projects
*/
gulp.task('lint', function() {
return gulp.src(['./src/**/*.js', '!./src/lib/**'])
.pipe(jshint())
// You can look into pretty reporters as well, but that's another story
.pipe(jshint.reporter('default'));
});
gulp.task('css-lint', ['build:ent', 'build:components'], function() {
return gulp.src(['./build/**/*.css', '!./build/lib/**/*.css'])
.pipe(csslint())
// You can look into pretty reporters as well, but that's another story
.pipe(csslint.reporter());
});
/*
Browserify task
*/
gulp.task('browserify', ['browserify:ent', 'browserify:components'], function(done){
done();
});
/*
Watching for changes to src files, and reloading the browser after any changes.
*/
gulp.task('watch', ['lint', 'browserify'], function() {
// Running lint and browserify on JS src changes and deploying the changes.
gulp.watch(['./src/**/*.js', './src/**/*.json', '!src/lib/**'],[
'lint',
'browserify'
]);
// Deploying changes to HTML and CSS files
// gulp.watch(['./src/**/*.html', './src/**/*.scss', '!src/lib/**'], [
//'views:ent',
//'views:components'
// ]);
// Reloading the browser when changes are deployed.
gulp.watch('./build/**').on('change', livereload.changed);
});
/*
Start local dev server
*/
gulp.task('dev', ['watch'], function() {
// Start webserver
require("../server").start(9000); // Requiring the server only when needed because it requires services that start DB connections.
// Start live reload
livereload.listen();
});
I copy from the resources directory, rather than generate.
Template