|
| 1 | +// Usage: node process-archives.js <targetPluginFolder> <prefix> |
| 2 | + |
| 3 | +const fs = require("fs"); |
| 4 | +const path = require("path"); |
| 5 | +const { execSync } = require("child_process"); |
| 6 | + |
| 7 | +const [,, targetFolderArg] = process.argv; |
| 8 | +if (!targetFolderArg) { |
| 9 | + console.error("Usage: node process-archives.js <targetPluginFolder>"); |
| 10 | + process.exit(1); |
| 11 | +} |
| 12 | + |
| 13 | +const distFolderPath = path.resolve(path.join(__dirname, '..', 'dist')); |
| 14 | +const targetFolder = path.resolve(targetFolderArg); |
| 15 | + |
| 16 | +// clean result folder just in case |
| 17 | +fs.rmSync(path.join(distFolderPath, 'result'), { recursive: true, force: true }); |
| 18 | + |
| 19 | +// get all .vsix files |
| 20 | +const vsixs = fs.readdirSync(distFolderPath).filter(f => f.endsWith(".vsix")); |
| 21 | + |
| 22 | +for (const vsix of vsixs) { |
| 23 | + const base = path.basename(vsix, ".vsix"); |
| 24 | + const outDir = path.join(distFolderPath, 'result', base); |
| 25 | + |
| 26 | + console.log(`Extracting ${vsix} -> ${outDir}`); |
| 27 | + fs.mkdirSync(outDir, { recursive: true }); |
| 28 | + // use system unzip (already available on Ubuntu) |
| 29 | + execSync(`unzip -o "${path.join(distFolderPath, vsix)}" -d "${outDir}"`); |
| 30 | + |
| 31 | + // rename the extracted folder itself |
| 32 | + let newName = base; |
| 33 | + |
| 34 | + // remove version suffix if present |
| 35 | + const versionPos = newName.lastIndexOf('-'); |
| 36 | + if (newName.lastIndexOf('-') > 0) { |
| 37 | + newName = newName.slice(0, versionPos); |
| 38 | + } |
| 39 | + |
| 40 | + // add prefix if not already there |
| 41 | + const prefix = newName.startsWith("builtin-extension-pack") ? "eclipse-theia.": "vscode."; |
| 42 | + if (!newName.startsWith(prefix)) { |
| 43 | + newName = prefix + newName; |
| 44 | + } |
| 45 | + |
| 46 | + let finalPath = outDir; |
| 47 | + if (newName !== base) { |
| 48 | + finalPath = path.join(distFolderPath, 'result', newName); |
| 49 | + fs.renameSync(outDir, finalPath); |
| 50 | + console.log(`Renamed folder: "${base}" -> "${newName}"`); |
| 51 | + } |
| 52 | + // Define blacklist for extensions that should not be copied, taken from theia's 'theiaPluginsExcludeIds' |
| 53 | + const blacklist = [ |
| 54 | + "extension-editing", |
| 55 | + "github", |
| 56 | + "github-authentication", |
| 57 | + "microsoft-authentication" |
| 58 | + ]; |
| 59 | + |
| 60 | + // after you determine newName |
| 61 | + let skip = blacklist.some(suffix => newName.endsWith(suffix)); |
| 62 | + |
| 63 | + if (skip) { |
| 64 | + console.log(`Skipping blacklisted folder: "${newName}"`); |
| 65 | + continue; // don’t copy this one |
| 66 | + } |
| 67 | + // copy to target folder (force override) |
| 68 | + console.log(`Copying "${finalPath}" -> "${targetFolder}"`); |
| 69 | + execSync(`cp -r -f "${finalPath}" "${targetFolder}/"`); |
| 70 | +} |
| 71 | + |
| 72 | +console.log("\nDone."); |
0 commit comments