|
| 1 | +// Copyright (C) 2015-2016 IBM Corporation and Others. All Rights Reserved. |
| 2 | + |
| 3 | +// Install by fetching ICU source tarball |
| 4 | +// This will only work for little endian systems, but will work for ancient ICU (back to v50) |
| 5 | + |
| 6 | +const fs = require('fs'); |
| 7 | +const { URL } = require('url') |
| 8 | +const process = require('process') |
| 9 | +const myFetch = require('./myFetch') |
| 10 | +const yauzl = require('yauzl'); |
| 11 | + |
| 12 | +// var isglobal = process.env.npm_config_global === 'true'; |
| 13 | + |
| 14 | +module.exports = async function installFromGithub (fullIcu, advice) { |
| 15 | + const {icupkg, icudat, icuend} = fullIcu |
| 16 | + |
| 17 | + if(fs.existsSync(icudat)) { |
| 18 | + console.log(` √ ${icudat} (exists)`); |
| 19 | + return; |
| 20 | + } |
| 21 | + |
| 22 | + if (icuend != 'l') { |
| 23 | + // Should not hit this, as versions 67 and prior are already in NPM |
| 24 | + console.error('Warning: this method probably will fail, because the ICU source tarball only contains little endian data.'); |
| 25 | + } |
| 26 | + |
| 27 | + // var cmdPath = nodePath = process.env.npm_node_execpath; |
| 28 | + |
| 29 | + // var npmPath = process.env.npm_execpath; |
| 30 | + |
| 31 | + // var args; |
| 32 | + // https://github.com/unicode-org/icu/releases/download/release-51-3/icu4c-51_3-src.zip |
| 33 | + const _baseUrl = process.env.FULL_ICU_BASEURL || 'https://github.com/unicode-org/icu/releases/' |
| 34 | + const baseUrl = new URL(_baseUrl) |
| 35 | + const versionsAsHyphen = fullIcu.icuver.replace(/\./g, '-') |
| 36 | + const versionsAsUnderscore = fullIcu.icuver.replace(/\./g, '_') |
| 37 | + const tag = `release-${versionsAsHyphen}` |
| 38 | + const file = `icu4c-${versionsAsUnderscore}-src.zip` |
| 39 | + const fullUrl = new URL(`./download/${tag}/${file}`, baseUrl) |
| 40 | + console.log(fullUrl.toString()) |
| 41 | + const [srcZip, tmpd] = await myFetch(fullUrl) |
| 42 | + |
| 43 | + console.log(srcZip, tmpd) |
| 44 | + // now, unpack it |
| 45 | + |
| 46 | + console.log(`Looking for ${icudat}`); |
| 47 | + return new Promise((resolve, reject) => |
| 48 | + yauzl.open(srcZip, {lazyEntries: true}, (err, zipfile) => { |
| 49 | + if (err) return reject(err); |
| 50 | + zipfile.readEntry(); |
| 51 | + zipfile.on("end", () => reject(`Not found in zipfile: ${icudat}`)); |
| 52 | + zipfile.on("entry", (entry) => { |
| 53 | + if (entry.fileName.endsWith('/')) { |
| 54 | + zipfile.readEntry(); |
| 55 | + } else if(entry.fileName.endsWith('/'+icudat)) { |
| 56 | + console.log('found ' + entry.fileName); |
| 57 | + zipfile.openReadStream(entry, (err, readStream) => { |
| 58 | + if (err) return reject(err); |
| 59 | + // if entry.file |
| 60 | + readStream.on("end", () => zipfile.readEntry()); |
| 61 | + const pipeOut = fs.createWriteStream(icudat); |
| 62 | + readStream.pipe(pipeOut); |
| 63 | + console.log(` √ ${icudat} (from ICU source tarball)`); |
| 64 | + return resolve(); |
| 65 | + }); |
| 66 | + } else { |
| 67 | + zipfile.readEntry(); // get next |
| 68 | + } |
| 69 | + }); |
| 70 | + })); |
| 71 | +} |
0 commit comments