diff options
Diffstat (limited to 'commands/install.js')
-rw-r--r-- | commands/install.js | 51 |
1 files changed, 34 insertions, 17 deletions
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();
|