@sfdx-falcon/builder-library
Version:
Collection of functions for building pre-defined SFDX-Falcon Tasks, Questions, and Task Bundles. Allows developers to quickly build common Task and Interview-driven workflows in their CLI plugins. Part of the SFDX-Falcon Library.
147 lines • 10.6 kB
JavaScript
;
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
/**
* @author Vivek M. Chawla <@VivekMChawla>
* @copyright 2019, Vivek M. Chawla / Salesforce. All rights reserved.
* @license BSD-3-Clause For full license text, see the LICENSE file in the repo root or
* `https://opensource.org/licenses/BSD-3-Clause`
* @file packages/builder-library/src/questions/sfdx.ts
* @summary Exports `Builder` classes for questions related to Salesforce DX functionality.
* @description Exports `Builder` classes for questions related to Salesforce DX functionality.
*/
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
// Import External Libraries, Modules, and Types
Object.defineProperty(exports, "__esModule", { value: true });
// Import SFDX-Falcon Libraries
const validator_1 = require("@sfdx-falcon/validator"); // Library of Type Validation helper functions.
// Import SFDX-Falcon Classes & Functions
const builder_1 = require("@sfdx-falcon/builder"); // Class. Classes derived from QuestionsBuilder can be used to build an Inquirer Questions object.
const debug_1 = require("@sfdx-falcon/debug"); // Class. Provides custom "debugging" services (ie. debug-style info to console.log()).
const prompt_1 = require("@sfdx-falcon/prompt"); // Class. Allows easy creation of Inquirer prompts that have a "confirmation" question that can be used to restart collection of the information.
// Set the File Local Debug Namespace
const dbgNs = '@sfdx-falcon:builder-library:questions';
debug_1.SfdxFalconDebug.msg(`${dbgNs}:`, `Debugging initialized for ${dbgNs}(sfdx)`);
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
/**
* @class ChooseSingleOrg
* @extends InterviewQuestionsBuilder
* @summary Interview Questions Builder for choosing a single salesforce org.
* @description Interview Questions Builder for choosing a single salesforce org.
*/
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
class ChooseSingleOrg extends builder_1.InterviewQuestionsBuilder {
//───────────────────────────────────────────────────────────────────────────┐
/**
* @constructs ChooseSingleOrg
* @param {ChooseSingleOrgOptions} opts Required.
*/
//───────────────────────────────────────────────────────────────────────────┘
constructor(opts) {
// Call the superclass constructor.
super(opts);
// Initialize debug for this method.
const dbgNS = this.initializeDebug(dbgNs, `constructor`, arguments);
// Validate incoming arguments.
validator_1.TypeValidator.throwOnEmptyNullInvalidArray(opts.standardOrgChoices, `${dbgNS.ext}`, `ChooseSingleOrgOptions.standardOrgChoices`);
validator_1.TypeValidator.throwOnEmptyNullInvalidArray(opts.scratchOrgChoices, `${dbgNS.ext}`, `ChooseSingleOrgOptions.scratchOrgChoices`);
// Validate optional arguments.
if (opts.msgStrings.promptIsScratchOrg)
validator_1.TypeValidator.throwOnEmptyNullInvalidString(opts.msgStrings.promptIsScratchOrg, `${dbgNS.ext}`, `msgStrings.promptIsScratchOrg`);
if (opts.msgStrings.promptScratchOrgChoice)
validator_1.TypeValidator.throwOnEmptyNullInvalidString(opts.msgStrings.promptScratchOrgChoice, `${dbgNS.ext}`, `msgStrings.promptScratchOrgChoice`);
if (opts.msgStrings.promptStandardOrgChoice)
validator_1.TypeValidator.throwOnEmptyNullInvalidString(opts.msgStrings.promptStandardOrgChoice, `${dbgNS.ext}`, `msgStrings.promptStandardOrgChoice`);
// Initialize member variables.
this.scratchOrgChoices = opts.scratchOrgChoices;
this.standardOrgChoices = opts.standardOrgChoices;
this.promptIsScratchOrg = opts.msgStrings.promptIsScratchOrg || `Is the target a Scratch Org?`;
this.promptScratchOrgChoice = opts.msgStrings.promptScratchOrgChoice || `Which scratch org would you like to work with?`;
this.promptStandardOrgChoice = opts.msgStrings.promptStandardOrgChoice || `Which org would you like to work with?`;
}
//───────────────────────────────────────────────────────────────────────────┐
/**
* @method build
* @returns {Questions}
* @description Builds the Interview Questions.
*/
//───────────────────────────────────────────────────────────────────────────┘
build() {
return [
{
type: 'confirm',
name: 'isScratchOrg',
message: this.promptIsScratchOrg,
default: ((validator_1.TypeValidator.isNotNullInvalidBoolean(this.defaultAnswers.isScratchOrg)) ? this.defaultAnswers.isScratchOrg : false),
when: true
},
{
type: 'list',
name: 'targetOrgUsername',
message: this.promptStandardOrgChoice,
choices: this.standardOrgChoices,
when: answerHash => (answerHash.isScratchOrg === false && this.standardOrgChoices.length > 0)
},
{
type: 'list',
name: 'targetOrgUsername',
message: this.promptScratchOrgChoice,
choices: this.scratchOrgChoices,
when: answerHash => (answerHash.isScratchOrg === true && this.scratchOrgChoices.length > 0)
}
];
}
}
exports.ChooseSingleOrg = ChooseSingleOrg;
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
/**
* @class ConfirmNoTargetOrg
* @extends InterviewQuestionsBuilder
* @summary Interview Questions Builder for confirming refusal of a Target Org selection.
* @description Interview Questions Builder for confirming refusal of a Target Org selection.
*/
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
class ConfirmNoTargetOrg extends builder_1.InterviewQuestionsBuilder {
//───────────────────────────────────────────────────────────────────────────┐
/**
* @constructs ConfirmNoTargetOrg
* @param {ConfirmNoTargetOrgOptions} opts Required.
*/
//───────────────────────────────────────────────────────────────────────────┘
constructor(opts) {
// Call the superclass constructor.
super(opts);
// Initialize debug for this method.
const dbgNS = this.initializeDebug(dbgNs, `constructor`, arguments);
// Validate optional options.
if (opts.msgStrings.promptStartOver)
validator_1.TypeValidator.throwOnEmptyNullInvalidString(opts.msgStrings.promptStartOver, `${dbgNS.ext}`, `msgStrings.promptStartOver`);
// Initialize member variables.
this.promptStartOver = opts.msgStrings.promptStartOver || `Selecting a target org is required. Would you like to see the choices again?`;
}
//───────────────────────────────────────────────────────────────────────────┐
/**
* @method build
* @returns {Questions}
* @description Builds the Interview Questions.
*/
//───────────────────────────────────────────────────────────────────────────┘
build(buildCtx) {
// Initialize debug for this method.
const dbgNS = this.initializeDebug(dbgNs, `build`, arguments);
// Validate the Build Context.
validator_1.TypeValidator.throwOnInvalidInstance(buildCtx, prompt_1.SfdxFalconPrompt, `${dbgNS.ext}`, `BuildContext`);
validator_1.TypeValidator.throwOnEmptyNullInvalidString(buildCtx.userAnswers.targetOrgUsername, `${dbgNS.ext}`, `BuildContext.userAnswers.targetOrgUsername`);
// Build and return the Questions object.
return [
{
type: 'confirm',
name: 'restart',
message: this.promptStartOver,
default: true,
when: buildCtx.userAnswers.targetOrgUsername === 'NOT_SPECIFIED'
}
];
}
}
exports.ConfirmNoTargetOrg = ConfirmNoTargetOrg;
//# sourceMappingURL=sfdx.js.map