// Preform action on each file in a directory function dive (directory, extension, action, callback) { // Make sure if (typeof action !== 'function') { action = function (error, file) {}; } fs.readdir(directory, function (err, contents) { if (err) return; // Preform action on file async.each(contents, function (file, cb) { var filePath = directory + '/' + file; var fileExtension = path.extname(file); fs.stat(filePath, function (err, stat) { // If the file is a directory if (stat && stat.isDirectory()) { // Dive into the directory dive(filePath, extension, action, callback); } else { // Do the action if (fileExtension === extension) action(null, filePath); // Tell async this function is done cb(); } }); }, function (err) { if (err) throw err; console.log('calling callback'); callback(); }); }); }
clear: function (options, callback) { fs.readdir(options.path, function (err, files) { if (files.length <= 0) return callback(); var errors = []; files.forEach(function (file, i) { if (options.filePattern.exec(file)) { fs.unlink(path.join(options.path, file), function (err) { if (err) { errors.push(err); } if (i >= files.length - 1) { callback(errors.length > 0 ? errors : undefined); } }); } else { if (i >= files.length - 1) { callback(errors.length > 0 ? errors : undefined); } } }); }); },
// npm cache clean [<path>] function clean (args, cb) { assert(typeof cb === 'function', 'must include callback') if (!args) args = [] var f = path.join(npm.cache, normalize(args)) if (f === npm.cache) { fs.readdir(npm.cache, function (er, files) { if (er) return cb() asyncMap( files.filter(function (f) { return npm.config.get('force') || f !== '-' }).map(function (f) { return path.join(npm.cache, f) }), rm, cb ) }) } else { rm(f, cb) } }
fs.exists(path, function(exist){ if (!exist) return callback(); fs.readdir(path, function(err, files){ if (err) return callback(err); async.each(files, function(item, next){ var extname = pathFn.extname(item), name = pathFn.basename(item, extname).toLowerCase().replace(/_/g, '-'); // Only accepts YAML files if (extname !== '.yml' && extname !== '.yaml') return next(); render.render({path: pathFn.join(path, item)}, function(err, content){ if (err) return callback(err); self.store[name] = content; next(); }); }, callback); }); });
function findPrefix_ (p, original, cb) { if (p === "/" || (process.platform === "win32" && p.match(/^[a-zA-Z]:(\\|\/)?$/))) { return cb(null, original) } fs.readdir(p, function (er, files) { // an error right away is a bad sign. if (er && p === original) return cb(er) // walked up too high or something. if (er) return cb(null, original) if (files.indexOf("node_modules") !== -1 || files.indexOf("package.json") !== -1) { return cb(null, p) } var d = path.dirname(p) if (d === p) return cb(null, original) return findPrefix_(d, original, cb) }) }
fs.exists(db, function (exists) { if(exists) { fs.readdir(db, function(err, files) { if(err) { callback('Cant read all indizies'); } else { var filesArray = []; var q = async.queue(function(file, cb) { fs.readFile(db+'/'+file, function(err, data) { if(!err) { try { data = JSON.parse(data) } catch(e) { console.log('File invalid!', db+'/'+file); } if(typeof data !== 'string') { filesArray.push(data); } } cb(); }); }, 100); q.drain = function() { callback(false, filesArray); }; q.push(files); } }); } else { callback('Database not found!'); } });
Gaze.prototype._wasAddedSub = function(dir) { var self = this; fs.readdir(dir, function(err, current) { helper.forEachSeries(current, function(file, next) { var filepath = path.join(dir, file); var relpath = path.relative(self.options.cwd, filepath); try { if (!fs.existsSync(filepath)) { return; } if (fs.lstatSync(filepath).isDirectory()) { self._wasAdded(filepath); } else if (globule.isMatch(self._patterns, relpath, self.options)) { // Make sure to watch the newly added sub file platform(filepath, self._trigger.bind(self)); self._emitAll('added', filepath); } } catch (err) { self.emit('error', err); } next(); }); }); };
var walk = function (dir, done) { var results = []; fs.readdir(dir, function (err, list) { if (err) { return done(err); } var i = 0; (function next() { var file = list[i++]; if (!file) { return done(null, results); } file = path.resolve(dir, file); fs.stat(file, function (err, stat) { if (stat && stat.isDirectory()) { walk(file, function (err, res) { results = results.concat(res); next(); }); } else { results.push(file); next(); } }); })(); }); };
function rebuildBundles(pkg, folder, parent, gtop, cb) { if (!npm.config.get("rebuild-bundle")) return cb() var deps = Object.keys(pkg.dependencies || {}) .concat(Object.keys(pkg.devDependencies || {})) , bundles = pkg.bundleDependencies || pkg.bundledDependencies || [] fs.readdir(path.resolve(folder, "node_modules"), function (er, files) { // error means no bundles if (er) return cb() log.verbose("rebuildBundles", files) // don't asyncMap these, because otherwise build script output // gets interleaved and is impossible to read chain(files.filter(function (file) { // rebuild if: // not a .folder, like .bin or .hooks return file.charAt(0) !== "." // not some old 0.x style bundle && file.indexOf("@") === -1 // either not a dep, or explicitly bundled && (deps.indexOf(file) === -1 || bundles.indexOf(file) !== -1) }).map(function (file) { file = path.resolve(folder, "node_modules", file) return function (cb) { if (build._didBuild[file]) return cb() log.verbose("rebuild bundle", file) // if file is not a package dir, then don't do it. fs.lstat(path.resolve(file, "package.json"), function (er, st) { if (er) return cb() build_(false)(file, cb) }) } }), cb) }) }
var _dir2json = function(jsonPart, done) { FS.readdir(jsonPart['-path'], function(err, results) { if (err) return done(err); // Keeps a total of files pending appendation to the object. var pending = results.length; // If there are no files in this directory, we're done on this path. if (pending === 0) return done(null, json); // For each of the files/directories in this directory, call this function. results.forEach(function(file) { try { var f = new File({ "path": jsonPart['-path'] + File.DIRECTORY_SEPARATOR + file, "exists": true }); // Insert the file as a readable file node into the object. jsonPart[file] = createFileNode(f, options); // If the file is a directory, we have more work to do. if (f.getType() === File.Types.directory) { // Recurse, creating a new callback for the next level of files. _dir2json(jsonPart[file], function(err) { if (err) throw err; if (--pending === 0) return done(null, json); }); } else { if (--pending === 0) return done(null, json); } } catch (err) { return done(err); } }); }); };
function targetResolver (where, context, deps) { var alreadyInstalledManually = context.explicit ? [] : null , nm = path.resolve(where, "node_modules") , parent = context.parent , wrap = context.wrap if (!context.explicit) fs.readdir(nm, function (er, inst) { if (er) return alreadyInstalledManually = [] // don't even mess with non-package looking things inst = inst.filter(function (p) { return !p.match(/^[\._-]/) }) asyncMap(inst, function (pkg, cb) { readJson(path.resolve(nm, pkg, "package.json"), log.warn, function (er, d) { if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er) // error means it's not a package, most likely. if (er) return cb(null, []) // if it's a bundled dep, then assume that anything there is valid. // otherwise, make sure that it's a semver match with what we want. var bd = parent.bundleDependencies if (bd && bd.indexOf(d.name) !== -1 || semver.satisfies(d.version, deps[d.name] || "*", true) || deps[d.name] === d._resolved) { return cb(null, d.name) } // see if the package had been previously linked fs.lstat(path.resolve(nm, pkg), function(err, s) { if (err) return cb(null, []) if (s.isSymbolicLink()) { return cb(null, d.name) } // something is there, but it's not satisfactory. Clobber it. return cb(null, []) }) }) }, function (er, inst) { // this is the list of things that are valid and should be ignored. alreadyInstalledManually = inst }) }) var to = 0 return function resolver (what, cb) { if (!alreadyInstalledManually) return setTimeout(function () { resolver(what, cb) }, to++) // now we know what's been installed here manually, // or tampered with in some way that npm doesn't want to overwrite. if (alreadyInstalledManually.indexOf(what.split("@").shift()) !== -1) { log.verbose("already installed", "skipping %s %s", what, where) return cb(null, []) } // check for a version installed higher in the tree. // If installing from a shrinkwrap, it must match exactly. if (context.family[what]) { if (wrap && wrap[what].version === context.family[what]) { log.verbose("shrinkwrap", "use existing", what) return cb(null, []) } } // if it's identical to its parent, then it's probably someone // doing `npm install foo` inside of the foo project. Print // a warning, and skip it. if (parent && parent.name === what && !npm.config.get("force")) { log.warn("install", "Refusing to install %s as a dependency of itself" , what) return cb(null, []) } if (wrap) { var name = what.split(/@/).shift() if (wrap[name]) { var wrapTarget = readWrap(wrap[name]) what = name + "@" + wrapTarget } else { log.verbose("shrinkwrap", "skipping %s (not in shrinkwrap)", what) } } else if (deps[what]) { what = what + "@" + deps[what] } // This is where we actually fetch the package, if it's not already // in the cache. // If it's a git repo, then we want to install it, even if the parent // already has a matching copy. // If it's not a git repo, and the parent already has that pkg, then // we can skip installing it again. cache.add(what, function (er, data) { if (er && parent && parent.optionalDependencies && parent.optionalDependencies.hasOwnProperty(what.split("@")[0])) { log.warn("optional dep failed, continuing", what) log.verbose("optional dep failed, continuing", [what, er]) return cb(null, []) } var isGit = false , maybeGit = what.split("@").slice(1).join() if (maybeGit) isGit = isGitUrl(url.parse(maybeGit)) if (!er && data && !context.explicit && context.family[data.name] === data.version && !npm.config.get("force") && !isGit) { log.info("already installed", data.name + "@" + data.version) return cb(null, []) } if (data && !data._from) data._from = what if (er && parent && parent.name) er.parent = parent.name return cb(er, data || []) }) } }
module.exports = function (req, res, next) { var formName = req.params.formName; if (typeof formName === 'undefined' || formName === null) { res.status(400).json({ status: 400, err: 'MISSING_PARAM', msg: 'You must specify a parameter for the formName in this end point.', path: '/odk/submissions/:formName.json' }); return; } var dir = settings.dataDir + '/submissions/' + formName; var aggregate = []; var dataErrors = []; // All of the submission dirs in the form directory fs.readdir(dir, function (err, submissionDirs) { if (err) { if (err.errno === -2) { // trying to open a directory that is not there. res.status(404).json({ status: 404, msg: 'You are trying to aggregate the ODK submissions for a form that has no submissions. Please submit at least one survey to see data. Also, check to see if you spelled the form name correctly. Form name: ' + formName, err: err }); return; } res.status(500).json({ status: 500, msg: 'Problem reading submissions directory.', err: err }); return; } var len = submissionDirs.length; if (submissionDirs.length === 0) { res.status(200).json([]); return; } var count = 0; submissionDirs.forEach(function (submissionDir) { if (submissionDir[0] === '.' || submissionDir.indexOf('.txt') > 0) { ++count; sendResponse(len, count, aggregate, []); } var dataFile = dir + '/' + submissionDir + '/data.json'; var dataContent = ''; // memory efficient try { var stream = fs.createReadStream(dataFile), parser = JSONStream.parse(); stream.pipe(parser); parser.on('root', function (obj) { // console.log('objects', obj) ++count; aggregate.push(obj); sendResponse(len, count, aggregate, []) }); } catch(e) { dataErrors.push({ status: 500, msg: 'Problem reading data.json file in submission directory. dataFile: ' + dataFile, err: e }); sendResponse(len, count, aggregate, dataErrors); } }); }); function sendResponse (len, count, data, error) { if (len === count) { if (error.length > 0){ // send the first error in the bunch res.status(500).json(error[0]); } else { res.status(200).json(data); } return; } } };
folders2.forEach(function (h){ fs.readdir('./projectsobeys/sobeysFlyerPart/'+latestFolder + '/' + h + '/', function (err3, folders3){ if(err3)throw err3; /** this is each flyer part */ var info = [] , dateOb = {}; async.map(folders3, function (flyerPart, complete) { fs.readFile('./projectsobeys/sobeysFlyerPart/'+latestFolder + '/' + h + '/' + flyerPart, 'utf8', function (err4, data){ if (err4) throw err4; /** this is each 14 departments parts of a flyer bakery = 49 beverage = 56 boxedMeats = 65 candy = 62 dairy = 61 deli = 48 floral = 54 grocery = 51 household = 58 meat = 43 pet = 59 produce = 45 seafood = 44 spread = 57 */ var name = '' , flyerDate = ''; switch(flyerPart.split('.')[0]){ case '49': name = 'bakery'; break; case '56': name = 'beverages'; break; case '65': name = 'boxedMeats'; break; case '62': name = 'candy'; break; case '61': name = 'dairy'; break; case '48': name = 'deli'; break; case '54': name = 'floral'; break; case '51': name = 'grocery'; break; case '58': name = 'household'; break; case '43': name = 'meat'; break; case '59': name = 'pet'; break; case '45': name = 'produce'; break; case '44': name = 'seafood'; break; case '57': name = 'spread'; break; } var $ = cheerio.load(data); if(flyerDate === ''){ flyerArr = $('.container .site-section .site-section-content .fancy-heading .h3-editorial').toArray(); if(flyerArr.length > 0){ flyerDate = flyerArr[0].children[0].data; var dateSplit = flyerDate.split(' '); if(dateSplit.length > 2 && dateSplit[2] === ''){ dateSplit.splice([2], 1); } if(dateSplit.length === 3){ var tmp = dateSplit[2].split('-'); dateOb.start = dateSplit[1] + " " + tmp[0]; dateOb.end = dateSplit[1] + " " + tmp[1]; } else if (dateSplit.length > 3){ var tmp = dateSplit[2].split('-'); //console.log(flyerDate); //console.log(dateSplit) //console.log(tmp) //console.log('\n'); dateOb.start = dateSplit[1] + " " + tmp[0]; dateOb.end = tmp[1] + " " + dateSplit[3]; } else{ dataOb.start = 'something off happened'; dataOb.end = 'something off happened'; } //console.log(dateOb); } else{ dataOb.start = ''; dataOb.end = ''; } } if($('.card .card-plain .card-inset p').text().indexOf('No flyer information at this time') > -1 || !$('div').hasClass('toggle-last')) { console.log('no flyer at file: ' + flyerPart); } else { $('.container .toggle-last .one-third .flyer-card .card-top').each(function (a, html){ var url = '' , price = '' , sav = '' , desc = '' , item = '' , bestSav = '' , bestPercent = '' , savings = '' , savings1 = '' , savings2 = ''; for (var i = html.children.length - 1; i >= 0; i--) { if(html.children[i].type === 'tag') { var class1 = html.children[i]; /** this finds url specifically from selecting a chain of classes */ if(class1.attribs.class === 'card-image'){ url = class1.attribs.style.split(' ')[1].substr(5); url = url.substr(0, url.length -3); } else if (class1.attribs.class==='card-inset'){ for (var j = class1.children.length - 1; j >= 0; j--) { var class2 = class1.children[j]; if(class2.type === 'tag'){ /** finds the desc */ if (class2.name === 'p'){ desc = class2.children[0].data; desc = desc.replace(/&/g, '&'); desc = desc.replace(/[^a-zA-Z 0-9+;():,.-\s*!%&\r\n\/]+/g,"'"); } /** finds the item name */ else if(class2.attribs.class.indexOf('h6') > -1){ item = class2.children[0].data; item = item.replace(/&/g, '&'); item = item.replace(/[^a-zA-Z 0-9+;():,.-\s*!%&\r\n\/]+/g,"'"); } /** finds the price and savings */ else if (class2.attribs.class.indexOf('price')>-1){ for (var k = class2.children.length - 1; k >= 0; k--) { var class3 = class2.children[k]; if(class3.type === 'tag'){ if(class3.attribs.class.indexOf('price-amount')){ if(class3.children.length > 1 && class3.children[1].children.length > 0){ sav = class3.children[1].children[0].data; sav = sav.replace(/&/g, '&'); sav = sav.replace(/[^a-zA-Z0-9+;():,\.$-\s*!%&\r\n\/]+/g,"|"); var savSplit = sav.split(' ') , tmp = '' , count = 0; for (var l = 0; l < savSplit.length; l++) { if(savSplit[l].indexOf('|') > -1){ tmp += '$0.' + savSplit[l].replace('|', '') + ' '; count++; } else if (!isNaN(savSplit[l]) && savSplit[l].indexOf('$') === -1 && count === 0){ tmp += '$'+savSplit[l] + ' '; count++; } else if (savSplit[l].indexOf('/') > -1){ tmp += '$'+savSplit[l] + ' '; } else{ tmp += savSplit[l] + ' '; } }; sav = tmp sav = sav.replace('100 g', '100g'); sav = sav.replace(' /100g', '/100g'); sav = sav.replace('lb ,ea', 'lb,ea'); sav = sav.replace('lb, ea', 'lb,ea'); sav = sav.replace('$$', '$'); } } else if (class3.attribs.class.indexOf('price-promos')) { if(class3.children.length > 1){ if(class3.children[1].children.length > 1){ savings = '$' + class3.children[0].data+'.'; savings1 = class3.children[1].children[0].data; savings2 = class3.children[1].children[1].children[0].data; } else if (class3.children[0].data.indexOf('%') > -1){ savings = 'noPrice'; savings1 = class3.children[0].data; savings2 = class3.children[1].children[0].data; } else if (class3.children[0].data.indexOf('/') === -1){ savings = '$0' + class3.children[0].data; savings1 = class3.children[1].children[0].data; } else{ savings = class3.children[0].data + '.'; savings = savings.replace('/', '/$'); savings1 = class3.children[1].children[0].data; } var price = savings + savings1 + savings2; } } } }; } } }; } /** gets the best savings from the price */ if(url !== '' && item !== ''){ var priceSav = {}; priceSav.price = price; priceSav.sav = sav; var listOfFrenchStores = ['34']; if(listOfFrenchStores.indexOf(h) === -1){ getBest(priceSav, function (percent, sav2, extra){ //console.log(name); /*var ob = {}; ob.item = item; ob.price = price; ob.savings = sav; ob.url = url; ob.description = desc; ob.bestPercent = percent; ob.bestSav = sav2; ob.extra = extra; info.push(ob);*/ Item.makeItem(item, price, sav, desc, url, extra, percent, sav2, name, h, function (errMakeItem){ if(errMakeItem) throw errMakeItem; }); }); } } } }; }); } if(info.indexOf(name) === -1){ info.push(name); } complete(err4, data); }); } , function (err7, results){ //console.log(info.sort()); Store.addCategoryParts(h, info.sort(), dateOb, function (err6){ if(err6) throw err6; if(h > 289) console.log('done'); else{ console.log(h.split('.')[0]) } }); }); }); });
app.get( '/', function _app_get( req, res ) { var dir='./testgames/'; var data={}; var most_accurate = []; fs.readdir( dir, function _fs_readdir( err, files ) { if( err ) throw err; var c = 0; files.forEach( function _files_foreach( file ) { c++; /* if( file.match( /.json$/ ) ) { console.log( c + " " + dir + file ); fs.readFile( dir + file, 'utf-8', function _fs_readfile( err, thedata ) { if( err ) { console.log( err ); throw err; } var j = JSON.parse( thedata ); if( file != 'undefined.json' ) { var AVG_ACC = 0; var MOST_ACCURATE_NICK = ""; var MOST_ACCURATE_NUM = 0; var DMG_DELIVERED_NICK = ""; var DMG_DELIVERED_NUM = 0; var DMG_TAKEN_NICK = ""; var DMG_TAKEN_NUM = 0; var LEAST_DEATHS_NICK = ""; var LEAST_DEATHS_NUM = 0; var MOST_DEATHS_NICK = ""; var MOST_DEATHS_NUM = 0; var TOTAL_ROUNDS = 0; var WINNING_TEAM = ""; if( !isNaN( j.AVG_ACC ) && j.AVG_ACC !== 'undefined' ) { AVG_ACC = j.AVG_ACC; } if( typeof j.MOST_ACCURATE !== 'undefined' ) { MOST_ACCURATE_NICK = j.MOST_ACCURATE.PLAYER_NICK; MOST_ACCURATE_NUM = j.MOST_ACCURATE.NUM; } if( typeof j.DMG_DELIVERED !== 'undefined' ) { DMG_DELIVERED_NICK = j.DMG_DELIVERED.PLAYER_NICK; DMG_DELIVERED_NUM = j.DMG_DELIVERED.NUM; } if( typeof j.DMG_TAKEN !== 'undefined' ) { DMG_TAKEN_NICK = j.DMG_TAKEN.PLAYER_NICK; DMG_TAKEN_NUM = j.DMG_TAKEN.NUM; } if( typeof j.LEAST_DEATHS !== 'undefined' ) { LEAST_DEATHS_NICK = j.LEAST_DEATHS.PLAYER_NICK; LEAST_DEATHS_NUM = j.LEAST_DEATHS.NUM; } if( typeof j.MOST_DEATHS !== 'undefined' ) { MOST_DEATHS_NICK = j.MOST_DEATHS.PLAYER_NICK; MOST_DEATHS_NUM = j.MOST_DEATHS.NUM; } if( typeof j.TOTAL_ROUNDS !== 'undefined' ) { TOTAL_ROUNDS = j.TOTAL_ROUNDS; WINNING_TEAM = j.WINNING_TEAM; } var sql1 = 'INSERT INTO Games(' + 'PUBLIC_ID,' + 'OWNER, ' + 'MAP, ' + 'NUM_PLAYERS, ' + 'AVG_ACC, ' + 'PREMIUM, ' + 'RANKED, ' + 'RESTARTED, ' + 'RULESET, ' + 'TIER, ' + 'TOTAL_KILLS, ' + 'TOTAL_ROUNDS, ' + 'WINNING_TEAM, ' + 'TSCORE0, ' + 'TSCORE1, ' + 'FIRST_SCORER, ' + 'LAST_SCORER, ' + 'GAME_LENGTH, ' + 'GAME_TYPE, ' + 'GAME_TIMESTAMP, ' + 'DMG_DELIVERED_NICK, ' + 'DMG_DELIVERED_NUM, ' + 'DMG_TAKEN_NICK, ' + 'DMG_TAKEN_NUM, ' + 'LEAST_DEATHS_NICK, ' + 'LEAST_DEATHS_NUM, ' + 'MOST_DEATHS_NICK, ' + 'MOST_DEATHS_NUM, ' + 'MOST_ACCURATE_NICK, ' + 'MOST_ACCURATE_NUM ' + ') values( '; var sql2 = '' + '\"' + j.PUBLIC_ID + '\",' + '\"' + j.OWNER + '\",' + '\"' + j.MAP + '\",' + '' + j.NUM_PLAYERS + ',' + '' + AVG_ACC + ',' + '' + j.PREMIUM + ',' + '' + j.RANKED + ',' + '' + j.RESTARTED + ',' + '' + j.RULESET + ',' + '' + j.TIER + ',' + '' + j.TOTAL_KILLS + ',' + '' + TOTAL_ROUNDS + ',' + '\"' + WINNING_TEAM + '\",' + '' + j.TSCORE0 + ',' + '' + j.TSCORE1 + ',' + '\"' + j.FIRST_SCORER + '\",' + '\"' + j.LAST_SCORER + '\",' + '' + j.GAME_LENGTH + ',' + '\"' + j.GAME_TYPE + '\",' + '' + new Date( j.GAME_TIMESTAMP ).getTime()/1000 + ',' + '\"' + DMG_DELIVERED_NICK + '\",' + '' + DMG_DELIVERED_NUM + ',' + '\"' + DMG_TAKEN_NICK + '\",' + '' + DMG_TAKEN_NUM + ',' + '\"' + LEAST_DEATHS_NICK + '\",' + '' + LEAST_DEATHS_NUM + ',' + '\"' + MOST_DEATHS_NICK + '\",' + '' + MOST_DEATHS_NUM + ',' + '\"' + MOST_ACCURATE_NICK + '\",' + '' + MOST_ACCURATE_NUM + ')'; //console.log( sql1 ); //console.log( sql2 ); db.query( sql1 + sql2, function _db_query_game( err, rows, fields ) { if( err ) { throw err; } //console.log( rows ); } ); for( var i in j.BLUE_SCOREBOARD ) { var p = j.BLUE_SCOREBOARD[i]; var IMPRESSIVE = 0; var EXCELLENT = 0; if( typeof p.IMPRESSIVE !== 'undefined' ) { IMPRESSIVE = p.IMPRESSIVE; } if( typeof p.EXCELLENT !== 'undefined' ) { EXCELLENT = p.EXCELLENT; } //console.log( j.PUBLIC_ID + " " + p.PLAYER_NICK + " " + p.TEAM ); var sql3 = 'INSERT INTO Players(' + 'PUBLIC_ID, ' + 'PLAYER_NICK, ' + 'PLAYER_CLAN, ' + 'PLAYER_COUNTRY, ' + 'RANK, ' + 'SCORE, ' + 'QUIT, ' + 'DAMAGE_DEALT, ' + 'DAMAGE_TAKEN, ' + 'KILLS, ' + 'DEATHS, ' + 'HITS, ' + 'SHOTS, ' + 'TEAM, ' + 'TEAM_RANK, ' + 'HUMILIATION, ' + 'IMPRESSIVE, ' + 'EXCELLENT, ' + 'PLAY_TIME, ' + 'G_A, ' + 'G_H, ' + 'G_K, ' + 'G_S, ' + 'GL_A, ' + 'GL_H, ' + 'GL_K, ' + 'GL_S, ' + 'LG_A, ' + 'LG_H, ' + 'LG_K, ' + 'LG_S, ' + 'MG_A, ' + 'MG_H, ' + 'MG_K, ' + 'MG_S, ' + 'PG_A, ' + 'PG_H, ' + 'PG_K, ' + 'PG_S, ' + 'RG_A, ' + 'RG_H, ' + 'RG_K, ' + 'RG_S, ' + 'RL_A, ' + 'RL_H, ' + 'RL_K, ' + 'RL_S, ' + 'SG_A, ' + 'SG_H, ' + 'SG_K, ' + 'SG_S' + ') values( '; var sql4 = '' + '\"' + j.PUBLIC_ID + '\",' + '\"' + p.PLAYER_NICK + '\",' + '\"' + p.PLAYER_CLAN + '\",' + '\"' + p.PLAYER_COUNTRY + '\",' + '' + p.RANK + ',' + '' + p.SCORE + ',' + '' + p.QUIT + ',' + '' + p.DAMAGE_DEALT + ',' + '' + p.DAMAGE_TAKEN + ',' + '' + p.KILLS + ',' + '' + p.DEATHS + ',' + '' + p.HITS + ',' + '' + p.SHOTS + ',' + '\"' + p.TEAM + '\",' + '' + p.TEAM_RANK + ',' + '' + p.HUMILIATION + ',' + '' + IMPRESSIVE + ',' + '' + EXCELLENT + ',' + '' + p.PLAY_TIME + ',' + '' + p.GAUNTLET_ACCURACY + ',' + '' + p.GAUNTLET_HITS + ',' + '' + p.GAUNTLET_KILLS + ',' + '' + p.GAUNTLET_SHOTS + ',' + '' + p.GRENADE_ACCURACY + ',' + '' + p.GRENADE_HITS + ',' + '' + p.GRENADE_KILLS + ',' + '' + p.GRENADE_SHOTS + ',' + '' + p.LIGHTNING_ACCURACY + ',' + '' + p.LIGHTNING_HITS + ',' + '' + p.LIGHTNING_KILLS + ',' + '' + p.LIGHTNING_SHOTS + ',' + '' + p.MACHINEGUN_ACCURACY + ',' + '' + p.MACHINEGUN_HITS + ',' + '' + p.MACHINEGUN_KILLS + ',' + '' + p.MACHINEGUN_SHOTS + ',' + '' + p.PLASMA_ACCURACY + ',' + '' + p.PLASMA_HITS + ',' + '' + p.PLASMA_KILLS + ',' + '' + p.PLASMA_SHOTS + ',' + '' + p.RAILGUN_ACCURACY + ',' + '' + p.RAILGUN_HITS + ',' + '' + p.RAILGUN_KILLS + ',' + '' + p.RAILGUN_SHOTS + ',' + '' + p.ROCKET_ACCURACY + ',' + '' + p.ROCKET_HITS + ',' + '' + p.ROCKET_KILLS + ',' + '' + p.ROCKET_SHOTS + ',' + '' + p.SHOTGUN_ACCURACY + ',' + '' + p.SHOTGUN_HITS + ',' + '' + p.SHOTGUN_KILLS + ',' + '' + p.SHOTGUN_SHOTS + ')'; //console.log( i + " " + sql3 ); //console.log( i + " " + sql4 ); db.query( sql3 + sql4, function _db_query_blue( err, rows, fields ) { if( err ) { throw err; } } ); } for( var i in j.RED_SCOREBOARD ) { var p = j.RED_SCOREBOARD[i]; var IMPRESSIVE = 0; var EXCELLENT = 0; if( typeof p.IMPRESSIVE !== 'undefined' ) { IMPRESSIVE = p.IMPRESSIVE; } if( typeof p.EXCELLENT !== 'undefined' ) { EXCELLENT = p.EXCELLENT; } //console.log( j.PUBLIC_ID + " " + p.PLAYER_NICK + " " + p.TEAM ); var sql3 = 'INSERT INTO Players(' + 'PUBLIC_ID, ' + 'PLAYER_NICK, ' + 'PLAYER_CLAN, ' + 'PLAYER_COUNTRY, ' + 'RANK, ' + 'SCORE, ' + 'QUIT, ' + 'DAMAGE_DEALT, ' + 'DAMAGE_TAKEN, ' + 'KILLS, ' + 'DEATHS, ' + 'HITS, ' + 'SHOTS, ' + 'TEAM, ' + 'TEAM_RANK, ' + 'HUMILIATION, ' + 'IMPRESSIVE, ' + 'EXCELLENT, ' + 'PLAY_TIME, ' + 'G_A, ' + 'G_H, ' + 'G_K, ' + 'G_S, ' + 'GL_A, ' + 'GL_H, ' + 'GL_K, ' + 'GL_S, ' + 'LG_A, ' + 'LG_H, ' + 'LG_K, ' + 'LG_S, ' + 'MG_A, ' + 'MG_H, ' + 'MG_K, ' + 'MG_S, ' + 'PG_A, ' + 'PG_H, ' + 'PG_K, ' + 'PG_S, ' + 'RG_A, ' + 'RG_H, ' + 'RG_K, ' + 'RG_S, ' + 'RL_A, ' + 'RL_H, ' + 'RL_K, ' + 'RL_S, ' + 'SG_A, ' + 'SG_H, ' + 'SG_K, ' + 'SG_S' + ') values( '; var sql4 = '' + '\"' + j.PUBLIC_ID + '\",' + '\"' + p.PLAYER_NICK + '\",' + '\"' + p.PLAYER_CLAN + '\",' + '\"' + p.PLAYER_COUNTRY + '\",' + '' + p.RANK + ',' + '' + p.SCORE + ',' + '' + p.QUIT + ',' + '' + p.DAMAGE_DEALT + ',' + '' + p.DAMAGE_TAKEN + ',' + '' + p.KILLS + ',' + '' + p.DEATHS + ',' + '' + p.HITS + ',' + '' + p.SHOTS + ',' + '\"' + p.TEAM + '\",' + '' + p.TEAM_RANK + ',' + '' + p.HUMILIATION + ',' + '' + IMPRESSIVE + ',' + '' + EXCELLENT + ',' + '' + p.PLAY_TIME + ',' + '' + p.GAUNTLET_ACCURACY + ',' + '' + p.GAUNTLET_HITS + ',' + '' + p.GAUNTLET_KILLS + ',' + '' + p.GAUNTLET_SHOTS + ',' + '' + p.GRENADE_ACCURACY + ',' + '' + p.GRENADE_HITS + ',' + '' + p.GRENADE_KILLS + ',' + '' + p.GRENADE_SHOTS + ',' + '' + p.LIGHTNING_ACCURACY + ',' + '' + p.LIGHTNING_HITS + ',' + '' + p.LIGHTNING_KILLS + ',' + '' + p.LIGHTNING_SHOTS + ',' + '' + p.MACHINEGUN_ACCURACY + ',' + '' + p.MACHINEGUN_HITS + ',' + '' + p.MACHINEGUN_KILLS + ',' + '' + p.MACHINEGUN_SHOTS + ',' + '' + p.PLASMA_ACCURACY + ',' + '' + p.PLASMA_HITS + ',' + '' + p.PLASMA_KILLS + ',' + '' + p.PLASMA_SHOTS + ',' + '' + p.RAILGUN_ACCURACY + ',' + '' + p.RAILGUN_HITS + ',' + '' + p.RAILGUN_KILLS + ',' + '' + p.RAILGUN_SHOTS + ',' + '' + p.ROCKET_ACCURACY + ',' + '' + p.ROCKET_HITS + ',' + '' + p.ROCKET_KILLS + ',' + '' + p.ROCKET_SHOTS + ',' + '' + p.SHOTGUN_ACCURACY + ',' + '' + p.SHOTGUN_HITS + ',' + '' + p.SHOTGUN_KILLS + ',' + '' + p.SHOTGUN_SHOTS + ')'; //console.log( i + " " + sql3 ); //console.log( i + " " + sql4 ); db.query( sql3 + sql4, function _db_query_red( err, rows, fields ) { if( err ) { throw err; } } ); } for( var i in j.SCOREBOARD ) { var p = j.SCOREBOARD[i]; var IMPRESSIVE = 0; var EXCELLENT = 0; var QUIT = 0; var TEAM_RANK = 0; if( typeof p.IMPRESSIVE !== 'undefined' ) { IMPRESSIVE = p.IMPRESSIVE; } if( typeof p.EXCELLENT !== 'undefined' ) { EXCELLENT = p.EXCELLENT; } if( typeof p.QUIT !== 'undefined' ) { QUIT = p.QUIT; } if( typeof p.TEAM_RANK !== 'undefined' ) { TEAM_RANK = p.TEAM_RANK; } //console.log( j.PUBLIC_ID + " " + p.PLAYER_NICK + " " + p.TEAM ); var sql3 = 'INSERT INTO Players(' + 'PUBLIC_ID, ' + 'PLAYER_NICK, ' + 'PLAYER_CLAN, ' + 'PLAYER_COUNTRY, ' + 'RANK, ' + 'SCORE, ' + 'QUIT, ' + 'DAMAGE_DEALT, ' + 'DAMAGE_TAKEN, ' + 'KILLS, ' + 'DEATHS, ' + 'HITS, ' + 'SHOTS, ' + 'TEAM, ' + 'TEAM_RANK, ' + 'HUMILIATION, ' + 'IMPRESSIVE, ' + 'EXCELLENT, ' + 'PLAY_TIME, ' + 'G_A, ' + 'G_H, ' + 'G_K, ' + 'G_S, ' + 'GL_A, ' + 'GL_H, ' + 'GL_K, ' + 'GL_S, ' + 'LG_A, ' + 'LG_H, ' + 'LG_K, ' + 'LG_S, ' + 'MG_A, ' + 'MG_H, ' + 'MG_K, ' + 'MG_S, ' + 'PG_A, ' + 'PG_H, ' + 'PG_K, ' + 'PG_S, ' + 'RG_A, ' + 'RG_H, ' + 'RG_K, ' + 'RG_S, ' + 'RL_A, ' + 'RL_H, ' + 'RL_K, ' + 'RL_S, ' + 'SG_A, ' + 'SG_H, ' + 'SG_K, ' + 'SG_S' + ') values( '; var sql4 = '' + '\"' + j.PUBLIC_ID + '\",' + '\"' + p.PLAYER_NICK + '\",' + '\"' + p.PLAYER_CLAN + '\",' + '\"' + p.PLAYER_COUNTRY + '\",' + '' + p.RANK + ',' + '' + p.SCORE + ',' + '' + QUIT + ',' + '' + p.DAMAGE_DEALT + ',' + '' + p.DAMAGE_TAKEN + ',' + '' + p.KILLS + ',' + '' + p.DEATHS + ',' + '' + p.HITS + ',' + '' + p.SHOTS + ',' + '\"' + p.TEAM + '\",' + '' + TEAM_RANK + ',' + '' + p.HUMILIATION + ',' + '' + IMPRESSIVE + ',' + '' + EXCELLENT + ',' + '' + p.PLAY_TIME + ',' + '' + p.GAUNTLET_ACCURACY + ',' + '' + p.GAUNTLET_HITS + ',' + '' + p.GAUNTLET_KILLS + ',' + '' + p.GAUNTLET_SHOTS + ',' + '' + p.GRENADE_ACCURACY + ',' + '' + p.GRENADE_HITS + ',' + '' + p.GRENADE_KILLS + ',' + '' + p.GRENADE_SHOTS + ',' + '' + p.LIGHTNING_ACCURACY + ',' + '' + p.LIGHTNING_HITS + ',' + '' + p.LIGHTNING_KILLS + ',' + '' + p.LIGHTNING_SHOTS + ',' + '' + p.MACHINEGUN_ACCURACY + ',' + '' + p.MACHINEGUN_HITS + ',' + '' + p.MACHINEGUN_KILLS + ',' + '' + p.MACHINEGUN_SHOTS + ',' + '' + p.PLASMA_ACCURACY + ',' + '' + p.PLASMA_HITS + ',' + '' + p.PLASMA_KILLS + ',' + '' + p.PLASMA_SHOTS + ',' + '' + p.RAILGUN_ACCURACY + ',' + '' + p.RAILGUN_HITS + ',' + '' + p.RAILGUN_KILLS + ',' + '' + p.RAILGUN_SHOTS + ',' + '' + p.ROCKET_ACCURACY + ',' + '' + p.ROCKET_HITS + ',' + '' + p.ROCKET_KILLS + ',' + '' + p.ROCKET_SHOTS + ',' + '' + p.SHOTGUN_ACCURACY + ',' + '' + p.SHOTGUN_HITS + ',' + '' + p.SHOTGUN_KILLS + ',' + '' + p.SHOTGUN_SHOTS + ')'; //console.log( i + " " + sql3 ); //console.log( i + " " + sql4 ); db.query( sql3 + sql4, function _db_query_scoreboard( err, rows, fields ) { if( err ) { throw err; } } ); } } } ); } */ } ); } ); res.jsonp( { doing: "it" } ); res.end(); } );
exports.init = function (callback) { externalFactors.forEach(function (factors) { if (factors.file) { var filepath = path.join(__dirname, '..', factors.file); var factorsList = require(filepath); if (factors.sublist) { factorsList = factorsList[factors.sublist]; } factorsList.forEach(function (factor) { qualifyingFactors[factor.code] = factors.weight; }); } }); var exclusionsDir = path.join(__dirname, '../exclusions'); fs.readdir(exclusionsDir, function (err, files) { if (err) { return callback(err); } (function readFile() { var file = files.pop(); if (!file) { return callback(null, Object.keys(robots).length); } var type = file.substr(0, file.indexOf('.')); var list; switch (type) { case 'hosts': list = hosts; break; case 'domains': list = domains; break; case 'robots': list = robots; break; default: return readFile(); } fs.readFile(path.join(exclusionsDir, file), function (err, content) { if (err) { return callback(err); } if (!content) { return readFile(); } var partial = /^[0-9]+\.[0-9]+\.[0-9]+$/; content.toString().split(/\r?\n/).forEach(function (line) { var comment = line.indexOf('#'); if (comment >= 0) { line = line.substr(0, comment); } line = line.trim(); if (line.length > 0) { if (partial.test(line)) { for (var i = 0; i <= 255; i++) { list[line + '.' + i] = 1; } } else { list[line] = 1; } } }); readFile(); }); })(); }); };
var f = ff(function () { fs.readdir(path, f()); }, function (files) {
function targetResolver (where, context, deps) { var alreadyInstalledManually = context.explicit ? [] : null , nm = path.resolve(where, "node_modules") , parent = context.parent , wrap = context.wrap if (!context.explicit) fs.readdir(nm, function (er, inst) { if (er) return alreadyInstalledManually = [] asyncMap(inst, function (pkg, cb) { readJson(path.resolve(nm, pkg, "package.json"), function (er, d) { // error means it's not a package, most likely. if (er) return cb(null, []) // if it's a bundled dep, then assume that anything there is valid. // otherwise, make sure that it's a semver match with what we want. var bd = parent.bundleDependencies if (bd && bd.indexOf(d.name) !== -1 || semver.satisfies(d.version, deps[d.name] || "*")) { return cb(null, d.name) } // something is there, but it's not satisfactory. Clobber it. return cb(null, []) }) }, function (er, inst) { // this is the list of things that are valid and should be ignored. alreadyInstalledManually = inst }) }) var to = 0 return function resolver (what, cb) { if (!alreadyInstalledManually) return setTimeout(function () { resolver(what, cb) }, to++) // now we know what's been installed here manually, // or tampered with in some way that npm doesn't want to overwrite. if (alreadyInstalledManually.indexOf(what.split("@").shift()) !== -1) { log.verbose("skipping "+what, "already installed in "+where) return cb(null, []) } // check for a version installed higher in the tree. // If installing from a shrinkwrap, it must match exactly. if (context.family[what]) { if (wrap && wrap[what].version === context.family[what]) { log.verbose(what, "using existing (matches shrinkwrap)") return cb(null, []) } } // if it's identical to its parent, then it's probably someone // doing `npm install foo` inside of the foo project. Print // a warning, and skip it. if (parent && parent.name === what && !npm.config.get("force")) { log.warn("Refusing to install "+what+" as a dependency of itself" ,"install") return cb(null, []) } if (wrap) { name = what.split(/@/).shift() if (wrap[name]) { var wrapTarget = wrap[name].from || wrap[name].version log.verbose("resolving "+what+" to "+wrapTarget, "shrinkwrap") what = name + "@" + wrapTarget } else { log.verbose("skipping "+what+" (not in shrinkwrap)", "shrinkwrap") } } else if (deps[what]) { what = what + "@" + deps[what] } cache.add(what, function (er, data) { if (er && parent && parent.optionalDependencies && parent.optionalDependencies.hasOwnProperty(what.split("@")[0])) { log.warn(what, "optional dependency failed, continuing") log.verbose([what, er], "optional dependency failed, continuing") return cb(null, []) } if (!er && data && !context.explicit && context.family[data.name] === data.version && !npm.config.get("force")) { log.info(data.name + "@" + data.version, "already installed") return cb(null, []) } if (data) data._from = what return cb(er, data) }) } }
var fs = require('graceful-fs'); var linked_data_dir = './linked-data'; var final_data_dir = './final-data'; fs.readdir(linked_data_dir, readdir); function readdir(err, directories) { if (err) { console.log(err); return; } for (var i = 0; i < directories.length; i++) { console.log(directories[i]); var current_directory = linked_data_dir + '/' + directories[i]; (function(current_directory){ fs.readdir(current_directory, function (err,files){ if (err) { console.log(err); return; } for (var i = 0; i < files.length; i++) { if(files[i].indexOf("linked-") != -1) { var file = current_directory + '/' + files[i];
return function (done) { fs.readdir(root, done) }
var f = ff(this, function () { fs.readdir(addonPath, f()); this.startupPlugins(f.waitPlain()); }, function (files) {
var f = ff(this, function () { // Make plugin root directory wrench.mkdirSyncRecursive(pluginsRoot, 511); // 0777 fs.readdir(pluginsRoot, f.slot()); }, function (contents) {
}, function() { fs.readdir(REGISTRY_PATH, f()); }, function (files) {
function getArt(name, options, cb) { const ext = paths.extname(name); options.basePath = miscUtil.valueWithDefault(options.basePath, Config.paths.art); options.asAnsi = miscUtil.valueWithDefault(options.asAnsi, true); // :TODO: make use of asAnsi option and convert from supported -> ansi if('' !== ext) { options.types = [ ext.toLowerCase() ]; } else { if(_.isUndefined(options.types)) { options.types = Object.keys(SUPPORTED_ART_TYPES); } else if(_.isString(options.types)) { options.types = [ options.types.toLowerCase() ]; } } // If an extension is provided, just read the file now if('' !== ext) { const directPath = paths.join(options.basePath, name); return getArtFromPath(directPath, options, cb); } fs.readdir(options.basePath, (err, files) => { if(err) { return cb(err); } const filtered = files.filter( file => { // // Ignore anything not allowed in |options.types| // const fext = paths.extname(file); if(!options.types.includes(fext.toLowerCase())) { return false; } const bn = paths.basename(file, fext).toLowerCase(); if(options.random) { const suppliedBn = paths.basename(name, fext).toLowerCase(); // // Random selection enabled. We'll allow for // basename1.ext, basename2.ext, ... // if(!bn.startsWith(suppliedBn)) { return false; } const num = bn.substr(suppliedBn.length); if(num.length > 0) { if(isNaN(parseInt(num, 10))) { return false; } } } else { // // We've already validated the extension (above). Must be an exact // match to basename here // if(bn != paths.basename(name, fext).toLowerCase()) { return false; } } return true; }); if(filtered.length > 0) { // // We should now have: // - Exactly (1) item in |filtered| if non-random // - 1:n items in |filtered| to choose from if random // let readPath; if(options.random) { readPath = paths.join(options.basePath, filtered[Math.floor(Math.random() * filtered.length)]); } else { assert(1 === filtered.length); readPath = paths.join(options.basePath, filtered[0]); } return getArtFromPath(readPath, options, cb); } return cb(new Error(`No matching art for supplied criteria: ${name}`)); }); }
function outdated_ (args, dir, parentHas, depth, cb) { // get the deps from package.json, or {<dir/node_modules/*>:"*"} // asyncMap over deps: // shouldHave = cache.add(dep, req).version // if has === shouldHave then // return outdated(args, dir/node_modules/dep, parentHas + has) // else if dep in args or args is empty // return [dir, dep, has, shouldHave] if (depth > npm.config.get("depth")) { return cb(null, []) } var deps = null readJson(path.resolve(dir, "package.json"), function (er, d) { d = d || {} if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er) deps = (er) ? true : (d.dependencies || {}) if (npm.config.get("save-dev")) { deps = d.devDependencies || {} return next() } if (npm.config.get("save")) { // remove optional dependencies from dependencies during --save. Object.keys(d.optionalDependencies || {}).forEach(function (k) { delete deps[k] }) return next() } if (npm.config.get("save-optional")) { deps = d.optionalDependencies || {} return next() } var doUpdate = npm.config.get("dev") || (!npm.config.get("production") && !Object.keys(parentHas).length && !npm.config.get("global")) if (!er && d && doUpdate) { Object.keys(d.devDependencies || {}).forEach(function (k) { if (!(k in parentHas)) { deps[k] = d.devDependencies[k] } }) } return next() }) var has = null fs.readdir(path.resolve(dir, "node_modules"), function (er, pkgs) { if (er) { has = Object.create(parentHas) return next() } pkgs = pkgs.filter(function (p) { return !p.match(/^[\._-]/) }) asyncMap(pkgs, function (pkg, cb) { var jsonFile = path.resolve(dir, "node_modules", pkg, "package.json") readJson(jsonFile, function (er, d) { if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er) cb(null, er ? [] : [[d.name, d.version, d._from]]) }) }, function (er, pvs) { if (er) return cb(er) has = Object.create(parentHas) pvs.forEach(function (pv) { has[pv[0]] = { version: pv[1], from: pv[2] } }) next() }) }) function next () { if (!has || !deps) return if (deps === true) { deps = Object.keys(has).reduce(function (l, r) { l[r] = "*" return l }, {}) } // now get what we should have, based on the dep. // if has[dep] !== shouldHave[dep], then cb with the data // otherwise dive into the folder asyncMap(Object.keys(deps), function (dep, cb) { shouldUpdate(args, dir, dep, has, deps[dep], depth, cb) }, cb) } }
var Mocha = require('mocha'), path = require('path'), fs = require('graceful-fs'), argv = require('optimist').argv; var mocha = new Mocha({ reporter: argv.reporter || 'dot' }); var rFilename = /\.test\.js$/; fs.readdir(__dirname, function(err, files){ files.forEach(function(item){ if (rFilename.test(item)){ mocha.addFile(path.join(__dirname, item)); } }); require('../lib/init')(path.join(__dirname, 'blog'), {_: [], _test: true}, function(){ mocha.run(function(failures){ process.exit(failures); }); }); });
module.exports=DirReader;var fs=require("graceful-fs");var inherits=require("inherits");var path=require("path");var Reader=require("./reader.js");var assert=require("assert").ok;inherits(DirReader,Reader);function DirReader(b){var a=this;if(!(a instanceof DirReader)){throw new Error("DirReader must be called as constructor.")}if(b.type!=="Directory"||!b.Directory){throw new Error("Non-directory type "+b.type)}a.entries=null;a._index=-1;a._paused=false;a._length=-1;if(b.sort){this.sort=b.sort}Reader.call(this,b)}DirReader.prototype._getEntries=function(){var a=this;if(a._gotEntries){return}a._gotEntries=true;fs.readdir(a._path,function(d,b){if(d){return a.error(d)}a.entries=b;a.emit("entries",b);if(a._paused){a.once("resume",c)}else{c()}function c(){a._length=a.entries.length;if(typeof a.sort==="function"){a.entries=a.entries.sort(a.sort.bind(a))}a._read()}})};DirReader.prototype._read=function(){var a=this;if(!a.entries){return a._getEntries()}if(a._paused||a._currentEntry||a._aborted){return}a._index++;if(a._index>=a.entries.length){if(!a._ended){a._ended=true;a.emit("end");a.emit("close")}return}var b=path.resolve(a._path,a.entries[a._index]);assert(b!==a._path);assert(a.entries[a._index]);a._currentEntry=b;fs[a.props.follow?"stat":"lstat"](b,function(j,f){if(j){return a.error(j)}var e=a._proxy||a;f.path=b;f.basename=path.basename(b);f.dirname=path.dirname(b);var c=a.getChildProps.call(e,f);c.path=b;c.basename=path.basename(b);c.dirname=path.dirname(b);var g=Reader(c,f);a._currentEntry=g;g.on("pause",function(k){if(!a._paused&&!g._disowned){a.pause(k)}});g.on("resume",function(k){if(a._paused&&!g._disowned){a.resume(k)}});g.on("stat",function(k){a.emit("_entryStat",g,k);if(g._aborted){return}if(g._paused){g.once("resume",function(){a.emit("entryStat",g,k)})}else{a.emit("entryStat",g,k)}});g.on("ready",function d(){if(a._paused){g.pause(a);return a.once("resume",d)}if(g.type==="Socket"){a.emit("socket",g)}else{a.emitEntry(g)}});var i=false;g.on("close",h);g.on("disown",h);function h(){if(i){return}i=true;a.emit("childEnd",g);a.emit("entryEnd",g);a._currentEntry=null;if(!a._paused){a._read()}}g.on("error",function(k){if(g._swallowErrors){a.warn(k);g.emit("end");g.emit("close")}else{a.emit("error",k)}});["child","childEnd","warn"].forEach(function(k){g.on(k,a.emit.bind(a,k))})})};DirReader.prototype.disown=function(a){a.emit("beforeDisown");a._disowned=true;a.parent=a.root=null;if(a===this._currentEntry){this._currentEntry=null}a.emit("disown")};DirReader.prototype.getChildProps=function(){return{depth:this.depth+1,root:this.root||this,parent:this,follow:this.follow,filter:this.filter,sort:this.props.sort,hardlinks:this.props.hardlinks}};DirReader.prototype.pause=function(b){var a=this;if(a._paused){return}b=b||a;a._paused=true;if(a._currentEntry&&a._currentEntry.pause){a._currentEntry.pause(b)}a.emit("pause",b)};DirReader.prototype.resume=function(b){var a=this;if(!a._paused){return}b=b||a;a._paused=false;a.emit("resume",b);if(a._paused){return}if(a._currentEntry){if(a._currentEntry.resume){a._currentEntry.resume(b)}}else{a._read()}};DirReader.prototype.emitEntry=function(a){this.emit("entry",a);this.emit("child",a)};
*/ //var fs = require('fs'); var fs = require('graceful-fs'); //fs.gracefulify(natFs); var os = require('os'); var path = require('path'); var srcDir = 'P:\\var\\nodes\\workspace\\webpack-react\\webpack\\node_modules\\'; var desDir = 'P:\\var\\alisvn\\workspace\\huiyou\\trunk\\assets\\node_modules\\'; //var srcDir = path.resolve('.') + '/../node_modules/'; //var desDir = path.resolve('.') + '/'; fs.readdir(srcDir, function(err, files) { files = Array.prototype.slice.call(files); // parseTreeJson(files, srcDir, desDir); iterator1(files); }); //递归实现 recursion var parseTreeJson = function(treeNodes, srcDir, desDir) { if (!treeNodes || !treeNodes.length) return; treeNodes.forEach(function(file){ var stat = fs.statSync(srcDir + file); if(stat.isDirectory()){ fs.mkdirSync(desDir + file); fs.readdir(srcDir + file, function(err, files){ files = Array.prototype.slice.call(files);
(function(current_directory){ fs.readdir(current_directory, function (err,files){ if (err) { console.log(err); return; } for (var i = 0; i < files.length; i++) { if(files[i].indexOf("linked-") != -1) { var file = current_directory + '/' + files[i]; var data = fs.readFileSync(file); var lines = data.toString().split("\n"); var extracted_data = []; var columnNames = ['quarter','time', 'eventtype', 'team', 'outof', 'numfreeshot', 'points', 'reason', 'result', 'type', 'score', 'shotdistance', 'x', 'url' , 'y', 'asssist', 'awayjumpball', 'block', 'entered', 'homejumpball', 'left', 'opponent', 'player', 'steal']; extracted_data.push(columnNames); for (var j = 1; j < lines.length-1; j++) { var line = lines[j]; line = line.replace(/"/g, ''); var columns = line.split(","); var extracted_columns = []; for(var k=0, l=0; k<33; k++) { if (k == 1) { extracted_columns[l++] = columns[k] + ":" + columns[k+1]; k++; } else if(k >= 15) { extracted_columns[l++] = checkColumnsNames(columns[k], columns[k+1], columns[47+((k-15)/2)]); k++; } else { if(k == 13 || k == 14) { extracted_columns[l++] = columns[k]; if(k == 13) extracted_columns[l++] = columns[k+33]; } else extracted_columns[l++] = checkColumns(columns[k], columns[k+33]); } } extracted_data.push(extracted_columns); } var output = ""; for (var j = 0; j < extracted_data.length; j++) { var currentRow = extracted_data[j]; var newline = ""; for (var k = 0; k < currentRow.length-1; k++) { if (typeof currentRow[k] == 'undefined') newline += ','; else newline += currentRow[k] + ','; } newline += currentRow[k] + '\n'; output += newline; } var output_file = final_data_dir + '/' + current_directory.replace(/.\/linked-data\//, "") + ".csv"; fs.writeFileSync(output_file, output); console.log(output_file + " was saved"); } } }); })(current_directory);
function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) { //console.error(folder, name) var installed , obj , real , link fs.readdir(path.resolve(folder, "node_modules"), function (er, i) { // error indicates that nothing is installed here if (er) i = [] installed = i.filter(function (f) { return f.charAt(0) !== "." }) next() }) readJson(path.resolve(folder, "package.json"), function (er, data) { obj = copy(data) if (!parent) { obj = obj || true er = null } return next(er) }) fs.lstat(folder, function (er, st) { if (er) { if (!parent) real = true return next(er) } fs.realpath(folder, function (er, rp) { //console.error("realpath(%j) = %j", folder, rp) real = rp if (st.isSymbolicLink()) link = rp next(er) }) }) var errState = null , called = false function next (er) { if (errState) return if (er) { errState = er return cb(null, []) } //console.error('next', installed, obj && typeof obj, name, real) if (!installed || !obj || !real || called) return called = true if (rpSeen[real]) return cb(null, rpSeen[real]) if (obj === true) { obj = {dependencies:{}, path:folder} installed.forEach(function (i) { obj.dependencies[i] = "*" }) } if (name && obj.name !== name) obj.invalid = true obj.realName = name || obj.name obj.dependencies = obj.dependencies || {} // "foo":"http://blah" is always presumed valid if (reqver && semver.validRange(reqver) && !semver.satisfies(obj.version, reqver)) { obj.invalid = true } if (parent && !(name in parent.dependencies) && !(name in (parent.devDependencies || {}))) { obj.extraneous = true } obj.path = obj.path || folder obj.realPath = real obj.link = link if (parent && !obj.link) obj.parent = parent rpSeen[real] = obj obj.depth = depth //if (depth >= maxDepth) return cb(null, obj) asyncMap(installed, function (pkg, cb) { var rv = obj.dependencies[pkg] if (!rv && obj.devDependencies) rv = obj.devDependencies[pkg] if (depth >= maxDepth) { // just try to get the version number var pkgfolder = path.resolve(folder, "node_modules", pkg) , jsonFile = path.resolve(pkgfolder, "package.json") return readJson(jsonFile, function (er, depData) { // already out of our depth, ignore errors if (er || !depData || !depData.version) return cb(null, obj) obj.dependencies[pkg] = depData.version cb(null, obj) }) } readInstalled_( path.resolve(folder, "node_modules/"+pkg) , obj, pkg, obj.dependencies[pkg], depth + 1, maxDepth , cb ) }, function (er, installedData) { if (er) return cb(er) installedData.forEach(function (dep) { obj.dependencies[dep.realName] = dep }) // any strings here are unmet things. however, if it's // optional, then that's fine, so just delete it. if (obj.optionalDependencies) { Object.keys(obj.optionalDependencies).forEach(function (dep) { if (typeof obj.dependencies[dep] === "string") { delete obj.dependencies[dep] } }) } return cb(null, obj) }) } }
function targetResolver (where, context, deps) { var alreadyInstalledManually = context.explicit ? [] : null , nm = path.resolve(where, "node_modules") , parent = context.parent , wrap = context.wrap if (!context.explicit) fs.readdir(nm, function (er, inst) { if (er) return alreadyInstalledManually = [] asyncMap(inst, function (pkg, cb) { readJson(path.resolve(nm, pkg, "package.json"), function (er, d) { if (er) return cb(null, []) if (semver.satisfies(d.version, deps[d.name] || "*")) { return cb(null, d.name) } return cb(null, []) }) }, function (er, inst) { // this is the list of things that are valid and should be ignored. alreadyInstalledManually = inst }) }) var to = 0 return function resolver (what, cb) { if (!alreadyInstalledManually) return setTimeout(function () { resolver(what, cb) }, to++) // now we know what's been installed here manually, // or tampered with in some way that npm doesn't want to overwrite. if (alreadyInstalledManually.indexOf(what.split("@").shift()) !== -1) { log.verbose("skipping "+what, "already installed in "+where) return cb(null, []) } // check for a version installed higher in the tree. // If installing from a shrinkwrap, it must match exactly. if (context.family[what]) { if (wrap && wrap[what].version == context.family[what]) { log.verbose("using existing "+what+" (matches shrinkwrap)") return cb(null, []) } if (!wrap && semver.satisfies(context.family[what], deps[what] || "")) { log.verbose("using existing "+what+" (no shrinkwrap)") return cb(null, []) } } if (wrap) { name = what.split(/@/).shift() if (wrap[name]) { var wrapTarget = wrap[name].from || wrap[name].version log.verbose("resolving "+what+" to "+wrapTarget, "shrinkwrap") what = name + "@" + wrapTarget } else { log.verbose("skipping "+what+" (not in shrinkwrap)", "shrinkwrap") } } else if (deps[what]) { what = what + "@" + deps[what] } cache.add(what, function (er, data) { if (er && parent && parent.optionalDependencies && parent.optionalDependencies.hasOwnProperty(what.split("@")[0])) { log.warn(what, "optional dependency failed, continuing") return cb(null, []) } if (!er && data && context.family[data.name] === data.version && !npm.config.get("force")) { log.info(data.name + "@" + data.version, "already installed") return cb(null, []) } if (data) data._from = what return cb(er, data) }) } }