Added Gulp.js for compiling SCSS stylesheets
This commit is contained in:
6
node_modules/vinyl-fs/lib/constants.js
generated
vendored
Normal file
6
node_modules/vinyl-fs/lib/constants.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
MASK_MODE: parseInt('7777', 8),
|
||||
DEFAULT_FILE_MODE: parseInt('0666', 8),
|
||||
};
|
45
node_modules/vinyl-fs/lib/dest/index.js
generated
vendored
Normal file
45
node_modules/vinyl-fs/lib/dest/index.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
var lead = require('lead');
|
||||
var pumpify = require('pumpify');
|
||||
var mkdirpStream = require('fs-mkdirp-stream');
|
||||
var createResolver = require('resolve-options');
|
||||
|
||||
var config = require('./options');
|
||||
var prepare = require('./prepare');
|
||||
var sourcemap = require('./sourcemap');
|
||||
var writeContents = require('./write-contents');
|
||||
|
||||
var folderConfig = {
|
||||
outFolder: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
|
||||
function dest(outFolder, opt) {
|
||||
if (!outFolder) {
|
||||
throw new Error('Invalid dest() folder argument.' +
|
||||
' Please specify a non-empty string or a function.');
|
||||
}
|
||||
|
||||
var optResolver = createResolver(config, opt);
|
||||
var folderResolver = createResolver(folderConfig, { outFolder: outFolder });
|
||||
|
||||
function dirpath(file, callback) {
|
||||
var dirMode = optResolver.resolve('dirMode', file);
|
||||
|
||||
callback(null, file.dirname, dirMode);
|
||||
}
|
||||
|
||||
var saveStream = pumpify.obj(
|
||||
prepare(folderResolver, optResolver),
|
||||
sourcemap(optResolver),
|
||||
mkdirpStream.obj(dirpath),
|
||||
writeContents(optResolver)
|
||||
);
|
||||
|
||||
// Sink the output stream to start flowing
|
||||
return lead(saveStream);
|
||||
}
|
||||
|
||||
module.exports = dest;
|
41
node_modules/vinyl-fs/lib/dest/options.js
generated
vendored
Normal file
41
node_modules/vinyl-fs/lib/dest/options.js
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
var config = {
|
||||
cwd: {
|
||||
type: 'string',
|
||||
default: process.cwd,
|
||||
},
|
||||
mode: {
|
||||
type: 'number',
|
||||
default: function(file) {
|
||||
return file.stat ? file.stat.mode : null;
|
||||
},
|
||||
},
|
||||
dirMode: {
|
||||
type: 'number',
|
||||
},
|
||||
overwrite: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
append: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
sourcemaps: {
|
||||
type: ['string', 'boolean'],
|
||||
default: false,
|
||||
},
|
||||
// Symlink options
|
||||
relativeSymlinks: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
// This option is ignored on non-Windows platforms
|
||||
useJunctions: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = config;
|
48
node_modules/vinyl-fs/lib/dest/prepare.js
generated
vendored
Normal file
48
node_modules/vinyl-fs/lib/dest/prepare.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var Vinyl = require('vinyl');
|
||||
var through = require('through2');
|
||||
|
||||
function prepareWrite(folderResolver, optResolver) {
|
||||
if (!folderResolver) {
|
||||
throw new Error('Invalid output folder');
|
||||
}
|
||||
|
||||
function normalize(file, enc, cb) {
|
||||
if (!Vinyl.isVinyl(file)) {
|
||||
return cb(new Error('Received a non-Vinyl object in `dest()`'));
|
||||
}
|
||||
|
||||
// TODO: Remove this after people upgrade vinyl/transition from gulp-util
|
||||
if (typeof file.isSymbolic !== 'function') {
|
||||
file = new Vinyl(file);
|
||||
}
|
||||
|
||||
var outFolderPath = folderResolver.resolve('outFolder', file);
|
||||
if (!outFolderPath) {
|
||||
return cb(new Error('Invalid output folder'));
|
||||
}
|
||||
var cwd = path.resolve(optResolver.resolve('cwd', file));
|
||||
var basePath = path.resolve(cwd, outFolderPath);
|
||||
var writePath = path.resolve(basePath, file.relative);
|
||||
|
||||
// Wire up new properties
|
||||
file.cwd = cwd;
|
||||
file.base = basePath;
|
||||
file.path = writePath;
|
||||
if (!file.isSymbolic()) {
|
||||
var mode = optResolver.resolve('mode', file);
|
||||
file.stat = (file.stat || new fs.Stats());
|
||||
file.stat.mode = mode;
|
||||
}
|
||||
|
||||
cb(null, file);
|
||||
}
|
||||
|
||||
return through.obj(normalize);
|
||||
}
|
||||
|
||||
module.exports = prepareWrite;
|
38
node_modules/vinyl-fs/lib/dest/sourcemap.js
generated
vendored
Normal file
38
node_modules/vinyl-fs/lib/dest/sourcemap.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
var through = require('through2');
|
||||
var sourcemap = require('vinyl-sourcemap');
|
||||
|
||||
function sourcemapStream(optResolver) {
|
||||
|
||||
function saveSourcemap(file, enc, callback) {
|
||||
var self = this;
|
||||
|
||||
var srcMap = optResolver.resolve('sourcemaps', file);
|
||||
|
||||
if (!srcMap) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
var srcMapLocation = (typeof srcMap === 'string' ? srcMap : undefined);
|
||||
|
||||
sourcemap.write(file, srcMapLocation, onWrite);
|
||||
|
||||
function onWrite(sourcemapErr, updatedFile, sourcemapFile) {
|
||||
if (sourcemapErr) {
|
||||
return callback(sourcemapErr);
|
||||
}
|
||||
|
||||
self.push(updatedFile);
|
||||
if (sourcemapFile) {
|
||||
self.push(sourcemapFile);
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
return through.obj(saveSourcemap);
|
||||
}
|
||||
|
||||
module.exports = sourcemapStream;
|
59
node_modules/vinyl-fs/lib/dest/write-contents/index.js
generated
vendored
Normal file
59
node_modules/vinyl-fs/lib/dest/write-contents/index.js
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
var through = require('through2');
|
||||
|
||||
var writeDir = require('./write-dir');
|
||||
var writeStream = require('./write-stream');
|
||||
var writeBuffer = require('./write-buffer');
|
||||
var writeSymbolicLink = require('./write-symbolic-link');
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
|
||||
function writeContents(optResolver) {
|
||||
|
||||
function writeFile(file, enc, callback) {
|
||||
// Write it as a symlink
|
||||
if (file.isSymbolic()) {
|
||||
return writeSymbolicLink(file, optResolver, onWritten);
|
||||
}
|
||||
|
||||
// If directory then mkdirp it
|
||||
if (file.isDirectory()) {
|
||||
return writeDir(file, optResolver, onWritten);
|
||||
}
|
||||
|
||||
// Stream it to disk yo
|
||||
if (file.isStream()) {
|
||||
return writeStream(file, optResolver, onWritten);
|
||||
}
|
||||
|
||||
// Write it like normal
|
||||
if (file.isBuffer()) {
|
||||
return writeBuffer(file, optResolver, onWritten);
|
||||
}
|
||||
|
||||
// If no contents then do nothing
|
||||
if (file.isNull()) {
|
||||
return onWritten();
|
||||
}
|
||||
|
||||
// This is invoked by the various writeXxx modules when they've finished
|
||||
// writing the contents.
|
||||
function onWritten(writeErr) {
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: optResolver.resolve('append', file),
|
||||
});
|
||||
if (fo.isFatalOverwriteError(writeErr, flags)) {
|
||||
return callback(writeErr);
|
||||
}
|
||||
|
||||
callback(null, file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return through.obj(writeFile);
|
||||
}
|
||||
|
||||
module.exports = writeContents;
|
31
node_modules/vinyl-fs/lib/dest/write-contents/write-buffer.js
generated
vendored
Normal file
31
node_modules/vinyl-fs/lib/dest/write-contents/write-buffer.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
|
||||
function writeBuffer(file, optResolver, onWritten) {
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: optResolver.resolve('append', file),
|
||||
});
|
||||
var opt = {
|
||||
mode: file.stat.mode,
|
||||
flags: flags,
|
||||
};
|
||||
|
||||
fo.writeFile(file.path, file.contents, opt, onWriteFile);
|
||||
|
||||
function onWriteFile(writeErr, fd) {
|
||||
if (writeErr) {
|
||||
return fo.closeFd(writeErr, fd, onWritten);
|
||||
}
|
||||
|
||||
fo.updateMetadata(fd, file, onUpdate);
|
||||
|
||||
function onUpdate(updateErr) {
|
||||
fo.closeFd(updateErr, fd, onWritten);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = writeBuffer;
|
51
node_modules/vinyl-fs/lib/dest/write-contents/write-dir.js
generated
vendored
Normal file
51
node_modules/vinyl-fs/lib/dest/write-contents/write-dir.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
|
||||
var mkdirp = require('fs-mkdirp-stream/mkdirp');
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
|
||||
function writeDir(file, optResolver, onWritten) {
|
||||
mkdirp(file.path, file.stat.mode, onMkdirp);
|
||||
|
||||
function onMkdirp(mkdirpErr) {
|
||||
if (mkdirpErr) {
|
||||
return onWritten(mkdirpErr);
|
||||
}
|
||||
|
||||
fs.open(file.path, 'r', onOpen);
|
||||
}
|
||||
|
||||
function onOpen(openErr, fd) {
|
||||
// If we don't have access, just move along
|
||||
if (isInaccessible(openErr)) {
|
||||
return fo.closeFd(null, fd, onWritten);
|
||||
}
|
||||
|
||||
if (openErr) {
|
||||
return fo.closeFd(openErr, fd, onWritten);
|
||||
}
|
||||
|
||||
fo.updateMetadata(fd, file, onUpdate);
|
||||
|
||||
function onUpdate(updateErr) {
|
||||
fo.closeFd(updateErr, fd, onWritten);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function isInaccessible(err) {
|
||||
if (!err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (err.code === 'EACCES') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = writeDir;
|
62
node_modules/vinyl-fs/lib/dest/write-contents/write-stream.js
generated
vendored
Normal file
62
node_modules/vinyl-fs/lib/dest/write-contents/write-stream.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
var readStream = require('../../src/read-contents/read-stream');
|
||||
|
||||
function writeStream(file, optResolver, onWritten) {
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: optResolver.resolve('append', file),
|
||||
});
|
||||
var opt = {
|
||||
mode: file.stat.mode,
|
||||
// TODO: need to test this
|
||||
flags: flags,
|
||||
};
|
||||
|
||||
// TODO: is this the best API?
|
||||
var outStream = fo.createWriteStream(file.path, opt, onFlush);
|
||||
|
||||
file.contents.once('error', onComplete);
|
||||
outStream.once('error', onComplete);
|
||||
outStream.once('finish', onComplete);
|
||||
|
||||
// TODO: should this use a clone?
|
||||
file.contents.pipe(outStream);
|
||||
|
||||
function onComplete(streamErr) {
|
||||
// Cleanup event handlers before closing
|
||||
file.contents.removeListener('error', onComplete);
|
||||
outStream.removeListener('error', onComplete);
|
||||
outStream.removeListener('finish', onComplete);
|
||||
|
||||
// Need to guarantee the fd is closed before forwarding the error
|
||||
outStream.once('close', onClose);
|
||||
outStream.end();
|
||||
|
||||
function onClose(closeErr) {
|
||||
onWritten(streamErr || closeErr);
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
function onFlush(fd, callback) {
|
||||
// TODO: removing this before readStream because it replaces the stream
|
||||
file.contents.removeListener('error', onComplete);
|
||||
|
||||
// TODO: this is doing sync stuff & the callback seems unnecessary
|
||||
// TODO: Replace the contents stream or use a clone?
|
||||
readStream(file, complete);
|
||||
|
||||
function complete() {
|
||||
if (typeof fd !== 'number') {
|
||||
return callback();
|
||||
}
|
||||
|
||||
fo.updateMetadata(fd, file, callback);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = writeStream;
|
77
node_modules/vinyl-fs/lib/dest/write-contents/write-symbolic-link.js
generated
vendored
Normal file
77
node_modules/vinyl-fs/lib/dest/write-contents/write-symbolic-link.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
var os = require('os');
|
||||
var path = require('path');
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
|
||||
var isWindows = (os.platform() === 'win32');
|
||||
|
||||
function writeSymbolicLink(file, optResolver, onWritten) {
|
||||
if (!file.symlink) {
|
||||
return onWritten(new Error('Missing symlink property on symbolic vinyl'));
|
||||
}
|
||||
|
||||
var isRelative = optResolver.resolve('relativeSymlinks', file);
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: optResolver.resolve('append', file),
|
||||
});
|
||||
|
||||
if (!isWindows) {
|
||||
// On non-Windows, just use 'file'
|
||||
return createLinkWithType('file');
|
||||
}
|
||||
|
||||
fo.reflectStat(file.symlink, file, onReflect);
|
||||
|
||||
function onReflect(statErr) {
|
||||
if (statErr && statErr.code !== 'ENOENT') {
|
||||
return onWritten(statErr);
|
||||
}
|
||||
|
||||
// This option provides a way to create a Junction instead of a
|
||||
// Directory symlink on Windows. This comes with the following caveats:
|
||||
// * NTFS Junctions cannot be relative.
|
||||
// * NTFS Junctions MUST be directories.
|
||||
// * NTFS Junctions must be on the same file system.
|
||||
// * Most products CANNOT detect a directory is a Junction:
|
||||
// This has the side effect of possibly having a whole directory
|
||||
// deleted when a product is deleting the Junction directory.
|
||||
// For example, JetBrains product lines will delete the entire contents
|
||||
// of the TARGET directory because the product does not realize it's
|
||||
// a symlink as the JVM and Node return false for isSymlink.
|
||||
|
||||
// This function is Windows only, so we don't need to check again
|
||||
var useJunctions = optResolver.resolve('useJunctions', file);
|
||||
|
||||
var dirType = useJunctions ? 'junction' : 'dir';
|
||||
// Dangling links are always 'file'
|
||||
var type = !statErr && file.isDirectory() ? dirType : 'file';
|
||||
|
||||
createLinkWithType(type);
|
||||
}
|
||||
|
||||
function createLinkWithType(type) {
|
||||
// This is done after prepare() to use the adjusted file.base property
|
||||
if (isRelative && type !== 'junction') {
|
||||
file.symlink = path.relative(file.base, file.symlink);
|
||||
}
|
||||
|
||||
var opts = {
|
||||
flags: flags,
|
||||
type: type,
|
||||
};
|
||||
fo.symlink(file.symlink, file.path, opts, onSymlink);
|
||||
|
||||
function onSymlink(symlinkErr) {
|
||||
if (symlinkErr) {
|
||||
return onWritten(symlinkErr);
|
||||
}
|
||||
|
||||
fo.reflectLinkStat(file.path, file, onWritten);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = writeSymbolicLink;
|
496
node_modules/vinyl-fs/lib/file-operations.js
generated
vendored
Normal file
496
node_modules/vinyl-fs/lib/file-operations.js
generated
vendored
Normal file
@ -0,0 +1,496 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var assign = require('object.assign');
|
||||
var date = require('value-or-function').date;
|
||||
var Writable = require('readable-stream').Writable;
|
||||
|
||||
var constants = require('./constants');
|
||||
|
||||
var APPEND_MODE_REGEXP = /a/;
|
||||
|
||||
function closeFd(propagatedErr, fd, callback) {
|
||||
if (typeof fd !== 'number') {
|
||||
return callback(propagatedErr);
|
||||
}
|
||||
|
||||
fs.close(fd, onClosed);
|
||||
|
||||
function onClosed(closeErr) {
|
||||
if (propagatedErr || closeErr) {
|
||||
return callback(propagatedErr || closeErr);
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function isValidUnixId(id) {
|
||||
if (typeof id !== 'number') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getFlags(options) {
|
||||
var flags = !options.append ? 'w' : 'a';
|
||||
if (!options.overwrite) {
|
||||
flags += 'x';
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
function isFatalOverwriteError(err, flags) {
|
||||
if (!err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (err.code === 'EEXIST' && flags[1] === 'x') {
|
||||
// Handle scenario for file overwrite failures.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, this is a fatal error
|
||||
return true;
|
||||
}
|
||||
|
||||
function isFatalUnlinkError(err) {
|
||||
if (!err || err.code === 'ENOENT') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getModeDiff(fsMode, vinylMode) {
|
||||
var modeDiff = 0;
|
||||
|
||||
if (typeof vinylMode === 'number') {
|
||||
modeDiff = (vinylMode ^ fsMode) & constants.MASK_MODE;
|
||||
}
|
||||
|
||||
return modeDiff;
|
||||
}
|
||||
|
||||
function getTimesDiff(fsStat, vinylStat) {
|
||||
|
||||
var mtime = date(vinylStat.mtime) || 0;
|
||||
if (!mtime) {
|
||||
return;
|
||||
}
|
||||
|
||||
var atime = date(vinylStat.atime) || 0;
|
||||
if (+mtime === +fsStat.mtime &&
|
||||
+atime === +fsStat.atime) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!atime) {
|
||||
atime = date(fsStat.atime) || undefined;
|
||||
}
|
||||
|
||||
var timesDiff = {
|
||||
mtime: vinylStat.mtime,
|
||||
atime: atime,
|
||||
};
|
||||
|
||||
return timesDiff;
|
||||
}
|
||||
|
||||
function getOwnerDiff(fsStat, vinylStat) {
|
||||
if (!isValidUnixId(vinylStat.uid) &&
|
||||
!isValidUnixId(vinylStat.gid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((!isValidUnixId(fsStat.uid) && !isValidUnixId(vinylStat.uid)) ||
|
||||
(!isValidUnixId(fsStat.gid) && !isValidUnixId(vinylStat.gid))) {
|
||||
return;
|
||||
}
|
||||
|
||||
var uid = fsStat.uid; // Default to current uid.
|
||||
if (isValidUnixId(vinylStat.uid)) {
|
||||
uid = vinylStat.uid;
|
||||
}
|
||||
|
||||
var gid = fsStat.gid; // Default to current gid.
|
||||
if (isValidUnixId(vinylStat.gid)) {
|
||||
gid = vinylStat.gid;
|
||||
}
|
||||
|
||||
if (uid === fsStat.uid &&
|
||||
gid === fsStat.gid) {
|
||||
return;
|
||||
}
|
||||
|
||||
var ownerDiff = {
|
||||
uid: uid,
|
||||
gid: gid,
|
||||
};
|
||||
|
||||
return ownerDiff;
|
||||
}
|
||||
|
||||
function isOwner(fsStat) {
|
||||
var hasGetuid = (typeof process.getuid === 'function');
|
||||
var hasGeteuid = (typeof process.geteuid === 'function');
|
||||
|
||||
// If we don't have either, assume we don't have permissions.
|
||||
// This should only happen on Windows.
|
||||
// Windows basically noops fchmod and errors on futimes called on directories.
|
||||
if (!hasGeteuid && !hasGetuid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var uid;
|
||||
if (hasGeteuid) {
|
||||
uid = process.geteuid();
|
||||
} else {
|
||||
uid = process.getuid();
|
||||
}
|
||||
|
||||
if (fsStat.uid !== uid && uid !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function reflectStat(path, file, callback) {
|
||||
// Set file.stat to the reflect current state on disk
|
||||
fs.stat(path, onStat);
|
||||
|
||||
function onStat(statErr, stat) {
|
||||
if (statErr) {
|
||||
return callback(statErr);
|
||||
}
|
||||
|
||||
file.stat = stat;
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function reflectLinkStat(path, file, callback) {
|
||||
// Set file.stat to the reflect current state on disk
|
||||
fs.lstat(path, onLstat);
|
||||
|
||||
function onLstat(lstatErr, stat) {
|
||||
if (lstatErr) {
|
||||
return callback(lstatErr);
|
||||
}
|
||||
|
||||
file.stat = stat;
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function updateMetadata(fd, file, callback) {
|
||||
|
||||
fs.fstat(fd, onStat);
|
||||
|
||||
function onStat(statErr, stat) {
|
||||
if (statErr) {
|
||||
return callback(statErr);
|
||||
}
|
||||
|
||||
// Check if mode needs to be updated
|
||||
var modeDiff = getModeDiff(stat.mode, file.stat.mode);
|
||||
|
||||
// Check if atime/mtime need to be updated
|
||||
var timesDiff = getTimesDiff(stat, file.stat);
|
||||
|
||||
// Check if uid/gid need to be updated
|
||||
var ownerDiff = getOwnerDiff(stat, file.stat);
|
||||
|
||||
// Set file.stat to the reflect current state on disk
|
||||
assign(file.stat, stat);
|
||||
|
||||
// Nothing to do
|
||||
if (!modeDiff && !timesDiff && !ownerDiff) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// Check access, `futimes`, `fchmod` & `fchown` only work if we own
|
||||
// the file, or if we are effectively root (`fchown` only when root).
|
||||
if (!isOwner(stat)) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
if (modeDiff) {
|
||||
return mode();
|
||||
}
|
||||
if (timesDiff) {
|
||||
return times();
|
||||
}
|
||||
owner();
|
||||
|
||||
function mode() {
|
||||
var mode = stat.mode ^ modeDiff;
|
||||
|
||||
fs.fchmod(fd, mode, onFchmod);
|
||||
|
||||
function onFchmod(fchmodErr) {
|
||||
if (!fchmodErr) {
|
||||
file.stat.mode = mode;
|
||||
}
|
||||
if (timesDiff) {
|
||||
return times(fchmodErr);
|
||||
}
|
||||
if (ownerDiff) {
|
||||
return owner(fchmodErr);
|
||||
}
|
||||
callback(fchmodErr);
|
||||
}
|
||||
}
|
||||
|
||||
function times(propagatedErr) {
|
||||
fs.futimes(fd, timesDiff.atime, timesDiff.mtime, onFutimes);
|
||||
|
||||
function onFutimes(futimesErr) {
|
||||
if (!futimesErr) {
|
||||
file.stat.atime = timesDiff.atime;
|
||||
file.stat.mtime = timesDiff.mtime;
|
||||
}
|
||||
if (ownerDiff) {
|
||||
return owner(propagatedErr || futimesErr);
|
||||
}
|
||||
callback(propagatedErr || futimesErr);
|
||||
}
|
||||
}
|
||||
|
||||
function owner(propagatedErr) {
|
||||
fs.fchown(fd, ownerDiff.uid, ownerDiff.gid, onFchown);
|
||||
|
||||
function onFchown(fchownErr) {
|
||||
if (!fchownErr) {
|
||||
file.stat.uid = ownerDiff.uid;
|
||||
file.stat.gid = ownerDiff.gid;
|
||||
}
|
||||
callback(propagatedErr || fchownErr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function symlink(srcPath, destPath, opts, callback) {
|
||||
// Because fs.symlink does not allow atomic overwrite option with flags, we
|
||||
// delete and recreate if the link already exists and overwrite is true.
|
||||
if (opts.flags === 'w') {
|
||||
// TODO What happens when we call unlink with windows junctions?
|
||||
fs.unlink(destPath, onUnlink);
|
||||
} else {
|
||||
fs.symlink(srcPath, destPath, opts.type, onSymlink);
|
||||
}
|
||||
|
||||
function onUnlink(unlinkErr) {
|
||||
if (isFatalUnlinkError(unlinkErr)) {
|
||||
return callback(unlinkErr);
|
||||
}
|
||||
fs.symlink(srcPath, destPath, opts.type, onSymlink);
|
||||
}
|
||||
|
||||
function onSymlink(symlinkErr) {
|
||||
if (isFatalOverwriteError(symlinkErr, opts.flags)) {
|
||||
return callback(symlinkErr);
|
||||
}
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Custom writeFile implementation because we need access to the
|
||||
file descriptor after the write is complete.
|
||||
Most of the implementation taken from node core.
|
||||
*/
|
||||
function writeFile(filepath, data, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (!Buffer.isBuffer(data)) {
|
||||
return callback(new TypeError('Data must be a Buffer'));
|
||||
}
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
// Default the same as node
|
||||
var mode = options.mode || constants.DEFAULT_FILE_MODE;
|
||||
var flags = options.flags || 'w';
|
||||
var position = APPEND_MODE_REGEXP.test(flags) ? null : 0;
|
||||
|
||||
fs.open(filepath, flags, mode, onOpen);
|
||||
|
||||
function onOpen(openErr, fd) {
|
||||
if (openErr) {
|
||||
return onComplete(openErr);
|
||||
}
|
||||
|
||||
fs.write(fd, data, 0, data.length, position, onComplete);
|
||||
|
||||
function onComplete(writeErr) {
|
||||
callback(writeErr, fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createWriteStream(path, options, flush) {
|
||||
return new WriteStream(path, options, flush);
|
||||
}
|
||||
|
||||
// Taken from node core and altered to receive a flush function and simplified
|
||||
// To be used for cleanup (like updating times/mode/etc)
|
||||
function WriteStream(path, options, flush) {
|
||||
// Not exposed so we can avoid the case where someone doesn't use `new`
|
||||
|
||||
if (typeof options === 'function') {
|
||||
flush = options;
|
||||
options = null;
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
Writable.call(this, options);
|
||||
|
||||
this.flush = flush;
|
||||
this.path = path;
|
||||
|
||||
this.mode = options.mode || constants.DEFAULT_FILE_MODE;
|
||||
this.flags = options.flags || 'w';
|
||||
|
||||
// Used by node's `fs.WriteStream`
|
||||
this.fd = null;
|
||||
this.start = null;
|
||||
|
||||
this.open();
|
||||
|
||||
// Dispose on finish.
|
||||
this.once('finish', this.close);
|
||||
}
|
||||
|
||||
util.inherits(WriteStream, Writable);
|
||||
|
||||
WriteStream.prototype.open = function() {
|
||||
var self = this;
|
||||
|
||||
fs.open(this.path, this.flags, this.mode, onOpen);
|
||||
|
||||
function onOpen(openErr, fd) {
|
||||
if (openErr) {
|
||||
self.destroy();
|
||||
self.emit('error', openErr);
|
||||
return;
|
||||
}
|
||||
|
||||
self.fd = fd;
|
||||
self.emit('open', fd);
|
||||
}
|
||||
};
|
||||
|
||||
// Use our `end` method since it is patched for flush
|
||||
WriteStream.prototype.destroySoon = WriteStream.prototype.end;
|
||||
|
||||
WriteStream.prototype._destroy = function(err, cb) {
|
||||
this.close(function(err2) {
|
||||
cb(err || err2);
|
||||
});
|
||||
};
|
||||
|
||||
WriteStream.prototype.close = function(cb) {
|
||||
var that = this;
|
||||
|
||||
if (cb) {
|
||||
this.once('close', cb);
|
||||
}
|
||||
|
||||
if (this.closed || typeof this.fd !== 'number') {
|
||||
if (typeof this.fd !== 'number') {
|
||||
this.once('open', closeOnOpen);
|
||||
return;
|
||||
}
|
||||
|
||||
return process.nextTick(function() {
|
||||
that.emit('close');
|
||||
});
|
||||
}
|
||||
|
||||
this.closed = true;
|
||||
|
||||
fs.close(this.fd, function(er) {
|
||||
if (er) {
|
||||
that.emit('error', er);
|
||||
} else {
|
||||
that.emit('close');
|
||||
}
|
||||
});
|
||||
|
||||
this.fd = null;
|
||||
};
|
||||
|
||||
WriteStream.prototype._final = function(callback) {
|
||||
if (typeof this.flush !== 'function') {
|
||||
return callback();
|
||||
}
|
||||
|
||||
this.flush(this.fd, callback);
|
||||
};
|
||||
|
||||
function closeOnOpen() {
|
||||
this.close();
|
||||
}
|
||||
|
||||
WriteStream.prototype._write = function(data, encoding, callback) {
|
||||
var self = this;
|
||||
|
||||
// This is from node core but I have no idea how to get code coverage on it
|
||||
if (!Buffer.isBuffer(data)) {
|
||||
return this.emit('error', new Error('Invalid data'));
|
||||
}
|
||||
|
||||
if (typeof this.fd !== 'number') {
|
||||
return this.once('open', onOpen);
|
||||
}
|
||||
|
||||
fs.write(this.fd, data, 0, data.length, null, onWrite);
|
||||
|
||||
function onOpen() {
|
||||
self._write(data, encoding, callback);
|
||||
}
|
||||
|
||||
function onWrite(writeErr) {
|
||||
if (writeErr) {
|
||||
self.destroy();
|
||||
callback(writeErr);
|
||||
return;
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
closeFd: closeFd,
|
||||
isValidUnixId: isValidUnixId,
|
||||
getFlags: getFlags,
|
||||
isFatalOverwriteError: isFatalOverwriteError,
|
||||
isFatalUnlinkError: isFatalUnlinkError,
|
||||
getModeDiff: getModeDiff,
|
||||
getTimesDiff: getTimesDiff,
|
||||
getOwnerDiff: getOwnerDiff,
|
||||
isOwner: isOwner,
|
||||
reflectStat: reflectStat,
|
||||
reflectLinkStat: reflectLinkStat,
|
||||
updateMetadata: updateMetadata,
|
||||
symlink: symlink,
|
||||
writeFile: writeFile,
|
||||
createWriteStream: createWriteStream,
|
||||
};
|
38
node_modules/vinyl-fs/lib/src/index.js
generated
vendored
Normal file
38
node_modules/vinyl-fs/lib/src/index.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
var gs = require('glob-stream');
|
||||
var pumpify = require('pumpify');
|
||||
var toThrough = require('to-through');
|
||||
var isValidGlob = require('is-valid-glob');
|
||||
var createResolver = require('resolve-options');
|
||||
|
||||
var config = require('./options');
|
||||
var prepare = require('./prepare');
|
||||
var wrapVinyl = require('./wrap-vinyl');
|
||||
var sourcemap = require('./sourcemap');
|
||||
var readContents = require('./read-contents');
|
||||
var resolveSymlinks = require('./resolve-symlinks');
|
||||
|
||||
function src(glob, opt) {
|
||||
var optResolver = createResolver(config, opt);
|
||||
|
||||
if (!isValidGlob(glob)) {
|
||||
throw new Error('Invalid glob argument: ' + glob);
|
||||
}
|
||||
|
||||
var streams = [
|
||||
gs(glob, opt),
|
||||
wrapVinyl(optResolver),
|
||||
resolveSymlinks(optResolver),
|
||||
prepare(optResolver),
|
||||
readContents(optResolver),
|
||||
sourcemap(optResolver),
|
||||
];
|
||||
|
||||
var outputStream = pumpify.obj(streams);
|
||||
|
||||
return toThrough(outputStream);
|
||||
}
|
||||
|
||||
|
||||
module.exports = src;
|
29
node_modules/vinyl-fs/lib/src/options.js
generated
vendored
Normal file
29
node_modules/vinyl-fs/lib/src/options.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
var config = {
|
||||
buffer: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
read: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
since: {
|
||||
type: 'date',
|
||||
},
|
||||
removeBOM: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
sourcemaps: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
resolveSymlinks: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = config;
|
22
node_modules/vinyl-fs/lib/src/prepare.js
generated
vendored
Normal file
22
node_modules/vinyl-fs/lib/src/prepare.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
var through = require('through2');
|
||||
|
||||
function prepareRead(optResolver) {
|
||||
|
||||
function normalize(file, enc, callback) {
|
||||
|
||||
var since = optResolver.resolve('since', file);
|
||||
|
||||
// Skip this file if since option is set and current file is too old
|
||||
if (file.stat && file.stat.mtime <= since) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
return through.obj(normalize);
|
||||
}
|
||||
|
||||
module.exports = prepareRead;
|
52
node_modules/vinyl-fs/lib/src/read-contents/index.js
generated
vendored
Normal file
52
node_modules/vinyl-fs/lib/src/read-contents/index.js
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
var through = require('through2');
|
||||
|
||||
var readDir = require('./read-dir');
|
||||
var readStream = require('./read-stream');
|
||||
var readBuffer = require('./read-buffer');
|
||||
var readSymbolicLink = require('./read-symbolic-link');
|
||||
|
||||
function readContents(optResolver) {
|
||||
|
||||
function readFile(file, enc, callback) {
|
||||
|
||||
// Skip reading contents if read option says so
|
||||
var read = optResolver.resolve('read', file);
|
||||
if (!read) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
// Don't fail to read a directory
|
||||
if (file.isDirectory()) {
|
||||
return readDir(file, optResolver, onRead);
|
||||
}
|
||||
|
||||
// Process symbolic links included with `resolveSymlinks` option
|
||||
if (file.stat && file.stat.isSymbolicLink()) {
|
||||
return readSymbolicLink(file, optResolver, onRead);
|
||||
}
|
||||
|
||||
// Read and pass full contents
|
||||
var buffer = optResolver.resolve('buffer', file);
|
||||
if (buffer) {
|
||||
return readBuffer(file, optResolver, onRead);
|
||||
}
|
||||
|
||||
// Don't buffer anything - just pass streams
|
||||
return readStream(file, optResolver, onRead);
|
||||
|
||||
// This is invoked by the various readXxx modules when they've finished
|
||||
// reading the contents.
|
||||
function onRead(readErr) {
|
||||
if (readErr) {
|
||||
return callback(readErr);
|
||||
}
|
||||
return callback(null, file);
|
||||
}
|
||||
}
|
||||
|
||||
return through.obj(readFile);
|
||||
}
|
||||
|
||||
module.exports = readContents;
|
25
node_modules/vinyl-fs/lib/src/read-contents/read-buffer.js
generated
vendored
Normal file
25
node_modules/vinyl-fs/lib/src/read-contents/read-buffer.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var removeBomBuffer = require('remove-bom-buffer');
|
||||
|
||||
function bufferFile(file, optResolver, onRead) {
|
||||
fs.readFile(file.path, onReadFile);
|
||||
|
||||
function onReadFile(readErr, data) {
|
||||
if (readErr) {
|
||||
return onRead(readErr);
|
||||
}
|
||||
|
||||
var removeBOM = optResolver.resolve('removeBOM', file);
|
||||
if (removeBOM) {
|
||||
file.contents = removeBomBuffer(data);
|
||||
} else {
|
||||
file.contents = data;
|
||||
}
|
||||
|
||||
onRead();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = bufferFile;
|
8
node_modules/vinyl-fs/lib/src/read-contents/read-dir.js
generated
vendored
Normal file
8
node_modules/vinyl-fs/lib/src/read-contents/read-dir.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
function readDir(file, optResolver, onRead) {
|
||||
// Do nothing for now
|
||||
onRead();
|
||||
}
|
||||
|
||||
module.exports = readDir;
|
31
node_modules/vinyl-fs/lib/src/read-contents/read-stream.js
generated
vendored
Normal file
31
node_modules/vinyl-fs/lib/src/read-contents/read-stream.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var removeBomStream = require('remove-bom-stream');
|
||||
var lazystream = require('lazystream');
|
||||
var createResolver = require('resolve-options');
|
||||
|
||||
function streamFile(file, optResolver, onRead) {
|
||||
if (typeof optResolver === 'function') {
|
||||
onRead = optResolver;
|
||||
optResolver = createResolver();
|
||||
}
|
||||
|
||||
var filePath = file.path;
|
||||
|
||||
var removeBOM = optResolver.resolve('removeBOM', file);
|
||||
|
||||
file.contents = new lazystream.Readable(function() {
|
||||
var contents = fs.createReadStream(filePath);
|
||||
|
||||
if (removeBOM) {
|
||||
return contents.pipe(removeBomStream());
|
||||
}
|
||||
|
||||
return contents;
|
||||
});
|
||||
|
||||
onRead();
|
||||
}
|
||||
|
||||
module.exports = streamFile;
|
20
node_modules/vinyl-fs/lib/src/read-contents/read-symbolic-link.js
generated
vendored
Normal file
20
node_modules/vinyl-fs/lib/src/read-contents/read-symbolic-link.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
|
||||
function readLink(file, optResolver, onRead) {
|
||||
fs.readlink(file.path, onReadlink);
|
||||
|
||||
function onReadlink(readErr, target) {
|
||||
if (readErr) {
|
||||
return onRead(readErr);
|
||||
}
|
||||
|
||||
// Store the link target path
|
||||
file.symlink = target;
|
||||
|
||||
onRead();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = readLink;
|
36
node_modules/vinyl-fs/lib/src/resolve-symlinks.js
generated
vendored
Normal file
36
node_modules/vinyl-fs/lib/src/resolve-symlinks.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
var through = require('through2');
|
||||
var fo = require('../file-operations');
|
||||
|
||||
function resolveSymlinks(optResolver) {
|
||||
|
||||
// A stat property is exposed on file objects as a (wanted) side effect
|
||||
function resolveFile(file, enc, callback) {
|
||||
|
||||
fo.reflectLinkStat(file.path, file, onReflect);
|
||||
|
||||
function onReflect(statErr) {
|
||||
if (statErr) {
|
||||
return callback(statErr);
|
||||
}
|
||||
|
||||
if (!file.stat.isSymbolicLink()) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
var resolveSymlinks = optResolver.resolve('resolveSymlinks', file);
|
||||
|
||||
if (!resolveSymlinks) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
// Get target's stats
|
||||
fo.reflectStat(file.path, file, onReflect);
|
||||
}
|
||||
}
|
||||
|
||||
return through.obj(resolveFile);
|
||||
}
|
||||
|
||||
module.exports = resolveSymlinks;
|
29
node_modules/vinyl-fs/lib/src/sourcemap.js
generated
vendored
Normal file
29
node_modules/vinyl-fs/lib/src/sourcemap.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
var through = require('through2');
|
||||
var sourcemap = require('vinyl-sourcemap');
|
||||
|
||||
function sourcemapStream(optResolver) {
|
||||
|
||||
function addSourcemap(file, enc, callback) {
|
||||
var srcMap = optResolver.resolve('sourcemaps', file);
|
||||
|
||||
if (!srcMap) {
|
||||
return callback(null, file);
|
||||
}
|
||||
|
||||
sourcemap.add(file, onAdd);
|
||||
|
||||
function onAdd(sourcemapErr, updatedFile) {
|
||||
if (sourcemapErr) {
|
||||
return callback(sourcemapErr);
|
||||
}
|
||||
|
||||
callback(null, updatedFile);
|
||||
}
|
||||
}
|
||||
|
||||
return through.obj(addSourcemap);
|
||||
}
|
||||
|
||||
module.exports = sourcemapStream;
|
18
node_modules/vinyl-fs/lib/src/wrap-vinyl.js
generated
vendored
Normal file
18
node_modules/vinyl-fs/lib/src/wrap-vinyl.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var File = require('vinyl');
|
||||
var through = require('through2');
|
||||
|
||||
function wrapVinyl() {
|
||||
|
||||
function wrapFile(globFile, enc, callback) {
|
||||
|
||||
var file = new File(globFile);
|
||||
|
||||
callback(null, file);
|
||||
}
|
||||
|
||||
return through.obj(wrapFile);
|
||||
}
|
||||
|
||||
module.exports = wrapVinyl;
|
43
node_modules/vinyl-fs/lib/symlink/index.js
generated
vendored
Normal file
43
node_modules/vinyl-fs/lib/symlink/index.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
var pumpify = require('pumpify');
|
||||
var lead = require('lead');
|
||||
var mkdirpStream = require('fs-mkdirp-stream');
|
||||
var createResolver = require('resolve-options');
|
||||
|
||||
var config = require('./options');
|
||||
var prepare = require('./prepare');
|
||||
var linkFile = require('./link-file');
|
||||
|
||||
var folderConfig = {
|
||||
outFolder: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
|
||||
function symlink(outFolder, opt) {
|
||||
if (!outFolder) {
|
||||
throw new Error('Invalid symlink() folder argument.' +
|
||||
' Please specify a non-empty string or a function.');
|
||||
}
|
||||
|
||||
var optResolver = createResolver(config, opt);
|
||||
var folderResolver = createResolver(folderConfig, { outFolder: outFolder });
|
||||
|
||||
function dirpath(file, callback) {
|
||||
var dirMode = optResolver.resolve('dirMode', file);
|
||||
|
||||
callback(null, file.dirname, dirMode);
|
||||
}
|
||||
|
||||
var stream = pumpify.obj(
|
||||
prepare(folderResolver, optResolver),
|
||||
mkdirpStream.obj(dirpath),
|
||||
linkFile(optResolver)
|
||||
);
|
||||
|
||||
// Sink the stream to start flowing
|
||||
return lead(stream);
|
||||
}
|
||||
|
||||
module.exports = symlink;
|
89
node_modules/vinyl-fs/lib/symlink/link-file.js
generated
vendored
Normal file
89
node_modules/vinyl-fs/lib/symlink/link-file.js
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
|
||||
var os = require('os');
|
||||
var path = require('path');
|
||||
|
||||
var through = require('through2');
|
||||
|
||||
var fo = require('../file-operations');
|
||||
|
||||
var isWindows = (os.platform() === 'win32');
|
||||
|
||||
function linkStream(optResolver) {
|
||||
|
||||
function linkFile(file, enc, callback) {
|
||||
var isRelative = optResolver.resolve('relativeSymlinks', file);
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: false,
|
||||
});
|
||||
|
||||
if (!isWindows) {
|
||||
// On non-Windows, just use 'file'
|
||||
return createLinkWithType('file');
|
||||
}
|
||||
|
||||
fo.reflectStat(file.symlink, file, onReflectTarget);
|
||||
|
||||
function onReflectTarget(statErr) {
|
||||
if (statErr && statErr.code !== 'ENOENT') {
|
||||
return callback(statErr);
|
||||
}
|
||||
// If target doesn't exist, the vinyl will still carry the target stats.
|
||||
// Let's use those to determine which kind of dangling link to create.
|
||||
|
||||
// This option provides a way to create a Junction instead of a
|
||||
// Directory symlink on Windows. This comes with the following caveats:
|
||||
// * NTFS Junctions cannot be relative.
|
||||
// * NTFS Junctions MUST be directories.
|
||||
// * NTFS Junctions must be on the same file system.
|
||||
// * Most products CANNOT detect a directory is a Junction:
|
||||
// This has the side effect of possibly having a whole directory
|
||||
// deleted when a product is deleting the Junction directory.
|
||||
// For example, JetBrains product lines will delete the entire contents
|
||||
// of the TARGET directory because the product does not realize it's
|
||||
// a symlink as the JVM and Node return false for isSymlink.
|
||||
|
||||
// This function is Windows only, so we don't need to check again
|
||||
var useJunctions = optResolver.resolve('useJunctions', file);
|
||||
|
||||
var dirType = useJunctions ? 'junction' : 'dir';
|
||||
var type = !statErr && file.isDirectory() ? dirType : 'file';
|
||||
|
||||
createLinkWithType(type);
|
||||
}
|
||||
|
||||
function createLinkWithType(type) {
|
||||
// This is done after prepare() to use the adjusted file.base property
|
||||
if (isRelative && type !== 'junction') {
|
||||
file.symlink = path.relative(file.base, file.symlink);
|
||||
}
|
||||
|
||||
var opts = {
|
||||
flags: flags,
|
||||
type: type,
|
||||
};
|
||||
fo.symlink(file.symlink, file.path, opts, onSymlink);
|
||||
}
|
||||
|
||||
function onSymlink(symlinkErr) {
|
||||
if (symlinkErr) {
|
||||
return callback(symlinkErr);
|
||||
}
|
||||
|
||||
fo.reflectLinkStat(file.path, file, onReflectLink);
|
||||
}
|
||||
|
||||
function onReflectLink(reflectErr) {
|
||||
if (reflectErr) {
|
||||
return callback(reflectErr);
|
||||
}
|
||||
|
||||
callback(null, file);
|
||||
}
|
||||
}
|
||||
|
||||
return through.obj(linkFile);
|
||||
}
|
||||
|
||||
module.exports = linkStream;
|
26
node_modules/vinyl-fs/lib/symlink/options.js
generated
vendored
Normal file
26
node_modules/vinyl-fs/lib/symlink/options.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var config = {
|
||||
cwd: {
|
||||
type: 'string',
|
||||
default: process.cwd,
|
||||
},
|
||||
dirMode: {
|
||||
type: 'number',
|
||||
},
|
||||
overwrite: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
relativeSymlinks: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
// This option is ignored on non-Windows platforms
|
||||
useJunctions: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = config;
|
51
node_modules/vinyl-fs/lib/symlink/prepare.js
generated
vendored
Normal file
51
node_modules/vinyl-fs/lib/symlink/prepare.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
|
||||
var fs = require('graceful-fs');
|
||||
var Vinyl = require('vinyl');
|
||||
var through = require('through2');
|
||||
|
||||
function prepareSymlink(folderResolver, optResolver) {
|
||||
if (!folderResolver) {
|
||||
throw new Error('Invalid output folder');
|
||||
}
|
||||
|
||||
function normalize(file, enc, cb) {
|
||||
if (!Vinyl.isVinyl(file)) {
|
||||
return cb(new Error('Received a non-Vinyl object in `symlink()`'));
|
||||
}
|
||||
|
||||
// TODO: Remove this after people upgrade vinyl/transition from gulp-util
|
||||
if (typeof file.isSymbolic !== 'function') {
|
||||
file = new Vinyl(file);
|
||||
}
|
||||
|
||||
var cwd = path.resolve(optResolver.resolve('cwd', file));
|
||||
|
||||
var outFolderPath = folderResolver.resolve('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
|
||||
// Note: keep the target stats for now, we may need them in link-file
|
||||
file.stat = (file.stat || new fs.Stats());
|
||||
file.cwd = cwd;
|
||||
file.base = basePath;
|
||||
// This is the path we are linking *TO*
|
||||
file.symlink = file.path;
|
||||
file.path = writePath;
|
||||
// We have to set contents to null for a link
|
||||
// Otherwise `isSymbolic()` returns false
|
||||
file.contents = null;
|
||||
|
||||
cb(null, file);
|
||||
}
|
||||
|
||||
return through.obj(normalize);
|
||||
}
|
||||
|
||||
module.exports = prepareSymlink;
|
Reference in New Issue
Block a user