UNPKG

build_salesforce_package

Version:

Build Saleforce Package to be deployed using git diff

110 lines (85 loc) 2.86 kB
var Q = require("q"); var fs = require('fs-extra'); var xmlBuilder = require('xmlbuilder'); var Util = require('./util'); var exec = require('child_process').exec; var spawn = require("child_process").spawn; class Ant{ constructor(options){ this.buildXml; this.options = options || {}; } generate(profile){ this.optionsCleaner(); var xml = xmlBuilder.create('project',{ encoding: 'utf-8' }) .att('xmlns:sf', 'antlib:com.salesforce') .att('basedir',".") .att('name',"Salesforce Builder") .ele('taskdef') .att('uri',"antlib:com.salesforce") .att('resource',"com/salesforce/antlib.xml") .att('classpath',require("path").join(__dirname,"/ant-salesforce.jar")) .up() .ele('property') .att('file','build.properties') .up() .ele('property') .att('environment',"env") .up() .ele('target') .att('name',"autoExecute"); if(this.options.mod == 'retrieve'){ xml = xml.ele("sf:retrieve") .att('retrieveTarget','retrieveCode') .att('unpackaged','retrieveCode/package.xml') }else if(this.options.mod == 'deploy'){ xml = xml.ele("sf:deploy") .att("testlevel",this.options.testlevel) .att("rollbackOnError",this.options.rollBack) .att("checkOnly",this.options.checkOnly); }else if(this.options.mod == 'cancelDeploy'){ xml = xml.ele("sf:cancelDeploy") } xml = xml .att("username",profile.username) .att("password",profile.password) .att("serverurl",profile.url) .att("maxPoll",this.options.maxPoll) .att("pollWaitMillis",this.options.pollWait) if(this.options.zip){ xml = xml.att("zipFile","package.zip"); }else{ xml = xml.att("deployRoot","package/"); } xml = xml.doc().end({ pretty: true}); //console.log(xml); fs.writeFileSync(Util.buildTargetPath(),xml); } optionsCleaner(){ this.options.testlevel = this.options.testlevel || 'RunLocalTests'; this.options.maxPoll = this.options.maxPoll || '10000000'; this.options.pollWait = this.options.pollWait || '10000'; this.options.rollBack = this.options.rollBack || true; this.options.checkOnly = this.options.checkOnly || false; } execute(){ var defer = Q.defer(); var test = exec('ant -file '+Util.buildTargetPath()+' -D-verbose= autoExecute',{cwd:null}); test.on('close', function(res) { console.log('close'); console.log(res); defer.resolve(res); }); test.stdout.on('data', function(res) { console.log(res) }); test.stderr.on('data', function(err) { console.log('there is an error'); console.log(err); process.exit(2); defer.reject(err); }); return defer.promise; } } module.exports = Ant;