forked from Pseudo-Corp/SynergismOfficial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-last-updated.js
28 lines (21 loc) · 1.06 KB
/
update-last-updated.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
const {readFileSync, writeFileSync} = require('fs');
const currentDate = new Date();
const UTC = `Date.UTC(${currentDate.getUTCFullYear()}, ${currentDate.getUTCMonth()}, ${currentDate.getUTCDate()}, ${currentDate.getUTCHours()}, ${currentDate.getUTCMinutes()}, ${currentDate.getUTCSeconds()})`;
console.log('\x1b[33m%s\x1b[0m', `Updating last updated config date to ${UTC}`);
try {
console.log('\x1b[33m%s\x1b[0m', 'Reading file & updating ##LAST_UPDATED##')
let config = readFileSync(`${__dirname}/src/Config.ts`, 'utf-8');
if (!/'##LAST_UPDATED##'/g.test(config)) {
throw new Error('File does not contain the \'##LAST_UPDATED##\' placeholder');
}
config = config.replace(/'##LAST_UPDATED##'/g, UTC);
if (!/Date\.UTC\(/g.test(config)) {
throw new Error('Couldn\'t replace the placeholder');
}
console.log('\x1b[33m%s\x1b[0m', 'writing file back to source')
writeFileSync(`${__dirname}/src/Config.ts`, config);
console.log('\x1b[32m%s\x1b[0m', 'Date updated');
} catch (e) {
console.error(e);
process.exit(1);
}