aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorScoots Dash <contact@minteck.org>2022-04-23 14:12:30 +0000
committerScoots Dash <contact@minteck.org>2022-04-23 14:12:30 +0000
commita927497b43cbe1438f3d7478932f3f7d03ea347c (patch)
tree0a3c88978b4294fb30afad58daa86c46fbedc2f6 /index.js
parentba5fa694351774f2684c1aefdc215da5c6f39ba6 (diff)
parentf0db5bbbcd623812a391862d217519afafe197c6 (diff)
downloadtwilight-trunk.tar.gz
twilight-trunk.tar.bz2
twilight-trunk.zip
Merge branch 'deprecation' into 'trunk'HEADtrunk
Disable the Twilight Package Manager See merge request minteck/twilight!1
Diffstat (limited to 'index.js')
-rw-r--r--index.js235
1 files changed, 111 insertions, 124 deletions
diff --git a/index.js b/index.js
index 605fe1c..5697cb2 100644
--- a/index.js
+++ b/index.js
@@ -23,138 +23,125 @@
*
*/
-if (require('fs').existsSync("emuAlicorn") || require('fs').existsSync('/System/AlicornCore')) {
- global.twiplatform = "alicorn";
-} else {
- global.twiplatform = require('os').platform();
-}
-
-process.on('uncaughtException', async (e) => {
- global.c = (await import('chalk')).default;
-
- if (!fs.existsSync(os.homedir() + "/.twilight/crashes")) {
- fs.mkdirSync(os.homedir() + "/.twilight/crashes")
- }
-
- let date = new Date().toISOString().replace(/[^a-zA-Z0-9-]/gm, "-");
- fs.writeFileSync(require('os').homedir() + "/.twilight/crashes/" + date + ".txt", e.stack);
-
- console.log(c.red("error:") + " an internal error occurred, did you forget to run 'twi update'?");
- if (twiplatform === "alicorn") {
- console.log(" additionally, a crash report has been saved to:\n /Library/Logs/TwilightCrashes/" + date + ".txt")
- } else {
- console.log(" additionally, a crash report has been saved to:\n " + require('os').homedir() + (twiplatform === "win32" ? "\\" : "/") + ".twilight" + (twiplatform === "win32" ? "\\" : "/") + "crashes" + (twiplatform === "win32" ? "\\" : "/") + date + ".txt")
- }
- process.exit(2);
-})
-
-try {
- (async () => {
- global.yargs = require('yargs/yargs');
- const { hideBin } = require('yargs/helpers');
- global.git = require('simple-git');
- global.ora = (await import('ora')).default;
- global.c = (await import('chalk')).default;
- global.fs = require('fs');
- global.os = require('os');
- global.axios = require('axios');
- global.moment = require('moment');
- global.prompts = require('prompts').prompts;
-
-
- if (!fs.existsSync(os.homedir() + "/.twilight")) {
- fs.mkdirSync(os.homedir() + "/.twilight")
- }
-
- if (!fs.existsSync(os.homedir() + "/.twilight/packages")) {
- fs.mkdirSync(os.homedir() + "/.twilight/packages")
- }
-
- if (!fs.existsSync(os.homedir() + "/.twilight/crashes")) {
- fs.mkdirSync(os.homedir() + "/.twilight/crashes")
- }
-
- if (!fs.existsSync(os.homedir() + "/.twilight/binaries")) {
- fs.mkdirSync(os.homedir() + "/.twilight/binaries")
- }
-
- if (!fs.existsSync(os.homedir() + "/.twilight/installed.json")) {
- fs.writeFileSync(os.homedir() + "/.twilight/installed.json", "[]");
- } else {
- fs.writeFileSync(os.homedir() + "/.twilight/installed.json", JSON.stringify(JSON.parse(fs.readFileSync(os.homedir() + "/.twilight/installed.json").toString()).filter(i => i !== null)));
- }
-
- global.home = os.homedir() + "/.twilight";
-
- global.die = (text, code) => {
- fs.rmSync(home + "/runtime.pid");
- if (text) {
- console.log(text);
- if (code) {
- process.exit(code);
- } else {
- process.exit();
+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);
}
- } else {
- if (code) {
- process.exit(code);
- } else {
- process.exit();
+ 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);
}
- }
- let pargv = process.argv;
- pargv[1] = "twi";
-
- global.argv = yargs(pargv.slice(2))
- .command(["install <package>", "i <package>", "a <package>", "add <package>"], "Install a package")
- .command(["reinstall <package>", "ri <package>", "reset <package>", "rs <package>"], "Online reinstall an installed package")
- .command(["remove <package>", "r <package>", "del <package>", "rm <package>", "delete <package>", "uninstall <package>", "u <package>"], "Delete a package")
- .command(["update", "ud", "fetch", "refresh", "reload", "rl"], "Fetches the repository")
- .command(["upgrade [package]", "ug [package]"], "Update one or all package(s)")
- .command(["purge <package>", "p <package>", "ori <package>", "ors <package>", "oreset <package>", "oreinstall <package>"], "Offline reinstall an installed package")
- .command(["info <package>", "inf <package>", "view <package>", "v <package>", "if <package>"], "Get info about a package")
- .command(["list", "l", "ls", "all"], "List all packages in the repository")
- .command(["installed", "il", "lil", "lsil", "allil"], "List all installed packages")
- .command(["installable", "ia", "lia", "lsia", "allia"], "List all compatible packages")
- .help()
- .alias("help", "h")
- .alias("version", "V")
- .option('ignore-unsigned-packages', {
- type: 'boolean',
- description: 'Do not ask for confirmation when installing an unsigned package update'
- })
- .example("twi install neutron", "Install Neutron")
- .example("twi update", "Update all packages")
- .example("twi info ponyfind", "Show info about Ponyfind")
- .strictCommands()
- .demandCommand(1)
- .usage('Usage: twi <command> [arguments...]')
- .argv;
- global.ignoreUnsignedPackages = !!argv.ignoreUnsignedPackages;
+ 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);
+ }
- if (fs.existsSync(home + "/runtime.pid")) {
- let pid = fs.readFileSync(home + "/runtime.pid") - 1 + 1;
try {
- process.kill(pid, 0);
- die(c.red("error:") + " another instance is running (" + pid + ")");
+ fs.mkdirSync(os.homedir() + "/Old Twilight Packages");
} catch (e) {
- console.log(c.yellow("warn:") + " process was stopped unexpectedly");
+ console.log("Error -6: Unable to create backup directory.");
+ process.exit(6);
}
- }
- fs.writeFileSync(home + "/runtime.pid", process.pid.toString());
- let command = argv._[0];
- let aliases = require('./commands/aliases.json');
- if ([].concat(Object.keys(aliases).map(i => aliases[i])).flat(1).includes(command)) {
- command = Object.keys(aliases).map(i => { if (aliases[i].includes(command)) { return i; } else { return null; } }).filter(i => i !== null)[0];
- }
- await require('./commands/' + command)(argv);
+ 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];
- fs.rmSync(home + "/runtime.pid");
- })()
-} catch (e) {
- console.log("error: an internal error occurred, did you forget to run 'twi update'?");
- process.exit(2);
+ 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("-------------------------------------------------------------------------------");
} \ No newline at end of file