forked from public/fvtt-cthulhu-eternal
Initial import with skill sheet working
This commit is contained in:
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 Transform = require('streamx').Transform;
|
||||
|
||||
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, 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 new Transform({
|
||||
transform: writeFile,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = writeContents;
|
||||
46
node_modules/vinyl-fs/lib/dest/write-contents/write-buffer.js
generated
vendored
Normal file
46
node_modules/vinyl-fs/lib/dest/write-contents/write-buffer.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
var getCodec = require('../../codecs');
|
||||
var DEFAULT_ENCODING = require('../../constants').DEFAULT_ENCODING;
|
||||
|
||||
function writeBuffer(file, optResolver, onWritten) {
|
||||
var flags = fo.getFlags({
|
||||
overwrite: optResolver.resolve('overwrite', file),
|
||||
append: optResolver.resolve('append', file),
|
||||
});
|
||||
|
||||
var encoding = optResolver.resolve('encoding', file);
|
||||
var codec = getCodec(encoding);
|
||||
if (encoding && !codec) {
|
||||
return onWritten(new Error('Unsupported encoding: ' + encoding));
|
||||
}
|
||||
|
||||
var opt = {
|
||||
mode: file.stat.mode,
|
||||
flags: flags,
|
||||
};
|
||||
|
||||
var contents = file.contents;
|
||||
|
||||
if (encoding && codec.enc !== DEFAULT_ENCODING) {
|
||||
contents = getCodec(DEFAULT_ENCODING).decode(contents);
|
||||
contents = codec.encode(contents);
|
||||
}
|
||||
|
||||
fo.writeFile(file.path, 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;
|
||||
50
node_modules/vinyl-fs/lib/dest/write-contents/write-dir.js
generated
vendored
Normal file
50
node_modules/vinyl-fs/lib/dest/write-contents/write-dir.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
'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;
|
||||
68
node_modules/vinyl-fs/lib/dest/write-contents/write-stream.js
generated
vendored
Normal file
68
node_modules/vinyl-fs/lib/dest/write-contents/write-stream.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
'use strict';
|
||||
|
||||
var pipeline = require('streamx').pipeline;
|
||||
|
||||
var fo = require('../../file-operations');
|
||||
var getCodec = require('../../codecs');
|
||||
var DEFAULT_ENCODING = require('../../constants').DEFAULT_ENCODING;
|
||||
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 encoding = optResolver.resolve('encoding', file);
|
||||
var codec = getCodec(encoding);
|
||||
if (encoding && !codec) {
|
||||
return onWritten(new Error('Unsupported encoding: ' + encoding));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// TODO: should this use a clone?
|
||||
var streams = [file.contents];
|
||||
|
||||
if (encoding && encoding.enc !== DEFAULT_ENCODING) {
|
||||
streams.push(getCodec(DEFAULT_ENCODING).decodeStream());
|
||||
streams.push(codec.encodeStream());
|
||||
}
|
||||
|
||||
streams.push(outStream);
|
||||
|
||||
pipeline(streams, onWritten);
|
||||
|
||||
// Cleanup
|
||||
function onFlush(fd, callback) {
|
||||
// TODO: this is doing sync stuff & the callback seems unnecessary
|
||||
readStream(file, { resolve: resolve }, complete);
|
||||
|
||||
function resolve(key) {
|
||||
if (key === 'encoding') {
|
||||
return encoding;
|
||||
}
|
||||
if (key === 'removeBOM') {
|
||||
return false;
|
||||
}
|
||||
throw new Error("Eek! stub resolver doesn't have " + key);
|
||||
}
|
||||
|
||||
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;
|
||||
Reference in New Issue
Block a user