diff options
author | Minteck <contact@minteck.org> | 2022-02-12 12:09:34 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-02-12 12:09:34 +0100 |
commit | 38e7fbe2f99a5d0b6a69e54ab3af7ebf451e8f4f (patch) | |
tree | 33266f2ba82dd1e22fe85cf77bc0b559e3917af8 /commands/install.js | |
parent | 01160246e4a0c0052181c72a53737e356ea7d02d (diff) | |
download | twilight-38e7fbe2f99a5d0b6a69e54ab3af7ebf451e8f4f.tar.gz twilight-38e7fbe2f99a5d0b6a69e54ab3af7ebf451e8f4f.tar.bz2 twilight-38e7fbe2f99a5d0b6a69e54ab3af7ebf451e8f4f.zip |
Update
Diffstat (limited to 'commands/install.js')
-rw-r--r-- | commands/install.js | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/commands/install.js b/commands/install.js index c2da58a..b65725d 100644 --- a/commands/install.js +++ b/commands/install.js @@ -15,12 +15,39 @@ module.exports = async (argv) => { 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 (os.platform() === "win32" && pkg.platforms.windows === 0) { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'win32'"); + if (typeof pkg.replaced.windows === "string") { + replacement = pkg.replaced.windows + } + } else if (os.platform() === "linux" && pkg.platforms.linux === 0) { + if (typeof pkg.replaced.linux === "string") { + replacement = pkg.replaced.linux + } + } else if (os.platform() === "darwin" && pkg.platforms.mac === 0) { + if (typeof pkg.replaced.mac === "string") { + replacement = pkg.replaced.mac + } + } + + if (os.platform() === "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) { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'linux'"); + 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) { - die(c.red("error: ") + "package '" + argv.package + "' not available on platform 'macos'"); + 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"); + } } if (os.platform() === "win32" && pkg.platforms.windows === 1) { @@ -85,7 +112,7 @@ module.exports = async (argv) => { console.log(" security: " + c.red.inverse("unsafe")); } - if (pkg.deprecated) { + if (typeof pkg.deprecated === "string") { if (pkg.deprecated.toString().trim() !== "") { console.log(c.yellow("warn: ") + "package '" + pkg.name + "' has been marked as deprecated: " + pkg.deprecated); } else { @@ -117,5 +144,18 @@ module.exports = async (argv) => { 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 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 (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 |