-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-badge.js
66 lines (38 loc) · 1.3 KB
/
update-badge.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
const fs = require('fs');
const path = require('path');
const package = require('./package');
// process.stdout.write(JSON.stringify(package, null, 4));
process.stdout.write(`\n`);
process.stdout.write('update badge -> package.version:');
process.stdout.write(JSON.stringify(package.version, null, 4));
process.stdout.write(`\n\n`);
const README_md = path.resolve(__dirname, 'README.md');
if ( ! fs.existsSync(README_md) ) {
throw `File '${README_md}' doesn't exist`;
process.exit(1);
}
let content = fs.readFileSync(README_md).toString();
content = content.split("\n");
let regnpm = /^\[!\[Build Status\]/;
//let regcov = /^\[!\[Coverage Status\]/;
let regcov = /^\[!\[codecov\]/;
const n = 'v' + package.version;
let done = 0;
for (let i = 0, l = content.length ; i < l ; i += 1 ) {
// if (regnpm.test(content[i]) || regcov.test(content[i])) {
if (regnpm.test(content[i])) {
content[i] = content[i].replace(/v\d+\.\d+\.\d+/g, n);
if (content[i].indexOf(n) > -1) {
done += 1;
}
if ( done === 2 ) {
break;
}
}
}
// if ( done !== 2 ) {
if ( done !== 1 ) {
throw `Badges not found, invalid badges or missing badges in file '${README_md}'`;
process.exit(2);
}
fs.writeFileSync(README_md, content.join("\n"));