Skip to content

Instantly share code, notes, and snippets.

@VinayaSathyanarayana
Forked from stevenkaspar/gulpfile.js
Created November 15, 2017 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VinayaSathyanarayana/ffb00dfe9c66d09479966b4aae1e9dfc to your computer and use it in GitHub Desktop.
Save VinayaSathyanarayana/ffb00dfe9c66d09479966b4aae1e9dfc to your computer and use it in GitHub Desktop.
KeystoneJS SASS Development Gulpfile
/**
* gulp file that will restart keystonejs app and compile sass
*/
'use strict';
var gulp = require('gulp');
var watch = require('gulp-watch');
var shell = require('gulp-shell')
var sass = require('gulp-sass');
var paths = {
'src':['./models/**/*.js','./routes/**/*.js', 'keystone.js', 'package.json']
,
'style': {
all: './public/styles/**/*.scss',
output: './public/styles/'
}
};
gulp.task('watch:sass', function () {
gulp.watch(paths.style.all, ['sass']);
});
gulp.task('sass', function(){
gulp.src(paths.style.all)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(paths.style.output));
});
/**
* logic for starting and restarting server process
*/
// node process
const spawn = require('child_process').spawn;
var node_process;
//
const dest_path = `.`;
let restartServer = function(){
node_process.kill();
node_process = startServer();
}
let startServer = function(){
var local_node_process = spawn('node', ['keystone'], {cwd: dest_path});
local_node_process.on('close', (code, signal) => {
console.log(`-- Server process closed --`);
});
local_node_process.stdout.on('data', (data) => {
console.log(`${data}`);
});
local_node_process.stderr.on('data', (data) => {
console.log(`Error: ${data}`);
});
return local_node_process;
}
const server_files = ['./models/**/*.js','./routes/**/*.js', 'keystone.js', 'package.json'];
const watcher = gulp.watch(server_files);
watcher.on('change', function(event){
restartServer();
})
// start the server process
node_process = startServer();
//gulp.task('runKeystone', shell.task('node keystone.js'));
gulp.task('watch', [
'watch:sass',
]);
gulp.task('default', ['watch']);//, 'runKeystone']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment