@salesforce/plugin-release-management
Version:
A plugin for preparing and publishing npm packages
88 lines • 3.37 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 path = require("path");
const os = require("os");
const chalk = require("chalk");
const command_1 = require("@salesforce/command");
const core_1 = require("@salesforce/core");
const ts_types_1 = require("@salesforce/ts-types");
const shelljs_1 = require("shelljs");
const types_1 = require("../../../types");
core_1.Messages.importMessagesDirectory(__dirname);
const messages = core_1.Messages.loadMessages('@salesforce/plugin-release-management', 'cli.tarballs.smoke');
class SmokeTest extends command_1.SfdxCommand {
// eslint-disable-next-line @typescript-eslint/require-await
async run() {
const cli = (0, ts_types_1.ensure)(this.flags.cli);
const executables = [path.join('tmp', cli, 'bin', cli)];
if (cli === types_1.CLI.SFDX) {
executables.push(path.join('tmp', cli, 'bin', types_1.CLI.SF));
}
for (const executable of executables) {
this.smokeTest(executable);
}
}
smokeTest(executable) {
this.execute(executable, '--version');
this.execute(executable, '--help');
this.execute(executable, 'plugins --core');
this.execute(executable, 'plugins:install @salesforce/plugin-alias@latest');
this.initializeAllCommands(executable);
}
initializeAllCommands(executable) {
for (const command of this.getAllCommands(executable)) {
if (this.flags.verbose) {
this.execute(executable, `${command} --help`);
}
else {
try {
this.execute(executable, `${command} --help`, true);
this.log(`${executable} ${command} --help ${chalk.green('PASSED')}`);
}
catch (err) {
this.log(`${executable} ${command} --help ${chalk.red('FAILED')}`);
throw err;
}
}
}
}
getAllCommands(executable) {
const commandsJson = JSON.parse(this.execute(executable, 'commands --json', true));
return commandsJson.map((c) => c.id);
}
execute(executable, args, silent = false) {
const command = `${executable} ${args}`;
const result = (0, shelljs_1.exec)(command, { silent: true });
if (result.code === 0) {
if (!silent) {
this.ux.styledHeader(command);
this.log(result.stdout);
}
return result.stdout;
}
else {
throw new core_1.SfError(`Failed: ${command}`);
}
}
}
exports.default = SmokeTest;
SmokeTest.description = messages.getMessage('description');
SmokeTest.examples = messages.getMessage('examples').split(os.EOL);
SmokeTest.flagsConfig = {
cli: command_1.flags.string({
description: messages.getMessage('cliFlag'),
options: Object.values(types_1.CLI),
char: 'c',
required: true,
}),
verbose: command_1.flags.builtin({
description: messages.getMessage('verboseFlag'),
}),
};
//# sourceMappingURL=smoke.js.map