Skip to content

Instantly share code, notes, and snippets.

@joepie91
Created March 16, 2016 06:38
Show Gist options
  • Save joepie91/5c88ca51d2b28db4eb00 to your computer and use it in GitHub Desktop.
Save joepie91/5c88ca51d2b28db4eb00 to your computer and use it in GitHub Desktop.
Gulpfile error swallowing failure case
'use strict';
const path = require('path');
const net = require("net");
const gulp = require('gulp');
const rename = require('gulp-rename');
const plumber = require('gulp-plumber');
const livereload = require('gulp-livereload');
const nodemon = require("gulp-nodemon");
const webpackStream = require("webpack-stream");
const webpack = require("webpack");
const namedLog = require("gulp-named-log");
const spy = require("through2-spy");
/* The following resolves JacksonGariety/gulp-nodemon#33 */
process.once("SIGINT", function() {
process.exit(0);
});
gulp.task('webpack', function(){
console.log("one");
try {
var wp = webpackStream({
watch: true,
module: {
preLoaders: [{ test: /\.tag$/, loader: "riotjs-loader", exclude: /node_modules/, query: { type: "babel", template: "jade" } }],
loaders: [
{
test: /\.js/,
loader: "babel-loader",
query: JSON.parse(fs.readFileSync("./.babelrc"))
},
{ test: /\.json$/, loader: "json-loader" },
]
},
plugins: [ new webpack.ProvidePlugin({riot: "riot"}) ],
resolve: {
extensions: [
"",
".tag",
".web.js", ".js",
".web.json", ".json"
]
}
});
} catch (err) {
console.err("error", err);
}
console.log("two");
return gulp.src("./src/index.js")
.pipe(plumber())
.pipe(wp)
.pipe(rename("bundle.js"))
.pipe(namedLog("webpack").stream())
.pipe(livereload())
.pipe(gulp.dest("./public/js"));
});
function checkServerUp(){
setTimeout(function(){
var sock = new net.Socket();
sock.setTimeout(50);
sock.on("connect", function(){
console.log("Triggering page reload...");
livereload.changed("*");
sock.destroy();
})
.on("timeout", checkServerUp)
.on("error", checkServerUp)
.connect(5000);
}, 70);
}
gulp.task('watch', function () {
livereload.listen();
gulp.watch(['./**/*.css', 'package.json', "./public/js/**/*.js"]).on('change', livereload.changed);
gulp.watch(['public/views/**/*.html', 'public/elements/**/*']).on('change', function() { livereload.changed("*"); });
nodemon({script: "./server.js", ext: "coffee", delay: 500}).on("start", checkServerUp);
});
gulp.task("default", ["watch", "webpack"]);
sven@linux-etoq:~/projects/riot-todo> gulp
one
[07:35:00] [nodemon] 1.9.1
[07:35:00] [nodemon] to restart at any time, enter `rs`
[07:35:00] [nodemon] watching: *.*
[07:35:00] [nodemon] starting `node ./server.js`
Triggering page reload...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment