forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhd.js
44 lines (37 loc) · 1.09 KB
/
hd.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
'use strict';
var child_process = require('child_process')
var fs = require('fs')
var copy_reg = /\(\*\s*Author:\s*Hongbo\s*Zhang\s*\*\)/
var utf8 = {encoding: 'utf8'}
var license_template =
fs.readFileSync('scripts/LICENSE.ml',utf8)
function handleFile(file){
if(!fs.existsSync(file)){
// console.log(file,'not exist')
} else{
var stat = fs.lstatSync(file);
if (stat.isSymbolicLink()){
console.error(file, 'is symbol link')
} else {
var contents = fs.readFileSync(file,utf8);
if (contents.includes('Author:')) {
var x = copy_reg.exec(contents)
if(x){
var valid_content = x.input.substr(x.index+x[0].length);
fs.writeFileSync(file,
license_template + valid_content,utf8)
}
else{
console.error(file,'wrong format')
}
}
else {
console.log(file, 'no authors')
}
}
}
}
child_process.execSync('git ls-files *.ml *.mli', utf8)
.split('\n')
.filter(function(x){return x && !(x.includes('/test/')) && !( x.includes('/tools/')) && !(x.includes('/stdlib/')) && !(x.includes('/test_npm/'))})
.forEach(handleFile)