From 05e53641c19cc0e4b19ba121b771039ac73a1691 Mon Sep 17 00:00:00 2001 From: Luis Blanco Date: Wed, 4 Jan 2023 13:22:46 +0400 Subject: [PATCH] Fix requires --- utils/action-zip.js | 6 +++--- utils/cpbin.js | 6 +++--- utils/install.js | 21 +++++++++++++++------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/utils/action-zip.js b/utils/action-zip.js index baee77d..80012f0 100644 --- a/utils/action-zip.js +++ b/utils/action-zip.js @@ -3,13 +3,13 @@ const util = require('node:util'); const exec = util.promisify(require('node:child_process').exec); -const { platform, bin } = require('..'); +const { getPlatform, getBin } = require('../include'); const actionZip = async () => { try { - await exec(`cd ${bin} && tar -acf ../${platform}.zip *`); - console.log(`zip=${platform}.zip`); + await exec(`cd ${getBin()} && tar -acf ../${getPlatform()}.zip *`); + console.log(`zip=${getPlatform()}.zip`); } catch (error) { console.error(error); process.exit(-1); diff --git a/utils/cpbin.js b/utils/cpbin.js index 0976ba6..0e82082 100644 --- a/utils/cpbin.js +++ b/utils/cpbin.js @@ -1,7 +1,7 @@ 'use strict'; const { copy, exists, mkdir, rm } = require('./files'); -const { bin } = require('..'); +const { getBin } = require('../include'); const cpbin = async (name) => { @@ -11,7 +11,7 @@ const cpbin = async (name) => { console.error(`Error. File "${srcDir}/build/Release/${name}.node" not found.`); } - const binAbs = `${srcDir}/../${bin}`; + const binAbs = `${srcDir}/../${getBin()}`; if (!await exists(binAbs)) { await mkdir(binAbs); @@ -25,7 +25,7 @@ const cpbin = async (name) => { await copy(`${srcDir}/build/Release/${name}.node`, destAbs); - console.log(`The binary "${name}.node" was copied to "${bin}".`); + console.log(`The binary "${name}.node" was copied to "${getBin()}".`); }; module.exports = { cpbin }; diff --git a/utils/install.js b/utils/install.js index c840e9a..458ac2c 100644 --- a/utils/install.js +++ b/utils/install.js @@ -1,11 +1,12 @@ 'use strict'; +const fs = require('node:fs'); const https = require('node:https'); const http = require('node:http'); const util = require('node:util'); const exec = util.promisify(require('node:child_process').exec); -const { bin, platform } = require('..'); +const { getBin, getPlatform } = require('../include'); const { mkdir, rmdir, rm } = require('./files'); @@ -16,7 +17,6 @@ const onError = (msg) => { process.exit(-1); }; -const zipPath = `${bin}/${bin}.zip`; const installRecursive = async (url, count = 1) => { @@ -44,10 +44,19 @@ const installRecursive = async (url, count = 1) => { throw new Error(`Response status was ${response.statusCode}`); } - await rmdir(bin); - await mkdir(bin); + await rmdir(getBin()); + await mkdir(getBin()); - await exec(`tar -xzvf ${platform}.zip --directory ${bin}`); + const zipPath = `${getBin()}/${getPlatform()}.zip`; + + await new Promise((res, rej) => { + const zipWriter = fs.createWriteStream(zipPath); + zipWriter.on('error', (err) => rej(err)); + zipWriter.on('finish', () => res()); + response.pipe(zipWriter); + }); + + await exec(`tar -xzvf ${zipPath} --directory ${getBin()}`); await rm(zipPath); } catch (ex) { @@ -57,7 +66,7 @@ const installRecursive = async (url, count = 1) => { const install = (folder) => { - const url = `${folder}/${platform}.zip`; + const url = `${folder}/${getPlatform()}.zip`; installRecursive(url).then(); };