Skip to content

Commit

Permalink
fix: Improve deps install
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Feb 27, 2024
1 parent 6f9a62c commit 650cd76
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 5 deletions.
48 changes: 43 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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();
});
}


Expand Down Expand Up @@ -343,14 +361,34 @@ 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);

exports.build = series(
clean,
createVersionFile,
// installCrossDeps,
installCrossDeps,
parallel(
buildRust,
buildBack,
Expand All @@ -364,7 +402,7 @@ exports.build = series(
exports.watch = series(
clean,
createVersionFile,
// installCrossDeps,
installCrossDeps,
parallel(
buildRust,
watchBack,
Expand Down
94 changes: 94 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 650cd76

Please sign in to comment.