-
Notifications
You must be signed in to change notification settings - Fork 34
/
update.js
56 lines (46 loc) · 1.95 KB
/
update.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
const fs = require('fs');
const { version } = require('./pokeclicker/package.json');
console.log('Updating script version in index.html');
// Get the index file
fs.readFile("index.html", function(err, buf) {
// Something went wrong loading the index file
if (err) return console.error('Error reading index.html', err);
const fileContents = buf.toString();
// Replace version numbers in file
fs.writeFile('index.html', fileContents.replace(/\?v=[\d\.]+/g, `?v=${version}`).replace(/\?t=\d+/g, `?t=${Date.now()}`), (err) => {
if (err) return console.error('Error updating index.html', err);
console.log('Successfully updated script version in index.html');
});
});
const glob = require('glob');
console.log('Updating symlinks for images');
// Get all our image files
const baseDir = 'pokeclicker/docs/assets/images/';
glob(`${baseDir}**/*`, (err, res) => {
if (err) {
console.error('Error getting images for symlinks', err);
} else {
res.forEach(filePath => {
// Get the file name
let fileName = filePath.replace(/.*\//, '');
if (!fileName.includes('.')) {
fileName = filePath.replace(baseDir, '').replace('/', '-');
}
// Ignore any files just named after IDs
if (/^-?\d+(-?\w)?\./.test(fileName)) return;
// Create a symlink
fs.symlink(`../${filePath}`, `./images/${fileName}`, 'file', (err) => {
// No error or File already exist
if (!err || err.code == 'EEXIST') return;
// Permissions error, run as admin
if (err.code == 'EPERM') {
console.error('Permission error creating file, may need to open admin console.');
process.exit();
}
// Unknown error, guess it will need to be dealt with
console.error('Error updating symlink', err);
});
});
console.log('Successfully updated symlinks for images');
}
});