@salesforce/plugin-release-management
Version:
A plugin for preparing and publishing npm packages
68 lines • 3.02 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 command_1 = require("@salesforce/command");
const core_1 = require("@salesforce/core");
const kit_1 = require("@salesforce/kit");
const ts_types_1 = require("@salesforce/ts-types");
const shelljs_1 = require("shelljs");
const chalk_1 = require("chalk");
const repository_1 = require("../../../repository");
core_1.Messages.importMessagesDirectory(__dirname);
const messages = core_1.Messages.loadMessages('@salesforce/plugin-release-management', 'npm.package.promote');
class Promote extends command_1.SfdxCommand {
async run() {
const pkg = await repository_1.PackageRepo.create({ ux: this.ux });
await pkg.writeNpmToken();
const token = (0, ts_types_1.ensureString)(new kit_1.Env().getString('NPM_TOKEN'), 'NPM_TOKEN must be set in the environment');
const tokens = JSON.parse((0, shelljs_1.exec)('npm token list --json', { silent: true }).stdout);
const publishTokens = tokens.filter((t) => t.readonly === false && t.automation === false);
const match = publishTokens.find((t) => token.substring(0, 6) === t.token);
if (!match) {
const errType = 'InvalidToken';
throw new core_1.SfError(messages.getMessage(errType), errType);
}
const tags = pkg.package.npmPackage['dist-tags'];
const candidate = (0, ts_types_1.ensureString)(this.flags.candidate);
const target = (0, ts_types_1.ensureString)(this.flags.target);
if (!tags[candidate]) {
const errType = 'InvalidTag';
throw new core_1.SfError(messages.getMessage(errType, [candidate]), errType);
}
this.log(`Promoting ${pkg.name}@${tags[candidate]} from ${(0, chalk_1.bold)(candidate)} to ${(0, chalk_1.bold)(target)}`);
if (target) {
this.warn(`This will overwrite the existing ${target} version: ${tags[target]}`);
this.log();
}
if (!this.flags.dryrun) {
(0, shelljs_1.exec)(`npm dist-tag add ${pkg.name}@${tags[candidate]} ${target} --json`);
}
}
}
exports.default = Promote;
Promote.description = messages.getMessage('description');
Promote.examples = messages.getMessage('examples').split(os.EOL);
Promote.flagsConfig = {
dryrun: command_1.flags.boolean({
char: 'd',
default: false,
description: messages.getMessage('dryrun'),
}),
target: command_1.flags.string({
char: 't',
default: 'latest',
description: messages.getMessage('target'),
}),
candidate: command_1.flags.string({
char: 'c',
description: messages.getMessage('candidate'),
required: true,
}),
};
//# sourceMappingURL=promote.js.map