-
Notifications
You must be signed in to change notification settings - Fork 4
/
diff.js
35 lines (33 loc) · 981 Bytes
/
diff.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
var fs = require('fs');
var readline = require('readline');
function readFileToArr(fReadName, callback) {
var fRead = fs.createReadStream(fReadName);
var objReadline = readline.createInterface({
input:fRead
});
var arr = new Array();
objReadline.on('line',function (line) {
arr.push(line);
});
objReadline.on('close',function () {
callback(arr);
});
}
var argvs = process.argv.splice(2);
var commonFile = argvs[0]; // common.jsbundle
var businessFile = argvs[1]; // business.jsbundle
var diffOut = argvs[2]; // diff.jsbundle
readFileToArr(commonFile, function (c_data) {
var diff = [];
var commonArrs = c_data;
readFileToArr(businessFile, function (b_data) {
var businessArrs = b_data;
for (let i = 0; i < businessArrs.length; i++) {
if (commonArrs.indexOf(businessArrs[i]) === -1) {
diff.push(businessArrs[i]);
}
}
var newContent = diff.join('\n');
fs.writeFileSync(diffOut, newContent);
});
});