Skip to content

Commit 24ca50f

Browse files
committed
tools: get latest tz version
Fixes: nodejs#43134
1 parent 0a4fd3e commit 24ca50f

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

tools/update-timezone.mjs

+40-14
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,57 @@
33
// Passing --dry will redirect output to stdout.
44
import { execSync, spawnSync } from 'node:child_process';
55
import { renameSync } from 'node:fs';
6+
import { exit } from 'node:process';
7+
68
const fileNames = [
79
'zoneinfo64.res',
810
'windowsZones.res',
911
'timezoneTypes.res',
1012
'metaZones.res',
1113
];
12-
1314
execSync('rm -rf icu-data');
1415
execSync('git clone https://github.com/unicode-org/icu-data');
15-
execSync('bzip2 -d deps/icu-small/source/data/in/icudt70l.dat.bz2');
16-
fileNames.forEach((file)=>{
17-
renameSync(`icu-data/tzdata/icunew/2022a/44/le/${file}`,`deps/icu-small/source/data/in/${file}`)
18-
})
16+
const dirs = spawnSync(
17+
'ls', {
18+
cwd: 'icu-data/tzdata/icunew',
19+
stdio: ['inherit', 'pipe', 'inherit']
20+
}
21+
);
22+
23+
const currentVersion = process.versions.tz;
24+
const availableVersions = dirs.stdout
25+
.toString()
26+
.split('\n')
27+
.filter((_) => _);
28+
29+
const latestVersion =
30+
availableVersions
31+
.reduce(
32+
(acc, version) => (version > acc ? version : acc),
33+
availableVersions[0]);
34+
35+
if (latestVersion === currentVersion) {
36+
exit();
37+
}
38+
39+
execSync('bzip2 -d deps/icu-small/source/data/in/icudt*.dat.bz2');
40+
fileNames.forEach((file) => {
41+
renameSync(`icu-data/tzdata/icunew/${latestVersion}/44/le/${file}`, `deps/icu-small/source/data/in/${file}`);
42+
});
1943
fileNames.forEach((file) => {
2044
spawnSync(
21-
`icupkg`,[
22-
`-a`,
45+
'icupkg', [
46+
'-a',
2347
file,
24-
`icudt70l.dat`
25-
],{cwd:`deps/icu-small/source/data/in/`}
48+
'icudt*.dat',
49+
], { cwd: 'deps/icu-small/source/data/in/' }
50+
);
51+
});
52+
execSync('bzip2 -z deps/icu-small/source/data/in/icudt*.dat');
53+
fileNames.forEach((file) => {
54+
renameSync(
55+
`deps/icu-small/source/data/in/${file}`,
56+
`icu-data/tzdata/icunew/${latestVersion}/44/le/${file}`
2657
);
2758
});
28-
execSync('bzip2 -z deps/icu-small/source/data/in/icudt70l.dat')
29-
fileNames.forEach((file)=>{
30-
renameSync(`deps/icu-small/source/data/in/${file}`,`icu-data/tzdata/icunew/2022a/44/le/${file}`)
31-
})
3259
execSync('rm -rf icu-data');
33-

0 commit comments

Comments
 (0)