Skip to content

Commit

Permalink
Update: Use new mkdirpStream in dest & symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkemperman authored and phated committed Nov 30, 2017
1 parent 00b6f88 commit 743d216
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 45 deletions.
4 changes: 2 additions & 2 deletions lib/dest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var lead = require('lead');
var pumpify = require('pumpify');
var prepare = require('vinyl-prepare');

var fo = require('../file-operations');
var sourcemap = require('./sourcemap');
var makeDirs = require('./make-dirs');
var writeContents = require('./write-contents');

function dest(outFolder, opt) {
Expand All @@ -16,7 +16,7 @@ function dest(outFolder, opt) {
var saveStream = pumpify.obj(
prepare.dest(outFolder, opt),
sourcemap(opt),
makeDirs(opt),
fo.mkdirpStream(opt),
writeContents(opt)
);

Expand Down
29 changes: 0 additions & 29 deletions lib/dest/make-dirs.js

This file was deleted.

22 changes: 22 additions & 0 deletions lib/file-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var fs = require('graceful-fs');
var path = require('path');
var assign = require('object-assign');
var date = require('value-or-function').date;
var number = require('value-or-function').number;
var through = require('through2');
var FlushWriteStream = require('flush-write-stream');

var constants = require('./constants');
Expand Down Expand Up @@ -321,6 +323,25 @@ function mkdirp(dirpath, customMode, callback) {
}
}

function mkdirpStream(opt) {

function makeFileDirs(file, enc, callback) {
// TODO: Can this be put on file.stat?
var dirMode = number(opt.dirMode, file);

mkdirp(file.dirname, dirMode, onMkdirp);

function onMkdirp(mkdirpErr) {
if (mkdirpErr) {
return callback(mkdirpErr);
}
callback(null, file);
}
}

return through.obj(makeFileDirs);
}

function createWriteStream(path, options, flush) {
return new WriteStream(path, options, flush);
}
Expand Down Expand Up @@ -427,5 +448,6 @@ module.exports = {
updateMetadata: updateMetadata,
writeFile: writeFile,
mkdirp: mkdirp,
mkdirpStream: mkdirpStream,
createWriteStream: createWriteStream,
};
16 changes: 2 additions & 14 deletions lib/symlink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var lead = require('lead');

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

var number = valueOrFunction.number;
var boolean = valueOrFunction.boolean;

var isWindows = (os.platform() === 'win32');
Expand Down Expand Up @@ -51,19 +50,7 @@ function symlink(outFolder, opt) {
srcPath = path.relative(file.base, srcPath);
}

// TODO: make DRY with .dest()
var dirMode = number(opt.dirMode, file);
var writeFolder = path.dirname(file.path);

fo.mkdirp(writeFolder, dirMode, onMkdirp);

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

fs.symlink(srcPath, file.path, symType, onSymlink);
}
fs.symlink(srcPath, file.path, symType, onSymlink);

function onSymlink(symlinkErr) {
if (isErrorFatal(symlinkErr)) {
Expand All @@ -75,6 +62,7 @@ function symlink(outFolder, opt) {

var stream = pumpify.obj(
prepare.dest(outFolder, opt),
fo.mkdirpStream(opt),
through.obj(linkFile)
);

Expand Down

0 comments on commit 743d216

Please sign in to comment.