-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwriteCopy.js
85 lines (62 loc) · 1.89 KB
/
writeCopy.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (c) 2020-present unTill Pro, Ltd.
*/
var path = require('path');
var fs = require('fs');
var async = require('async');
var _ = require('lodash');
const COPY = `/*
* Copyright (c) 2020-present unTill Pro, Ltd.
*/
`;
function getFiles (dirPath, callback) {
fs.readdir(dirPath, function (err, files) {
if (err) return callback(err);
var filePaths = [];
async.eachSeries(files, function (fileName, eachCallback) {
var filePath = path.join(dirPath, fileName);
fs.stat(filePath, function (err, stat) {
if (err) return eachCallback(err);
if (stat.isDirectory()) {
getFiles(filePath, function (err, subDirFiles) {
if (err) return eachCallback(err);
filePaths = filePaths.concat(subDirFiles);
eachCallback(null);
});
} else {
if (stat.isFile() && /\.js$/.test(filePath)) {
filePaths.push(filePath);
}
eachCallback(null);
}
});
}, function (err) {
callback(err, filePaths);
});
});
}
function checkForCopy(content) {
if (content.indexOf("Copyright") >= 0) {
return true;
}
return false;
}
async function checkFiles(files) {
const noCopyFiles = [];
_.forEach(files, (path) => {
const content = fs.readFileSync(path);
if (!checkForCopy(content)) {
noCopyFiles.push(path);
const data = COPY + content;
fs.writeFileSync(path, data);
}
});
console.log('files withoud copy:');
console.log(noCopyFiles);
}
getFiles('./src', function (err, files) {
//console.log(err || files);
if (files && _.size(files) > 0) {
checkFiles(files);
}
});