-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack-zip.js
More file actions
47 lines (37 loc) · 1.37 KB
/
pack-zip.js
File metadata and controls
47 lines (37 loc) · 1.37 KB
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
import path from 'path';
import fs from 'fs';
import jszip from 'jszip';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const iconFile = path.join(__dirname, 'icon.png');
const pluginJSON = path.join(__dirname, 'plugin.json');
const distFolder = path.join(__dirname, 'dist');
const readmeDotMd = path.join(__dirname, 'readme.md');
const changelogDotMd = path.join(__dirname, 'changelogs.md');
const zip = new jszip();
zip.file('icon.png', fs.readFileSync(iconFile));
zip.file('plugin.json', fs.readFileSync(pluginJSON));
zip.file("readme.md", fs.readFileSync(readmeDotMd));
zip.file("changelogs.md", fs.readFileSync(changelogDotMd));
loadFile('', distFolder);
zip
.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
.pipe(fs.createWriteStream(path.join(__dirname, 'plugin.zip')))
.on('finish', () => {
console.log('Plugin plugin.zip written.');
});
function loadFile(root, folder) {
const distFiles = fs.readdirSync(folder);
distFiles.forEach((file) => {
const stat = fs.statSync(path.join(folder, file));
if (stat.isDirectory()) {
zip.folder(file);
loadFile(path.join(root, file), path.join(folder, file));
return;
}
if (!/LICENSE.txt/.test(file)) {
zip.file(path.join(root, file), fs.readFileSync(path.join(folder, file)));
}
});
}