From 4081c2036a5af21519095da1b8b99c507b0fba93 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sun, 17 Apr 2022 17:37:10 +0200 Subject: Deprecation --- commands/aliases.json | 12 --- commands/info.js | 152 ------------------------------ commands/install.js | 218 ------------------------------------------ commands/installable.js | 105 --------------------- commands/installed.js | 95 ------------------- commands/list.js | 101 -------------------- commands/purge.js | 79 ---------------- commands/reinstall.js | 30 ------ commands/remove.js | 121 ------------------------ commands/update.js | 28 ------ commands/upgrade.js | 245 ------------------------------------------------ 11 files changed, 1186 deletions(-) delete mode 100644 commands/aliases.json delete mode 100644 commands/info.js delete mode 100644 commands/install.js delete mode 100644 commands/installable.js delete mode 100644 commands/installed.js delete mode 100644 commands/list.js delete mode 100644 commands/purge.js delete mode 100644 commands/reinstall.js delete mode 100644 commands/remove.js delete mode 100644 commands/update.js delete mode 100644 commands/upgrade.js (limited to 'commands') diff --git a/commands/aliases.json b/commands/aliases.json deleted file mode 100644 index 667eca9..0000000 --- a/commands/aliases.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "install": [ "i", "a", "add" ], - "reinstall": [ "ri", "reset", "rs" ], - "remove": [ "r", "del", "rm", "delete", "uninstall", "u" ], - "update": [ "ud", "fetch", "refresh", "reload", "rl" ], - "upgrade": [ "ug" ], - "purge": [ "p", "ori", "ors", "oreset", "oreinstall" ], - "info": [ "inf", "view", "v", "if" ], - "list": [ "l", "ls", "all" ], - "installed": [ "il", "lil", "lsil", "allil" ], - "installable": [ "ia", "lia", "lsia", "allia" ] -} \ No newline at end of file diff --git a/commands/info.js b/commands/info.js deleted file mode 100644 index e7afd40..0000000 --- a/commands/info.js +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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. - * - */ - -module.exports = async (argv) => { - const installed = JSON.parse(fs.readFileSync(home + "/installed.json").toString()); - let pkgInstalled = false - if (installed.map(i => i.id).includes(argv.package)) { - pkgInstalled = true; - } - - let packages = JSON.parse(fs.readFileSync(home + "/repository/list.json").toString()); - - if (!packages.includes(argv.package)) { - die(c.red("error: ") + "package '" + argv.package + "' not in repository"); - } - - let dir = argv.package.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pkg = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()); - - let compatible = true; - let replacement = null; - if (twiplatform === "win32" && pkg.platforms.windows === 0) { - compatible = false; - if (typeof pkg.replaced.windows === "string") { - replacement = pkg.replaced.windows - } - } else if (twiplatform === "linux" && pkg.platforms.linux === 0) { - compatible = false; - if (typeof pkg.replaced.linux === "string") { - replacement = pkg.replaced.linux - } - } else if (twiplatform === "darwin" && pkg.platforms.mac === 0) { - compatible = false; - if (typeof pkg.replaced.mac === "string") { - replacement = pkg.replaced.mac - } - } else if (twiplatform === "alicorn" && pkg.platforms.alicorn === 0) { - compatible = false; - if (typeof pkg.replaced.alicorn === "string") { - replacement = pkg.replaced.alicorn - } - } - - let experimental = false; - if (twiplatform === "win32" && pkg.platforms.windows === 1) { - experimental = true; - } else if (twiplatform === "linux" && pkg.platforms.linux === 1) { - experimental = true; - } else if (twiplatform === "darwin" && pkg.platforms.mac === 1) { - experimental = true; - } else if (twiplatform === "alicorn" && pkg.platforms.alicorn === 1) { - experimental = true; - } - - let version = pkg.verdata.latest; - let publisher = pkg.verdata.publisher.name; - let publisherMail = pkg.verdata.publisher.email; - let date = moment(pkg.verdata.date).fromNow(); - - let signed = false; - let signInfo = ""; - let verified = false; - - if (pkg.sign.signed) { - signed = true; - verified = pkg.sign.verified; - if (pkg.sign.signer.name && pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.name + " <" + pkg.sign.signer.email + "> " + c.gray("(" + pkg.sign.key + ")"); - } else if (pkg.sign.signer.name && pkg.sign.key) { - signInfo = pkg.sign.signer.name + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.email + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.key) { - signInfo = pkg.sign.key; - } - } - - console.log(c.bold(pkg.name + ": " + pkg.description)) - console.log(" " + c.magentaBright("version:") + " " + version); - console.log(" " + c.magentaBright("last update:") + " " + date); - console.log(" " + c.magentaBright("publisher:") + " " + publisher + " <" + publisherMail + ">"); - - if (signed) { - if (verified) { - console.log(" " + c.magentaBright("security:") + " " + c.green("verified") + "\n " + signInfo); - } else { - console.log(" " + c.magentaBright("security:") + " " + c.yellow("unverified") + "\n " + signInfo); - } - } else { - console.log(" " + c.magentaBright("security:") + " " + c.red.inverse("unsafe")); - } - - if (pkgInstalled) { - if (experimental) { - console.log(" " + c.magentaBright("state:") + " " + c.cyan("installed") + " (" + moment(installed.filter(i => i.id === pkg.id)[0].date).fromNow() + "), " + c.yellow("experimental")) - } else { - console.log(" " + c.magentaBright("state:") + " " + c.cyan("installed") + " (" + moment(installed.filter(i => i.id === pkg.id)[0].date).fromNow() + ")") - } - } else { - if (compatible) { - if (experimental) { - console.log(" " + c.magentaBright("state:") + " " + c.green("compatible") + ", " + c.yellow("experimental")); - } else { - console.log(" " + c.magentaBright("state:") + " " + c.green("compatible")); - } - } else { - if (typeof replacement === "string") { - console.log(" " + c.magentaBright("state:") + " " + c.red("incompatible") + " (replaced by: " + replacement + ")"); - } else { - console.log(" " + c.magentaBright("state:") + " " + c.red("incompatible") + " (no replacement)"); - } - } - } - - if (typeof pkg.deprecated === "string") { - if (pkg.deprecated.toString().trim() !== "") { - console.log(" " + c.magentaBright("support:") + " " + c.red("unsupported") + " (" + pkg.deprecated + ")"); - } else { - console.log(" " + c.magentaBright("support:") + " " + c.red("unsupported")); - } - } else if (typeof pkg.extended === "string") { - if (pkg.extended.toString().trim() !== "") { - console.log(" " + c.magentaBright("support:") + " " + c.yellow("extended") + " (" + pkg.extended + ")"); - } else { - console.log(" " + c.magentaBright("support:") + " " + c.yellow("extended")); - } - } else { - console.log(" " + c.magentaBright("support:") + " " + c.green("supported")); - } -} \ No newline at end of file diff --git a/commands/install.js b/commands/install.js deleted file mode 100644 index f8a238b..0000000 --- a/commands/install.js +++ /dev/null @@ -1,218 +0,0 @@ -/* - * 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. - * - */ - -module.exports = async (argv) => { - - const installed = JSON.parse(fs.readFileSync(home + "/installed.json").toString()); - if (installed.map(i => i.id).includes(argv.package)) { - die(c.red("error: ") + "package '" + argv.package + "' is already installed (version " + installed.filter(i => i.id === argv.package)[0].version + ", installed " + moment(installed.filter(i => i.id === argv.package)[0].date).fromNow() + ")"); - } - - let spinner = ora("Reading package lists...").start(); - let packages = JSON.parse(fs.readFileSync(home + "/repository/list.json").toString()); - spinner.succeed("Reading packages lists... done"); - - if (!packages.includes(argv.package)) { - die(c.red("error: ") + "package '" + argv.package + "' not in repository"); - } - - let dir = argv.package.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pkg = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()); - - let replacement = null; - if (twiplatform === "win32" && pkg.platforms.windows === 0) { - if (typeof pkg.replaced.windows === "string") { - replacement = pkg.replaced.windows - } - } else if (twiplatform === "linux" && pkg.platforms.linux === 0) { - if (typeof pkg.replaced.linux === "string") { - replacement = pkg.replaced.linux - } - } else if (twiplatform === "darwin" && pkg.platforms.mac === 0) { - if (typeof pkg.replaced.mac === "string") { - replacement = pkg.replaced.mac - } - } else if (twiplatform === "alicorn" && pkg.platforms.alicorn === 0) { - if (typeof pkg.replaced.alicorn === "string") { - replacement = pkg.replaced.alicorn - } - } - - if (twiplatform === "win32" && pkg.platforms.windows === 0) { - if (typeof replacement === "string") { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'win32', replaced by '" + replacement + "'"); - } else { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'win32', no replacement available"); - } - } else if (twiplatform === "linux" && pkg.platforms.linux === 0) { - if (typeof replacement === "string") { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'linux', replaced by '" + replacement + "'"); - } else { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'linux', no replacement available"); - } - } else if (twiplatform === "darwin" && pkg.platforms.mac === 0) { - if (typeof replacement === "string") { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'macos', replaced by '" + replacement + "'"); - } else { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'macos', no replacement available"); - } - } else if (twiplatform === "alicorn" && pkg.platforms.alicorn === 0) { - if (typeof replacement === "string") { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'alicorn', replaced by '" + replacement + "'"); - } else { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'alicorn', no replacement available"); - } - } - - if (twiplatform === "win32" && pkg.platforms.windows === 1) { - console.log(c.yellow("warn: ") + "package '" + argv.package + "' is experimental on platform 'win32'"); - } else if (twiplatform === "linux" && pkg.platforms.linux === 1) { - console.log(c.yellow("warn: ") + "package '" + argv.package + "' is experimental on platform 'linux'"); - } else if (twiplatform === "darwin" && pkg.platforms.mac === 1) { - console.log(c.yellow("warn: ") + "package '" + argv.package + "' is experimental on platform 'macos'"); - } else if (twiplatform === "alicorn" && pkg.platforms.alicorn === 1) { - console.log(c.yellow("warn: ") + "package '" + argv.package + "' is experimental on platform 'alicorn'"); - } - - spinner = ora("Checking dependencies...").start(); - for (let dependency of pkg.depends) { - let cmd = "which"; - if (twiplatform === "win32") { cmd = "where"; } - try { - if (require('child_process').spawnSync(cmd, [dependency]).status !== 0) { - spinner.fail("Checking dependencies... failed") - die(c.red("error: ") + "package '" + argv.package + "' depends on '" + dependency + "' which is not installed"); - } - } catch (e) { - spinner.fail("Checking dependencies... failed") - die(c.red("error: ") + "unable to check for '" + dependency + "'"); - } - } - spinner.succeed("Checking dependencies... done") - - let version = pkg.verdata.latest; - let publisher = pkg.verdata.publisher.name; - let publisherMail = pkg.verdata.publisher.email; - let date = moment(pkg.verdata.date).fromNow(); - - let signed = false; - let signInfo = ""; - let verified = false; - - if (pkg.sign.signed) { - signed = true; - verified = pkg.sign.verified; - if (pkg.sign.signer.name && pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.name + " <" + pkg.sign.signer.email + "> " + c.gray("(" + pkg.sign.key + ")"); - } else if (pkg.sign.signer.name && pkg.sign.key) { - signInfo = pkg.sign.signer.name + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.email + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.key) { - signInfo = pkg.sign.key; - } - } - - console.log(" Installing '" + pkg.name + "'...") - console.log(" version: " + version); - console.log(" release: " + date); - console.log(" publisher: " + publisher + " <" + publisherMail + ">"); - - if (signed) { - if (verified) { - console.log(" security: " + c.green("verified") + " " + signInfo); - } else { - console.log(" security: " + c.yellow("unverified") + " " + signInfo); - } - } else { - console.log(" security: " + c.red.inverse("unsafe")); - } - - if (typeof pkg.deprecated === "string") { - if (pkg.deprecated.toString().trim() !== "") { - console.log(c.yellow("warn: ") + "package '" + pkg.id + "' has been marked as deprecated: " + pkg.deprecated); - } else { - console.log(c.yellow("warn: ") + "package '" + pkg.id + "' has been marked as deprecated"); - } - } - - try { - if (!signed && !ignoreUnsignedPackages && !(await prompts.confirm({ - message: "This package is unsafe, installing it may damage your system. Are you sure you want to continue?", - initial: false - }))) { - die(); - } - } catch (e) { - die(); - } - - if (fs.existsSync(home + "/buildroot")) { fs.rmSync(home + "/buildroot", { recursive: true }) } - require('../hooks/clone')(pkg.repo, pkg.branch, () => { - spinner = ora("Extracting package...").start(); - fs.renameSync(home + "/buildroot", home + "/packages/" + (twiplatform === "alicorn" ? pkg.id.replaceAll("_", "-").replaceAll(".", "-").split("-").map((i) => { return i.substring(0, 1).toUpperCase() + i.substring(1).toLowerCase() }).join("") : pkg.id)); - installed.push({ - id: pkg.id, - date: new Date().toISOString(), - version, - files: require('../hooks/files')(pkg.id) - }) - fs.writeFileSync(os.homedir() + "/.twilight/installed.json", JSON.stringify(installed)); - spinner.succeed("Extracting package... done"); - console.log(" Size change: +" + require('../hooks/size')(pkg.id)); - - let exec = argv.package; - if (typeof JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()).execname === "string") { - exec = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()).execname; - } - - if (twiplatform === "win32" && typeof pkg.executable.windows === "string") { - fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + exec + ".bat", pkg.executable.windows); - } else if (twiplatform === "linux" && typeof pkg.executable.linux === "string") { - fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + exec, pkg.executable.linux); - require('child_process').spawnSync("chmod", [ "+x", os.homedir() + "/.twilight/binaries/" + exec ]) - } else if (twiplatform === "darwin" && typeof pkg.executable.mac === "string") { - fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + exec, pkg.executable.mac); - require('child_process').spawnSync("chmod", [ "+x", os.homedir() + "/.twilight/binaries/" + exec ]) - } else if (twiplatform === "alicorn" && typeof pkg.executable.alicorn === "string") { - fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + exec, pkg.executable.alicorn); - require('child_process').spawnSync("chmod", [ "+x", os.homedir() + "/.twilight/binaries/" + exec ]) - } - - let postinstall = []; - if (twiplatform === "win32") postinstall = pkg.postinstall.windows; - if (twiplatform === "linux") postinstall = pkg.postinstall.linux; - if (twiplatform === "darwin") postinstall = pkg.postinstall.mac; - if (twiplatform === "alicorn") postinstall = pkg.postinstall.alicorn; - - if (postinstall.length > 0) { - spinner = ora("Running post-install hooks...").start(); - for (let hook of postinstall) { - require('child_process').execSync(hook, { stdio: "inherit" }) - } - spinner.succeed("Running post-install hooks... done"); - } - }) -} \ No newline at end of file diff --git a/commands/installable.js b/commands/installable.js deleted file mode 100644 index db7e30f..0000000 --- a/commands/installable.js +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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. - * - */ - -module.exports = async () => { - let packages = JSON.parse(fs.readFileSync(home + "/repository/list.json").toString()).sort(); - let installed = JSON.parse(fs.readFileSync(home + "/installed.json").toString()).map(i => i.id); - let installs = JSON.parse(fs.readFileSync(home + "/installed.json").toString()); - - let signs = {}; - let dates = {}; - let platforms = {}; - - for (let pkg of packages) { - let dir = pkg.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pack = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg + ".json").toString()); - - let signed = false; - let signInfo = ""; - let verified = false; - - if (pack.sign.signed) { - signed = true; - verified = pack.sign.verified; - if (pack.sign.signer.name && pack.sign.signer.email && pack.sign.key) { - signInfo = pack.sign.signer.name + " <" + pack.sign.signer.email + "> " + c.gray("(" + pack.sign.key + ")"); - } else if (pack.sign.signer.name && pack.sign.key) { - signInfo = pack.sign.signer.name + c.gray(" (" + pack.sign.key + ")"); - } else if (pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.email + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.key) { - signInfo = pkg.sign.key; - } - } - - if (signed) { - if (verified) { - signs[pack.id] = c.green("verified"); - } else { - signs[pack.id] = c.yellow("unverified"); - } - } else { - signs[pack.id] = c.red("unsafe"); - } - - if (pack.platforms.windows === 2 && pack.platforms.linux === 2 && pack.platforms.mac === 2 && pack.platforms.alicorn === 2) { - platforms[pack.id] = c.cyan("all"); - } else if (pack.platforms.windows === 1 && pack.platforms.linux === 1 && pack.platforms.mac === 1 && pack.platforms.alicorn === 1) { - platforms[pack.id] = c.yellow("all"); - } else { - platforms[pack.id] = ""; - if (pack.platforms.windows === 1) { platforms[pack.id] += c.yellow("win32") + "," } - if (pack.platforms.windows === 2) { platforms[pack.id] += c.cyan("win32") + "," } - if (pack.platforms.linux === 1) { platforms[pack.id] += c.yellow("linux") + "," } - if (pack.platforms.linux === 2) { platforms[pack.id] += c.cyan("linux") + "," } - if (pack.platforms.mac === 1) { platforms[pack.id] += c.yellow("macos") + "," } - if (pack.platforms.mac === 2) { platforms[pack.id] += c.cyan("macos") + "," } - if (pack.platforms.alicorn === 1) { platforms[pack.id] += c.yellow("alicorn") + "," } - if (pack.platforms.alicorn === 2) { platforms[pack.id] += c.cyan("alicorn") + "," } - - if (platforms[pack.id].endsWith(",")) { platforms[pack.id] = platforms[pack.id].substring(0, platforms[pack.id].length - 1) } - } - } - - for (let pkg of packages) { - let dir = pkg.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pack = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg + ".json").toString()); - - installable = true; - if (twiplatform === "win32" && pack.platforms.windows === 0) { - installable = false; - } else if (twiplatform === "linux" && pack.platforms.linux === 0) { - installable = false; - } else if (twiplatform === "darwin" && pack.platforms.mac === 0) { - installable = false; - } else if (twiplatform === "alicorn" && pack.platforms.alicorn === 0) { - installable = false; - } - - if (installable) { - console.log(c.green(pack.id) + "/" + signs[pack.id] + " " + pack.verdata.latest + " " + platforms[pack.id]) - } - } -} \ No newline at end of file diff --git a/commands/installed.js b/commands/installed.js deleted file mode 100644 index b1f048b..0000000 --- a/commands/installed.js +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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. - * - */ - -module.exports = async () => { - let packages = JSON.parse(fs.readFileSync(home + "/repository/list.json").toString()).sort(); - let installed = JSON.parse(fs.readFileSync(home + "/installed.json").toString()).map(i => i.id); - let installs = JSON.parse(fs.readFileSync(home + "/installed.json").toString()); - - let signs = {}; - let dates = {}; - let platforms = {}; - - for (let pkg of packages) { - let dir = pkg.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pack = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg + ".json").toString()); - - let signed = false; - let signInfo = ""; - let verified = false; - - if (pack.sign.signed) { - signed = true; - verified = pack.sign.verified; - if (pack.sign.signer.name && pack.sign.signer.email && pack.sign.key) { - signInfo = pack.sign.signer.name + " <" + pack.sign.signer.email + "> " + c.gray("(" + pack.sign.key + ")"); - } else if (pack.sign.signer.name && pack.sign.key) { - signInfo = pack.sign.signer.name + c.gray(" (" + pack.sign.key + ")"); - } else if (pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.email + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.key) { - signInfo = pkg.sign.key; - } - } - - if (signed) { - if (verified) { - signs[pack.id] = c.green("verified"); - } else { - signs[pack.id] = c.yellow("unverified"); - } - } else { - signs[pack.id] = c.red("unsafe"); - } - - if (pack.platforms.windows === 2 && pack.platforms.linux === 2 && pack.platforms.mac === 2 && pack.platforms.alicorn === 2) { - platforms[pack.id] = c.cyan("all"); - } else if (pack.platforms.windows === 1 && pack.platforms.linux === 1 && pack.platforms.mac === 1 && pack.platforms.alicorn === 1) { - platforms[pack.id] = c.yellow("all"); - } else { - platforms[pack.id] = ""; - if (pack.platforms.windows === 1) { platforms[pack.id] += c.yellow("win32") + "," } - if (pack.platforms.windows === 2) { platforms[pack.id] += c.cyan("win32") + "," } - if (pack.platforms.linux === 1) { platforms[pack.id] += c.yellow("linux") + "," } - if (pack.platforms.linux === 2) { platforms[pack.id] += c.cyan("linux") + "," } - if (pack.platforms.mac === 1) { platforms[pack.id] += c.yellow("macos") + "," } - if (pack.platforms.mac === 2) { platforms[pack.id] += c.cyan("macos") + "," } - if (pack.platforms.alicorn === 1) { platforms[pack.id] += c.yellow("alicorn") + "," } - if (pack.platforms.alicorn === 2) { platforms[pack.id] += c.cyan("alicorn") + "," } - - if (platforms[pack.id].endsWith(",")) { platforms[pack.id] = platforms[pack.id].substring(0, platforms[pack.id].length - 1) } - } - } - - for (let pkg of packages) { - let dir = pkg.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pack = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg + ".json").toString()); - - let add = ""; - if (installed.includes(pack.id)) { - console.log(c.green(pack.id) + "/" + signs[pack.id] + " " + pack.verdata.latest + " " + platforms[pack.id] + add) - } - } -} \ No newline at end of file diff --git a/commands/list.js b/commands/list.js deleted file mode 100644 index a9560ef..0000000 --- a/commands/list.js +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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. - * - */ - -module.exports = async () => { - let packages = JSON.parse(fs.readFileSync(home + "/repository/list.json").toString()).sort(); - let installed = JSON.parse(fs.readFileSync(home + "/installed.json").toString()).map(i => i.id); - let installs = JSON.parse(fs.readFileSync(home + "/installed.json").toString()); - - let signs = {}; - let dates = {}; - let platforms = {}; - - for (let pkg of packages) { - let dir = pkg.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pack = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg + ".json").toString()); - - let signed = false; - let signInfo = ""; - let verified = false; - - if (pack.sign.signed) { - signed = true; - verified = pack.sign.verified; - if (pack.sign.signer.name && pack.sign.signer.email && pack.sign.key) { - signInfo = pack.sign.signer.name + " <" + pack.sign.signer.email + "> " + c.gray("(" + pack.sign.key + ")"); - } else if (pack.sign.signer.name && pack.sign.key) { - signInfo = pack.sign.signer.name + c.gray(" (" + pack.sign.key + ")"); - } else if (pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.email + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.key) { - signInfo = pkg.sign.key; - } - } - - if (signed) { - if (verified) { - signs[pack.id] = c.green("verified"); - } else { - signs[pack.id] = c.yellow("unverified"); - } - } else { - signs[pack.id] = c.red("unsafe"); - } - - if (pack.platforms.windows === 2 && pack.platforms.linux === 2 && pack.platforms.mac === 2 && pack.platforms.alicorn === 2) { - platforms[pack.id] = c.cyan("all"); - } else if (pack.platforms.windows === 1 && pack.platforms.linux === 1 && pack.platforms.mac === 1 && pack.platforms.alicorn === 1) { - platforms[pack.id] = c.yellow("all"); - } else { - platforms[pack.id] = ""; - if (pack.platforms.windows === 1) { platforms[pack.id] += c.yellow("win32") + "," } - if (pack.platforms.windows === 2) { platforms[pack.id] += c.cyan("win32") + "," } - if (pack.platforms.linux === 1) { platforms[pack.id] += c.yellow("linux") + "," } - if (pack.platforms.linux === 2) { platforms[pack.id] += c.cyan("linux") + "," } - if (pack.platforms.mac === 1) { platforms[pack.id] += c.yellow("macos") + "," } - if (pack.platforms.mac === 2) { platforms[pack.id] += c.cyan("macos") + "," } - if (pack.platforms.alicorn === 1) { platforms[pack.id] += c.yellow("alicorn") + "," } - if (pack.platforms.alicorn === 2) { platforms[pack.id] += c.cyan("alicorn") + "," } - - if (platforms[pack.id].endsWith(",")) { platforms[pack.id] = platforms[pack.id].substring(0, platforms[pack.id].length - 1) } - } - } - - for (let pkg of packages) { - let dir = pkg.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pack = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg + ".json").toString()); - - let add = ""; - if (installed.includes(pack.id)) { - if (installs.filter(i => i.id === pack.id)[0].version !== pack.verdata.latest) { - add = c.gray(" [upgradable]"); - } else { - add = c.gray(" [installed]"); - } - } - - console.log(c.green(pack.id) + "/" + signs[pack.id] + " " + pack.verdata.latest + " " + platforms[pack.id] + add) - } -} \ No newline at end of file diff --git a/commands/purge.js b/commands/purge.js deleted file mode 100644 index f698bdc..0000000 --- a/commands/purge.js +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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. - * - */ - -module.exports = async (argv) => { - const installed = JSON.parse(fs.readFileSync(home + "/installed.json").toString()); - if (!installed.map(i => i.id).includes(argv.package)) { - die(c.red("error: ") + "package '" + argv.package + "' is not installed"); - } - - let spinner = ora("Reading package lists...").start(); - let packages = JSON.parse(fs.readFileSync(home + "/repository/list.json").toString()); - spinner.succeed("Reading packages lists... done"); - - let dir = argv.package.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - - if (!packages.includes(argv.package)) { - console.log(c.yellow("warn: ") + "package '" + argv.package + "' not in repository anymore"); - name = argv.package; - } else { - name = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()).name; - } - - instInfo = installed.filter(i => i.id === argv.package)[0]; - - console.log(" Purging '" + name + "'...") - console.log(" version: " + instInfo.version); - console.log(" installed: " + moment(instInfo.date).fromNow()); - - try { - if (!(await prompts.confirm({ - message: "Purging this package will delete all associated data. Are you sure you want to continue?", - initial: false - }))) { - die(); - } - } catch (e) { - die(); - } - - spinner = ora("Reading files list...").start(); - files1 = instInfo.files; - files2 = require('../hooks/files')(instInfo.id); - filesR = files2.filter(f => !files1.includes(f)); - spinner.succeed("Reading files list... done"); - if (filesR.length === 0) { - die(c.red("error: ") + "this installation of package '" + argv.package + "' cannot be purged, use 'twi reinstall' instead"); - } - - spinner = ora("Removing user files...").start(); - let index = 0 - for (let file of filesR) { - spinner.text = "Removing user files... " + Math.round((index / filesR.length) * 100) + "%"; - fs.rmSync(home + "/packages/" + argv.package + "/" + file); - index++; - } - spinner.succeed("Removing user files... done"); -} \ No newline at end of file diff --git a/commands/reinstall.js b/commands/reinstall.js deleted file mode 100644 index dbadf8a..0000000 --- a/commands/reinstall.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - * - */ - -module.exports = async (argv) => { - await require('./remove')(argv, true); - fs.writeFileSync(os.homedir() + "/.twilight/installed.json", JSON.stringify(JSON.parse(fs.readFileSync(os.homedir() + "/.twilight/installed.json").toString()).filter(i => i !== null))); - await require('./install')(argv); -} \ No newline at end of file diff --git a/commands/remove.js b/commands/remove.js deleted file mode 100644 index 7ee1caa..0000000 --- a/commands/remove.js +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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. - * - */ - -module.exports = async (argv, reinstalling) => { - if (reinstalling === undefined) { - reinstalling = false; - } - - const installed = JSON.parse(fs.readFileSync(home + "/installed.json").toString()); - if (!installed.map(i => i.id).includes(argv.package)) { - die(c.red("error: ") + "package '" + argv.package + "' is not installed"); - } - - let spinner = ora("Reading package lists...").start(); - let packages = JSON.parse(fs.readFileSync(home + "/repository/list.json").toString()); - spinner.succeed("Reading packages lists... done"); - let updated = false; - - let dir = argv.package.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - - if (!packages.includes(argv.package)) { - console.log(c.yellow("warn: ") + "package '" + argv.package + "' not in repository anymore, unable to fetch for name"); - name = argv.package; - } else { - name = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()).name; - } - - if (argv.package === "twilight") { - die(c.red("error: ") + "package 'twilight' is system package and cannot be uninstalled, use 'twilight-setup' instead"); - } - - instInfo = installed.filter(i => i.id === argv.package)[0]; - - console.log(" Uninstalling '" + name + "'...") - console.log(" version: " + instInfo.version); - console.log(" installed: " + moment(instInfo.date).fromNow()); - console.log(" size: " + require('../hooks/size.js')(argv.package)); - - if (reinstalling) { - try { - if (!(await prompts.confirm({ - message: "Reinstalling this package will delete all associated data. Are you sure you want to continue?", - initial: false - }))) { - die(); - } - } catch (e) { - die(); - } - } else { - try { - if (!(await prompts.confirm({ - message: "Uninstalling this package will also delete all associated data. Are you sure you want to continue?", - initial: false - }))) { - die(); - } - } catch (e) { - die(); - } - } - - spinner = ora("Removing package...").start(); - fs.rmSync(home + "/packages/" + (twiplatform === "alicorn" ? argv.package.replaceAll("_", "-").replaceAll(".", "-").split("-").map((i) => { return i.substring(0, 1).toUpperCase() + i.substring(1).toLowerCase() }).join("") : argv.package), { recursive: true }); - delete installed[installed.map(i => i.id).indexOf(argv.package)]; - fs.writeFileSync(os.homedir() + "/.twilight/installed.json", JSON.stringify(installed)); - - let exec = argv.package; - if (!packages.includes(argv.package)) { - exec = argv.package; - } else if (typeof JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()).execname === "string") { - exec = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()).execname; - } - if (fs.existsSync(os.homedir() + "/.twilight/binaries/" + exec + ".bat")) fs.unlinkSync(os.homedir() + "/.twilight/binaries/" + exec + ".bat"); - if (fs.existsSync(os.homedir() + "/.twilight/binaries/" + exec + ".sh")) fs.unlinkSync(os.homedir() + "/.twilight/binaries/" + exec + ".sh"); - if (fs.existsSync(os.homedir() + "/.twilight/binaries/" + exec)) fs.unlinkSync(os.homedir() + "/.twilight/binaries/" + exec); - - spinner.succeed("Removing package... done"); - - if (!packages.includes(argv.package)) { - console.log(c.yellow("warn: ") + "package '" + argv.package + "' not in repository anymore, unable to fetch for post-remove hooks"); - } else { - ppr = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()).postremove; - - let postremove = []; - if (twiplatform === "win32") postremove = ppr.windows; - if (twiplatform === "linux") postremove = ppr.linux; - if (twiplatform === "darwin") postremove = ppr.mac; - if (twiplatform === "alicorn") postremove = ppr.alicorn; - - if (postremove.length > 0) { - spinner = ora("Running post-remove hooks...").start(); - for (let hook of postremove) { - require('child_process').execSync(hook, { stdio: "inherit" }) - } - spinner.succeed("Running post-remove hooks... done"); - } - } -} \ No newline at end of file diff --git a/commands/update.js b/commands/update.js deleted file mode 100644 index ad34165..0000000 --- a/commands/update.js +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - * - */ - -module.exports = async (argv) => { - await require('../hooks/update')(); -} \ No newline at end of file diff --git a/commands/upgrade.js b/commands/upgrade.js deleted file mode 100644 index 6ba31f3..0000000 --- a/commands/upgrade.js +++ /dev/null @@ -1,245 +0,0 @@ -/* - * 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. - * - */ - -async function processQueue() { - let pack = installed.filter(i => i.id === queue[0])[0]; - let dir = pack.id.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pkg = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pack.id + ".json").toString()); - let installable = true; - - let version = pkg.verdata.latest; - let publisher = pkg.verdata.publisher.name; - let publisherMail = pkg.verdata.publisher.email; - let date = moment(pkg.verdata.date).fromNow(); - - let signed = false; - let signInfo = ""; - let verified = false; - - if (pkg.sign.signed) { - signed = true; - verified = pkg.sign.verified; - if (pkg.sign.signer.name && pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.name + " <" + pkg.sign.signer.email + "> " + c.gray("(" + pkg.sign.key + ")"); - } else if (pkg.sign.signer.name && pkg.sign.key) { - signInfo = pkg.sign.signer.name + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.email + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.key) { - signInfo = pkg.sign.key; - } - } - - spinner = ora("Checking dependencies...").start(); - for (let dependency of pkg.depends) { - let cmd = "which"; - if (twiplatform === "win32") { cmd = "where"; } - try { - if (require('child_process').spawnSync(cmd, [dependency]).status !== 0) { - spinner.fail("Checking dependencies... failed") - die(c.red("error: ") + "package '" + pack.id + "' depends on '" + dependency + "' which is not installed"); - } - } catch (e) { - spinner.fail("Checking dependencies... failed") - die(c.red("error: ") + "unable to check for '" + dependency + "'"); - } - } - spinner.succeed("Checking dependencies... done") - - console.log(" Installing '" + pkg.name + "'...") - console.log(" version: " + pack.version + " -> " + version); - console.log(" release: " + date); - console.log(" publisher: " + publisher + " <" + publisherMail + ">"); - - if (signed) { - if (verified) { - console.log(" security: " + c.green("verified") + " " + signInfo); - } else { - console.log(" security: " + c.yellow("unverified") + " " + signInfo); - } - } else { - console.log(" security: " + c.red.inverse("unsafe")); - } - - try { - if (!signed && !ignoreUnsignedPackages && !(await prompts.confirm({ - message: "This package is unsafe, installing it may damage your system. Are you sure you want to continue?", - initial: false - }))) { - installable = false; - } - } catch (e) { - installable = false; - } - - if (installable) { - if (fs.existsSync(home + "/buildroot")) { fs.rmSync(home + "/buildroot", { recursive: true }) } - require('../hooks/clone')(pkg.repo, pkg.branch, async () => { - spinner = ora("Extracting package...").start(); - if (fs.existsSync(home + "/packages/" + pkg.id + "--update-" + version)) fs.rmSync(home + "/packages/" + pkg.id + "--update-" + version, { recursive: true }) - fs.renameSync(home + "/buildroot", home + "/packages/" + pkg.id + "--update-" + version); - let change = require('../hooks/diff')((twiplatform === "alicorn" ? pkg.id.replaceAll("_", "-").replaceAll(".", "-").split("-").map((i) => { return i.substring(0, 1).toUpperCase() + i.substring(1).toLowerCase() }).join("") : pkg.id), pkg.id + "--update-" + version); - require('../hooks/apply_update')(pkg.id, pkg.id + "--update-" + version); - fs.rmSync(home + "/packages/" + pkg.id + "--update-" + version, { recursive: true }); - delete installed[installed.map(i => i.id).indexOf(pkg.id)]; - installed.push({ - id: pkg.id, - date: new Date().toISOString(), - version, - files: require('../hooks/files')(pkg.id) - }) - fs.writeFileSync(os.homedir() + "/.twilight/installed.json", JSON.stringify(installed)); - spinner.succeed("Extracting package... done"); - console.log(" Size change: " + change); - - let exec = pkg.id; - if (typeof JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg.id + ".json").toString()).execname === "string") { - exec = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg.id + ".json").toString()).execname; - } - - if (twiplatform === "win32" && typeof pkg.executable.windows === "string") { - fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + pkg.id + ".bat", pkg.executable.windows); - } else if (twiplatform === "linux" && typeof pkg.executable.linux === "string") { - fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + exec, pkg.executable.linux); - require('child_process').spawnSync("chmod", [ "+x", os.homedir() + "/.twilight/binaries/" + exec ]) - } else if (twiplatform === "darwin" && typeof pkg.executable.mac === "string") { - fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + exec, pkg.executable.mac); - require('child_process').spawnSync("chmod", [ "+x", os.homedir() + "/.twilight/binaries/" + exec ]) - } else if (twiplatform === "alicorn" && typeof pkg.executable.alicorn === "string") { - fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + exec, pkg.executable.alicorn); - require('child_process').spawnSync("chmod", [ "+x", os.homedir() + "/.twilight/binaries/" + exec ]) - } - - let postinstall = []; - if (twiplatform === "win32") postinstall = pkg.postinstall.windows; - if (twiplatform === "linux") postinstall = pkg.postinstall.linux; - if (twiplatform === "darwin") postinstall = pkg.postinstall.mac; - if (twiplatform === "alicorn") postinstall = pkg.postinstall.alicorn; - - if (postinstall.length > 0) { - spinner = ora("Running post-install hooks...").start(); - for (let hook of postinstall) { - require('child_process').execSync(hook, { stdio: "inherit" }) - } - spinner.succeed("Running post-install hooks... done"); - } - - queue.shift(); - if (queue.length > 0) await processQueue(); - }) - } -} - -module.exports = async (argv) => { - global.installed = JSON.parse(fs.readFileSync(home + "/installed.json").toString()); - - let spinner = ora("Reading package lists...").start(); - let packages = JSON.parse(fs.readFileSync(home + "/repository/list.json").toString()); - spinner.succeed("Reading packages lists... done"); - let updated = false; - let affected = false; - global.queue = []; - - for (let pack of installed) { - if (!packages.includes(pack.id)) { - console.log(c.yellow("warn: ") + "package '" + pack.id + "' not in repository anymore"); - } else { - let installable = true; - let dir = pack.id.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#"); - let pkg = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pack.id + ".json").toString()); - if ((argv.package !== undefined && argv.package === pack.id) || argv.package === undefined) { - updated = true; - - if (twiplatform === "win32" && pkg.platforms.windows === 0) { - console.log(c.yellow("warn: ") + "package '" + pack.id + "' not available on platform 'win32' anymore"); - installable = false; - } else if (twiplatform === "linux" && pkg.platforms.linux === 0) { - console.log(c.yellow("warn: ") + "package '" + pack.id + "' not available on platform 'linux' anymore"); - installable = false; - } else if (twiplatform === "darwin" && pkg.platforms.mac === 0) { - console.log(c.yellow("warn: ") + "package '" + pack.id + "' not available on platform 'macos' anymore"); - installable = false; - } else if (twiplatform === "alicorn" && pkg.platforms.alicorn === 0) { - console.log(c.yellow("warn: ") + "package '" + pack.id + "' not available on platform 'alicorn' anymore"); - installable = false; - } - - if (twiplatform === "win32" && pkg.platforms.windows === 1) { - console.log(c.yellow("warn: ") + "package '" + pack.id + "' is experimental on platform 'win32'"); - } else if (twiplatform === "linux" && pkg.platforms.linux === 1) { - console.log(c.yellow("warn: ") + "package '" + pack.id + "' is experimental on platform 'linux'"); - } else if (twiplatform === "darwin" && pkg.platforms.mac === 1) { - console.log(c.yellow("warn: ") + "package '" + pack.id + "' is experimental on platform 'macos'"); - } else if (twiplatform === "alicorn" && pkg.platforms.mac === 1) { - console.log(c.yellow("warn: ") + "package '" + pack.id + "' is experimental on platform 'alicorn'"); - } - - if (installable) { - let version = pkg.verdata.latest; - let publisher = pkg.verdata.publisher.name; - let publisherMail = pkg.verdata.publisher.email; - let date = moment(pkg.verdata.date).fromNow(); - - let signed = false; - let signInfo = ""; - let verified = false; - - if (pkg.sign.signed) { - signed = true; - verified = pkg.sign.verified; - if (pkg.sign.signer.name && pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.name + " <" + pkg.sign.signer.email + "> " + c.gray("(" + pkg.sign.key + ")"); - } else if (pkg.sign.signer.name && pkg.sign.key) { - signInfo = pkg.sign.signer.name + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.signer.email && pkg.sign.key) { - signInfo = pkg.sign.signer.email + c.gray(" (" + pkg.sign.key + ")"); - } else if (pkg.sign.key) { - signInfo = pkg.sign.key; - } - } - - if (pack.version !== version) { - queue.push(pack.id); - affected = true; - } else if (argv.package !== undefined && argv.package === pack.id) { - die(c.red("error: ") + "package '" + argv.package + "' is up to date"); - } - } else if (argv.package !== undefined && argv.package === pack.id) { - die(c.red("error: ") + "package '" + argv.package + "' cannot be updated"); - } - } - } - } - - if (!updated) { - die(c.red("error: ") + "package '" + argv.package + "' not installed"); - } - - if (!affected) { - die("All packages are up to date"); - } - - await processQueue(); -} \ No newline at end of file -- cgit