Last active
March 8, 2017 02:58
-
-
Save TheEnigmaBlade/fc8e9883984aabd0064cadb580625146 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const gulp = require("gulp"); | |
var plumber = require("gulp-plumber"); | |
var sass = require("gulp-sass"); | |
var sourcemaps = require("gulp-sourcemaps"); | |
var exec = require("gulp-exec"); | |
var rename = require("gulp-rename"); | |
var tap = require("gulp-tap"); | |
var handlebars = require("handlebars"); | |
var glob = require("glob"); | |
var fs = require("fs"); | |
var path = require("path"); | |
var pkg = require("../package.json"); | |
var dirs = pkg.directories; | |
var gprint = require("gulp-print"); | |
const electronRebuild = require("electron-rebuild"); | |
let childProcess = require("child_process"); | |
let pathToElectron = require("electron-prebuilt"); | |
gulp.task("build:app", function() { | |
//TODO: copy dependencies from top-level package.json and copy to src/package.json | |
gulp.src(dirs.src+"/**/*.json") | |
.pipe(gulp.dest(dirs.build)); | |
}); | |
gulp.task("build:sass", function() { | |
gulp.src(dirs.src+"/**/*.{sass,scss}") | |
.pipe(plumber()) | |
.pipe(sourcemaps.init()) | |
.pipe(sass().on("error", sass.logError)) | |
.pipe(sourcemaps.write("./")) | |
.pipe(gulp.dest(dirs.build)); | |
}); | |
gulp.task("build:gs", function() { | |
let options = { | |
continueOnError: false, | |
pipeStdout: true | |
}; | |
gulp.src(dirs.src+"/**/*.gs") | |
.pipe(plumber()) | |
.pipe(exec("guavac \"<%= file.path %>\"", options)) | |
.pipe(rename(function(path) { | |
path.extname = ".js"; | |
})) | |
.pipe(gulp.dest(dirs.build)); | |
}); | |
gulp.task("build:js", function() { | |
gulp.src(dirs.src+"/**/*.js").pipe(gulp.dest(dirs.build)); | |
}); | |
gulp.task("build:html", function() { | |
const partialExt = ".partial.html"; | |
let partialFiles = glob.sync(dirs.src+"/**/*"+partialExt); | |
partialFiles.forEach(function(filename) { | |
var name = path.basename(filename, partialExt); | |
console.log("Using partial: "+name+" ("+filename+")"); | |
var partial = fs.readFileSync(filename, "utf8"); | |
handlebars.registerPartial(name, partial); | |
}); | |
gulp.src([ | |
dirs.src+"/**/*.html", | |
"!"+dirs.src+"/**/*.partial.html" | |
]) | |
.pipe(plumber()) | |
//.pipe(handlebars({})) | |
.pipe(tap(function(file) { | |
var template = handlebars.compile(file.contents.toString()); | |
var html = template({}); | |
file.contents = new Buffer(html); | |
})) | |
.pipe(gulp.dest(dirs.build)); | |
}); | |
gulp.task("build:resources", function() { | |
gulp.src(dirs.src+"/resources/**/*.{woff,ttf,png,jpg}") | |
.pipe(gulp.dest(dirs.build+"/resources")); | |
}); | |
gulp.task("watch", function() { | |
gulp.watch(dirs.src+"/**/*.json", ["build:app"]); | |
gulp.watch(dirs.src+"/**/*.{sass,scss}", ["build:sass"]); | |
gulp.watch(dirs.src+"/**/*.gs", ["build:gs"]); | |
gulp.watch(dirs.src+"/**/*.js", ["build:js"]); | |
gulp.watch(dirs.src+"/**/*.html", ["build:html"]); | |
gulp.watch(dirs.src+"/resources/**/*.{woff,ttf,png,jpg}", ["build:resources"]); | |
}); | |
gulp.task("rebuild", function() { | |
electronRebuild.shouldRebuildNativeModules(pathToElectron) | |
.then((shouldBuild) => { | |
if (!shouldBuild) { | |
return true; | |
} | |
console.log("Rebuilding..."); | |
let electronVersion = childProcess.execSync(`"${pathToElectron}" --version`, {encoding: "utf8"}); | |
electronVersion = electronVersion.match(/v(\d+\.\d+\.\d+)/)[1]; | |
console.log(` Electron version: ${electronVersion}`); | |
return electronRebuild.installNodeHeaders(electronVersion) | |
.then(() => electronRebuild.rebuildNativeModules(electronVersion, "./build/node_modules")) | |
.then(() => electronRebuild.preGypFixRun("./build/node_modules", true, pathToElectron)); | |
}) | |
.catch((e) => { | |
console.error("Building modules didn't work!"); | |
console.error(e); | |
}); | |
}); | |
gulp.task("build", ["build:app", "build:sass", "build:gs", "build:js", "build:html", "build:resources"]); | |
gulp.task("fullbuild", ["build", "rebuild"]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
require("./tasks/build"); | |
require("./tasks/start"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
... | |
"scripts": { | |
"build": "gulp build", | |
"start": "gulp start" | |
}, | |
"devDependencies": { | |
... | |
"glob": "^7.1.1", | |
"gulp": "3.9.1", | |
"gulp-batch": "1.0.5", | |
"gulp-exec": "2.1.2", | |
"gulp-mocha": "3.0.1", | |
"gulp-plumber": "1.1.0", | |
"gulp-rename": "1.2.2", | |
"gulp-sass": "2.3.2", | |
"gulp-sourcemaps": "1.6.0", | |
"gulp-tap": "0.1.3", | |
"handlebars": "4.0.6" | |
}, | |
"directories": { | |
"src": "src", | |
"build": "build", | |
"dist": "dist" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const childProcess = require("child_process"); | |
const electron = require("electron-prebuilt"); | |
const gulp = require("gulp"); | |
var build_dir = "./build"; | |
gulp.task("start", ["build", "watch"], function () { | |
childProcess.spawn(electron, [build_dir], { | |
stdio: "inherit" | |
}) | |
.on("close", function() { | |
process.exit(); | |
}) | |
.on("error", function() { | |
console.log("Closed due to error") | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment