-
Notifications
You must be signed in to change notification settings - Fork 184
/
update-version-number-in-viewer.js
50 lines (42 loc) · 1.87 KB
/
update-version-number-in-viewer.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
const fs = require('fs');
function updateVersionNumber(file, replacementVersion) {
if (fs.existsSync(file)) {
// console.log('Updating version number in', file, 'to version', replacementVersion);
const js = fs.readFileSync(file).toString();
let regex = /(ngxExtendedPdfViewerVersion\s*=\s*')\d+\.\d+\.\d+.*(')/;
let modifiedString = js.replace(regex, `$1${replacementVersion}$2`);
if (modifiedString !== js) {
console.log('Updated version number', file);
} else {
let regex = /(ngxExtendedPdfViewerVersion:\(\)=>.*")\d+\.\d+\.\d+.{0-10}("\},)\d/;
modifiedString = js.replace(regex, `$1${replacementVersion}$2`);
}
if (modifiedString !== js) {
console.log('Updated version number', file);
fs.writeFileSync(file, modifiedString);
} else {
console.log('Version number already up to date', file);
}
}
}
function getMatchingFiles(directoryPath, pattern) {
try {
const files = fs.readdirSync(directoryPath);
const matchingFiles = files.filter((file) => file.startsWith(pattern)).filter((file) => file.endsWith('.mjs'));
return matchingFiles;
} catch (err) {
throw err;
}
}
const packageJsonFile = fs.readFileSync('./projects/ngx-extended-pdf-viewer/package.json');
const packageJson = JSON.parse(packageJsonFile);
const currentVersion = packageJson['version'];
console.log('Updating the version number of the viewer*.mjs files to ', currentVersion);
let matchingFiles = getMatchingFiles('./projects/ngx-extended-pdf-viewer/assets', 'viewer-');
matchingFiles.forEach((file) => {
updateVersionNumber(`./projects/ngx-extended-pdf-viewer/assets/${file}`, currentVersion);
});
matchingFiles = getMatchingFiles('./projects/ngx-extended-pdf-viewer/bleeding-edge', 'viewer-');
matchingFiles.forEach((file) => {
updateVersionNumber(`./projects/ngx-extended-pdf-viewer/bleeding-edge/${file}`, currentVersion);
});