var gulp = require ( 'gulp' ) ;
var path = require ( 'path' ) ;
var rename = require ( 'gulp-rename' ) ;
var livereload = require ( 'gulp-livereload' ) ;
var nodemon = require ( "gulp-nodemon" ) ;
var net = require ( "net" ) ;
var webpack = require ( "webpack-stream-fixed" ) ;
var webpackLib = require ( "webpack" )
const presetSCSS = require ( "@joepie91/gulp-preset-scss" ) ;
var nodemonRestarting = false ;
function tryReload ( ) {
if ( nodemonRestarting === false ) {
livereload . changed . apply ( null , arguments ) ;
}
}
/* The following resolves JacksonGariety/gulp-nodemon#33 */
process . once ( "SIGINT" , function ( ) {
process . exit ( 0 ) ;
} ) ;
gulp . task ( 'webpack' , function ( ) {
return gulp . src ( "./lib/frontend/index.js" )
. pipe ( webpack ( {
watch : true ,
module : {
preLoaders : [ {
test : /\.tag$/ ,
loader : "riotjs-loader" ,
exclude : /node_modules/ ,
query : {
type : "es6" ,
template : "pug" ,
/ * N O T E : ` n o d e - s a s s ` i s i m p l i c i t l y r e q u i r e d b a s e d o n t h e
` type ` attribute in the components * /
parserOptions : {
js : {
presets : [ "es2015-riot" ]
}
}
}
} ] ,
loaders : [
{ test : /\.js$/ , loader : "babel-loader" } ,
{ test : /\.json$/ , loader : "json-loader" } ,
//{ loader: "logging-loader" }
]
} ,
plugins : [ new webpackLib . ProvidePlugin ( { riot : "riot" } ) ] ,
resolveLoader : { root : path . join ( _ _dirname , "node_modules" ) } ,
resolve : {
extensions : [
"" ,
".tag" ,
".web.js" , ".js" ,
".web.json" , ".json"
]
} ,
debug : false
} ) )
. pipe ( rename ( "bundle.js" ) )
. pipe ( gulp . dest ( "./public/js" ) ) ;
} ) ;
gulp . task ( "scss" , ( ) => {
return gulp . src ( "./scss/**/*" )
. pipe ( presetSCSS ( {
livereload : livereload
} ) )
. pipe ( gulp . dest ( "./public/stylesheets/" ) ) ;
} ) ;
function checkServerUp ( ) {
setTimeout ( function ( ) {
var sock = new net . Socket ( ) ;
sock . setTimeout ( 50 ) ;
sock . on ( "connect" , function ( ) {
nodemonRestarting = false ;
console . log ( "Triggering page reload..." ) ;
tryReload ( "*" ) ;
sock . destroy ( ) ;
} )
. on ( "timeout" , checkServerUp )
. on ( "error" , checkServerUp )
. connect ( 3000 ) ;
} , 70 ) ;
}
gulp . task ( "nodemon" , function ( ) {
nodemon ( {
script : "./app.js" ,
delay : 500 ,
ignore : [ "public" ]
} ) . on ( "restart" , function ( ) {
nodemonRestarting = true ;
} ) . on ( "start" , checkServerUp ) ;
} )
gulp . task ( 'watch' , [ "nodemon" ] , function ( ) {
livereload . listen ( ) ;
gulp . watch ( [ './**/*.css' , 'views/**/*.pug' , '!views/client/**/*.pug' , 'package.json' , "./public/js/**/*.js" ] ) . on ( 'change' , tryReload ) ;
gulp . watch ( [ 'public/views/**/*.html' , 'public/elements/**/*' ] ) . on ( 'change' , function ( ) { tryReload ( "*" ) ; } ) ; // We need to explicitly reload everything here; Polymer doesn't do partial reloading
} ) ;
gulp . task ( "default" , [ "watch" , "webpack" ] ) ;