-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage-zip-jszip.js
More file actions
114 lines (98 loc) · 2.95 KB
/
Copy pathpackage-zip-jszip.js
File metadata and controls
114 lines (98 loc) · 2.95 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const JSZip = require('jszip');
// Read package.json to get package info
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const packageName = packageJson.name.replace('@', '').replace('/', '-');
const version = packageJson.version;
// Create output filename
const outputFile = `${packageName}-${version}.zip`;
// Files to include
const filesToInclude = [
'manifest.json',
'dist',
'src',
'README.md',
'LICENSE',
'CHANGELOG.md',
'package.json'
];
// Files to exclude patterns
const excludePatterns = [
/node_modules/,
/\.git/,
/\.gitignore/,
/\.npmignore/,
/\.log$/,
/\.env/,
/package-zip.*\.js$/,
/\.zip$/,
/\.tgz$/,
/\.d\.ts$/,
/\.d\.ts\.map$/,
/\.js\.map$/,
/\.css\.map$/
];
const shouldIncludeFile = (filePath) => {
return !excludePatterns.some(pattern => pattern.test(filePath));
};
const addFileToZip = (zip, filePath, relativePath) => {
if (!fs.existsSync(filePath)) return;
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
const entries = fs.readdirSync(filePath);
for (const entry of entries) {
const fullPath = path.join(filePath, entry);
const relPath = path.join(relativePath, entry).replace(/\\/g, '/');
if (shouldIncludeFile(relPath)) {
addFileToZip(zip, fullPath, relPath);
}
}
} else {
const content = fs.readFileSync(filePath);
zip.file(relativePath.replace(/\\/g, '/'), content);
console.log(`Added: ${relativePath}`);
}
};
async function createZip() {
try {
const zip = new JSZip();
// Add files to ZIP
for (const fileOrDir of filesToInclude) {
if (fs.existsSync(fileOrDir)) {
const stats = fs.statSync(fileOrDir);
if (stats.isDirectory()) {
addFileToZip(zip, fileOrDir, fileOrDir);
} else {
if (shouldIncludeFile(fileOrDir)) {
const content = fs.readFileSync(fileOrDir);
zip.file(fileOrDir, content);
console.log(`Added: ${fileOrDir}`);
}
}
}
}
// Generate ZIP with maximum compatibility settings
const zipBuffer = await zip.generateAsync({
type: 'nodebuffer',
compression: 'STORE', // No compression for maximum compatibility
compressionOptions: {
level: 0
},
platform: 'UNIX', // Use UNIX platform for better compatibility
comment: `Plugin package created by JSZip for ${packageName} v${version}`
});
// Write to file
fs.writeFileSync(outputFile, zipBuffer);
// Show file info
const stats = fs.statSync(outputFile);
console.log(`✅ Created ${outputFile} using JSZip (STORE compression)`);
console.log(`📦 Package size: ${(stats.size / 1024).toFixed(1)} KB`);
console.log(`📁 Location: ${path.resolve(outputFile)}`);
} catch (error) {
console.error('❌ Failed to create package:', error.message);
process.exit(1);
}
}
createZip();