heroku-source-deployer
Advanced tools
{ | ||
"name": "heroku-source-deployer", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Deploys sources to Heroku", | ||
@@ -27,3 +27,4 @@ "main": "plugin.js", | ||
"heroku-client": "~2.3.2", | ||
"tar.gz": "~1.0.2" | ||
"tar-fs": "~1.8.1", | ||
"gitignore-parser": "~0.0.2" | ||
}, | ||
@@ -30,0 +31,0 @@ "engines": { |
'use strict'; | ||
var Promise = require('bluebird'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
// deploy a dir | ||
function deployDir(apiToken, appName, dir) { | ||
function dirToTarGz(dir, useGitIgnore) { | ||
if (useGitIgnore === undefined) { | ||
useGitIgnore = true; | ||
} | ||
// only use the .gitignore if it exists | ||
useGitIgnore = useGitIgnore & fs.existsSync(path.join(dir, '.gitignore')); | ||
var stat = Promise.promisify(require('fs').stat); | ||
var tarGzPromise = stat(dir).then(function(dirStat) { | ||
return stat(dir).then(function(dirStat) { | ||
if (!dirStat.isDirectory()) { | ||
@@ -16,7 +24,7 @@ throw new Error('The specifed dir does not exist or is not a directory.'); | ||
return new Promise(function (resolve, reject) { | ||
var zlib = require('zlib'); | ||
var gzip = zlib.createGzip(); | ||
var tar = require('tar-fs'); | ||
var stream = require('stream'); | ||
var targz = require('tar.gz'); | ||
var read = targz().createReadStream(dir); | ||
var bufs = []; | ||
@@ -30,6 +38,15 @@ var write = new stream.Writable({ | ||
// tar gz the dir | ||
read.pipe(write); | ||
var options = {}; | ||
read.on('error', reject); | ||
if (useGitIgnore) { | ||
var parser = require('gitignore-parser'); | ||
var gitignore = parser.compile(fs.readFileSync(path.join(dir, '.gitignore'), 'utf8')); | ||
options.ignore = function(name) { | ||
return gitignore.denies(name); | ||
}; | ||
} | ||
tar.pack(dir, options).pipe(gzip).pipe(write); | ||
write.on('error', reject); | ||
@@ -41,4 +58,7 @@ write.on('finish', function () { | ||
}); | ||
} | ||
return tarGzPromise.then(function(data) { | ||
// deploy a dir | ||
function deployDir(apiToken, appName, dir, useGitIgnore) { | ||
return dirToTarGz(dir, useGitIgnore).then(function(data) { | ||
return deploy(apiToken, appName, data); | ||
@@ -126,2 +146,3 @@ }); | ||
module.exports = { | ||
dirToTarGz: dirToTarGz, | ||
deploy: deploy, | ||
@@ -128,0 +149,0 @@ deployDir: deployDir, |
@@ -28,2 +28,6 @@ 'use strict'; | ||
it('dirToTarGz should create a tar.gz and apply the .gitignore', function() { | ||
return assert.eventually.isBelow(herokuSourceDeployer.dirToTarGz('.').then(function(d) {return d.length;}), 5000000); | ||
}); | ||
it('deploy should fail when the dir does not exist', function() { | ||
@@ -30,0 +34,0 @@ return assert.isRejected(herokuSourceDeployer.deployDir(apiToken, 'foo', 'foo'), /no such file or directory, stat 'foo'/); |
7279
13.42%165
13.79%5
25%4
33.33%