Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var loader = module.exports = function(dir, context, callback) {
if (!helpers.isDirectory(dir)) return;
// Add trailing slash
dir = dir.replace(/\/+$/, '') + '/';
// Context must be defined
context = context || {};
var objects = {},
weighted = [],
args = Array.prototype.slice.call(arguments, 1);
addInvokeMethods(context, weighted);
watch.walk(dir, function(err, files_obj) {
if (err) {
console.log(err);
return;
}
var files = [];
for (var file in files_obj) {
if (!files_obj.hasOwnProperty(file)) continue;
files.push(file);
}
// Replace kind of wildcard '?' with objects itself,
// So objects can be passed to context on demand
for (var i in context) if (context[i] === '?') context[i] = objects;
if ( prev === null ) {
// f is a new file or directory
// if we are a file, we can be synced with Shopify (probably)
if ( curr.isFile() ) {
updateTitle( util.format( "Creating: %s\n", f ) );
shopify.create( f, wrap( handleResponse, f + " created" ) );
}
// only some directories can be synced, make sure we are one of these before trying.
else if ( curr.isDirectory() && !filter( f, curr, validDirectories ) ) {
// a directory was created (or just renamed), sync its files.
watch.walk( f, options, function( err, files ) {
for ( var _f in files ){
if ( _f !== f ) {
sync( _f, files[_f], null );
}
}
});
}
}
else if ( curr.nlink === 0 ) {
// f was removed
updateTitle( util.format( "Deleting: %s\n", f ) );
shopify.delete( f, wrap( handleResponse, f + " deleted\n" ) );
}
else {
function copytree (source, dest) {
watch.walk(source, function (err , files) {
for (i in files) {
(function (i) {
if (files[i].isDirectory()) {
try {
fs.mkdirSync(i.replace(source, dest), 0755)
} catch(e) {
console.log('Could not create '+i.replace(source,dest))
}
} else {
var stream = fs.createReadStream(i).pipe(fs.createWriteStream(i.replace(source, dest)));
stream.on("error", function (err) {
throw err;
});
}
})(i);
}
return memo.concat(curr);
}, []);
initialFiles.forEach(babelify);
}
const options = {
ignoreDotFiles: true,
ignoreNotPermitted: true,
interval: 0.5,
filter(filename) {
return !blackFlagsReg.test(filename);
}
};
walk(PKGS, options, initialWalkCallback);
if (watchFlag) {
createMonitor(PKGS, options, watchCallback);
}
app.doc.__attachments.forEach(function (att) {
watch.walk(att.root, {ignoreDotFiles:true}, function (err, files) {
for (i in files) { (function (f) {
pending += 1
fs.readFile(f, function (err, data) {
f = f.replace(att.root, att.prefix || '');
if (f[0] == '/') f = f.slice(1)
if (!err) {
var d = data.toString('base64')
, md5 = crypto.createHash('md5')
, mime = mimetypes.lookup(path.extname(f).slice(1))
;
md5.update(d)
md5 = md5.digest('hex')
if (app.doc.attachments_md5[f] && app.doc._attachments[f]) {
if (app.doc._attachments[f].revpos === app.doc.attachments_md5[f].revpos &&
app.doc.attachments_md5[f].md5 === md5) {
pending -= 1
app.doc.__attachments.forEach(function (att) {
watch.walk(att.root, {ignoreDotFiles:true}, function (err, files) {
pending_dirs += 1;
var pending_files = Object.keys(files).length;
for (i in files) { (function (f) {
fs.readFile(f, function (err, data) {
if(f.match(coffeeExt)){
data = new Buffer( coffeeCompile.compile(data.toString()) );
f = f.replace(coffeeExt,'.js');
}
f = f.replace(att.root, att.prefix || '').replace(/\\/g,"/");
if (f[0] == '/') f = f.slice(1)
if (!err) {
var d = data.toString('base64')
, md5 = crypto.createHash('md5')
, mime = mimetypes.lookup(path.extname(f).slice(1))
;
md5.update(d)
app.doc.__attachments.forEach(function (att) {
watch.walk(att.root, {ignoreDotFiles:true}, function (err, files) {
for (i in files) { (function (f) {
pending += 1
fs.readFile(f, function (err, data) {
f = f.replace(att.root, att.prefix || '');
if (f[0] == '/') f = f.slice(1)
if (!err) {
var d = data.toString('base64')
, md5 = crypto.createHash('md5')
, mime = mimetypes.lookup(path.extname(f).slice(1))
;
md5.update(d)
md5 = md5.digest('hex')
if (app.doc.attachments_md5[f] && app.doc._attachments[f]) {
if (app.doc._attachments[f].revpos === app.doc.attachments_md5[f].revpos &&
app.doc.attachments_md5[f].md5 === md5) {
pending -= 1
app.doc.__attachments.forEach(function (att) {
watch.walk(att.root, {ignoreDotFiles:true}, function (err, files) {
if (err) {
return callback(err);
}
for (i in files) { (function (f) {
pending += 1
fs.readFile(f, function (err, data) {
f = f.replace(att.root, att.prefix || '');
if (f[0] == '/') f = f.slice(1)
if (!err) {
var d = data.toString('base64')
, mime = mimetypes.lookup(path.extname(f).slice(1))
;
app.doc._attachments[f] = {data:d, content_type:mime};
}
pending -= 1
if (pending === 0) {