11cb0ef41Sopenharmony_ci#!/usr/bin/env node
21cb0ef41Sopenharmony_ci// Usage: tools/update-timezone.mjs
31cb0ef41Sopenharmony_ciimport { execSync } from 'node:child_process';
41cb0ef41Sopenharmony_ciimport { renameSync, readdirSync, rmSync } from 'node:fs';
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst fileNames = [
71cb0ef41Sopenharmony_ci  'zoneinfo64.res',
81cb0ef41Sopenharmony_ci  'windowsZones.res',
91cb0ef41Sopenharmony_ci  'timezoneTypes.res',
101cb0ef41Sopenharmony_ci  'metaZones.res',
111cb0ef41Sopenharmony_ci];
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst availableVersions = readdirSync('icu-data/tzdata/icunew', { withFileTypes: true })
141cb0ef41Sopenharmony_ci.filter((dirent) => dirent.isDirectory())
151cb0ef41Sopenharmony_ci.map((dirent) => dirent.name);
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciconst latestVersion = availableVersions.sort().at(-1);
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciexecSync('bzip2 -d deps/icu-small/source/data/in/icudt*.dat.bz2');
201cb0ef41Sopenharmony_cifileNames.forEach((file) => {
211cb0ef41Sopenharmony_ci  renameSync(`icu-data/tzdata/icunew/${latestVersion}/44/le/${file}`, `deps/icu-small/source/data/in/${file}`);
221cb0ef41Sopenharmony_ci  execSync(`icupkg -a ${file} icudt*.dat`, { cwd: 'deps/icu-small/source/data/in/' });
231cb0ef41Sopenharmony_ci  rmSync(`deps/icu-small/source/data/in/${file}`);
241cb0ef41Sopenharmony_ci});
251cb0ef41Sopenharmony_ciexecSync('bzip2 -z deps/icu-small/source/data/in/icudt*.dat');
261cb0ef41Sopenharmony_cirmSync('icu-data', { recursive: true });
27