-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-extension-zip.js
executable file
·50 lines (40 loc) · 1.59 KB
/
create-extension-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
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
const { createWriteStream } = require('node:fs');
const { readdir, stat } = require('node:fs/promises');
const { join, resolve } = require('node:path');
const archiver = require('archiver');
async function addDirectoryToArchive(archive, directory, baseDir) {
const files = await readdir(directory);
for (const file of files) {
const filePath = join(directory, file);
const stats = await stat(filePath);
if (stats.isDirectory()) {
await addDirectoryToArchive(archive, filePath, baseDir);
} else {
const relativePath = filePath.slice(baseDir.length + 1);
archive.file(filePath, { name: relativePath });
}
}
}
async function createExtensionZip() {
const rootDir = resolve(__dirname);
const distDir = join(rootDir, 'dist');
const assetsDir = join(rootDir, 'assets');
const outputFile = join(rootDir, 'extension.zip');
const output = createWriteStream(outputFile);
const archive = archiver('zip', { zlib: { level: 9 } });
archive.pipe(output);
try {
// Add manifest.json from the parent directory
archive.file(join(rootDir, 'manifest.json'), { name: 'manifest.json' });
// Add all files from the dist directory, maintaining the folder structure
await addDirectoryToArchive(archive, distDir, rootDir);
// Add all files from the assets directory, maintaining the folder structure
await addDirectoryToArchive(archive, assetsDir, rootDir);
await archive.finalize();
console.log(`Extension zip created: ${outputFile}`);
} catch (error) {
console.error('Error creating zip:', error);
}
}
createExtensionZip();