Last active
January 7, 2024 15:06
-
-
Save WalterWoshid/cad366d5824423de916f684fe54c99f9 to your computer and use it in GitHub Desktop.
Remove JetBrains plugin version restrictions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Place in: | |
// Linux: ~/.local/share/JetBrains/IntelliJIdea2022.2 | |
// Windows: %APPDATA%\JetBrains\IntelliJIdea2022.2\plugins | |
// MacOS: ~/Library/Application Support/JetBrains/IntelliJIdea2022.2/plugins | |
// Run with "tsx ./remove-plugin-restrictions.ts" or "bun run ./remove-plugin-restrictions.ts" | |
import fs from 'fs'; | |
import path from 'path'; | |
import { execSync } from 'child_process'; | |
const currentDirectory = process.cwd(); | |
function walk(dir: string, callback: (filePath: string) => void) { | |
if (!fs.existsSync(dir)) { | |
return; | |
} | |
fs.readdirSync(dir).forEach((f) => { | |
const dirPath = path.join(dir, f); | |
if (!fs.existsSync(dirPath)) { | |
return; | |
} | |
const isDirectory = fs.statSync(dirPath).isDirectory(); | |
isDirectory ? walk(dirPath, callback) : callback(path.join(dir, f)); | |
}); | |
} | |
walk(currentDirectory, (filePath) => { | |
if (filePath.endsWith('.jar')) { | |
const escapedFilePath = filePath.replace(/ /g, '\\ '); | |
// Extract the jar file into a folder with the same name | |
const jarFolderPath = filePath.replace('.jar', ''); | |
const escapedJarFolderPath = jarFolderPath.replace(/ /g, '\\ '); | |
const extractedJarFolderPath = `${jarFolderPath}-extracted`; | |
const escapedExtractedJarFolderPath = `${escapedJarFolderPath}-extracted`; | |
execSync(`mkdir -p ${escapedExtractedJarFolderPath}`); | |
execSync(`unzip -o ${escapedFilePath} -d ${escapedExtractedJarFolderPath}`); | |
let needsUpdate = false; | |
walk(extractedJarFolderPath, (filePath) => { | |
if (filePath.endsWith('plugin.xml')) { | |
const xmlContents = fs.readFileSync(filePath, 'utf8'); | |
// Search with regex for until-build="..." and remove it | |
const regex = /until-build=".*?"/g; | |
if (regex.test(xmlContents)) { | |
needsUpdate = true; | |
const newXmlContents = xmlContents.replace(regex, ''); | |
fs.writeFileSync(filePath, newXmlContents); | |
} | |
} | |
}) | |
if (needsUpdate) { | |
execSync(`cd ${escapedExtractedJarFolderPath} && zip -r ${escapedFilePath} .`); | |
} | |
execSync(`rm -rf ${escapedExtractedJarFolderPath}`) | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment