upgrade-utils
Advanced tools
Comparing version 1.0.0 to 1.0.1
84
index.js
var fs = require('fs') | ||
var async = require('async') | ||
var path = require('path') | ||
@@ -11,3 +12,2 @@ var diff = require('diff') | ||
var suggestions = require('./lib/suggestions.js')() | ||
var processed = 0 | ||
var changed = [] | ||
@@ -17,37 +17,4 @@ var suggested = {} | ||
// Recursive function searching files and directories in a path to process files | ||
function searchFiles (file) { | ||
fs.lstat(file, function (err, stats) { | ||
if (err) throw err | ||
var isFile = stats.isFile() | ||
if (stats.isSymbolicLink()) { | ||
return | ||
} | ||
// Looking just for filtered extensions | ||
if (isFile && filters.indexOf(path.extname(file)) !== -1) { | ||
console.log('Processing ' + file) | ||
// Adding the file to the queue | ||
processed++ | ||
processFile(file) | ||
} else if (stats.isDirectory() && file.indexOf('node_modules') === -1) { | ||
// Reading directories | ||
fs.readdir(file, function (err, files) { | ||
if (err) throw err | ||
for (var i = 0; i < files.length; i++) { | ||
// Avoid hidden files and directories | ||
if (/^[^.].*$/.test(files[i])) { | ||
searchFiles(path.join(file, files[i])) | ||
} | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
// Function replacing all regex in a file and returning the new content | ||
function processFile (file) { | ||
var queue = async.queue(function (file, callback) { | ||
fs.readFile(file, 'utf-8', function (err, text) { | ||
@@ -76,15 +43,50 @@ if (err) { | ||
fs.writeFile(file, content, function (err) { | ||
if (err) throw err | ||
if (err) return callback(err) | ||
console.log('The file ' + file + ' was updated') | ||
return callback(null, file) | ||
}) | ||
} else { | ||
return callback(null, file) | ||
} | ||
} else { | ||
return callback(null, file) | ||
} | ||
}) | ||
}, 5) | ||
// reducing the queue | ||
processed-- | ||
queue.drain = function () { | ||
printResults() | ||
} | ||
// Printing results after process all files | ||
if (processed === 0) { | ||
printResults() | ||
// Recursive function searching files and directories in a path to process files | ||
function searchFiles (file) { | ||
fs.lstat(file, function (err, stats) { | ||
if (err) throw err | ||
var isFile = stats.isFile() | ||
if (stats.isSymbolicLink()) { | ||
return | ||
} | ||
// Looking just for filtered extensions | ||
if (isFile && filters.indexOf(path.extname(file)) !== -1) { | ||
console.log('Processing ' + file) | ||
// Adding the file to the queue | ||
queue.push(file, function (err, cfile) { | ||
if (err) throw err | ||
}) | ||
} else if (stats.isDirectory() && file.indexOf('node_modules') === -1) { | ||
// Reading directories | ||
fs.readdir(file, function (err, files) { | ||
if (err) throw err | ||
for (var i = 0; i < files.length; i++) { | ||
// Avoid hidden files and directories | ||
if (/^[^.].*$/.test(files[i])) { | ||
searchFiles(path.join(file, files[i])) | ||
} | ||
} | ||
}) | ||
} | ||
}) | ||
@@ -91,0 +93,0 @@ } |
{ | ||
"name": "upgrade-utils", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A tool to help with the process of upgrading modules to the latest version of Node.js latest Node version (currently v4), replacing old NAN C++ bindings and adjusting for Node.js API changes", | ||
@@ -35,2 +35,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"async": "^1.4.2", | ||
"chalk": "^1.1.1", | ||
@@ -37,0 +38,0 @@ "diff": "^2.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
81921
743
8
+ Addedasync@^1.4.2
+ Addedasync@1.5.2(transitive)