UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

170 lines (169 loc) 10.2 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const commandline_1 = require("../../util/commandline"); const codepush_release_command_base_1 = require("./lib/codepush-release-command-base"); const interaction_1 = require("../../util/interaction"); const util_1 = require("util"); const pfs = require("../../util/misc/promisfied-fs"); const path = require("path"); const mkdirp = require("mkdirp"); const file_utils_1 = require("./lib/file-utils"); const validation_utils_1 = require("./lib/validation-utils"); const electron_utils_1 = require("./lib/electron-utils"); const chalk = require("chalk"); const debug = require("debug")("appcenter-cli:commands:codepush:release-electron"); let CodePushReleaseElectronCommand = class CodePushReleaseElectronCommand extends codepush_release_command_base_1.default { run(client) { return __awaiter(this, void 0, void 0, function* () { if (!electron_utils_1.isElectronProject()) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `The project in the CWD is not a Electron project.`); } if (!(yield validation_utils_1.isValidDeployment(client, this.app, this.specifiedDeploymentName))) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `Deployment "${this.specifiedDeploymentName}" does not exist.`); } else { this.deploymentName = this.specifiedDeploymentName; } const appInfo = yield interaction_1.out.progress("Getting app info...", client.apps.get(this.app.ownerName, this.app.appName)); this.os = appInfo.os.toLowerCase(); this.updateContentsPath = this.outputDir || (yield pfs.mkTempDir("code-push")); // we have to add "CodePush" root folder to make update contents file structure // to be compatible with Electron-CodePush client SDK this.updateContentsPath = path.join(this.updateContentsPath, "CodePush"); mkdirp.sync(this.updateContentsPath); if (!electron_utils_1.isValidOS(this.os)) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `OS must be "linux", "macos" or "windows".`); } if (!this.bundleName) { this.bundleName = `index.electron.bundle`; } this.mode = this.development ? "development" : "production"; if (!this.config) { if (!file_utils_1.fileDoesNotExistOrIsDirectory("webpack.config.js")) { this.config = "webpack.config.js"; } } else { if (file_utils_1.fileDoesNotExistOrIsDirectory(this.config)) { return commandline_1.failure(commandline_1.ErrorCodes.NotFound, `WebPack Config file "${this.config}" does not exist.`); } } if (!this.entryFile) { this.entryFile = `index.${this.os}.js`; if (file_utils_1.fileDoesNotExistOrIsDirectory(this.entryFile)) { this.entryFile = `index.js`; } if (file_utils_1.fileDoesNotExistOrIsDirectory(this.entryFile)) { return commandline_1.failure(commandline_1.ErrorCodes.NotFound, `Entry file "index.${this.os}.js" or "index.js" does not exist.`); } } else { if (file_utils_1.fileDoesNotExistOrIsDirectory(this.entryFile)) { return commandline_1.failure(commandline_1.ErrorCodes.NotFound, `Entry file "${this.entryFile}" does not exist.`); } } if (this.sourcemapOutputDir && this.sourcemapOutput) { interaction_1.out.text('\n"sourcemap-output-dir" argument will be ignored as "sourcemap-output" argument is provided.\n'); } if ((this.outputDir || this.sourcemapOutputDir) && !this.sourcemapOutput) { const sourcemapDir = this.sourcemapOutputDir || this.updateContentsPath; this.sourcemapOutput = path.join(sourcemapDir, this.bundleName + ".map"); } this.targetBinaryVersion = this.specifiedTargetBinaryVersion; if (this.targetBinaryVersion && !validation_utils_1.isValidRange(this.targetBinaryVersion)) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, "Invalid binary version(s) for a release."); } else if (!this.targetBinaryVersion) { this.targetBinaryVersion = yield electron_utils_1.getElectronProjectAppVersion(); } if (typeof this.extraBundlerOptions === "string") { this.extraBundlerOptions = [this.extraBundlerOptions]; } try { file_utils_1.createEmptyTmpReleaseFolder(this.updateContentsPath); yield electron_utils_1.runWebPackBundleCommand(this.bundleName, this.mode, this.config, this.entryFile, this.updateContentsPath, this.sourcemapOutput, this.extraBundlerOptions); interaction_1.out.text(chalk.cyan("\nReleasing update contents to CodePush:\n")); return yield this.release(client); } catch (error) { debug(`Failed to release a CodePush update - ${util_1.inspect(error)}`); return commandline_1.failure(commandline_1.ErrorCodes.Exception, "Failed to release a CodePush update."); } finally { if (!this.outputDir) { yield pfs.rmDir(this.updateContentsPath); } } }); } }; __decorate([ commandline_1.help("Name of the generated JS bundle file. If unspecified, the standard bundle name will be used 'index.electron.bundle'"), commandline_1.shortName("b"), commandline_1.longName("bundle-name"), commandline_1.hasArg ], CodePushReleaseElectronCommand.prototype, "bundleName", void 0); __decorate([ commandline_1.help("Specifies whether to generate a Development or Production build"), commandline_1.longName("development") ], CodePushReleaseElectronCommand.prototype, "development", void 0); __decorate([ commandline_1.help('Path to the webpack config file. If omitted, "webpack.config.js" will be used (if they exist)'), commandline_1.shortName("c"), commandline_1.longName("config"), commandline_1.hasArg ], CodePushReleaseElectronCommand.prototype, "config", void 0); __decorate([ commandline_1.help('Path to the app\'s entry JavaScript file. If omitted, "index.<platform>.js" and then "index.js" will be used (if they exist)'), commandline_1.shortName("e"), commandline_1.longName("entry-file"), commandline_1.hasArg ], CodePushReleaseElectronCommand.prototype, "entryFile", void 0); __decorate([ commandline_1.help("Filename (including path) for the sourcemap of the resulting bundle. If 'sourcemap-output' and 'sourcemap-output-dir' are omitted, a sourcemap will not be generated"), commandline_1.shortName("s"), commandline_1.longName("sourcemap-output"), commandline_1.hasArg ], CodePushReleaseElectronCommand.prototype, "sourcemapOutput", void 0); __decorate([ commandline_1.help("Path to directory where the sourcemap for the resulting bundle should be written. Name of sourcemap file will be generated automatically. This argument will be ignored if 'sourcemap-output' argument is provided. If 'sourcemap-output' and 'sourcemap-output-dir' are omitted, a sourcemap will not be generated"), commandline_1.longName("sourcemap-output-dir"), commandline_1.hasArg ], CodePushReleaseElectronCommand.prototype, "sourcemapOutputDir", void 0); __decorate([ commandline_1.help("Output path for the bundle and sourcemap. If omitted, a bundle and sourcemap will not be generated"), commandline_1.shortName("o"), commandline_1.longName("output-dir"), commandline_1.hasArg ], CodePushReleaseElectronCommand.prototype, "outputDir", void 0); __decorate([ commandline_1.help("Semver expression that specifies the binary app version(s) this release is targeting (e.g. 1.1.0, ~1.2.3)"), commandline_1.shortName("t"), commandline_1.longName("target-binary-version"), commandline_1.hasArg ], CodePushReleaseElectronCommand.prototype, "specifiedTargetBinaryVersion", void 0); __decorate([ commandline_1.help("Option that gets passed to webpack bundler. Can be specified multiple times"), commandline_1.longName("extra-bundler-option"), commandline_1.defaultValue([]), commandline_1.hasArg ], CodePushReleaseElectronCommand.prototype, "extraBundlerOptions", void 0); CodePushReleaseElectronCommand = __decorate([ commandline_1.help("Release an Electron update to a deployment") ], CodePushReleaseElectronCommand); exports.default = CodePushReleaseElectronCommand;