-
Notifications
You must be signed in to change notification settings - Fork 29.6k
/
update-timezone.mjs
executable file
·39 lines (34 loc) · 1.18 KB
/
update-timezone.mjs
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
#!/usr/bin/env node
// Usage: tools/update-timezone.mjs
import { execSync, spawnSync } from 'node:child_process';
import { renameSync, readdirSync, rmSync } from 'node:fs';
import { exit } from 'node:process';
const fileNames = [
'zoneinfo64.res',
'windowsZones.res',
'timezoneTypes.res',
'metaZones.res',
];
const availableVersions = readdirSync('icu-data/tzdata/icunew', { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
const currentVersion = process.versions.tz;
const latestVersion = availableVersions.sort().at(-1);
if (latestVersion === currentVersion) {
console.log(`Terminating early, tz version is latest @ ${currentVersion}`);
exit();
}
execSync('bzip2 -d deps/icu-small/source/data/in/icudt*.dat.bz2');
fileNames.forEach((file) => {
renameSync(`icu-data/tzdata/icunew/${latestVersion}/44/le/${file}`, `deps/icu-small/source/data/in/${file}`);
spawnSync(
'icupkg', [
'-a',
file,
'icudt*.dat',
], { cwd: 'deps/icu-small/source/data/in/' }
);
rmSync(`deps/icu-small/source/data/in/${file}`);
});
execSync('bzip2 -z deps/icu-small/source/data/in/icudt*.dat');
rmSync('icu-data', { recursive: true });