-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
package-binaries.js
52 lines (42 loc) · 1.39 KB
/
package-binaries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
const AdmZip = require('adm-zip');
// Define the folder path and the list of file names
const folderPath = './binaries/';
const fileNames = ['geostyler-win.exe', 'geostyler-linux', 'geostyler-macos'];
function renameFile(oldPath, newPath) {
return new Promise((resolve, reject) => {
fs.rename(oldPath, newPath, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
}
// Function to execute the renaming and zipping process
async function processFiles() {
try {
for (const fileName of fileNames) {
const filePath = folderPath + fileName;
const renamedFilePath = folderPath + fileName.replace('-win', '').replace('-macos', '').replace('-linux', '');
// Rename the file
await renameFile(filePath, renamedFilePath);
// Zip the file
const outputZipFilePath = filePath + '.zip';
const zip = new AdmZip();
zip.addLocalFile(renamedFilePath);
// Save the zip archive
zip.writeZip(outputZipFilePath);
// Rename the zipped file back to its original name
await renameFile(renamedFilePath, filePath);
console.log(`Processed file: ${fileName}`);
}
console.log('All files processed successfully.');
} catch (error) {
console.error('An error occurred:', error);
}
}
processFiles();