-
Notifications
You must be signed in to change notification settings - Fork 74
/
testFile.js
49 lines (46 loc) · 1.78 KB
/
testFile.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
39
40
41
42
43
44
45
46
47
48
49
//
// _oo8oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/'==='\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||_ \
// | | \\\ - /// | |
// | \_| ''\---/'' |_/ |
// \ .-\__ '-' __/-. /
// ___'. .' /--.--\ '. .'___
// ."" '< '.___\_<|>_/___.' >' "".
// | | : `- \`.:`\ _ /`:.`/ -` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// =====`-.____`.___ \_____/ ___.`____.-`=====
// `=---=`
//
//
// ~~~~~~~Powered by https://github.com/ottomao/bugfreejs~~~~~~~
//
// 佛祖保佑 永无bug
//
function dealFile(filePath) {
if(!fs.existsSync(filePath)){
console.log("file not exist :" + filePath);
}else{
fs.readFile(filePath,function(err,data){
if(err) throw err;
//add comment prefix
var commentData = isUtf8(data) ? commentContent_forUTF8 : commentContent;
var lineArr = commentData.split("\n");
lineArr.map(function(line,index){
lineArr[index] = configItem.prefix + line;
});
var currentComment = new Buffer(lineArr.join("\n") + "\n"); //TODO :cache this result
process.stdout.write("--> " + filePath + "...");
var finalResult = buffer.concat([currentComment,data]);
fs.unlinkSync(filePath);
fs.writeFileSync(filePath,finalResult)
process.stdout.write("done\r\n");
});
}
}