office-addin-dev-settings
Version:
Configure developer settings for Office Add-ins.
60 lines • 2.13 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.stopProcess = exports.startDetachedProcess = exports.startProcess = void 0;
const tslib_1 = require("tslib");
const child_process_1 = tslib_1.__importDefault(require("child_process"));
/* global console process */
function startProcess(commandLine, verbose = false) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
if (verbose) {
console.log(`Starting: ${commandLine}`);
}
child_process_1.default.exec(commandLine, (error, stdout /* eslint-disable-line @typescript-eslint/no-unused-vars */, stderr /* eslint-disable-line @typescript-eslint/no-unused-vars */) => {
if (error) {
reject(error);
}
else {
resolve();
}
});
});
});
}
exports.startProcess = startProcess;
function startDetachedProcess(commandLine, verbose = false) {
if (verbose) {
console.log(`Starting: ${commandLine}`);
}
const subprocess = child_process_1.default.spawn(commandLine, [], {
detached: true,
shell: true,
stdio: "ignore",
windowsHide: false,
});
subprocess.on("error", (err) => {
console.log(`Unable to run command: ${commandLine}.\n${err}`);
});
subprocess.unref();
return subprocess;
}
exports.startDetachedProcess = startDetachedProcess;
function stopProcess(processId) {
if (processId) {
try {
if (process.platform === "win32") {
child_process_1.default.spawn("taskkill", ["/pid", `${processId}`, "/f", "/t"]);
}
else {
process.kill(processId);
}
}
catch (err) {
console.log(`Unable to kill process id ${processId}: ${err}`);
}
}
}
exports.stopProcess = stopProcess;
//# sourceMappingURL=process.js.map