UNPKG

qforce

Version:

Commands to help with salesforce development.

66 lines (65 loc) 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const cli_ux_1 = require("cli-ux"); const utility_1 = require("../../helper/utility"); const path = require('path'); const fs = require('fs'); const sfdx = require('sfdx-node'); class DxDescribe extends command_1.Command { async run() { cli_ux_1.default.action.start('Getting sObject description'); const { flags } = this.parse(DxDescribe); let settings; if (fs.existsSync(utility_1.getAbsolutePath('.qforce/settings.json'))) { settings = JSON.parse(fs.readFileSync(utility_1.getAbsolutePath('.qforce/settings.json'))); } const targetusername = flags.username || settings.targetusername; if (!fs.existsSync(utility_1.getAbsolutePath('.qforce/definitions'))) { fs.mkdirSync(utility_1.getAbsolutePath('.qforce/definitions'), { recursive: true }); } let objectsToDescribe = []; if (flags.all) { let options = {}; if (targetusername) options.targetusername = targetusername; options.sobjecttypecategory = 'all'; objectsToDescribe = await sfdx.schema.sobjectList(options); } else { objectsToDescribe.push(flags.sobject); } const resultPath = flags.result || settings.describeResultsPath || settings.exeResultsPath || 'exe.log'; let sobjectByPrefix = {}; if (fs.existsSync(utility_1.getAbsolutePath('.qforce/definitions/sobjectsByPrefix.json'))) { sobjectByPrefix = JSON.parse(fs.readFileSync(utility_1.getAbsolutePath('.qforce/definitions/sobjectsByPrefix.json'))); } for (let sobject of objectsToDescribe) { let options = {}; if (targetusername) options.targetusername = targetusername; options.sobjecttype = sobject.toLowerCase(); let describeResults = await sfdx.schema.sobjectDescribe(options); sobjectByPrefix[describeResults.keyPrefix] = sobject; fs.writeFileSync(utility_1.getAbsolutePath('.qforce/definitions/' + sobject.toLowerCase() + '.json'), JSON.stringify(describeResults, null, 2), { encoding: 'utf-8' }); if (flags.sobject) { fs.writeFileSync(utility_1.getAbsolutePath(resultPath), JSON.stringify(describeResults, null, 2), { encoding: 'utf-8' }); } } fs.writeFileSync(utility_1.getAbsolutePath('.qforce/definitions/sobjectsByPrefix.json'), JSON.stringify(sobjectByPrefix, null, 2), { encoding: 'utf-8' }); cli_ux_1.default.action.stop(); } } exports.default = DxDescribe; DxDescribe.description = 'describe the command here'; DxDescribe.aliases = ['describe', 'dx:describe']; DxDescribe.flags = { help: command_1.flags.help({ char: 'h' }), username: command_1.flags.string({ char: 'u' }), sobject: command_1.flags.string({ char: 's', description: 'sObject name.' }), result: command_1.flags.string({ char: 'r', description: 'Relative path to save results.' }), all: command_1.flags.boolean({ char: 'a', description: 'To get all sObjects.' }) };