@copado/copado-cli
Version:
Copado Developer CLI
95 lines • 4.68 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const inquirer = __importStar(require("inquirer"));
const core_1 = require("@salesforce/core");
const theme_1 = __importDefault(require("../../../service/theme"));
const restConnections_1 = require("../../../service/restConnections");
const repositories_1 = __importDefault(require("../../../selector/repositories"));
const sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
core_1.Messages.importMessagesDirectory(__dirname);
const messages = core_1.Messages.loadMessages('@copado/copado-cli', 'copado_pipeline');
class CreatePipeline extends sf_plugins_core_1.SfCommand {
async run() {
const ux = new sf_plugins_core_1.Ux({ jsonEnabled: this.jsonEnabled() });
const { flags } = await this.parse(CreatePipeline);
try {
const pipelineRecord = await this.pipelineRecord(flags);
ux.spinner.start('Creating pipeline');
const result = await restConnections_1.RestConnections.create('copado__Deployment_Flow__c', pipelineRecord);
ux.spinner.stop();
ux.log(theme_1.default.status.Successful(messages.getMessage('create.success')));
ux.log(`${messages.getMessage('create.openInstruction')} ${theme_1.default.format.underlineBold(messages.getMessage('create.openExample'), result.id)}`);
return result;
}
catch (error) {
ux.spinner.stop();
throw new core_1.SfError(error.message);
}
}
async pipelineRecord(flags) {
const repositoryId = flags.repository || await this.askRepository();
return {
Name: flags.name,
copado__Active__c: true,
copado__Platform__c: flags.platform,
copado__Git_Repository__c: repositoryId,
copado__Main_Branch__c: flags.branch
};
}
async askRepository() {
const repositoryOptions = await this.repositoryOptions();
const selectedRepository = await inquirer.prompt(repositoryOptions);
return selectedRepository.Id;
}
async repositoryOptions() {
const ux = new sf_plugins_core_1.Ux();
ux.spinner.start('Fetching Repository');
const repositories = await new repositories_1.default().all();
ux.spinner.stop();
return [{
name: 'Id',
type: 'list',
message: 'Select Repository',
choices: repositories === null || repositories === void 0 ? void 0 : repositories.map(repository => ({ name: repository.Name, value: repository.Id }))
}];
}
static flagConfig() {
return {
name: sf_plugins_core_1.Flags.string({ char: 'n', description: messages.getMessage('create.flags.name'), required: true }),
platform: sf_plugins_core_1.Flags.string({ char: 't', description: messages.getMessage('create.flags.platform'), default: 'Other' }),
branch: sf_plugins_core_1.Flags.string({ char: 'b', description: messages.getMessage('create.flags.branch'), default: 'main' }),
repository: sf_plugins_core_1.Flags.string({ char: 'r', description: messages.getMessage('create.flags.repository') })
};
}
}
exports.default = CreatePipeline;
CreatePipeline.description = messages.getMessage('create.description');
CreatePipeline.examples = [messages.getMessage('create.example')];
CreatePipeline.flags = CreatePipeline.flagConfig();
//# sourceMappingURL=create.js.map