-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-runTest.js
38 lines (33 loc) · 1.02 KB
/
node-runTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var toMarkdown = require("./js/to-markdown");
var fs = require('fs'),
dirNames = {
"sourceFile" : process.argv[2] || "testSource" ,
"resultFile" : process.argv[3] || "testResult"
}
/*if(!Array.prototype.forEach){
Array.prototype.forEach = function(callback) {
if (this == null) return;
var returnAry = [];
//判断length为num
if (this.length === +this.length) {
for (var i = 0, l = this.length; i < l; i++) {
returnAry.push(callback(this[i]));
}
}
return returnAry;
};
}*/
fs.readdir('./' + dirNames["sourceFile"] , function( e , files) {
if(e) throw e;
files.forEach(function(filename){
fs.readFile('./' + dirNames["sourceFile"] + '/' + filename, function (er, data) {
if(er) throw er;
if(!filename) return;
var newfilename = filename.replace(/\.[\s\S]+$/,".md");
if(!fs.existsSync('./' + dirNames["resultFile"])){
fs.mkdirSync('./' + dirNames["resultFile"]);
}
fs.writeFileSync('./' + dirNames["resultFile"] + '/' + newfilename, toMarkdown.toMarkdown(data.toString()));
});
});
});