From 8e5a02fbe012c9fa5fa34961857f73936c6491a9 Mon Sep 17 00:00:00 2001
From: Unknown
Date: Fri, 20 Apr 2018 18:19:57 +0100
Subject: add descriptions and api docs
---
pkg93.js | 126 ++++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 81 insertions(+), 45 deletions(-)
(limited to 'pkg93.js')
diff --git a/pkg93.js b/pkg93.js
index 3152c43..44058f6 100644
--- a/pkg93.js
+++ b/pkg93.js
@@ -1,19 +1,3 @@
-/***************************
- * This code was created *
- * by 1024x2, and is *
- * licensed under the MIT *
- * License, which means *
- * you can do whatever you *
- * want on it as long as *
- * you keep this copyright *
- * notice included with *
- * this software. Please *
- * respect that by not *
- * deleting 'LICENSE' or *
- * this notice. Thank you! *
- * ~1024x2 *
- ***************************/
-
console.group("[pkg93]");
console.log("[pkg93] Injecting packages...");
try {
@@ -40,8 +24,8 @@ var pkg93 = {
}
},
pull: function() {
- var config = pkg93.getConfig();
- var request = new XMLHttpRequest();
+ var config = pkg93.getConfig(),
+ request = new XMLHttpRequest();
$log("WARN Windows93 may lag while getting packages.\n This is a normal thing.");
config.pkglist = [];
config.repos.forEach(function (source) {
@@ -68,8 +52,8 @@ var pkg93 = {
localStorage[".pkg93/config.json"] = JSON.stringify(config);
},
get: function(pkg) {
- var config = pkg93.getConfig();
- var request = new XMLHttpRequest();
+ var config = pkg93.getConfig(),
+ request = new XMLHttpRequest();
$log("SRCH " + pkg);
var index = config.pkglist.findIndex(function(string) {
return string.split("@")[0] == pkg;
@@ -119,9 +103,9 @@ var pkg93 = {
}
},
rm: function(pkg) {
- var config = pkg93.getConfig();
- var request = new XMLHttpRequest();
- var index = config.installed.indexOf(pkg);
+ var config = pkg93.getConfig(),
+ request = new XMLHttpRequest(),
+ index = config.installed.indexOf(pkg);
if (index < 0) {
$log("ERR Not found.");
return false;
@@ -152,6 +136,33 @@ var pkg93 = {
return false;
}
}
+ },
+ pkgInfo: function (pkg, onlineOnly) {
+ var config = pkg93.getConfig(),
+ request = new XMLHttpRequest();
+ try {
+ if (localStorage[".pkg93/packages/" + pkg + ".json"] && !onlineOnly) {
+ return JSON.parse(localStorage[".pkg93/packages/" + pkg + ".json"]);
+ } else {
+ var index = config.pkglist.findIndex(function(string) {
+ return string.split("@")[0] == pkg;
+ });
+ if (index < 0) {
+ return false;
+ } else {
+ var pkgname = config.pkglist[index].split("@")[0];
+ var pkgsource = config.pkglist[index].split("@")[1];
+ request.open('GET', pkgsource + "/" + pkgname + "/package.json", false);
+ request.send(null);
+ var json = JSON.parse(request.responseText);
+ localStorage[".pkg93/packages/" + pkgname + ".json"] = request.responseText; // save it for later
+ return json;
+ }
+ }
+ } catch (err) {
+ console.error("[pkg93] " + err.stack);
+ return false;
+ }
}
}
@@ -164,19 +175,21 @@ le._apps.pkg93 = {
Usage: pkg93 [command]
List of Commands
-pull Updates package listing
-get [package] Installs a package
-rm [package] Uninstalls a package
-add-repo [url] Adds a repository
-rm-repo [id] Removes a repository
-ls [pkgs|installed|repos] Lists all packages, installed
+pull Updates package listing
+get [package] Installs a package
+rm [package] Uninstalls a package
+add-repo [url] Adds a repository
+rm-repo [id] Removes a repository
+info [pkg] Gets information on a package
+ls [pkgs|installed|repos] Lists packages, installed
packages or repositories.
Color meanings
-Executing OK Error Warning
+Executing OK Error Warning Info
Examples
-pkg93 get gud
-pkg93 rm kebab`;
+pkg93 get gud
+pkg93 rm kebab
+`;
if (localStorage[".pkg93/config.json"] === undefined) {
localStorage[".pkg93/config.json"] = '{"repos": ["http://codinggamerhd.com/main-repo"], "installed": [], "pkglist": []}';
}
@@ -206,20 +219,28 @@ pkg93 rm kebab`;
pkg93.rm(args[1]);
}
} else if (args[0] == "add-repo") {
- try {
- config.repos.push(args[1]); // well, that was easy
- localStorage[".pkg93/config.json"] = JSON.stringify(config);
- $log("OK Done!\n Run \"pkg93 pull\" to update the package listing.");
- } catch (err) {
- $log("ERR " + err.message);
+ if (args.length < 2) {
+ $log("ERR No repository specified.");
+ } else {
+ try {
+ config.repos.push(args[1]); // well, that was easy
+ localStorage[".pkg93/config.json"] = JSON.stringify(config);
+ $log("OK Done!\n Run \"pkg93 pull\" to update the package listing.");
+ } catch (err) {
+ $log("ERR " + err.message);
+ }
}
} else if (args[0] == "rm-repo") {
- try {
- config.repos.splice(parseInt(args[1]), 1);
- localStorage[".pkg93/config.json"] = JSON.stringify(config);
- $log("OK Done!\n Run \"pkg93 pull\" to update the package listing.");
- } catch (err) {
- $log("ERR " + err.message);
+ if (args.length < 2) {
+ $log("ERR No repository specified.");
+ } else {
+ try {
+ config.repos.splice(parseInt(args[1]), 1);
+ localStorage[".pkg93/config.json"] = JSON.stringify(config);
+ $log("OK Done!\n Run \"pkg93 pull\" to update the package listing.");
+ } catch (err) {
+ $log("ERR " + err.message);
+ }
}
} else if (args[0] == "ls") {
if (args[1] == "pkgs") {
@@ -235,6 +256,21 @@ pkg93 rm kebab`;
} else {
$log("ERR You must select either pkgs, installed, or repos.");
}
+ } else if (args[0] == "info") {
+ if (args.length > 2) {
+ $log("ERR No package specified.");
+ } else {
+ var pkgInfo = JSON.parse(pkg93.pkgInfo(args[1]));
+ if (!pkgInfo) {
+ $log("ERR Either the package doesn't exist, or an error occoured.")
+ } else {
+ depends = pkgInfo.dependencies ? pkgInfo.dependencies.join(" , ") : "None!";
+ console.log(pkgInfo);
+ $log(`${pkgInfo.name}
+Description: ${pkgInfo.description}
+Dependencies: ${depends}`);
+ }
+ }
} else if (args[0] == "help") {
$log(help);
} else if (args[0] == "wtf") {
@@ -249,5 +285,5 @@ pkg93 rm kebab`;
icon: "//cdn.rawgit.com/1024x2/pkg93/70039c02/pkg.png",
terminal: true,
hascli: true,
- categories: "Network;"
+ categories: "Network;Utility;Settings;PackageManager"
};
--
cgit v1.2.3