-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_and_zip.js
37 lines (31 loc) · 1.1 KB
/
build_and_zip.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
import { execSync } from 'child_process';
import { zip } from 'zip-a-folder';
import fs from 'fs';
import path from 'path';
// Read configuration
const config = JSON.parse(await fs.promises.readFile('./build_folder_name.json', 'utf-8'));
const buildFolder = config.buildFolder;
const rootBuildPath = 'mod-io-build';
const buildPath = path.join(rootBuildPath, buildFolder);
const zipFileName = `${buildFolder}.zip`;
// Delete the zip file if it exists
if (fs.existsSync(zipFileName)) {
fs.unlinkSync(zipFileName);
console.log(`Deleted existing zip file: ${zipFileName}`);
}
// Ensure the build path exists
if (!fs.existsSync(buildPath)) {
fs.mkdirSync(buildPath, { recursive: true });
}
// Run Vite build with the specified output directory
execSync(`vite build --outDir ${buildPath}`, { stdio: 'inherit' });
// Zip the build folder
const zipBuildFolder = async () => {
await zip(rootBuildPath, zipFileName, {
includeBasePath: true
});
console.log(`Build folder zipped as ${zipFileName}`);
};
zipBuildFolder().catch(err => {
console.error('Error zipping the build folder:', err);
});