Skip to content

Commit

Permalink
Breaking: Remove superfluous argument from write-xxx modules & use fi…
Browse files Browse the repository at this point in the history
…le.path instead (#173)
  • Loading branch information
erikkemperman authored and phated committed Nov 28, 2017
1 parent ac7a96c commit 9b6f1be
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lib/dest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ function dest(outFolder, opt) {
['boolean', 'string', 'object'], opt.sourcemaps);

function saveFile(file, enc, cb) {
prepareWrite(outFolder, file, opt, function(err, writePath) {
prepareWrite(outFolder, file, opt, function(err) {
if (err) {
return cb(err);
}
writeContents(writePath, file, cb);
writeContents(file, cb);
});
}

Expand Down
10 changes: 5 additions & 5 deletions lib/dest/write-contents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ var writeStream = require('./write-stream');
var writeBuffer = require('./write-buffer');
var writeSymbolicLink = require('./write-symbolic-link');

function writeContents(writePath, file, callback) {
function writeContents(file, callback) {
// If directory then mkdirp it
if (file.isDirectory()) {
return writeDir(writePath, file, written);
return writeDir(file, written);
}

// Stream it to disk yo
if (file.isStream()) {
return writeStream(writePath, file, written);
return writeStream(file, written);
}

// Write it as a symlink
if (file.symlink) {
return writeSymbolicLink(writePath, file, written);
return writeSymbolicLink(file, written);
}

// Write it like normal
if (file.isBuffer()) {
return writeBuffer(writePath, file, written);
return writeBuffer(file, written);
}

// If no contents then do nothing
Expand Down
4 changes: 2 additions & 2 deletions lib/dest/write-contents/write-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

var fo = require('../../file-operations');

function writeBuffer(writePath, file, written) {
function writeBuffer(file, written) {
var opt = {
mode: file.stat.mode,
flag: file.flag,
};

fo.writeFile(writePath, file.contents, opt, onWriteFile);
fo.writeFile(file.path, file.contents, opt, onWriteFile);

function onWriteFile(writeErr, fd) {
if (writeErr) {
Expand Down
6 changes: 3 additions & 3 deletions lib/dest/write-contents/write-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ var mkdirp = require('mkdirp');

var fo = require('../../file-operations');

function writeDir(writePath, file, written) {
function writeDir(file, written) {
var mkdirpOpts = {
mode: file.stat.mode,
fs: fs,
};
mkdirp(writePath, mkdirpOpts, onMkdirp);
mkdirp(file.path, mkdirpOpts, onMkdirp);

function onMkdirp(mkdirpErr) {
if (mkdirpErr) {
return written(mkdirpErr);
}

fs.open(writePath, 'r', onOpen);
fs.open(file.path, 'r', onOpen);
}

function onOpen(openErr, fd) {
Expand Down
4 changes: 2 additions & 2 deletions lib/dest/write-contents/write-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ var fs = require('graceful-fs');
var fo = require('../../file-operations');
var readStream = require('../../src/get-contents/read-stream');

function writeStream(writePath, file, written) {
function writeStream(file, written) {
var opt = {
mode: file.stat.mode,
flag: file.flag,
};

var outStream = fs.createWriteStream(writePath, opt);
var outStream = fs.createWriteStream(file.path, opt);

file.contents.once('error', complete);
file.contents.once('end', readStreamEnd);
Expand Down
4 changes: 2 additions & 2 deletions lib/dest/write-contents/write-symbolic-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

var fs = require('graceful-fs');

function writeSymbolicLink(writePath, file, written) {
function writeSymbolicLink(file, written) {
// TODO handle symlinks properly
fs.symlink(file.symlink, writePath, function(err) {
fs.symlink(file.symlink, file.path, function(err) {
if (isFatalError(err)) {
return written(err);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/prepare-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function prepareWrite(outFolder, file, opt, cb) {
if (err) {
return cb(err);
}
cb(null, writePath);
cb(null);
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/symlink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ function symlink(outFolder, opt) {
function linkFile(file, enc, cb) {
var srcPath = file.path;
var symType = (file.isDirectory() ? 'dir' : 'file');
prepareWrite(outFolder, file, opt, function(err, writePath) {
prepareWrite(outFolder, file, opt, function(err) {
if (err) {
return cb(err);
}
fs.symlink(srcPath, writePath, symType, function(err) {
fs.symlink(srcPath, file.path, symType, function(err) {
if (err && err.code !== 'EEXIST') {
return cb(err);
}
Expand Down

0 comments on commit 9b6f1be

Please sign in to comment.