appcenter-cli
Version:
Command line tool for Visual Studio App Center
93 lines (92 loc) • 3.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const chalk = require("chalk");
const interaction_1 = require("../../../util/interaction");
const childProcess = require("child_process");
exports.spawn = childProcess.spawn;
function getElectronProjectAppVersion(projectRoot) {
projectRoot = projectRoot || process.cwd();
try {
/* tslint:disable-next-line:non-literal-require */
const projectPackageJson = require(path.join(projectRoot, "package.json"));
const projectVersion = projectPackageJson.version;
if (!projectVersion) {
throw new Error(`The package.json file in "${projectRoot}" does not have the "version" field set.`);
}
return projectVersion;
}
catch (error) {
throw new Error(`Unable to find or read "package.json" in "${projectRoot}". The "release-electron" command must be executed in a Electron project folder.`);
}
}
exports.getElectronProjectAppVersion = getElectronProjectAppVersion;
function runWebPackBundleCommand(bundleName, mode, webpackConfig, entryFile, outputFolder, sourcemapFileName, extraBundlerOptions) {
const webpackArgs = [];
const envNodeArgs = process.env.CODE_PUSH_NODE_ARGS;
if (typeof envNodeArgs !== "undefined") {
Array.prototype.push.apply(webpackArgs, envNodeArgs.trim().split(/\s+/));
}
Array.prototype.push.apply(webpackArgs, [
path.join("node_modules", "webpack-cli", "bin", "cli.js"),
"--output-filename", bundleName,
"--output-path", outputFolder,
"--mode", mode,
"--entry-file", entryFile,
...extraBundlerOptions,
]);
if (webpackConfig) {
webpackArgs.push("--config", webpackConfig);
}
if (sourcemapFileName) {
webpackArgs.push("--output-source-map-filename", sourcemapFileName);
}
interaction_1.out.text(chalk.cyan(`Running "webpack bundle" command:\n`));
const webpackProcess = exports.spawn("node", webpackArgs);
interaction_1.out.text(`node ${webpackArgs.join(" ")}`);
return new Promise((resolve, reject) => {
webpackProcess.stdout.on("data", (data) => {
interaction_1.out.text(data.toString().trim());
});
webpackProcess.stderr.on("data", (data) => {
console.error(data.toString().trim());
});
webpackProcess.on("close", (exitCode) => {
if (exitCode) {
reject(new Error(`"webpack bundle" command exited with code ${exitCode}.`));
}
resolve(null);
});
});
}
exports.runWebPackBundleCommand = runWebPackBundleCommand;
function isValidOS(os) {
switch (os.toLowerCase()) {
case "linux":
case "macos":
case "windows":
return true;
default:
return false;
}
}
exports.isValidOS = isValidOS;
function isValidPlatform(platform) {
return platform.toLowerCase() === "electron";
}
exports.isValidPlatform = isValidPlatform;
function isElectronProject() {
try {
/* tslint:disable-next-line:non-literal-require */
const projectPackageJson = require(path.join(process.cwd(), "package.json"));
const projectName = projectPackageJson.name;
if (!projectName) {
throw new Error(`The "package.json" file in the CWD does not have the "name" field set.`);
}
return projectPackageJson.dependencies["electron"] || (projectPackageJson.devDependencies && projectPackageJson.devDependencies["electron"]);
}
catch (error) {
throw new Error(`Unable to find or read "package.json" in the CWD. The "release-electron" command must be executed in a Electron project folder.`);
}
}
exports.isElectronProject = isElectronProject;