Skip to content

Commit

Permalink
Renamed Packer to PackageDirReader
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed May 22, 2012
1 parent ac2961a commit a9fc6d1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
20 changes: 10 additions & 10 deletions lib/packer.js → lib/package-dir-reader.js
Expand Up @@ -3,28 +3,28 @@ var IgnoreReader = require("fstream-ignore"),
path = require("path"),
env = require('./env');

module.exports = Packer;
inherits(Packer, IgnoreReader);
module.exports = PackageDirReader;
inherits(PackageDirReader, IgnoreReader);

/**
* A directory stream that collects up files and folders to be included in a package.
* @param {String|Object} props - if an Object then a hash of properties for this packaging, if a string then the path to the folder to pack
*/
function Packer (props) {
function PackageDirReader (props) {
// If called without new then do it now
if (!(this instanceof Packer)) {
return new Packer(props);
if (!(this instanceof PackageDirReader)) {
return new PackageDirReader(props);
}

// If props is a string then wrap it up in an object hash
if (typeof props === "string") {
props = { path: props };
}

// The Packer will ignore paths in these files
// The PackageDirReader will ignore paths in these files
props.ignoreFiles = [ ".kansoignore"];

// Call the prototype from which the Packer is inheriting
// Call the prototype from which the PackageDirReader is inheriting
IgnoreReader.call(this, props);

// files should *always* get into tarballs in a user-writable state, even if they're being installed from some wackey vm-mounted read-only filesystem.
Expand All @@ -37,7 +37,7 @@ function Packer (props) {
/**
* We override applyIgnores to ignore certain files
*/
Packer.prototype.applyIgnores = function (entry, partial, entryObj) {
PackageDirReader.prototype.applyIgnores = function (entry, partial, entryObj) {
// package.json files can never be ignored.
if (entry === "package.json") return true;
// special rules for packages. see below.
Expand Down Expand Up @@ -80,7 +80,7 @@ Packer.prototype.applyIgnores = function (entry, partial, entryObj) {
/**
* Ensure children are read correctly
*/
Packer.prototype.getChildProps = function (stat) {
PackageDirReader.prototype.getChildProps = function (stat) {
var props = IgnoreReader.prototype.getChildProps.call(this, stat);

// Directories have to be read as Packers
Expand All @@ -96,7 +96,7 @@ Packer.prototype.getChildProps = function (stat) {
};


Packer.prototype.emitEntry = function (entry) {
PackageDirReader.prototype.emitEntry = function (entry) {
if (this._paused) {
this.once("resume", this.emitEntry.bind(this, entry));
return;
Expand Down
14 changes: 8 additions & 6 deletions lib/tar.js
Expand Up @@ -3,7 +3,7 @@ var child_process = require('child_process'),
settings = require('./settings'),
logger = require('./logger'),
utils = require('./utils'),
Packer = require('./packer'),
PackageDirReader = require('./package-dir-reader'),
tar = require('tar'),
zlib = require("zlib"),
path = require('path'),
Expand All @@ -25,14 +25,16 @@ exports.create = function (outfile, dir, callback) {

var tmpfile = path.resolve(repository.TMP_DIR, path.basename(outfile) + '-' + new Date().getTime());

new Packer({ path: folder, type: "Directory", isDirectory: true })
.on("error", logger.error("error reading "+folder))
var error = function(message) { return function() {logger.error(message);}; };

new PackageDirReader({ path: folder })
.on("error", error("error reading "+folder))
.pipe(tar.Pack())
.on("error", logger.error("tar creation error "+tmpfile))
.on("error", error("tar creation error "+tmpfile))
.pipe(zlib.Gzip())
.on("error", logger.error("gzip error "+tmpfile))
.on("error", error("gzip error "+tmpfile))
.pipe(fstream.Writer({ type: "File", path: tmpfile }))
.on("error", logger.error(cb, "Could not write "+tmpfile))
.on("error", error("Could not write "+tmpfile))
.on("close", function () {
utils.mv(tmpfile, outfile, callback);
callback();
Expand Down
7 changes: 1 addition & 6 deletions test/test-pack.js
Expand Up @@ -29,12 +29,7 @@ var TMPDIR = path.resolve(__dirname, 'tmp');


exports.setUp = function (callback) {
rimraf(TMPDIR, function (err) {
if (err) {
return callback(err);
}
mkdirp(TMPDIR, callback);
});
mkdirp(TMPDIR, callback);
};

exports.tearDown = function (callback) {
Expand Down
4 changes: 2 additions & 2 deletions test/test-packer.js → test/test-package-dir-reader.js
@@ -1,7 +1,7 @@
var path = require('path'),
sets = require('simplesets'),
settings = require('../lib/settings'),
Packer = require('../lib/packer.js');
PackageDirReader = require('../lib/package-dir-reader.js');

function packagePath(pkg) {
return path.resolve(__dirname,'testapps', pkg);
Expand All @@ -22,7 +22,7 @@ function testPackage(pkg, expectedPaths) {
var actualPaths = [];

settings.load(pkgPath, function(err, cfg) {
Packer({path: pkgPath, bundledDependencies: cfg.bundledDependencies }).
PackageDirReader({path: pkgPath, bundledDependencies: cfg.bundledDependencies }).
on('error', function(err) {
test.fail(err);
test.done();
Expand Down
1 change: 1 addition & 0 deletions test/test-transform-csv.js
Expand Up @@ -19,6 +19,7 @@ function transformTest(trans, p) {

exec(cmd, function (err, stdout, stderr) {
if (err) {
console.log(stdout);
return test.done(err);
}
var expected = fs.readFileSync(path.resolve(datadir,'expected')).toString();
Expand Down

0 comments on commit a9fc6d1

Please sign in to comment.