aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-02-12 10:33:06 +0100
committerMinteck <contact@minteck.org>2022-02-12 10:33:06 +0100
commit01160246e4a0c0052181c72a53737e356ea7d02d (patch)
treec6f8ea675f9147d4c06ef503697fb35d58493991 /index.js
parentaf898a152a14e31bdbcbbedb952ad333697553ef (diff)
downloadtwilight-01160246e4a0c0052181c72a53737e356ea7d02d.tar.gz
twilight-01160246e4a0c0052181c72a53737e356ea7d02d.tar.bz2
twilight-01160246e4a0c0052181c72a53737e356ea7d02d.zip
First commit
Diffstat (limited to 'index.js')
-rw-r--r--index.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..2b5fe82
--- /dev/null
+++ b/index.js
@@ -0,0 +1,88 @@
+(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/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();
+ }
+ } else {
+ if (code) {
+ process.exit(code);
+ } else {
+ process.exit();
+ }
+ }
+ }
+
+ let pargv = process.argv;
+ pargv[1] = "twi";
+
+ global.argv = yargs(pargv.slice(2))
+ .command("install <package>", "Install a package")
+ .command("reinstall <package>", "Online reinstall an installed package")
+ .command("remove <package>", "Delete a package")
+ .command("update", "Fetches the repository")
+ .command("upgrade [package]", "Update one or all package(s)")
+ .command("purge [package]", "Offline reinstall an installed package")
+ .command("info <package>", "Get info about a package")
+ .command("list", "List all packages in the repository")
+ .command("installed", "List all installed packages")
+ .command("installable", "List all compatible packages")
+ .help()
+ .alias("help", "h")
+ .alias("version", "V")
+ .example("twi install neutron", "Install Neutron")
+ .example("twi update", "Update all packages")
+ .example("twi info ponyfind", "Show info about Ponyfind")
+ .strictCommands()
+ .demandCommand(1)
+ .epilog("Twilight Package Manager v" + require('./package.json').version)
+ .usage('Usage: twi <command> [arguments...]')
+ .argv;
+
+ 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 + ")");
+ } catch (e) {
+ console.log(c.yellow("warn:") + " process was stopped unexpectedly");
+ }
+ }
+ fs.writeFileSync(home + "/runtime.pid", process.pid.toString());
+ let command = argv._[0];
+ await require('./commands/' + command)(argv);
+
+ fs.rmSync(home + "/runtime.pid");
+})() \ No newline at end of file