feat: docker compose maybe
This commit is contained in:
47
node_modules/sander/src/extraMethods/copyFile.js
generated
vendored
Normal file
47
node_modules/sander/src/extraMethods/copyFile.js
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
import * as fs from 'graceful-fs';
|
||||
import { dirname } from 'path';
|
||||
import mkdirp from 'mkdirp';
|
||||
import resolvePathAndOptions from '../utils/resolvePathAndOptions';
|
||||
|
||||
export function copyFile () {
|
||||
const { resolvedPath: src, options: readOptions } = resolvePathAndOptions( arguments );
|
||||
|
||||
return {
|
||||
to () {
|
||||
const { resolvedPath: dest, options: writeOptions } = resolvePathAndOptions( arguments );
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
mkdirp( dirname( dest ), err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
const readStream = fs.createReadStream( src, readOptions );
|
||||
const writeStream = fs.createWriteStream( dest, writeOptions );
|
||||
|
||||
readStream.on( 'error', reject );
|
||||
writeStream.on( 'error', reject );
|
||||
|
||||
writeStream.on( 'close', fulfil );
|
||||
|
||||
readStream.pipe( writeStream );
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function copyFileSync () {
|
||||
const { resolvedPath: src, options: readOptions } = resolvePathAndOptions( arguments );
|
||||
|
||||
return {
|
||||
to () {
|
||||
const { resolvedPath: dest, options: writeOptions } = resolvePathAndOptions( arguments );
|
||||
|
||||
const data = fs.readFileSync( src, readOptions );
|
||||
|
||||
mkdirp.sync( dirname( dest ) );
|
||||
fs.writeFileSync( dest, data, writeOptions );
|
||||
}
|
||||
};
|
||||
}
|
99
node_modules/sander/src/extraMethods/copydir.js
generated
vendored
Normal file
99
node_modules/sander/src/extraMethods/copydir.js
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
import { sep } from 'path';
|
||||
import * as fs from 'graceful-fs';
|
||||
import mkdirp from 'mkdirp';
|
||||
import resolvePathAndOptions from '../utils/resolvePathAndOptions';
|
||||
|
||||
export function copydir () {
|
||||
const { resolvedPath: src, options: readOptions } = resolvePathAndOptions( arguments );
|
||||
|
||||
return {
|
||||
to () {
|
||||
const { resolvedPath: dest, options: writeOptions } = resolvePathAndOptions( arguments );
|
||||
|
||||
function copydir ( src, dest, cb ) {
|
||||
mkdirp( dest, err => {
|
||||
if ( err ) return cb( err );
|
||||
|
||||
fs.readdir( src, ( err, files ) => {
|
||||
if ( err ) return cb( err );
|
||||
|
||||
let remaining = files.length;
|
||||
|
||||
if ( !remaining ) return cb();
|
||||
|
||||
function check ( err ) {
|
||||
if ( err ) {
|
||||
return cb( err );
|
||||
}
|
||||
|
||||
if ( !--remaining ) {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
files.forEach( function ( filename ) {
|
||||
const srcpath = src + sep + filename;
|
||||
const destpath = dest + sep + filename;
|
||||
|
||||
fs.stat( srcpath, ( err, stats ) => {
|
||||
var readStream, writeStream;
|
||||
|
||||
if ( stats.isDirectory() ) {
|
||||
return copydir( srcpath, destpath, check );
|
||||
}
|
||||
|
||||
readStream = fs.createReadStream( srcpath, readOptions );
|
||||
writeStream = fs.createWriteStream( destpath, writeOptions );
|
||||
|
||||
readStream.on( 'error', cb );
|
||||
writeStream.on( 'error', cb );
|
||||
|
||||
writeStream.on( 'close', check );
|
||||
|
||||
readStream.pipe( writeStream );
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
copydir( src, dest, err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function copydirSync () {
|
||||
const { resolvedPath: src, options: readOptions } = resolvePathAndOptions( arguments );
|
||||
|
||||
return {
|
||||
to () {
|
||||
const { resolvedPath: dest, options: writeOptions } = resolvePathAndOptions( arguments );
|
||||
|
||||
function copydir ( src, dest ) {
|
||||
mkdirp.sync( dest );
|
||||
|
||||
fs.readdirSync( src ).forEach( filename => {
|
||||
const srcpath = src + sep + filename;
|
||||
const destpath = dest + sep + filename;
|
||||
|
||||
if ( fs.statSync( srcpath ).isDirectory() ) {
|
||||
return copydir( srcpath, destpath );
|
||||
}
|
||||
|
||||
const data = fs.readFileSync( srcpath, readOptions );
|
||||
fs.writeFileSync( destpath, data, writeOptions );
|
||||
});
|
||||
}
|
||||
|
||||
copydir( src, dest );
|
||||
}
|
||||
};
|
||||
}
|
70
node_modules/sander/src/extraMethods/lsr.js
generated
vendored
Normal file
70
node_modules/sander/src/extraMethods/lsr.js
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
import * as fs from 'fs';
|
||||
import { resolve, sep } from 'path';
|
||||
import resolvePath from '../utils/resolvePath';
|
||||
|
||||
function walk ( dir, callback ) {
|
||||
let results = [];
|
||||
|
||||
fs.readdir( dir, ( err, files ) => {
|
||||
if ( err ) return callback( err );
|
||||
|
||||
let pending = files.length;
|
||||
if ( !pending ) return callback( null, results );
|
||||
|
||||
files.forEach( file => {
|
||||
file = resolve( dir, file );
|
||||
|
||||
fs.stat( file, ( err, stats ) => {
|
||||
if ( stats && stats.isDirectory() ) {
|
||||
walk( file, ( err, res ) => {
|
||||
results = results.concat( res );
|
||||
if ( !--pending ) callback( null, results );
|
||||
});
|
||||
} else {
|
||||
results.push( file );
|
||||
if ( !--pending ) callback( null, results );
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export function lsr () {
|
||||
const basedir = resolvePath( arguments );
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
walk( basedir, function ( err, result ) {
|
||||
if ( err ) return reject( err );
|
||||
|
||||
// files should be relative to basedir
|
||||
const index = basedir.length + 1;
|
||||
let i = result.length;
|
||||
while ( i-- ) {
|
||||
result[i] = result[i].substring( index );
|
||||
}
|
||||
|
||||
fulfil( result );
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function lsrSync () {
|
||||
const basedir = resolvePath( arguments );
|
||||
|
||||
let result = [];
|
||||
|
||||
function processdir ( dir ) {
|
||||
fs.readdirSync( dir ).forEach( file => {
|
||||
const filepath = dir + sep + file;
|
||||
|
||||
if ( fs.statSync( filepath ).isDirectory() ) {
|
||||
processdir( filepath );
|
||||
} else {
|
||||
result.push( filepath.replace( basedir + sep, '' ) );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
processdir( basedir );
|
||||
return result;
|
||||
}
|
20
node_modules/sander/src/extraMethods/rimraf.js
generated
vendored
Normal file
20
node_modules/sander/src/extraMethods/rimraf.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
import _rimraf from 'rimraf';
|
||||
import resolvePath from '../utils/resolvePath';
|
||||
|
||||
export function rimraf () {
|
||||
const target = resolvePath( arguments );
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
_rimraf( target, err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function rimrafSync () {
|
||||
_rimraf.sync( resolvePath( arguments ) );
|
||||
}
|
40
node_modules/sander/src/extraMethods/symlinkOrCopy.js
generated
vendored
Normal file
40
node_modules/sander/src/extraMethods/symlinkOrCopy.js
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
import { stat, statSync } from '../sander';
|
||||
import { copydir, copydirSync } from './copydir';
|
||||
import { copyFile, copyFileSync } from './copyFile';
|
||||
import { symlink, symlinkSync } from '../specialMethods/symlink';
|
||||
import resolvePathAndOptions from '../utils/resolvePathAndOptions';
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
export function symlinkOrCopy () {
|
||||
if ( isWindows ) {
|
||||
const { resolvedPath: src, options: readOptions } = resolvePathAndOptions( arguments );
|
||||
|
||||
let copyDirOrFileTo = stat( src )
|
||||
.then( stats => {
|
||||
return ( stats.isDirectory() ? copydir : copyFile )
|
||||
.apply( null, arguments )
|
||||
.to;
|
||||
});
|
||||
|
||||
return {
|
||||
to () {
|
||||
return copyDirOrFileTo
|
||||
.then(fn => {
|
||||
return fn.apply(null, arguments);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return symlink.apply( null, arguments );
|
||||
}
|
||||
|
||||
export function symlinkOrCopySync () {
|
||||
if ( isWindows ) {
|
||||
const { resolvedPath: src, options: readOptions } = resolvePathAndOptions( arguments );
|
||||
return ( statSync( src ).isDirectory() ? copydirSync : copyFileSync ).apply( null, arguments );
|
||||
}
|
||||
|
||||
return symlinkSync.apply( null, arguments );
|
||||
}
|
24
node_modules/sander/src/methodMakers/fileDescriptorMethod.js
generated
vendored
Normal file
24
node_modules/sander/src/methodMakers/fileDescriptorMethod.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
import * as fs from 'graceful-fs';
|
||||
|
||||
export function asyncFileDescriptorMethod ( methodName ) {
|
||||
return function () {
|
||||
let args = [];
|
||||
let i = arguments.length;
|
||||
|
||||
while ( i-- ) {
|
||||
args[i] = arguments[i];
|
||||
}
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
args.push( ( err, result ) => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil( result );
|
||||
}
|
||||
});
|
||||
|
||||
fs[ methodName ].apply( fs, args );
|
||||
});
|
||||
};
|
||||
}
|
49
node_modules/sander/src/methodMakers/standardMethod.js
generated
vendored
Normal file
49
node_modules/sander/src/methodMakers/standardMethod.js
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
import * as fs from 'graceful-fs';
|
||||
import resolvePath from '../utils/resolvePath';
|
||||
|
||||
function normaliseArguments ( args ) {
|
||||
const len = args.length;
|
||||
|
||||
let buildingPath = true;
|
||||
let pathargs = [];
|
||||
let normalised = [ null ]; // null is a placeholder for the resolved path
|
||||
let i;
|
||||
|
||||
for ( i = 0; i < len; i += 1 ) {
|
||||
if ( buildingPath && typeof args[i] === 'string' ) {
|
||||
pathargs[i] = args[i];
|
||||
} else {
|
||||
buildingPath = false;
|
||||
normalised.push( args[i] );
|
||||
}
|
||||
}
|
||||
|
||||
normalised[0] = resolvePath( pathargs );
|
||||
|
||||
return normalised;
|
||||
}
|
||||
|
||||
export function asyncMethod ( methodName ) {
|
||||
return function () {
|
||||
const args = normaliseArguments( arguments );
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
args.push( ( err, result ) => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil( result );
|
||||
}
|
||||
});
|
||||
|
||||
fs[ methodName ].apply( fs, args );
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function syncMethod ( methodName ) {
|
||||
return function () {
|
||||
const args = normaliseArguments( arguments );
|
||||
return fs[ methodName ].apply( fs, args );
|
||||
};
|
||||
}
|
81
node_modules/sander/src/sander.js
generated
vendored
Normal file
81
node_modules/sander/src/sander.js
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
import * as fs from 'graceful-fs';
|
||||
import * as es6Promise from 'es6-promise';
|
||||
import { syncMethod, asyncMethod } from './methodMakers/standardMethod';
|
||||
import { asyncFileDescriptorMethod } from './methodMakers/fileDescriptorMethod';
|
||||
|
||||
// standard async methods
|
||||
export const chmod = asyncMethod( 'chmod' );
|
||||
export const chown = asyncMethod( 'chown' );
|
||||
export const createReadStream = asyncMethod( 'createReadStream' );
|
||||
export const createWriteStream = asyncMethod( 'createWriteStream' );
|
||||
export const lchmod = asyncMethod( 'lchmod' );
|
||||
export const lchown = asyncMethod( 'lchown' );
|
||||
export const lstat = asyncMethod( 'lstat' );
|
||||
export const readdir = asyncMethod( 'readdir' );
|
||||
export const readFile = asyncMethod( 'readFile' );
|
||||
export const readlink = asyncMethod( 'readlink' );
|
||||
export const realpath = asyncMethod( 'realpath' );
|
||||
export const rmdir = asyncMethod( 'rmdir' );
|
||||
export const stat = asyncMethod( 'stat' );
|
||||
export const truncate = asyncMethod( 'truncate' );
|
||||
export const unlink = asyncMethod( 'unlink' );
|
||||
export const utimes = asyncMethod( 'utimes' );
|
||||
export const unwatchFile = asyncMethod( 'unwatchFile' );
|
||||
export const watch = asyncMethod( 'watch' );
|
||||
export const watchFile = asyncMethod( 'watchFile' );
|
||||
|
||||
// standard sync methods
|
||||
export const chmodSync = syncMethod( 'chmodSync' );
|
||||
export const chownSync = syncMethod( 'chownSync' );
|
||||
export const lchmodSync = syncMethod( 'lchmodSync' );
|
||||
export const lchownSync = syncMethod( 'lchownSync' );
|
||||
export const lstatSync = syncMethod( 'lstatSync' );
|
||||
export const readdirSync = syncMethod( 'readdirSync' );
|
||||
export const readFileSync = syncMethod( 'readFileSync' );
|
||||
export const readlinkSync = syncMethod( 'readlinkSync' );
|
||||
export const realpathSync = syncMethod( 'realpathSync' );
|
||||
export const rmdirSync = syncMethod( 'rmdirSync' );
|
||||
export const statSync = syncMethod( 'statSync' );
|
||||
export const truncateSync = syncMethod( 'truncateSync' );
|
||||
export const unlinkSync = syncMethod( 'unlinkSync' );
|
||||
export const utimesSync = syncMethod( 'utimesSync' );
|
||||
|
||||
// file descriptor async methods
|
||||
export const close = asyncFileDescriptorMethod( 'close' );
|
||||
export const fchmod = asyncFileDescriptorMethod( 'fchmod' );
|
||||
export const fchown = asyncFileDescriptorMethod( 'fchown' );
|
||||
export const fstat = asyncFileDescriptorMethod( 'fstat' );
|
||||
export const fsync = asyncFileDescriptorMethod( 'fsync' );
|
||||
export const ftruncate = asyncFileDescriptorMethod( 'ftruncate' );
|
||||
export const futimes = asyncFileDescriptorMethod( 'futimes' );
|
||||
export const read = asyncFileDescriptorMethod( 'read' );
|
||||
|
||||
// file descriptor sync methods
|
||||
export const closeSync = fs.closeSync;
|
||||
export const fchmodSync = fs.fchmodSync;
|
||||
export const fchownSync = fs.fchownSync;
|
||||
export const fstatSync = fs.fstatSync;
|
||||
export const fsyncSync = fs.fsyncSync;
|
||||
export const ftruncateSync = fs.ftruncateSync;
|
||||
export const futimesSync = fs.futimesSync;
|
||||
export const readSync = fs.readSync;
|
||||
|
||||
// special methods
|
||||
export { createReadStream, createWriteStream } from './specialMethods/createReadStream-createWriteStream'; // TODO aren't these covered by the standard methods?
|
||||
export { exists, existsSync } from './specialMethods/exists';
|
||||
export { link, linkSync, rename, renameSync } from './specialMethods/link-rename';
|
||||
export { mkdir, mkdirSync } from './specialMethods/mkdir';
|
||||
export { open, openSync } from './specialMethods/open';
|
||||
export { symlink, symlinkSync } from './specialMethods/symlink';
|
||||
export { writeFile, writeFileSync, appendFile, appendFileSync } from './specialMethods/writeFile-appendFile';
|
||||
|
||||
// extra methods
|
||||
export { copydir, copydirSync } from './extraMethods/copydir';
|
||||
export { copyFile, copyFileSync } from './extraMethods/copyFile';
|
||||
export { lsr, lsrSync } from './extraMethods/lsr';
|
||||
export { rimraf, rimrafSync } from './extraMethods/rimraf';
|
||||
export { symlinkOrCopy, symlinkOrCopySync } from './extraMethods/symlinkOrCopy';
|
||||
|
||||
// expose Promise for convenience
|
||||
// https://github.com/esperantojs/esperanto/issues/161
|
||||
export const Promise = es6Promise.Promise;
|
16
node_modules/sander/src/specialMethods/createReadStream-createWriteStream.js
generated
vendored
Normal file
16
node_modules/sander/src/specialMethods/createReadStream-createWriteStream.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
import * as fs from 'graceful-fs';
|
||||
import { dirname } from 'path';
|
||||
import mkdirp from 'mkdirp';
|
||||
import resolvePathAndOptions from '../utils/resolvePathAndOptions';
|
||||
|
||||
export function createReadStream () {
|
||||
const { resolvedPath, options } = resolvePathAndOptions( arguments );
|
||||
return fs.createReadStream( resolvedPath, options );
|
||||
}
|
||||
|
||||
export function createWriteStream () {
|
||||
const { resolvedPath, options } = resolvePathAndOptions( arguments );
|
||||
|
||||
mkdirp.sync( dirname( resolvedPath ) );
|
||||
return fs.createWriteStream( resolvedPath, options );
|
||||
}
|
14
node_modules/sander/src/specialMethods/exists.js
generated
vendored
Normal file
14
node_modules/sander/src/specialMethods/exists.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
import * as fs from 'graceful-fs';
|
||||
import resolvePath from '../utils/resolvePath';
|
||||
|
||||
export function exists () {
|
||||
const target = resolvePath( arguments );
|
||||
|
||||
return new Promise( fulfil => {
|
||||
fs.exists( target, exists => fulfil( exists ) );
|
||||
});
|
||||
}
|
||||
|
||||
export function existsSync () {
|
||||
return fs.existsSync( resolvePath( arguments ) );
|
||||
}
|
53
node_modules/sander/src/specialMethods/link-rename.js
generated
vendored
Normal file
53
node_modules/sander/src/specialMethods/link-rename.js
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
import * as fs from 'graceful-fs';
|
||||
import { dirname } from 'path';
|
||||
import mkdirp from 'mkdirp';
|
||||
import resolvePath from '../utils/resolvePath';
|
||||
|
||||
export const rename = asyncMethod( 'rename' );
|
||||
export const link = asyncMethod( 'link' );
|
||||
|
||||
export const renameSync = syncMethod( 'renameSync' );
|
||||
export const linkSync = syncMethod( 'linkSync' );
|
||||
|
||||
function asyncMethod ( methodName ) {
|
||||
return function () {
|
||||
const src = resolvePath( arguments );
|
||||
|
||||
return {
|
||||
to () {
|
||||
const dest = resolvePath( arguments );
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
mkdirp( dirname( dest ), err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fs[ methodName ]( src, dest, err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function syncMethod ( methodName ) {
|
||||
return function () {
|
||||
const src = resolvePath( arguments );
|
||||
|
||||
return {
|
||||
to () {
|
||||
const dest = resolvePath( arguments );
|
||||
|
||||
mkdirp.sync( dirname( dest ) );
|
||||
return fs[ methodName ]( src, dest );
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
21
node_modules/sander/src/specialMethods/mkdir.js
generated
vendored
Normal file
21
node_modules/sander/src/specialMethods/mkdir.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
import mkdirp from 'mkdirp';
|
||||
import resolvePath from '../utils/resolvePath';
|
||||
|
||||
export function mkdir () {
|
||||
const dir = resolvePath( arguments );
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
mkdirp( dir, err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function mkdirSync () {
|
||||
const dir = resolvePath( arguments );
|
||||
mkdirp.sync( dir );
|
||||
}
|
97
node_modules/sander/src/specialMethods/open.js
generated
vendored
Normal file
97
node_modules/sander/src/specialMethods/open.js
generated
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
import { dirname } from 'path';
|
||||
import * as fs from 'graceful-fs';
|
||||
import mkdirp from 'mkdirp';
|
||||
import resolvePath from '../utils/resolvePath';
|
||||
|
||||
function normaliseArguments ( args ) {
|
||||
let options;
|
||||
let flags;
|
||||
let i;
|
||||
|
||||
if ( typeof args[ args.length - 1 ] === 'object' ) {
|
||||
options = args[ args.length - 1 ];
|
||||
flags = args[ args.length - 2 ];
|
||||
i = args.length - 2;
|
||||
} else {
|
||||
options = {};
|
||||
flags = args[ args.length - 1 ];
|
||||
i = args.length - 1;
|
||||
}
|
||||
|
||||
let pathargs = new Array( i );
|
||||
while ( i-- ) {
|
||||
pathargs[i] = args[i];
|
||||
}
|
||||
|
||||
const resolvedPath = resolvePath( pathargs );
|
||||
|
||||
return { resolvedPath, options, flags };
|
||||
}
|
||||
|
||||
function bailIfExists ( src, flags, mode ) {
|
||||
let alreadyExists;
|
||||
|
||||
try {
|
||||
fs.statSync( src );
|
||||
alreadyExists = true;
|
||||
} catch ( err ) {
|
||||
if ( err.code !== 'ENOENT' ) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
if ( alreadyExists ) {
|
||||
// attempt the operation = that way, we get the intended error message
|
||||
// TODO can't we just do this in the first place?
|
||||
fs.openSync( src, flags, mode );
|
||||
}
|
||||
}
|
||||
|
||||
export function open () {
|
||||
const { resolvedPath: src, options, flags } = normaliseArguments( arguments );
|
||||
|
||||
if ( /^.x/.test( flags ) ) {
|
||||
bailIfExists( src, flags, options.mode );
|
||||
}
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
function open () {
|
||||
fs.open( src, flags, options.mode, ( err, fd ) => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil( fd );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// create dirs if necessary
|
||||
if ( /^[wa]/.test( flags ) ) {
|
||||
mkdirp( dirname( src ), err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
open();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
open();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function openSync () {
|
||||
const { resolvedPath: src, options, flags } = normaliseArguments( arguments );
|
||||
|
||||
if ( /^.x/.test( flags ) ) {
|
||||
bailIfExists( src, flags, options.mode );
|
||||
}
|
||||
|
||||
// create dirs if necessary
|
||||
if ( /^[wa]/.test( flags ) ) {
|
||||
mkdirp.sync( dirname( src ) );
|
||||
}
|
||||
|
||||
return fs.openSync( src, flags, options.mode );
|
||||
}
|
43
node_modules/sander/src/specialMethods/symlink.js
generated
vendored
Normal file
43
node_modules/sander/src/specialMethods/symlink.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
import { dirname } from 'path';
|
||||
import * as fs from 'graceful-fs';
|
||||
import mkdirp from 'mkdirp';
|
||||
import resolvePath from '../utils/resolvePath';
|
||||
import resolvePathAndOptions from '../utils/resolvePathAndOptions';
|
||||
|
||||
export function symlink () {
|
||||
const src = resolvePath( arguments );
|
||||
|
||||
return {
|
||||
to () {
|
||||
const { options, resolvedPath: dest } = resolvePathAndOptions( arguments );
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
mkdirp( dirname( dest ), err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fs.symlink( src, dest, options.type, err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function symlinkSync () {
|
||||
const src = resolvePath( arguments );
|
||||
|
||||
return {
|
||||
to () {
|
||||
const { options, resolvedPath: dest } = resolvePathAndOptions( arguments );
|
||||
mkdirp.sync( dirname( dest ) );
|
||||
return fs.symlinkSync( src, dest, options.type );
|
||||
}
|
||||
};
|
||||
}
|
52
node_modules/sander/src/specialMethods/writeFile-appendFile.js
generated
vendored
Normal file
52
node_modules/sander/src/specialMethods/writeFile-appendFile.js
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
import * as fs from 'graceful-fs';
|
||||
import { dirname } from 'path';
|
||||
import mkdirp from 'mkdirp';
|
||||
import resolvePath from '../utils/resolvePath';
|
||||
|
||||
export const writeFile = asyncMethod( 'writeFile' );
|
||||
export const appendFile = asyncMethod( 'appendFile' );
|
||||
|
||||
export const writeFileSync = syncMethod( 'writeFileSync' );
|
||||
export const appendFileSync = syncMethod( 'appendFileSync' );
|
||||
|
||||
function normaliseArguments ( args ) {
|
||||
args = Array.prototype.slice.call( args, 0 );
|
||||
let opts = {};
|
||||
|
||||
if ( typeof args[ args.length - 1 ] === 'object' && !( args[ args.length - 1 ] instanceof Buffer ) ) {
|
||||
opts = args.pop();
|
||||
}
|
||||
|
||||
return { opts, data: args.pop(), dest: resolvePath( args ) };
|
||||
}
|
||||
|
||||
function asyncMethod ( methodName ) {
|
||||
return function () {
|
||||
const { dest, data, opts } = normaliseArguments( arguments );
|
||||
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
mkdirp( dirname( dest ), err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fs[ methodName ]( dest, data, opts, err => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil( data );
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function syncMethod ( methodName ) {
|
||||
return function () {
|
||||
const { dest, data } = normaliseArguments( arguments );
|
||||
|
||||
mkdirp.sync( dirname( dest ) );
|
||||
return fs[ methodName ]( dest, data );
|
||||
};
|
||||
}
|
5
node_modules/sander/src/utils/resolvePath.js
generated
vendored
Normal file
5
node_modules/sander/src/utils/resolvePath.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import { resolve } from 'path';
|
||||
|
||||
export default function resolvePath ( args ) {
|
||||
return resolve.apply( null, args );
|
||||
}
|
24
node_modules/sander/src/utils/resolvePathAndOptions.js
generated
vendored
Normal file
24
node_modules/sander/src/utils/resolvePathAndOptions.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
import { resolve } from 'path';
|
||||
|
||||
export default function resolvePathAndOptions ( args ) {
|
||||
let options;
|
||||
let pathargs;
|
||||
|
||||
if ( typeof args[ args.length - 1 ] === 'object' ) {
|
||||
options = args[ args.length - 1 ];
|
||||
|
||||
let i = args.length - 1;
|
||||
pathargs = new Array( i );
|
||||
|
||||
while ( i-- ) {
|
||||
pathargs[i] = args[i];
|
||||
}
|
||||
} else {
|
||||
options = {};
|
||||
pathargs = args;
|
||||
}
|
||||
|
||||
const resolvedPath = resolve.apply( null, pathargs );
|
||||
|
||||
return { options, resolvedPath };
|
||||
}
|
Reference in New Issue
Block a user