UNPKG

build_salesforce_package

Version:

Build Saleforce Package to be deployed using git diff

188 lines (140 loc) 6 kB
#! /usr/bin/env node var program = require('commander'); var cmd = require('node-cmd'); var Q = require("q"); var Util = require('../bin/util'); var Package = require('../bin/package'); var Profile = require('../bin/profile'); var Config = require('../bin/config'); var Ant = require('../bin/ant'); var exec = require('child_process').exec; var fs = require('fs-extra'); var xmlBuilder = require('xmlbuilder'); var AdmZip = require('adm-zip'); var chalk = require('chalk'); var Cryptr = require('cryptr'); cryptr = new Cryptr('build_salesforce_package'); var figlet = require('figlet'); // var config = new Config().loadFile(); // Create package from git diff, git folder program .command('build <profile> <origin>') .description('Build the package to deploy') .option('-z, --zip','Create build/package.zip otherwise build/package/') .option('-apiV, --apiVersion <n>','Api Version') .option('-t, --target <target>','Target') .option('-p, --path <path>','Path to the src') .option('-k, --key <target>','Encryption key for the profile') .action(function (profile,origin,options) { Util.clean([Util.buildFolderPath,Util.retrieveFolderPath]); program.origin = origin; program.target = options.target; program.branch = program.origin.split('/')[1]; program.profile = profile; program.path = options.path || 'src/'; program.apiVersion = options.apiVersion || '39'; program.zip = options.zip || false; program.key = options.key || Profile.defaultKey(); if(program.target !== undefined){ Package.generatePackageByDiff(config,program); }else if(program.target === undefined && program.origin !== undefined){ Package.generatePackageByBranch(config,program); } }) program .command('retrieve <profile>') .description('Retrieve code') .option('-apiV, --apiVersion <n>','Api Version') .option('-k, --key <target>','Encryption key for the profile') .action(function (profile,options) { Util.clean([Util.buildFolderPath,Util.retrieveFolderPath]); Util.buildFolders([Util.buildFolderPath(),Util.retrieveFolderPath()]); program.profile = profile; program.apiVersion = options.apiVersion || '39'; program.key = options.key || Profile.defaultKey(); let _profile = config.getProfile(program.profile,program.key); // Build Package let _package = new Package(null,null,program.apiVersion,false); _package.buildXmlPackage(true); // Generate new Build File console.log(chalk.yellow('Generate new Build.xml file')) var _ant = new Ant({mod:'retrieve'}); _ant.generate(_profile); _ant.execute() .then(function(res){ process.exit(0); }).fail(function(err){ console.log(chalk.red(err)); process.exit(2); }) }) program .command('deploy <name> ') .description('Deploy package') .option('-k, --key <target>','Encryption key') // .option('-r, --rollBack','Rollback on error') .option('-c, --checkOnly','Validate only') .option('-t, --testlevel <target>','Test level (NoTestRun|RunSpecifiedTests|RunLocalTests|RunAllTestsInOrg)',/^(NoTestRun|RunSpecifiedTests|RunLocalTests|RunAllTestsInOrg)$/i) .option('-l, --testList [value]','List of test to run',Util.collect, []) .option('-m, --maxPoll <n>','Max polling (default 1000000 ms)') .option('-p, --pollWait <n>','Poll Interval (default 10000ms)') .option('-z, --zip','Deploy zipped package') .action(function (name,options) { options.mod = 'deploy'; options.zip = options.zip || false; let _profile = config.getProfile(name,options.key); var ant = new Ant(options); ant.generate(_profile); ant.execute(); }); program .command('add <name> <username> <password> <url>') .description('Add a profile') .option('-k, --key <target>','Encryption key') .action(function (name,username, password,url,options) { let _key = options.key || Profile.defaultKey(); let cryptEngine = new Cryptr(_key); config .add(name,{'username':username,'password':cryptEngine.encrypt(password),'url':url}) .saveFile(); }); program .command('list') .description('Get list of profiles') .action(function () { config .print(); }); program .command('remove <name>') .description('Remove a profile') .action(function (name) { config .remove(name) .saveFile(); }); program.on('--help', function() { //console.log(chalk.bold.green('To deploy code (example):')); //console.log(chalk.magenta('Step 1:')) //console.log(chalk.bold.cyan('build_salesforce_package settings profile1 username password login.salesforce.com')); //console.log(chalk.magenta('Step 2:')) //console.log(chalk.bold.cyan('build_salesforce_package build origin/fullSdbx origin/master src/ -apiV 39 -z')); //console.log(chalk.magenta('Step 3:')) //console.log(chalk.bold.cyan('build_salesforce_package deploy login.salesforce.com username password --validate')); // console.log(" ") // console.log(" ____ _ _ _ _ ____ "); // console.log(" | _ \\(_) __ _(_) |_ __ _| | | _ \\ ___ ___ _ __ "); // console.log(" | | | | |/ _` | | __/ _` | | | | | |/ _ \\/ _ \\ '__| "); // console.log(" | |_| | | (_| | | || (_| | | | |_| | __/ __/ | "); // console.log(" |____/|_|\\__, |_|\\__\\__,_|_| |____/ \\___|\\___|_| "); // console.log(" |___/ "); console.log(chalk.bold.green('To deploy code (example):')); console.log(chalk.magenta('Step 1:')) console.log(chalk.bold.cyan('build_salesforce_package add profile1 username password login.salesforce.com')); console.log(chalk.magenta('Step 2:')) console.log(chalk.bold.cyan('build_salesforce_package build --target origin/fullSdbx --path src/ -apiV 39 -z')); console.log(chalk.magenta('Step 3:')) console.log(chalk.bold.cyan('build_salesforce_package deploy profile1 --validate')); }); program.parse(process.argv);