Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function removeDir(dir, done) {
// Have to collect directories and delete them at the end
// so we delete in proper order
// path.resolve call normalizes forward and backslashes to match path.sep
// as well as making path absolute.
dir = path.resolve(dir);
var dirs = [dir.split(path.sep)];
var walker = walk.walk(dir);
walker.on('files', function (root, stats, next) {
var numFiles = stats.length;
stats
.map(function (stat) { return path.join(root, stat.name); })
.forEach(function (file) {
fs.unlink(file, function () {
--numFiles;
if (numFiles === 0) {
next();
}
});
});
})
.on('directory', function (root, stats, next) {
var dirPath = path.resolve(path.join(root, stats.name));
walker.walkDirs = function(directoryToWalk, extensionFilter, callback) {
// var content = process.env.ELF_CONTENT;
// console.log('walk called', walker.content);
var walkInstance = walk.walk(directoryToWalk, walker.options);
walkInstance.on("file", function (root, fileStats, next) {
// console.log('file found', fileStats.name);
var fileExtension = path.extname(fileStats.name);
if(fileExtension === extensionFilter) {
walker.fileReport.push({root: root, fileStats: fileStats});
}
next();
/* fs.readFile(fileStats.name, function () { next(); }); */
});
walkInstance.on("errors", function (root, nodeStatsArray, next) {
console.log(root, nodeStatsArray);
next();
});
function walkDirs(folderName) { 'use strict';
var options = {
followLinks : false,
};
var walker = walk.walk(folderName, options);
walker.on("names", function(root, nodeNamesArray) {
nodeNamesArray.sort(function(a, b) {
if (a > b)
return 1;
if (a < b)
return -1;
return 0;
});
});
walker.on("directories", function(root, dirStatsArray, next) {
// dirStatsArray is an array of `stat` objects with the additional attributes
// * type
// * error
function render_code_folder_structure(folder, title, callback) {
var folder_depth = 0; // Pointer to indicate how deep we've gone through the folders
var folder_history = [];
// ------------------------------------------------
// Iterate through the folders
//
var files = [];
// Walker options
var walker = walk.walk(folder, {
followLinks: false
});
// ------------------------------------------------
// Open the code block
//
markdown_contents += "\n\n";
markdown_contents += "### " + title;
markdown_contents += "\n\n";
markdown_contents += '````';
markdown_contents += "\n";
walker.on('file', function(root, stat, next) {
output = path.join(path.dirname(input), path.basename(input, ext) + newExt);
}
// output is a directory
else if (fs.statSync(output).isDirectory())
output = path.join(output, path.basename(input, ext) + newExt);
// call the function
return fn(input, output);
}
// output is undefined
if (output == undefined)
output = input;
// get out grandpa's walker
const walker = walk.walk(input);
// when we encounter a file
walker.on('file', (root, stats, next) => {
// get the extension
const ext = path.extname(stats.name).toLocaleLowerCase();
// skip files that aren't JSON or XNB
if (ext != '.json' && ext != '.xnb')
return next();
// swap the input base directory with the base output directory for our target directory
const target = root.replace(input, output);
// get the source path
const inputFile = path.join(root, stats.name);
// get the target ext
const targetExt = ext == '.xnb' ? '.json' : '.xnb';
// form the output file path
return new Promise(resolve => {
const tasks = []
walk
.walk(appDir, options)
.on('file', (root, fileStats, next) => {
const extname = path.extname(fileStats.name).toLowerCase()
if (targetExts.includes(extname)) {
tasks.push(async () => {
const srcPath = path.join(root, fileStats.name)
const tgtPath = changeExt(srcPath, '.js')
// const src = await fs.readFile(srcPath, 'utf-8')
let tgt
try {
const result = await promisify(transformFile)(srcPath, {
presets,
plugins,
})
tgt = result.code
} catch (e) {
module.exports = function (ws) {
if (walker) {
walker.pause();
}
let pref = preferences.getPreferences(),
n = 0,
wd = USER_WD;
walker = walk.walk(USER_WD, { followLinks: false });
// reindex file search
walker = walk.walk(USER_WD, { followLinks: false });
ws.sendJSON({ msg: 'file-index-start' });
walker.on('file', function (root, stat, next) {
// handles issue w/ extra files being emitted if you're indexing a large directory and
// then cd into another directory
if (wd != USER_WD) {
return;
}
let dir = root.replace(USER_WD, '') || '',
displayFilename = path.join(dir, stat.name).replace(/^\//, '');
compileUploadList: function (rootDir, success, error) {
var assets = [];
var walker = walk.walk(rootDir, { followLinks: false });
walker.on('file', function(root, stat, next) {
var filepath = root + '/' + stat.name;
var key = filepath.substring(rootDir.length + 1)
var meta = coreutils.contentType(path.basename(key));
var content = fs.readFileSync(filepath);
var hash = storage.md5(content);
var etag = new Buffer(hash, 'base64').toString('hex');
assets.push({meta: meta, key: key, path: filepath, hash: hash, etag: etag});
next();
});
walker.on('end', function() {
success(assets);
});
}
function syncFiles(cb, src, dst) {
var walker = fsWalk(src)
;
walker.on('file', function (root, stat, next) {
var curFile = path.join(root, stat.name)
, newFile = path.join(dst, root.substr(src.length + 1), stat.name)
;
fsCopy(curFile, newFile, function (err) {
if (err) {
cb(err);
return;
}
next();
});
});
fetchLayouts: function(callback) {
var files = [], hiddenFiles = [], walker, path, i;
path = cfg.appPublic;
walker = walk.walk(path, { followLinks: false});
walker.on("names", function (root, nodeNamesArray, next) {
var newlist = utils.filterEditableSync(nodeNamesArray);
var cleanList = _.intersection(nodeNamesArray, newlist);
for (i = 0; i < nodeNamesArray.length; i++) {
if (nodeNamesArray[i][0] === '.' ) {
nodeNamesArray.splice(i,1);
}
}
for (i = 0; i < nodeNamesArray.length; i++) {
if (!_.contains(cleanList, nodeNamesArray[i]) ) {
nodeNamesArray.splice(i,1);
}
}