-
Notifications
You must be signed in to change notification settings - Fork 778
/
Copy pathsite-set-version.js
51 lines (44 loc) · 1.36 KB
/
site-set-version.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
'use strict';
const fs = require('fs');
const { CommandError, isValidVersion, versionAnywhereRegPattern } = require('./utils.js');
const cdnLinks = [
// Match qunit-VERSION.js, qunit-VERSION.css, qunit-VERSION.{css.js}
'qunit-VERSION'
];
const files = {
'docs/index.md': [
'vVERSION',
'blob/VERSION/History.md',
...cdnLinks
],
'docs/intro.md': [...cdnLinks],
'docs/browser.md': [...cdnLinks],
'docs/resources/example-add.html': [...cdnLinks],
'docs/resources/example-fail.html': [...cdnLinks],
'docs/resources/example-index.html': [...cdnLinks],
'docs/resources/q4000.html': [...cdnLinks]
};
try {
const version = process.argv[2];
if (typeof version !== 'string' || !isValidVersion(version)) {
throw new CommandError('Invalid or missing version argument');
}
for (const [file, patterns] of Object.entries(files)) {
console.log(`... updating ${file}`);
for (let pattern of patterns) {
const replacement = pattern.replace('VERSION', version);
pattern = pattern.replace('VERSION', versionAnywhereRegPattern);
const find = new RegExp(`\\b${pattern}\\b`, 'g');
const content = fs.readFileSync(file, 'utf8').toString();
fs.writeFileSync(
file,
content.replace(find, replacement),
'utf8'
);
}
}
console.log('Done!');
} catch (e) {
console.error(e);
process.exit(1);
}