You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const path = require("path");
|
|
const xtend = require("xtend");
|
|
const runProcess = require("@joepie91/gulp-partial-run-process");
|
|
const namedLog = require("gulp-named-log");
|
|
const defaultValue = require("default-value");
|
|
|
|
const getProjectRoot = require("./get-project-root");
|
|
|
|
module.exports = function(options = {}) {
|
|
let electronLogger = namedLog("electron");
|
|
|
|
let environmentVariables = xtend(process.env, {
|
|
NODE_ENV: "development"
|
|
});
|
|
|
|
let electronBinary = defaultValue(options.electronBinary, () => {
|
|
return path.join(getProjectRoot(), "node_modules", ".bin", "electron");
|
|
}, {evaluate: true});
|
|
|
|
let projectRoot = defaultValue(options.projectRoot, () => {
|
|
return getProjectRoot();
|
|
}, {evaluate: true});
|
|
|
|
let processArguments = [projectRoot];
|
|
|
|
if (options.arguments != null && Array.isArray(options.arguments)) {
|
|
processArguments = options.arguments.concat(processArguments);
|
|
}
|
|
|
|
if (options.environmentVariables != null) {
|
|
environmentVariables = xtend(environmentVariables, options.environmentVariables);
|
|
}
|
|
|
|
var electronProcess = runProcess(electronBinary, processArguments, {
|
|
logger: electronLogger,
|
|
env: environmentVariables
|
|
});
|
|
|
|
return {
|
|
kill: electronProcess.kill.bind(electronProcess),
|
|
pid: electronProcess.pid
|
|
}
|
|
} |