diff --git a/gulpfile.js b/gulpfile.js index eb4e05c40..b03c12520 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,10 +2,16 @@ const fs = require("fs-extra"); const gulp = require("gulp"); const builder = require("electron-builder"); +const tar = require("tar-fs"); +const zlib = require("zlib"); const { parallel, series } = require("gulp"); const { installExtensions, buildExtensions, watchExtensions } = require("./gulpfile.extensions"); const { execute } = require("./gulpfile.util"); const { execSync } = require('child_process'); +const { promisify } = require("util"); + +// Promisify the pipeline function +const pipeline = promisify(require("stream").pipeline); const packageJson = JSON.parse(fs.readFileSync("./package.json", { encoding: 'utf-8' })); const config = { @@ -149,9 +155,21 @@ function installCrossDeps(done) { // Pacakge not installed, carry on } - execSync(`npm install --no-save --force ${packageName}@${fpa.version}`); - console.log(`Installed ${packageName}@${fpa.version}`); - done(); + const packageFilename = `fparchive-${packageName.split('/')[1]}-${fpa.version}.tgz`; + execSync(`npm pack ${packageName}@${fpa.version}`); + console.log('Unpacking ' + packageFilename); + // Extract and move all files to new folder + extractTarball(packageFilename, "./package-extract") + .then(() => { + fs.removeSync(packageFilename); + fs.mkdirSync(`./node_modules/${packageName}`, { recursive: true }); + for (const file of fs.readdirSync('./package-extract/package/')) { + fs.moveSync('./package-extract/package/' + file, packageLocation + '/' + file); + } + fs.removeSync('./package-extract'); + console.log(`Installed ${packageName}@${fpa.version}`); + done(); + }); } @@ -343,6 +361,26 @@ function clean(done) { }); } +/* ------ Util ------ */ + +async function extractTarball(inputFilePath, outputDirectory) { + try { + // Create a readable stream from the input file + const readStream = fs.createReadStream(inputFilePath); + + // Pipe the readable stream through zlib.createGunzip() and then through tar.extract() + await pipeline( + readStream, + zlib.createGunzip(), + tar.extract(outputDirectory) + ); + + console.log('Extraction complete.'); + } catch (error) { + console.error('Extraction failed:', error); + } +} + /* ------ Meta Tasks ------*/ exports.clean = series(clean); @@ -350,7 +388,7 @@ exports.clean = series(clean); exports.build = series( clean, createVersionFile, -// installCrossDeps, + installCrossDeps, parallel( buildRust, buildBack, @@ -364,7 +402,7 @@ exports.build = series( exports.watch = series( clean, createVersionFile, -// installCrossDeps, + installCrossDeps, parallel( buildRust, watchBack, diff --git a/package-lock.json b/package-lock.json index 6a266d041..1385df816 100644 --- a/package-lock.json +++ b/package-lock.json @@ -90,6 +90,7 @@ "jest": "29.4.2", "lefthook": "^1.5.5", "swc-loader": "0.2.3", + "tar-fs": "^3.0.5", "ts-jest": "29.0.5", "ts-loader": "9.4.1", "ts-node": "10.8.0", @@ -4084,6 +4085,12 @@ "node": ">= 6" } }, + "node_modules/b4a": { + "version": "1.6.6", + "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.6.tgz", + "integrity": "sha512-5Tk1HLk6b6ctmjIkAcU/Ujv/1WqiDl0F0JdRCR80VsOcUlHcu7pWeWRlOqQLHfDEsVx9YH/aif5AG4ehoCtTmg==", + "dev": true + }, "node_modules/babel-jest": { "version": "29.4.2", "dev": true, @@ -4266,6 +4273,43 @@ "dev": true, "license": "MIT" }, + "node_modules/bare-events": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.2.0.tgz", + "integrity": "sha512-Yyyqff4PIFfSuthCZqLlPISTWHmnQxoPuAvkmgzsJEmG3CesdIv6Xweayl0JkCZJSB2yYIdJyEz97tpxNhgjbg==", + "dev": true, + "optional": true + }, + "node_modules/bare-fs": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-2.2.0.tgz", + "integrity": "sha512-+VhW202E9eTVGkX7p+TNXtZC4RTzj9JfJW7PtfIbZ7mIQ/QT9uOafQTx7lx2n9ERmWsXvLHF4hStAFn4gl2mQw==", + "dev": true, + "optional": true, + "dependencies": { + "bare-events": "^2.0.0", + "bare-os": "^2.0.0", + "bare-path": "^2.0.0", + "streamx": "^2.13.0" + } + }, + "node_modules/bare-os": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/bare-os/-/bare-os-2.2.0.tgz", + "integrity": "sha512-hD0rOPfYWOMpVirTACt4/nK8mC55La12K5fY1ij8HAdfQakD62M+H4o4tpfKzVGLgRDTuk3vjA4GqGXXCeFbag==", + "dev": true, + "optional": true + }, + "node_modules/bare-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/bare-path/-/bare-path-2.1.0.tgz", + "integrity": "sha512-DIIg7ts8bdRKwJRJrUMy/PICEaQZaPGZ26lsSx9MJSwIhSrcdHn7/C8W+XmnG/rKi6BaRcz+JO00CjZteybDtw==", + "dev": true, + "optional": true, + "dependencies": { + "bare-os": "^2.1.0" + } + }, "node_modules/base": { "version": "0.11.2", "dev": true, @@ -7898,6 +7942,12 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-fifo": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz", + "integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==", + "dev": true + }, "node_modules/fast-glob": { "version": "3.2.11", "dev": true, @@ -14688,6 +14738,12 @@ ], "license": "MIT" }, + "node_modules/queue-tick": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/queue-tick/-/queue-tick-1.0.1.tgz", + "integrity": "sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==", + "dev": true + }, "node_modules/quick-lru": { "version": "5.1.1", "dev": true, @@ -16151,6 +16207,19 @@ "dev": true, "license": "MIT" }, + "node_modules/streamx": { + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.16.1.tgz", + "integrity": "sha512-m9QYj6WygWyWa3H1YY69amr4nVgy61xfjys7xO7kviL5rfIEc2naf+ewFiOA+aEJD7y0JO3h2GoiUv4TDwEGzQ==", + "dev": true, + "dependencies": { + "fast-fifo": "^1.1.0", + "queue-tick": "^1.0.1" + }, + "optionalDependencies": { + "bare-events": "^2.2.0" + } + }, "node_modules/string_decoder": { "version": "1.0.3", "license": "MIT", @@ -16414,6 +16483,31 @@ "node": ">= 10" } }, + "node_modules/tar-fs": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.5.tgz", + "integrity": "sha512-JOgGAmZyMgbqpLwct7ZV8VzkEB6pxXFBVErLtb+XCOqzc6w1xiWKI9GVd6bwk68EX7eJ4DWmfXVmq8K2ziZTGg==", + "dev": true, + "dependencies": { + "pump": "^3.0.0", + "tar-stream": "^3.1.5" + }, + "optionalDependencies": { + "bare-fs": "^2.1.1", + "bare-path": "^2.1.0" + } + }, + "node_modules/tar-stream": { + "version": "3.1.7", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.7.tgz", + "integrity": "sha512-qJj60CXt7IU1Ffyc3NJMjh6EkuCFej46zUqJ4J7pqYlThyd9bO0XBTmcOIhSzZJVWfsLks0+nle/j538YAW9RQ==", + "dev": true, + "dependencies": { + "b4a": "^1.6.4", + "fast-fifo": "^1.2.0", + "streamx": "^2.15.0" + } + }, "node_modules/tar/node_modules/mkdirp": { "version": "1.0.4", "dev": true, diff --git a/package.json b/package.json index 57fdba596..fa55268d0 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "jest": "29.4.2", "lefthook": "^1.5.5", "swc-loader": "0.2.3", + "tar-fs": "^3.0.5", "ts-jest": "29.0.5", "ts-loader": "9.4.1", "ts-node": "10.8.0",