29 lines
764 B
JavaScript
29 lines
764 B
JavaScript
import { existsSync, mkdirSync, rmSync } from 'node:fs';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { spawnSync } from 'node:child_process';
|
|
|
|
export const packDist = ({ distDir, outFile }) => {
|
|
const absoluteDist = resolve(distDir);
|
|
const absoluteOut = resolve(outFile);
|
|
|
|
if (!existsSync(absoluteDist)) {
|
|
throw new Error(`Cannot pack missing dist directory: ${absoluteDist}`);
|
|
}
|
|
|
|
mkdirSync(dirname(absoluteOut), { recursive: true });
|
|
rmSync(absoluteOut, { force: true });
|
|
|
|
const result = spawnSync('zip', ['-qr', absoluteOut, '.'], {
|
|
cwd: absoluteDist,
|
|
stdio: 'inherit'
|
|
});
|
|
|
|
if (result.error) {
|
|
throw result.error;
|
|
}
|
|
|
|
if (result.status !== 0) {
|
|
throw new Error(`zip exited with status ${result.status}`);
|
|
}
|
|
};
|