-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b88b0ee
Showing
9 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- 0.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GulpJSforceTestResource.resource |
5 changes: 5 additions & 0 deletions
5
pkg/staticresources/GulpJSforceTestResource.resource-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
|
||
}); |