-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Remove vinyl-prepare & embed logic once again
- Loading branch information
Showing
7 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
|
||
var fs = require('graceful-fs'); | ||
var koalas = require('koalas'); | ||
var through = require('through2'); | ||
var valueOrFunction = require('value-or-function'); | ||
|
||
var string = valueOrFunction.string; | ||
var number = valueOrFunction.number; | ||
var boolean = valueOrFunction.boolean; | ||
|
||
function prepareWrite(outFolder, opt) { | ||
if (!opt) { | ||
opt = {}; | ||
} | ||
|
||
if (!outFolder) { | ||
throw new Error('Invalid output folder'); | ||
} | ||
|
||
function normalize(file, enc, cb) { | ||
var defaultMode = file.stat ? file.stat.mode : null; | ||
var mode = koalas(number(opt.mode, file), defaultMode); | ||
var flag = koalas(boolean(opt.overwrite, file), true) ? 'w' : 'wx'; | ||
var cwd = path.resolve(koalas(string(opt.cwd, file), process.cwd())); | ||
|
||
var outFolderPath = string(outFolder, file); | ||
if (!outFolderPath) { | ||
return cb(new Error('Invalid output folder')); | ||
} | ||
var basePath = path.resolve(cwd, outFolderPath); | ||
var writePath = path.resolve(basePath, file.relative); | ||
|
||
// Wire up new properties | ||
file.stat = (file.stat || new fs.Stats()); | ||
file.stat.mode = mode; | ||
file.flag = flag; | ||
file.cwd = cwd; | ||
file.base = basePath; | ||
file.path = writePath; | ||
|
||
cb(null, file); | ||
} | ||
|
||
return through.obj(normalize); | ||
} | ||
|
||
module.exports = prepareWrite; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
var through = require('through2'); | ||
var valueOrFunction = require('value-or-function'); | ||
|
||
var date = valueOrFunction.date; | ||
|
||
function prepareRead(opt) { | ||
if (!opt) { | ||
opt = {}; | ||
} | ||
|
||
function normalize(file, enc, callback) { | ||
|
||
// Skip this file if since option is set and current file is too old | ||
if (opt.since != null) { | ||
var since = date(opt.since, file); | ||
if (since === null) { | ||
return callback(new Error('Invalid since option')); | ||
} | ||
if (file.stat && file.stat.mtime <= since) { | ||
return callback(); | ||
} | ||
} | ||
|
||
return callback(null, file); | ||
} | ||
|
||
return through.obj(normalize); | ||
} | ||
|
||
module.exports = prepareRead; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
// TODO: currently a copy-paste of prepareWrite but should be customized | ||
|
||
var path = require('path'); | ||
|
||
var fs = require('graceful-fs'); | ||
var koalas = require('koalas'); | ||
var through = require('through2'); | ||
var valueOrFunction = require('value-or-function'); | ||
|
||
var string = valueOrFunction.string; | ||
var number = valueOrFunction.number; | ||
var boolean = valueOrFunction.boolean; | ||
|
||
function prepareSymlink(outFolder, opt) { | ||
if (!opt) { | ||
opt = {}; | ||
} | ||
|
||
if (!outFolder) { | ||
throw new Error('Invalid output folder'); | ||
} | ||
|
||
function normalize(file, enc, cb) { | ||
var defaultMode = file.stat ? file.stat.mode : null; | ||
var mode = koalas(number(opt.mode, file), defaultMode); | ||
var flag = koalas(boolean(opt.overwrite, file), true) ? 'w' : 'wx'; | ||
var cwd = path.resolve(koalas(string(opt.cwd, file), process.cwd())); | ||
|
||
var outFolderPath = string(outFolder, file); | ||
if (!outFolderPath) { | ||
return cb(new Error('Invalid output folder')); | ||
} | ||
var basePath = path.resolve(cwd, outFolderPath); | ||
var writePath = path.resolve(basePath, file.relative); | ||
|
||
// Wire up new properties | ||
file.stat = (file.stat || new fs.Stats()); | ||
file.stat.mode = mode; | ||
file.flag = flag; | ||
file.cwd = cwd; | ||
file.base = basePath; | ||
file.path = writePath; | ||
|
||
cb(null, file); | ||
} | ||
|
||
return through.obj(normalize); | ||
} | ||
|
||
module.exports = prepareSymlink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters