UNPKG

qforce

Version:

Commands to help with salesforce development.

60 lines (59 loc) 2.85 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 execa = require('execa'); const YAML = require('yaml'); class DevRetrieve extends command_1.Command { async run() { const { args, flags } = this.parse(DevRetrieve); let settings, sfdxConfig; if (fs.existsSync(utility_1.getAbsolutePath('.qforce/settings.json'))) { settings = JSON.parse(fs.readFileSync(utility_1.getAbsolutePath('.qforce/settings.json'))); } if (fs.existsSync(path.join(process.cwd(), '.sfdx', 'sfdx-config.json'))) { sfdxConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.sfdx', 'sfdx-config.json'))); } const targetusername = flags.username || settings.targetusername || sfdxConfig.defaultusername; let retrieveYAML; let filePath = flags.file || 'feature.yml'; if (!fs.existsSync(utility_1.getAbsolutePath(filePath))) { filePath = settings.retrieveBasePath + '/' + filePath; } if (!fs.existsSync(utility_1.getAbsolutePath(filePath))) { cli_ux_1.default.action.stop('File not found. Check file path.'); } retrieveYAML = YAML.parse(fs.readFileSync(filePath, 'utf-8')); for (let metadataType in retrieveYAML) { if (retrieveYAML[metadataType]) { for (let metadataName of retrieveYAML[metadataType]) { let command = `sfdx force:source:retrieve -m ${metadataType}:${metadataName} -u ${targetusername} --json`; let cmdOut = JSON.parse(execa.commandSync(command).stdout); for (let file of cmdOut.result.inboundFiles) { this.log('Retrieved ' + file.filePath); } } } else { let command = `sfdx force:source:retrieve -m ${metadataType} -u ${targetusername} --json`; let cmdOut = JSON.parse(execa.commandSync(command).stdout); for (let file of cmdOut.result.inboundFiles) { this.log('Retrieved ' + file.filePath); } } } cli_ux_1.default.action.stop(); } } exports.default = DevRetrieve; DevRetrieve.description = 'To retrieve metadat based on items listed in a YAML file.'; DevRetrieve.aliases = ['retrieve', 'dev:retrieve']; DevRetrieve.flags = { help: command_1.flags.help({ char: 'h' }), username: command_1.flags.string({ char: 'u' }), file: command_1.flags.string({ char: 'f', description: 'Relative path of YAML file in unix format.' }), }; DevRetrieve.args = [{ name: 'file' }];