From 44b4222bc02f102480d1afe05d940612ff6cb983 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sun, 27 Mar 2022 17:56:40 +0200 Subject: WIP Alicorn port (abandonned, To be removed) --- commands/info.js | 19 ++++++++++++------ commands/install.js | 51 ++++++++++++++++++++++++++++++++----------------- commands/installable.js | 14 +++++++++----- commands/installed.js | 6 ++++-- commands/list.js | 6 ++++-- commands/remove.js | 9 +++++---- commands/upgrade.js | 37 +++++++++++++++++++++-------------- 7 files changed, 92 insertions(+), 50 deletions(-) (limited to 'commands') diff --git a/commands/info.js b/commands/info.js index b88e2b3..e7afd40 100644 --- a/commands/info.js +++ b/commands/info.js @@ -41,29 +41,36 @@ module.exports = async (argv) => { let compatible = true; let replacement = null; - if (os.platform() === "win32" && pkg.platforms.windows === 0) { + if (twiplatform === "win32" && pkg.platforms.windows === 0) { compatible = false; if (typeof pkg.replaced.windows === "string") { replacement = pkg.replaced.windows } - } else if (os.platform() === "linux" && pkg.platforms.linux === 0) { + } else if (twiplatform === "linux" && pkg.platforms.linux === 0) { compatible = false; if (typeof pkg.replaced.linux === "string") { replacement = pkg.replaced.linux } - } else if (os.platform() === "darwin" && pkg.platforms.mac === 0) { + } 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 (os.platform() === "win32" && pkg.platforms.windows === 1) { + if (twiplatform === "win32" && pkg.platforms.windows === 1) { + experimental = true; + } else if (twiplatform === "linux" && pkg.platforms.linux === 1) { experimental = true; - } else if (os.platform() === "linux" && pkg.platforms.linux === 1) { + } else if (twiplatform === "darwin" && pkg.platforms.mac === 1) { experimental = true; - } else if (os.platform() === "darwin" && pkg.platforms.mac === 1) { + } else if (twiplatform === "alicorn" && pkg.platforms.alicorn === 1) { experimental = true; } diff --git a/commands/install.js b/commands/install.js index 837f9ef..ebd0a82 100644 --- a/commands/install.js +++ b/commands/install.js @@ -24,6 +24,7 @@ */ 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() + ")"); @@ -41,52 +42,64 @@ module.exports = async (argv) => { let pkg = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()); let replacement = null; - if (os.platform() === "win32" && pkg.platforms.windows === 0) { + if (twiplatform === "win32" && pkg.platforms.windows === 0) { if (typeof pkg.replaced.windows === "string") { replacement = pkg.replaced.windows } - } else if (os.platform() === "linux" && pkg.platforms.linux === 0) { + } else if (twiplatform === "linux" && pkg.platforms.linux === 0) { if (typeof pkg.replaced.linux === "string") { replacement = pkg.replaced.linux } - } else if (os.platform() === "darwin" && pkg.platforms.mac === 0) { + } 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 (os.platform() === "win32" && pkg.platforms.windows === 0) { + 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 (os.platform() === "linux" && pkg.platforms.linux === 0) { + } 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 (os.platform() === "darwin" && pkg.platforms.mac === 0) { + } 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 (os.platform() === "win32" && pkg.platforms.windows === 1) { + if (twiplatform === "win32" && pkg.platforms.windows === 1) { console.log(c.yellow("warn: ") + "package '" + argv.package + "' is experimental on platform 'win32'"); - } else if (os.platform() === "linux" && pkg.platforms.linux === 1) { + } else if (twiplatform === "linux" && pkg.platforms.linux === 1) { console.log(c.yellow("warn: ") + "package '" + argv.package + "' is experimental on platform 'linux'"); - } else if (os.platform() === "darwin" && pkg.platforms.mac === 1) { + } 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 (os.platform() === "win32") { cmd = "where"; } + if (twiplatform === "win32") { cmd = "where"; } try { if (require('child_process').spawnSync(cmd, [dependency]).status !== 0) { spinner.fail("Checking dependencies... failed") @@ -159,7 +172,7 @@ module.exports = async (argv) => { 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/" + pkg.id); + 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(), @@ -175,20 +188,24 @@ module.exports = async (argv) => { exec = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()).execname; } - if (os.platform() === "win32" && typeof pkg.executable.windows === "string") { + if (twiplatform === "win32" && typeof pkg.executable.windows === "string") { fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + exec + ".bat", pkg.executable.windows); - } else if (os.platform() === "linux" && typeof pkg.executable.linux === "string") { + } 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 (os.platform() === "darwin" && typeof pkg.executable.mac === "string") { + } 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 (os.platform() === "win32") postinstall = pkg.postinstall.windows; - if (os.platform() === "linux") postinstall = pkg.postinstall.linux; - if (os.platform() === "darwin") postinstall = pkg.postinstall.mac; + 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(); diff --git a/commands/installable.js b/commands/installable.js index 2c80d58..db7e30f 100644 --- a/commands/installable.js +++ b/commands/installable.js @@ -64,9 +64,9 @@ module.exports = async () => { signs[pack.id] = c.red("unsafe"); } - if (pack.platforms.windows === 2 && pack.platforms.linux === 2 && pack.platforms.mac === 2) { + 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) { + } 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] = ""; @@ -76,6 +76,8 @@ module.exports = async () => { 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) } } @@ -86,11 +88,13 @@ module.exports = async () => { let pack = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg + ".json").toString()); installable = true; - if (os.platform() === "win32" && pack.platforms.windows === 0) { + if (twiplatform === "win32" && pack.platforms.windows === 0) { installable = false; - } else if (os.platform() === "linux" && pack.platforms.linux === 0) { + } else if (twiplatform === "linux" && pack.platforms.linux === 0) { installable = false; - } else if (os.platform() === "darwin" && pack.platforms.mac === 0) { + } else if (twiplatform === "darwin" && pack.platforms.mac === 0) { + installable = false; + } else if (twiplatform === "alicorn" && pack.platforms.alicorn === 0) { installable = false; } diff --git a/commands/installed.js b/commands/installed.js index c22e538..b1f048b 100644 --- a/commands/installed.js +++ b/commands/installed.js @@ -64,9 +64,9 @@ module.exports = async () => { signs[pack.id] = c.red("unsafe"); } - if (pack.platforms.windows === 2 && pack.platforms.linux === 2 && pack.platforms.mac === 2) { + 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) { + } 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] = ""; @@ -76,6 +76,8 @@ module.exports = async () => { 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) } } diff --git a/commands/list.js b/commands/list.js index 871f821..a9560ef 100644 --- a/commands/list.js +++ b/commands/list.js @@ -64,9 +64,9 @@ module.exports = async () => { signs[pack.id] = c.red("unsafe"); } - if (pack.platforms.windows === 2 && pack.platforms.linux === 2 && pack.platforms.mac === 2) { + 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) { + } 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] = ""; @@ -76,6 +76,8 @@ module.exports = async () => { 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) } } diff --git a/commands/remove.js b/commands/remove.js index dc26eae..7ee1caa 100644 --- a/commands/remove.js +++ b/commands/remove.js @@ -83,7 +83,7 @@ module.exports = async (argv, reinstalling) => { } spinner = ora("Removing package...").start(); - fs.rmSync(home + "/packages/" + argv.package, { recursive: true }); + 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)); @@ -105,9 +105,10 @@ module.exports = async (argv, reinstalling) => { ppr = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + argv.package + ".json").toString()).postremove; let postremove = []; - if (os.platform() === "win32") postremove = ppr.windows; - if (os.platform() === "linux") postremove = ppr.linux; - if (os.platform() === "darwin") postremove = ppr.mac; + 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(); diff --git a/commands/upgrade.js b/commands/upgrade.js index ac36fd9..0113278 100644 --- a/commands/upgrade.js +++ b/commands/upgrade.js @@ -55,7 +55,7 @@ async function processQueue() { spinner = ora("Checking dependencies...").start(); for (let dependency of pkg.depends) { let cmd = "which"; - if (os.platform() === "win32") { cmd = "where"; } + if (twiplatform === "win32") { cmd = "where"; } try { if (require('child_process').spawnSync(cmd, [dependency]).status !== 0) { spinner.fail("Checking dependencies... failed") @@ -100,7 +100,7 @@ async function processQueue() { 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')(pkg.id, 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)]; @@ -119,20 +119,24 @@ async function processQueue() { exec = JSON.parse(fs.readFileSync(home + "/repository/" + dir + "/" + pkg.id + ".json").toString()).execname; } - if (os.platform() === "win32" && typeof pkg.executable.windows === "string") { + if (twiplatform === "win32" && typeof pkg.executable.windows === "string") { fs.writeFileSync(os.homedir() + "/.twilight/binaries/" + pkg.id + ".bat", pkg.executable.windows); - } else if (os.platform() === "linux" && typeof pkg.executable.linux === "string") { + } 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 (os.platform() === "darwin" && typeof pkg.executable.mac === "string") { + } 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 (os.platform() === "win32") postinstall = pkg.postinstall.windows; - if (os.platform() === "linux") postinstall = pkg.postinstall.linux; - if (os.platform() === "darwin") postinstall = pkg.postinstall.mac; + 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(); @@ -168,23 +172,28 @@ module.exports = async (argv) => { if ((argv.package !== undefined && argv.package === pack.id) || argv.package === undefined) { updated = true; - if (os.platform() === "win32" && pkg.platforms.windows === 0) { + 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 (os.platform() === "linux" && pkg.platforms.linux === 0) { + } 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 (os.platform() === "darwin" && pkg.platforms.mac === 0) { + } 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 (os.platform() === "win32" && pkg.platforms.windows === 1) { + if (twiplatform === "win32" && pkg.platforms.windows === 1) { console.log(c.yellow("warn: ") + "package '" + pack.id + "' is experimental on platform 'win32'"); - } else if (os.platform() === "linux" && pkg.platforms.linux === 1) { + } else if (twiplatform === "linux" && pkg.platforms.linux === 1) { console.log(c.yellow("warn: ") + "package '" + pack.id + "' is experimental on platform 'linux'"); - } else if (os.platform() === "darwin" && pkg.platforms.mac === 1) { + } 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) { -- cgit