Skip to content

Commit

Permalink
tools: get latest tz version
Browse files Browse the repository at this point in the history
  • Loading branch information
98lenvi committed Aug 9, 2022
1 parent eaa919e commit 50b226f
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions tools/update-timezone.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,57 @@
// Passing --dry will redirect output to stdout.
import { execSync, spawnSync } from 'node:child_process';
import { renameSync } from 'node:fs';
import { exit } from 'node:process';

const fileNames = [
'zoneinfo64.res',
'windowsZones.res',
'timezoneTypes.res',
'metaZones.res',
];

execSync('rm -rf icu-data');
execSync('git clone https://github.com/unicode-org/icu-data');
execSync('bzip2 -d deps/icu-small/source/data/in/icudt70l.dat.bz2');
fileNames.forEach((file)=>{
renameSync(`icu-data/tzdata/icunew/2022a/44/le/${file}`,`deps/icu-small/source/data/in/${file}`)
})
const dirs = spawnSync(
'ls', {
cwd: 'icu-data/tzdata/icunew',
stdio: ['inherit', 'pipe', 'inherit']
}
);

const currentVersion = process.versions.tz;
const availableVersions = dirs.stdout
.toString()
.split('\n')
.filter((_) => _);

const latestVersion =
availableVersions
.reduce(
(acc, version) => (version > acc ? version : acc),
availableVersions[0]);

if (latestVersion === 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}`);
});
fileNames.forEach((file) => {
spawnSync(
`icupkg`,[
`-a`,
'icupkg', [
'-a',
file,
`icudt70l.dat`
],{cwd:`deps/icu-small/source/data/in/`}
'icudt*.dat',
], { cwd: 'deps/icu-small/source/data/in/' }
);
});
execSync('bzip2 -z deps/icu-small/source/data/in/icudt*.dat');
fileNames.forEach((file) => {
renameSync(
`deps/icu-small/source/data/in/${file}`,
`icu-data/tzdata/icunew/${latestVersion}/44/le/${file}`
);
});
execSync('bzip2 -z deps/icu-small/source/data/in/icudt70l.dat')
fileNames.forEach((file)=>{
renameSync(`deps/icu-small/source/data/in/${file}`,`icu-data/tzdata/icunew/2022a/44/le/${file}`)
})
execSync('rm -rf icu-data');

0 comments on commit 50b226f

Please sign in to comment.