/* * MIT License * * Copyright (c) 2022- Minteck * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ const fs = require('fs'); const os = require('os'); if (process.argv.includes("--remove")) { console.log("Removing the Twilight Package Manager and all installed packages in 5 seconds."); console.log("Press Ctrl+C to abort."); global.to = 6; global.toi = setInterval(() => { to--; if (to <= 0) { clearInterval(toi); console.log(""); console.log("Preparing..."); if (fs.existsSync(os.homedir() + "/.twilight")) { try { fs.mkdirSync(os.homedir() + "/.twilight/.uninstalltest"); fs.rmdirSync(os.homedir() + "/.twilight/.uninstalltest"); } catch (e) { console.log("Error -2: Cannot write to the Twilight install directory."); process.exit(2); } try { fs.mkdirSync(os.homedir() + "/.uninstalltest"); fs.rmdirSync(os.homedir() + "/.uninstalltest"); } catch (e) { console.log("Error -3: Cannot write to the Twilight install directory's parent directory."); process.exit(3); } } else { console.log("Error -1: Cannot find an existing Twilight install."); process.exit(1); } console.log("Reading installed packages..."); try { global.installed = require(os.homedir() + "/.twilight/installed.json"); } catch (e) { console.log("Error -4: Unable to read installed packages."); process.exit(4); } try { global.repository = require(os.homedir() + "/.twilight/repository/list.json").map((i) => {return require(os.homedir() + "/.twilight/repository/" + i.substring(0, 1) + "/" + i + ".json");}); global.ids = repository.map((i) => { return i.id; }); } catch (e) { console.log("Error -5: Unable to read packages lists."); process.exit(4); } try { fs.mkdirSync(os.homedir() + "/Old Twilight Packages"); } catch (e) { console.log("Error -6: Unable to create backup directory."); process.exit(6); } console.log("Backing up installed packages..."); for (let pkg of installed) { if (!ids.includes(pkg.id)) { console.log("Error -7: Unable to find reference to package: " + pkg.id); process.exit(7); } let select = repository.filter((i) => i.id === pkg.id)[0]; if (!fs.existsSync(os.homedir() + "/.twilight/packages/" + pkg.id)) { console.log("Error -8: Unable to find package on disk: " + pkg.id); process.exit(8); } try { fs.renameSync(os.homedir() + "/.twilight/packages/" + pkg.id, os.homedir() + "/Old Twilight Packages/" + select.name.replaceAll("/", "")); } catch (e) { console.log("Error -9: Unable to move package to backup directory: " + pkg.id); process.exit(9); } if (fs.existsSync(os.homedir() + "/.twilight/binaries/" + (select.execname ?? pkg.id) + (os.platform() === "win32" ? ".bat" : ""))) { try { fs.renameSync(os.homedir() + "/.twilight/binaries/" + (select.execname ?? pkg.id) + (os.platform() === "win32" ? ".bat" : ""), os.homedir() + "/Old Twilight Packages/" + select.name.replaceAll("/", "") + "/" + (select.execname ?? pkg.id) + (os.platform() === "win32" ? ".bat" : "")); } catch (e) { console.log("Error -10: Unable to reproduce package executable: " + pkg.id); process.exit(9); } } } console.log("-------------------------------------------------------------------------------"); console.log("The Twilight Package Manager has now been uninstalled from your system."); console.log("You may need to update the $PATH variable and restart your system to complete"); console.log("the uninstall process."); console.log(""); console.log("To get more details about this change and how it affects the way you use"); console.log("Minteck's software and services, visit the following the page:"); console.log(" * https://gitlab.minteck.org/minteck/twilight/-/blob/trunk/README.md"); console.log(""); console.log("All packages you had installed, including the command you could have used to"); console.log("run them, have been moved to the following directory:"); console.log(" * " + (os.homedir() + "/Old Twilight Packages").replaceAll("/", (os.platform() === "win32" ? "\\" : "/"))); console.log(""); console.log("Thanks to everyone who used this package manager!") console.log("-------------------------------------------------------------------------------"); } else { process.stdout.write(" ..." + to); } }, 1000); } else { console.log("-------------------------------------------------------------------------------"); console.log("The Twilight Package Manager is now out of support and cannot be working again."); console.log("Your installed packages are still usable, although it is recommended that you"); console.log("use the standalone packages instead."); console.log(""); console.log("To get more details about this change and how it affects the way you use"); console.log("Minteck's software and services, visit the following the page:"); console.log(" * https://gitlab.minteck.org/minteck/twilight/-/blob/trunk/README.md"); console.log(""); console.log("To uninstall the Twilight Package Manager (and your installed packages), run"); console.log("this command:"); console.log(" * twi --remove"); console.log(""); console.log("Thanks to everyone who used this package manager!") console.log("-------------------------------------------------------------------------------"); }