UNPKG

salesforce-alm

Version:

This package contains tools, and APIs, for an improved salesforce.com developer experience.

73 lines (71 loc) 2.59 kB
"use strict"; /* * 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 */ const BBPromise = require("bluebird"); const orgSnapshotApi_1 = require("./orgSnapshotApi"); const Org = require("../../core/scratchOrgApi"); const Messages = require("../../messages"); const messages = Messages(); const logger = require("../../core/logApi"); /** * Create a snapshot of given scratch source org. */ class OrgSnapshotCreateCommand { constructor() { this.logger = logger.child('org:snapshot:create'); } execute(context) { // double-check if (!context.flags.sourceorg) { throw new Error(messages.getMessage('sourceOrgInvalid', [], 'orgSnapshot')); } if (!context.flags.snapshotname) { throw new Error(messages.getMessage('nameInvalid', [], 'orgSnapshot')); } return this._getSourceOrgId(context).then((orgId) => orgSnapshotApi_1.OrgSnapshotApiImpl.create(context.org).then((orgSnapshotApi) => { this.orgSnapshotApi = orgSnapshotApi; return this.orgSnapshotApi.create({ SourceOrg: orgId, SnapshotName: context.flags.snapshotname, Description: context.flags.description, }); })); } // resolve sourceorg to orgId _getSourceOrgId(context) { if (context.flags.sourceorg.startsWith('00D')) { return BBPromise.resolve(context.flags.sourceorg); } else { return Org.create(context.flags.sourceorg, Org.Defaults.USERNAME) .then((org) => org.getConfig()) .then((orgConfig) => orgConfig.orgId); } } /** * returns a human readable message for a cli output * * @param result - the data representing the Org Snapshot * @returns {string} */ getHumanSuccessMessage(result) { const data = this.orgSnapshotApi.mapDataToLabel(result); if (result.Error) { data.push({ name: 'Error', value: result.Error }); } this.logger.styledHeader(this.logger.color.blue('Org Snapshot')); this.logger.table(data, { columns: [ { key: 'name', label: 'Name' }, { key: 'value', label: 'Value' }, ], }); return ''; } } module.exports = OrgSnapshotCreateCommand; //# sourceMappingURL=orgSnapshotCreateCommand.js.map