@salesforce/plugin-release-management
Version:
A plugin for preparing and publishing npm packages
155 lines • 6 kB
JavaScript
;
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
Object.defineProperty(exports, "__esModule", { value: true });
const os = require("os");
const chalk = require("chalk");
const command_1 = require("@salesforce/command");
const core_1 = require("@salesforce/core");
const shelljs_1 = require("shelljs");
const dependencies_1 = require("../../../dependencies");
const repository_1 = require("../../../repository");
core_1.Messages.importMessagesDirectory(__dirname);
const messages = core_1.Messages.loadMessages('@salesforce/plugin-release-management', 'npm.package.release');
class Release extends command_1.SfdxCommand {
async run() {
const deps = (0, dependencies_1.verifyDependencies)(this.flags);
if (deps.failures > 0) {
const errType = 'MissingDependencies';
const missing = deps.results.filter((d) => d.passed === false).map((d) => d.message);
throw new core_1.SfError(messages.getMessage(errType), errType, missing);
}
const pkg = await repository_1.PackageRepo.create({ ux: this.ux, useprerelease: this.flags.prerelease });
if (!pkg.shouldBePublished) {
this.ux.log('Found no commits that warrant a release. Exiting...');
return;
}
await pkg.writeNpmToken();
if (this.flags.githubtag) {
this.ux.log(`Using Version: ${pkg.nextVersion}`);
}
else {
pkg.printStage('Validate Next Version');
const pkgValidation = pkg.validate();
if (!pkgValidation.valid) {
const errType = 'InvalidNextVersion';
throw new core_1.SfError(messages.getMessage(errType, [pkgValidation.nextVersion]), errType);
}
this.ux.log(`Name: ${pkgValidation.name}`);
this.ux.log(`Current Version: ${pkgValidation.currentVersion}`);
this.ux.log(`Next Version: ${pkgValidation.nextVersion}`);
}
if (this.flags.install) {
pkg.printStage('Install');
pkg.install();
pkg.printStage('Build');
pkg.build();
}
if (!this.flags.githubtag) {
pkg.printStage('Prepare Release');
pkg.prepare({ dryrun: this.flags.dryrun });
}
let signature;
if (this.flags.sign && !this.flags.dryrun) {
pkg.printStage('Sign and Upload Security Files');
signature = await pkg.sign();
}
pkg.printStage('Publish');
try {
await pkg.publish({
signatures: [signature],
access: this.flags.npmaccess,
tag: this.flags.npmtag,
dryrun: this.flags.dryrun,
});
}
catch (e) {
this.error(e, { code: 'NPM_PUBLISH_FAILED', exit: 1 });
}
if (!this.flags.dryrun && this.flags.verify) {
pkg.printStage('Waiting For Availability');
const found = await pkg.waitForAvailability();
if (!found) {
this.ux.warn(`Exceeded timeout waiting for ${pkg.name}@${pkg.nextVersion} to become available`);
}
}
try {
if (this.flags.sign && this.flags.verify && !this.flags.dryrun) {
pkg.printStage('Verify Signed Packaged');
this.verifySign(pkg.getPkgInfo());
}
}
finally {
if (!this.flags.dryrun && !this.flags.githubtag) {
pkg.printStage('Push Changes to Git');
pkg.pushChangesToGit();
}
}
this.ux.log(pkg.getSuccessMessage());
return {
version: pkg.nextVersion,
name: pkg.name,
};
}
verifySign(pkgInfo) {
const cmd = 'plugins:trust:verify';
const argv = `--npm ${pkgInfo.name}@${pkgInfo.nextVersion} ${pkgInfo.registryParam}`;
this.ux.log(chalk.dim(`sf-release ${cmd} ${argv}`) + os.EOL);
try {
const result = (0, shelljs_1.exec)(`DEBUG=sfdx:* ${this.config.root}/bin/run ${cmd} ${argv}`);
if (result.code !== 0) {
const sfdxVerifyCmd = `sfdx plugins:trust:verify ${argv}`;
this.ux.warn('Unable to verify the package signature due to:\n\nFailed to find @salesforce/sfdx-scanner@3.1.0 in the registry\n' +
`\nYou can manually validate the package signature by running:\n\n${sfdxVerifyCmd}\n`);
}
}
catch (err) {
throw new core_1.SfError(err, 'FailedCommandExecution');
}
}
}
exports.default = Release;
Release.description = messages.getMessage('description');
Release.flagsConfig = {
dryrun: command_1.flags.boolean({
char: 'd',
default: false,
description: messages.getMessage('dryrun'),
}),
sign: command_1.flags.boolean({
char: 's',
default: false,
description: messages.getMessage('sign'),
}),
npmtag: command_1.flags.string({
char: 't',
default: 'latest',
description: messages.getMessage('npmTag'),
}),
npmaccess: command_1.flags.string({
char: 'a',
default: 'public',
description: messages.getMessage('npmAccess'),
}),
install: command_1.flags.boolean({
default: true,
description: messages.getMessage('install'),
allowNo: true,
}),
prerelease: command_1.flags.string({
description: messages.getMessage('prerelease'),
}),
verify: command_1.flags.boolean({
description: messages.getMessage('verify'),
default: true,
allowNo: true,
}),
githubtag: command_1.flags.string({
description: messages.getMessage('githubtag'),
}),
};
//# sourceMappingURL=release.js.map