UNPKG

sfdx

Version:

Performs Salesforce DX operations with ease! Life is good.

59 lines (48 loc) 1.96 kB
const config = require('../config/config') const yargsBuilder = require('../lib/yargsBuilder') const getResults = require('../helpers/compileResults') const shell = require('shelljs') module.exports = { desc: 'Deploys metadata code into an org.', command: ['deploy [deploytoalias] [deployto|to|t|a] [outputdir|dir|d]'], aliases: [], builder: yargs => { yargs = yargsBuilder.builder(yargs) yargs .positional('deploytoalias', { describe: 'Alias of the org to deploy code into' }) .option('deployto', { alias: ['to', 't', 'a'], describe: 'Alias of the org to deploy code into' }) .option('outputdirectory', { alias: ['outputdir', 'dir', 'd'], describe: 'Directory containing the Metadata API source code to deploy', default: config.mdApiDir }) .example('$0 deploy --deployto DeployTest', "- Deploys Metadata API code into org with the alias 'DeployTest'") .example( '$0 deploy -a DeployTest -d myOutputDir', "- Deploys Metadata API code from the directory 'myOutputDir' into 'DeployTest'" ) }, handler: argv => { argv = yargsBuilder.handler(argv) const alias = argv.deploytoalias || argv.deployto const outputdir = argv.outputdirectory || config.mdApiDir if (!argv.quiet) { console.log('Deploying metadata into' + (alias ? " '" + alias + "'" : ' default org') + '...') } if (!argv.quiet) console.log() let numResults = 0 const results = [] let deployCommand = 'sfdx force:mdapi:deploy --deploydir ' + outputdir + (alias ? ' --targetusername ' + alias : '') + ' --wait 100' if (argv.json) deployCommand += ' --json' results[numResults++] = shell.exec(deployCommand) // Do not delete converted code if there is an error if (!results[numResults - 1].stderr) results[numResults++] = shell.exec('rm -r -f ' + outputdir) return getResults(results) } }