This commit is contained in:
@@ -4,16 +4,20 @@ import path from "node:path";
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import yazl from "yazl";
|
||||
|
||||
export async function createReleaseArchive({ archivePath, sourceDir }) {
|
||||
export async function createReleaseArchive({
|
||||
archivePath,
|
||||
rootDirName = "star-chart-search-enhancer-internal",
|
||||
sourceDir
|
||||
}) {
|
||||
const zip = new yazl.ZipFile();
|
||||
const output = createWriteStream(archivePath);
|
||||
|
||||
await addDirectory(zip, sourceDir, sourceDir);
|
||||
await addDirectory(zip, sourceDir, sourceDir, rootDirName);
|
||||
zip.end();
|
||||
await pipeline(zip.outputStream, output);
|
||||
}
|
||||
|
||||
async function addDirectory(zip, rootDir, currentDir) {
|
||||
async function addDirectory(zip, rootDir, currentDir, rootDirName) {
|
||||
const entries = await readdir(currentDir, { withFileTypes: true });
|
||||
entries.sort((left, right) => left.name.localeCompare(right.name));
|
||||
|
||||
@@ -22,12 +26,12 @@ async function addDirectory(zip, rootDir, currentDir) {
|
||||
const relativePath = path.relative(rootDir, absolutePath);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
await addDirectory(zip, rootDir, absolutePath);
|
||||
await addDirectory(zip, rootDir, absolutePath, rootDirName);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry.isFile()) {
|
||||
zip.addFile(absolutePath, relativePath);
|
||||
zip.addFile(absolutePath, path.join(rootDirName, relativePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user