Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
stomita committed Feb 20, 2015
0 parents commit b88b0ee
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
lib-cov
*.seed
*.log
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log

.npmignore
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 0.10
22 changes: 22 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* global process, __dirname */
'use strict';
var fs = require('fs');
var gulp = require('gulp');
var zip = require('gulp-zip');
var forceDeploy = require('./');

gulp.task('forceDeploy', function() {
gulp.src("./pkg/**", { base: "." })
.pipe(zip("pkg.zip"))
.pipe(forceDeploy({
username: process.env.SF_USERNAME,
password: process.env.SF_PASSWORD
}));
});

gulp.task('build', function(cb) {
var data = "Random: " + Math.random();
fs.writeFile(__dirname + '/pkg/staticresources/GulpJSforceTestResource.resource', data, cb);
});

gulp.task('deploy', [ 'build', 'forceDeploy' ]);
67 changes: 67 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var jsforce = require('jsforce');

module.exports = function(options) {
return through.obj(function(file, enc, callback) {
var err;
if (file.isNull()) {
return callback(null, file);
}
if (file.isStream()) {
err = new gutil.PluginError('gulp-jsforce-deploy', 'Stream input is not supported');
return callback(err);
}
if ((!options.username || !options.password) && (!options.accessToken || !options.instanceUrl)) {
err = new gutil.PluginError('gulp-jsforce-deploy',
'Credential to salesforce server is not found in options.\n' +
'Specify "username" and "password" in options.');
return callback(err);
}
var config = {};
"loginUrl,accessToken,instanceUrl,refreshToken,clientId,clientSecret,redirectUri,logLevel".split(',').forEach(function(prop) {
if (options[prop]) { config[prop] = options[prop]; }
});
var conn = new jsforce.Connection(config);
(
options.username && options.password ?
conn.login(options.username, options.password).then(function() { return conn.identity(); }) :
conn.identity()
)
.then(function(identity) {
gutil.log('Logged in as : ' + identity.username);
gutil.log('Deploying to Server ...');
conn.metadata.pollTimeout = options.pollTimeout || 60*1000; // timeout in 60 sec by default
conn.metadata.pollInterval = options.pollInterval || 5*1000; // polling interval to 5 sec by default
return conn.metadata.deploy(file.contents).complete({ details: true });
})
.then(function(res) {
if (res.status === 'Failed') {
gutil.log('Deploy failed.');
if (res.details && res.details.componentFailures) {
reportFailures(res.details);
}
callback(new gutil.PluginError('gulp-jsforce-deploy', 'Deploy failed'));
} else {
gutil.log('Deploy successful.');
callback();
}
})
.then(null, function(err) {
gutil.log('Deploy faiiled.');
err = new gutil.PluginError('test', err, { showStack: true });
callback(err);
});
});

function reportFailures(details) {
var failures = details.componentFailures;
if (!failures) { return; }
if (!failures.length) { failures = [ failures ]; }
failures.forEach(function(f) {
gutil.log(' - ' + f.problemType + ' on ' + f.fileName + ' : ' + f.problem);
});
}

};
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "gulp-jsforce-deploy",
"version": "1.0.0",
"description": "Deploying Salesforce package using JSforce (no Migration Tool dependency)",
"main": "index.js",
"keywords": [
"salesforce",
"salesforce.com",
"sfdc",
"force.com",
"database.com",
"gulpplugin",
"deploy"
],
"scripts": {
"pretest": "./node_modules/.bin/gulp deploy",
"test": "./node_modules/.bin/mocha --require intelli-espower-loader"
},
"files": [
"index.js"
],
"author": "Shinichi Tomita <[email protected]>",
"license": "MIT",
"dependencies": {
"gulp-util": "^3.0.3",
"jsforce": "^1.4.0",
"through2": "^0.6.3"
},
"devDependencies": {
"espower-loader": "^0.10.0",
"gulp": "^3.8.11",
"gulp-zip": "^2.0.2",
"intelli-espower-loader": "^0.6.0",
"mocha": "^2.1.0",
"power-assert": "^0.10.2"
}
}
8 changes: 8 additions & 0 deletions pkg/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>GulpJSforceTestResource</members>
<name>StaticResource</name>
</types>
<version>33.0</version>
</Package>
1 change: 1 addition & 0 deletions pkg/staticresources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GulpJSforceTestResource.resource
5 changes: 5 additions & 0 deletions pkg/staticresources/GulpJSforceTestResource.resource-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<StaticResource xmlns="http://soap.sforce.com/2006/04/metadata">
<cacheControl>Private</cacheControl>
<contentType>text/plain</contentType>
</StaticResource>
28 changes: 28 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* global process, describe, it, Buffer, __dirname */
'use strict';
var fs = require('fs');
var jsforce = require('jsforce');
var assert = require('power-assert');

/**
*
*/
describe('jsforce-deploy', function() {
this.timeout(20000);

it("should match deployed static file's content to the local one", function() {
var conn = new jsforce.Connection();
return conn.login(process.env.SF_USERNAME, process.env.SF_PASSWORD)
.then(function() {
return conn.identity();
})
.then(function(identity) {
return conn.metadata.read('StaticResource', 'GulpJSforceTestResource');
})
.then(function(res) {
var data = fs.readFileSync(__dirname + '/pkg/staticresources/GulpJSforceTestResource.resource', 'utf8');
assert(new Buffer(res.content, 'base64').toString('utf8') === data);
});
});

});

0 comments on commit b88b0ee

Please sign in to comment.