forked from fregante/chrome-webstore-upload-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipdir.js
25 lines (22 loc) · 749 Bytes
/
zipdir.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
import { basename } from 'node:path';
import { isNotJunk } from 'junk';
import yazl from 'yazl';
import recursiveDir from 'recursive-readdir';
import { zipPath } from './util.js';
export default async function zipStreamFromDir(dir) {
const files = await recursiveDir(dir);
const zip = new yazl.ZipFile();
let hasManifest = false;
for (const file of files) {
if (isNotJunk(basename(file))) {
const relativePath = zipPath(dir, file);
zip.addFile(file, relativePath);
hasManifest = hasManifest || relativePath === 'manifest.json';
}
}
if (!hasManifest) {
throw new Error(`manifest.json was not found in ${dir}`);
}
zip.end();
return zip.outputStream;
}