-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathlicense.js
58 lines (52 loc) · 1.71 KB
/
license.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
const glob = require('glob');
const fs = require('sync-fs');
const prepend = require('prepend');
const date = new Date();
const particlMarket = '// Copyright (c) 2017-' + String(date.getFullYear()) + ', The Particl Market developers';
const underLicense = '// Distributed under the GPL software license, see the accompanying';
const licenseLink = '// file COPYING or https://github.com/particl/particl-market/blob/develop/LICENSE';
function getFiles(filePath) {
console.log(filePath);
let filenames = glob.sync(filePath + '{src,test}/**/*.ts', {nodir: true, ignore: filePath + 'data/**'});
console.log(filenames);
return filenames;
}
function update(filename) {
try {
let file = String(fs.readFile(filename));
if (file.indexOf('// Copyright (c) 2017-') < 0) {
return;
}
let lines = file.split('\n');
lines.shift();
lines.unshift(particlMarket);
file = lines.join('\n');
fs.writeFile(filename, file);
} catch (error) {
console.error(error);
}
}
function add(filename) {
try {
let file = fs.readFile(filename);
if (file.indexOf('// Copyright (c) 2017-') >= 0) {
return;
}
} catch (error) {
console.error(error);
}
prepend(filename, particlMarket + '\n' + underLicense + '\n' + licenseLink + '\n', function(error) {
if (error) console.error(error.message);
});
}
function run(updateMethod, filePath) {
let filenames = getFiles(filePath ? filePath : '');
for (filename of filenames) {
if (updateMethod == 'add') {
add(filename);
} else {
update(filename);
}
}
}
run(process.argv[2], process.argv[3]);