|
3 | 3 | // Passing --dry will redirect output to stdout.
|
4 | 4 | import { execSync, spawnSync } from 'node:child_process';
|
5 | 5 | import { renameSync } from 'node:fs';
|
| 6 | +import { exit } from 'node:process'; |
| 7 | + |
6 | 8 | const fileNames = [
|
7 | 9 | 'zoneinfo64.res',
|
8 | 10 | 'windowsZones.res',
|
9 | 11 | 'timezoneTypes.res',
|
10 | 12 | 'metaZones.res',
|
11 | 13 | ];
|
12 |
| - |
13 | 14 | execSync('rm -rf icu-data');
|
14 | 15 | 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 | +}); |
19 | 43 | fileNames.forEach((file) => {
|
20 | 44 | spawnSync(
|
21 |
| - `icupkg`,[ |
22 |
| - `-a`, |
| 45 | + 'icupkg', [ |
| 46 | + '-a', |
23 | 47 | 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}` |
26 | 57 | );
|
27 | 58 | });
|
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 |
| -}) |
32 | 59 | execSync('rm -rf icu-data');
|
33 |
| - |
|
0 commit comments