Skip to content

Commit

Permalink
refactor: remove path overrides, properly create directories
Browse files Browse the repository at this point in the history
  • Loading branch information
vadzz-dev committed Oct 3, 2024
1 parent 6c7d148 commit 6fbdb9d
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions bin/altv-pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,18 @@ async function start() {
}

for (let [file, hash] of Object.entries(data.hashList)) {
const correctedFileName = correctPathIfNecessary(file);

if (getLocalFileHash(correctedFileName) === hash) {
console.log(chalk.cyanBright('✓'), chalk.whiteBright(correctedFileName));
if (getLocalFileHash(file) === hash) {
console.log(chalk.cyanBright('✓'), chalk.whiteBright(file));
continue;
}

console.log(chalk.redBright('x'), chalk.whiteBright(correctedFileName));
console.log(chalk.redBright('x'), chalk.whiteBright(file));

if (anyHashRejected) {
return;
}

filesToDownload[correctedFileName] = filesToUse[file];
filesToDownload[file] = filesToUse[file];
}

resolve();
Expand Down Expand Up @@ -378,7 +376,11 @@ async function start() {
}

const body = Readable.fromWeb(response.body);
const writeStream = fs.createWriteStream(path.join(rootPath, file));

const fullPath = path.join(rootPath, file);
fs.mkdirSync(path.dirname(fullPath), { recursive: true });

const writeStream = fs.createWriteStream(fullPath);
body.pipe(writeStream);
body.on('close', () => {
resolve();
Expand Down Expand Up @@ -408,18 +410,6 @@ function getLocalFileHash(file) {
return crypto.createHash('sha1').update(fileBuffer).digest('hex');
}

// I dont't know why altv-pkg has different file paths than alt:V cdn
const pathsCorrects = {
'modules/js-module/js-module.dll': 'modules/js-module.dll',
'modules/js-module/libnode.dll': 'libnode.dll',
'modules/js-module/libjs-module.so': 'modules/libjs-module.so',
'modules/js-module/libnode.so.108': 'libnode.so.108',
};

function correctPathIfNecessary(file) {
return pathsCorrects[file] ?? file;
}

function loadRuntimeConfig() {
let loadJSModule = true;

Expand Down

0 comments on commit 6fbdb9d

Please sign in to comment.