Created
March 26, 2015 13:15
-
-
Save getchenge/1889113ffb789bb83e7b to your computer and use it in GitHub Desktop.
a thrift files generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var fs = require('fs'); | |
var path = require('path'); | |
var async = require('async'); | |
var childProcess = require('child_process'); | |
var walk = function (dir, done) { | |
var results = []; | |
fs.readdir(dir, function (err, list) { | |
if (err) return done(err); | |
var pending = list.length; | |
if (!pending) return done(null, results); | |
list.forEach(function (file) { | |
file = dir + '/' + file; | |
fs.stat(file, function (err, stat) { | |
if (stat && stat.isDirectory()) { | |
walk(file, function (err, res) { | |
results = results.concat(res); | |
if (!--pending) done(null, results); | |
}); | |
} else { | |
results.push(file); | |
if (!--pending) done(null, results); | |
} | |
}); | |
}); | |
}); | |
}; | |
walk('./thrift-api', function (err, files) { | |
async.map(files, function (item, cb) { | |
var out_path; | |
if (item.indexOf('.thrift') != -1) { | |
console.info('item_', item); | |
out_path = path.dirname(item); | |
childProcess.exec('thrift' + ' -o ' + out_path + ' -r --gen js:node ' + item, cb); | |
} else { | |
cb(); | |
} | |
}, function (err, results) { | |
if (err) { | |
console.error('thrift_generate_err', err); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment