-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpack-extension.js
More file actions
74 lines (63 loc) · 1.54 KB
/
pack-extension.js
File metadata and controls
74 lines (63 loc) · 1.54 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const fs = require('fs-extra');
const path = require('path');
const archiver = require('archiver');
const ignoreList = [
'.idea',
'node_modules',
'.gitignore',
'.git',
'README.md',
'LICENSE',
'yarn.lock',
'extension.crx',
'privacy_policy.md',
'pack-extension.js',
'update.xml',
'build',
'cheatsheet',
'tests'
];
const srcDir = path.resolve('.');
const buildDir = path.resolve('./build');
const zipFile = path.resolve(buildDir, 'autoApplylinkedin.zip');
async function packExtension() {
try {
if (!fs.existsSync(buildDir)) {
await fs.mkdir(buildDir);
}
console.log('Creating .zip file...');
const output = fs.createWriteStream(zipFile);
const archive = archiver('zip', {
zlib: { level: 9 },
});
output.on('close', () => {
console.log(`.zip file created: ${zipFile} (${archive.pointer()} bytes)`);
});
archive.on('error', (err) => {
throw err;
});
archive.pipe(output);
const files = await fs.readdir(srcDir);
for (const file of files) {
const fullPath = path.join(srcDir, file);
const relativePath = path.relative(srcDir, fullPath);
if (
!ignoreList.some(
(pattern) =>
relativePath === pattern || relativePath.startsWith(`${pattern}${path.sep}`)
)
) {
const stats = await fs.stat(fullPath);
if (stats.isFile()) {
archive.file(fullPath, { name: file });
} else if (stats.isDirectory()) {
archive.directory(fullPath, file);
}
}
}
await archive.finalize();
} catch (err) {
console.error('Error during packaging:', err);
}
}
packExtension();