Skip to content

Commit

Permalink
New: Add overwrite option to dest() that sets flag property on …
Browse files Browse the repository at this point in the history
…options
  • Loading branch information
yocontra authored and phated committed Nov 28, 2017
1 parent 0d3022c commit e45e639
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 0 additions & 1 deletion lib/dest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var through2 = require('through2');
var prepareWrite = require('../prepareWrite');
var writeContents = require('./writeContents');


function dest(outFolder, opt) {
function saveFile (file, enc, cb) {
prepareWrite(outFolder, file, opt, function (err, writePath) {
Expand Down
15 changes: 7 additions & 8 deletions lib/prepareWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ module.exports = function (outFolder, file, opt, cb) {
var options = assign({
cwd: process.cwd(),
mode: (file.stat ? file.stat.mode : null),
dirMode: null
dirMode: null,
overwrite: true
}, (opt || {}));
options.flag = (options.overwrite ? 'w' : 'wx');

var cwd = path.resolve(options.cwd);

if (typeof outFolder !== 'string' && typeof outFolder !== 'function') {
throw new Error('Invalid output folder');
}

var basePath;
if (typeof outFolder === 'string') {
basePath = path.resolve(cwd, outFolder);
} else if (typeof outFolder === 'function') {
basePath = path.resolve(cwd, outFolder(file));
}

var outFolderPath = (
typeof outFolder === 'string' ? outFolder : outFolder(file)
);
var basePath = path.resolve(cwd, outFolderPath);
var writePath = path.resolve(basePath, file.relative);
var writeFolder = path.dirname(writePath);

Expand Down

0 comments on commit e45e639

Please sign in to comment.