-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchiver.js
70 lines (58 loc) · 1.69 KB
/
archiver.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const fs = require('fs');
const path = require('path');
const archiver = require('archiver');
const glob = require('glob');
const pluginDir = path.resolve(__dirname);
const outputDir = path.resolve(pluginDir, '../');
const outputZip = path.join(outputDir, 'time-based-product-pricing.zip');
const includePatterns = [
'**/*.php',
'**/*.css',
'**/*.js',
'**/*.html',
'**/*.txt',
'readme.txt',
'!node_modules/**',
'!archiver.js',
'!**/*.log',
'!**/*.DS_Store',
'!**/__MACOSX/**',
'!**/tests/**',
'!**/docs/**',
'!**/*.md',
'!**/.git/**'
];
function createZip() {
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const output = fs.createWriteStream(outputZip);
const archive = archiver('zip', {
zlib: { level: 9 }
});
output.on('close', function () {
console.log(`${archive.pointer()} total bytes`);
console.log('Plugin zip has been created successfully.');
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(output);
// Collect all files matching the patterns
const files = includePatterns.reduce((acc, pattern) => {
return acc.concat(glob.sync(pattern, { cwd: pluginDir, dot: true }));
}, []);
// Add files to the archive
files.forEach(file => {
if (file !== 'archiver.js' && !file.includes('node_modules') && !file.match(/readme.txt$/i)) {
const filePath = path.join(pluginDir, file);
archive.file(filePath, { name: file });
}
});
// Ensure root readme.txt is included if it exists
if (fs.existsSync(path.join(pluginDir, 'readme.txt'))) {
archive.file(path.join(pluginDir, 'readme.txt'), { name: 'readme.txt' });
}
archive.finalize();
}
createZip();