Browse Source

Abstract out more of the build stack

master
Sven Slootweg 5 years ago
parent
commit
4bcb3fb0a1
  1. 21
      gulpfile.js
  2. 10
      package.json
  3. 11
      src/gulp/log-stream.js
  4. 11
      src/gulp/patch-livereload-logger.js
  5. 28
      src/gulp/run-process.js

21
gulpfile.js

@ -6,24 +6,16 @@ var rfr = require("rfr");
var livereload = require("gulp-livereload");
var rename = require("gulp-rename");
var namedLog = require("gulp-named-log");
var presetES2015 = require("@joepie91/gulp-preset-es2015");
var presetJade = require("@joepie91/gulp-preset-jade");
var presetSCSS = require("@joepie91/gulp-preset-scss");
var presetRiot = require("@joepie91/gulp-preset-riot");
var runProcess = rfr("src/gulp/run-process");
var patchLivereloadLogger = rfr("src/gulp/patch-livereload-logger");
var patchLivereloadLogger = require("@joepie91/gulp-partial-patch-livereload-logger");
var runElectron = require("@joepie91/gulp-partial-electron");
var loggerOptions = {
basePath: __dirname
}
var electronLogger = namedLog("electron", loggerOptions);
var livereloadLogger = namedLog("livereload", loggerOptions);
patchLivereloadLogger(livereload, livereloadLogger);
patchLivereloadLogger(livereload);
var sources = {
"babel-main": "app.js",
@ -34,12 +26,7 @@ var sources = {
}
gulp.task("electron", ['babel-lib', 'babel-main', 'jade-views', 'sass-main', 'riot-components'], function() {
var electronProcess = runProcess(path.join(__dirname, "node_modules/.bin/electron"), [__dirname], {
logger: electronLogger,
env: xtend(process.env, {
NODE_ENV: "development"
})
});
var electronProcess = runElectron();
});
gulp.task('babel-main', function() {

10
package.json

@ -26,8 +26,6 @@
"document-ready-promise": "^3.0.1",
"electron-prebuilt": "^0.37.5",
"file-url": "^1.1.0",
"gulp-named-log": "0.0.1",
"gulp-sass": "^2.2.0",
"ia-headers": "^1.0.0",
"jquery": "^2.2.3",
"natural-sort": "^1.0.0",
@ -37,6 +35,8 @@
"xtend": "^4.0.1"
},
"devDependencies": {
"@joepie91/gulp-partial-electron": "^1.0.1",
"@joepie91/gulp-partial-patch-livereload-logger": "^1.0.0",
"@joepie91/gulp-preset-es2015": "^1.0.0",
"@joepie91/gulp-preset-jade": "^1.0.0",
"@joepie91/gulp-preset-riot": "^1.0.0",
@ -45,14 +45,8 @@
"babel-preset-es2015": "^6.6.0",
"babel-preset-es2015-riot": "^1.0.4",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-cached": "^1.1.0",
"gulp-jade": "^1.1.0",
"gulp-livereload": "^3.8.1",
"gulp-plumber": "^1.1.0",
"gulp-remember": "^0.3.1",
"gulp-rename": "^1.2.2",
"gulp-riot": "^0.4.9",
"jade": "^1.11.0",
"node-sass": "^3.4.2",
"split": "^1.0.0",

11
src/gulp/log-stream.js

@ -1,11 +0,0 @@
'use strict';
const split = require("split");
module.exports = function logStream(stream, logger) {
stream.pipe(split()).on("data", function(data) {
if (data.trim() !== "") {
logger(data);
}
})
}

11
src/gulp/patch-livereload-logger.js

@ -1,11 +0,0 @@
'use strict';
const chalk = require("chalk");
module.exports = function(livereload, logger) {
var _oldChanged = livereload.changed.bind(livereload);
livereload.changed = function(filePath) {
logger.log(chalk.magenta(filePath) + " reloaded.");
_oldChanged.apply(null, arguments);
}
}

28
src/gulp/run-process.js

@ -1,28 +0,0 @@
'use strict';
const childProcess = require("child_process");
const rfr = require("rfr");
const logStream = rfr("src/gulp/log-stream");
module.exports = function runProcess(path, args, options) {
if (options.logger != null) {
options.logger.info(`Starting ${path}...`);
}
let proc = childProcess.spawn(path, args, options);
if (options.logger != null) {
logStream(proc.stdout, options.logger.log);
logStream(proc.stderr, options.logger.error);
}
proc.on("error", (err) => {
if (options.logger != null) {
options.logger.error(err.stack);
}
});
proc.on("close", (code) => {
options.logger.info(`Exited with code ${code.toString()}: ${path}.`);
});
}
Loading…
Cancel
Save