From 152914365aa906fc639cc43ceed620698f5cc976 Mon Sep 17 00:00:00 2001 From: 1024x2 Date: Sat, 11 Aug 2018 17:08:29 +0100 Subject: w --- .eslintrc.js | 2 +- README.md | 34 ++++++++++++++++++--------------- pkg93.js | 61 +++++++++++++++++++++++++++++++++++++----------------------- 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index a882e02..05f6b6e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,7 +19,7 @@ module.exports = { "globals": { "$log": function(){}, "le": { - apps: {} + "_apps": {} }, "$window": function(){}, "$alert": function(){} diff --git a/README.md b/README.md index 1b0f699..359ce8f 100644 --- a/README.md +++ b/README.md @@ -40,15 +40,15 @@ Here's an example: Finally put all the packages in seperate folders named after the package. The end result should look like this: ``` -example-repo +example-repo/ ├── repo.json -├── examplepkg1 +├── examplepkg1/ │ │ (package files go here) │   └── package.json -├── examplepkg2 +├── examplepkg2/ │ │ (package files go here) │   └── package.json -└── examplepkg3 +└── examplepkg3/ │ (package files go here)    └── package.json ``` @@ -59,28 +59,32 @@ Then, you want to make a file called package.json in the folder. In it, there should be 4 keys. - `name`: **Must be the same as the folder name and command name!** (unless you've provided a uninstaller) - `description` A description of your package. +- `versions` All versions of your package, newest version goes first, oldest version goes last. - `inject`: It should be the name of the injection script. - `uninstall`: Optional, It should be the name of the uninstaller script, if it doesn't exist pkg93 will simply delete the command for you. -- `dependencies`: Optional, Packages this package depends on. These will be automatically installed. Here's a example: ```json { "name": "examplepkg", "description": "my kewl pakeg!!11", + "versions": [ + "1.0.0", + "0.9.0" + ], "inject": "installer.js", - "uninstall": "optionaluninstaller.js", - "dependencies": [ - "anoptionaldependency", - "anotherone" - ] + "uninstall": "optionaluninstaller.js" } ``` And the directory structure: ``` -examplepkg +examplepkg/ ├── package.json -├── installer.js -└── optionaluninstaller.js +├── 1.0.0/ +│   ├── installer.js +│ └── optionaluninstaller.js +└── 0.9.9/ +    ├── installer.js + └── optionaluninstaller.js ``` ## API @@ -137,10 +141,10 @@ if (succeded) { ``` ### `pkg93.pkginfo(package)` -Returns the package.json of `package` or `false` if it failed. +Returns the package.json of `package` or an error if it failed. ```js package = await pkg93.pkgInfo("wget93"); -if (package == false) { +if (package instanceof Error) { alert("Something went wrong..."); } else { alert("wget93's description is: " + package.description); diff --git a/pkg93.js b/pkg93.js index 3f241ab..c1f0232 100644 --- a/pkg93.js +++ b/pkg93.js @@ -29,7 +29,7 @@ async function wrap(f) { var originalPrompt = this.cli.prompt.innerHTML; var originalOnenter = this.cli.onenter; - try { + try { this.cli.prompt.innerHTML = ""; this.cli.onenter = () => false; var lastLog = $log(""); @@ -42,6 +42,10 @@ async function wrap(f) { }, arg: this.arg }); + } catch (err) { + console.error(err); + this.cli.prompt.innerHTML = originalPrompt; + this.cli.onenter = originalOnenter; } finally { this.cli.prompt.innerHTML = originalPrompt; this.cli.onenter = originalOnenter; @@ -65,19 +69,15 @@ try { $alert({ title: "Couldn't load pkg93!", msg: "
" + (err.stack || err.toString()) + "
", - btnOk: "Send a bug report", btnCancel: "OK" - }, function(ok) { - if (ok) { - window.open("https://github.com/pkg93/pkg93/issues/new" + - "?title=" + encodeURIComponent(err.toString()) + - "&body=Type what you were doing here...%0A%0A```%0A" + encodeURIComponent(err.stack) + "%0A```", - "_blank"); - } + img: "/c/sys/skins/w93/error.png", + icon: "//cdn.rawgit.com/1024x2/pkg93/70039c02/pkg.png" }); } console.log("%c[pkg93]%c Done!", "font-weight:bold", "font-weight:normal"); console.groupEnd(); + +var errbar = "[---------------------------------------------------] ERR! !"; // thanks robbie! sauce: https://gist.github.com/robbie0630/e1386fb10676598e7d60d4f406a41042 // NOTE: this is a modified version var _abarpkg93uses = (width, percent) => { @@ -131,7 +131,11 @@ var pkg93 = { bardiv.innerHTML = _abarpkg93uses(60, e.loaded / e.total); }; xhr.onerror = () => { + bardiv.innerHTML = errbar; cli.log("ERR Fatal error while retriving package.json."); + if (xhr.status != 0) { + cli.log("ERR " + xhr.status + " " + xhr.statusText); + } }; xhr.onload = () => { try { @@ -164,8 +168,9 @@ var pkg93 = { res(); }); }, - get: async function(pkg, cli) { + get: async function(pkg, version, cli) { cli = cli || {log: (i) => {$log(i);}}; + version = version || "latest"; var config = pkg93.getConfig(); cli.log("SRCH " + pkg); var index = config.pkglist.findIndex(function(string) { @@ -193,18 +198,24 @@ var pkg93 = { }; return new Promise((res, rej) => { xhr.onerror = () => { + bardiv.innerHTML = errbar; cli.log("ERR Fatal error while retriving package.json."); + if (xhr.status == 0) { + cli.log("ERR " + xhr.status + " " + xhr.statusText); + } rej(); }; xhr.onload = () => { try { - if (xhr.status != 200) { - throw new Error("Got status " + xhr.status + " from server."); - } cli.log("DONE " + dest); var json = JSON.parse(xhr.responseText); localStorage[".pkg93/packages/" + pkgname + ".json"] = JSON.stringify(json); - var dest2 = pkgsource + "/" + pkgname + "/" + json.inject; + if (!json.versions) { + cli.log("WARN This package does not support versioning, using latest\n version instead."); + } else { + version = (version == "latest") ? json.versions[0] : version; + } + var dest2 = pkgsource + "/" + pkgname + "/" + (json.versions ? version + "/" : "") + json.inject; cli.log("GET " + dest2); var bardiv2 = cli.log(_abarpkg93uses(60, 0)); var xhr2 = new XMLHttpRequest(); @@ -218,7 +229,11 @@ var pkg93 = { } }; xhr2.onerror = () => { + bardiv2.innerHTML = errbar; cli.log("ERR Fatal error while retriving " + dest2); + if (xhr2.status != 0) { + cli.log("ERR " + xhr2.status + " " + xhr2.statusText); + } rej(); }; xhr2.onload = async () => { @@ -232,10 +247,9 @@ var pkg93 = { eval(script); if (json.uninstall) { // no xhr this time - var uninst = await (await (fetch(pkgsource + "/" + pkgname + "/" + json.uninstall))).text(); + var uninst = await (await (fetch(pkgsource + "/" + pkgname + "/" + (json.versions ? version + "/" : "") + json.uninstall))).text(); localStorage[".pkg93/packages/" + pkgname + ".rm.js"] = uninst; } - cli.log("OK Injected package!"); if (!config.installed.includes(pkgname)) { config.installed.push(pkgname); } @@ -344,7 +358,6 @@ async function _pkg93execdonotcallplsusetheapi(cli) { info [pkg] Gets information on a package ls [pkgs|installed|repos] Lists packages, installed packages or repositories. -credits Displays the credits Color meanings Executing OK Error Warning Info @@ -369,7 +382,9 @@ If you find my software useful, consider donating ERR You're trying to modify a pre-installed Windows93 app.\n Don't do that!"); } else { - await pkg93.get(args[1], cli); + var name = args[1].split("@")[0]; + var version = args[1].split("@")[1]; + await pkg93.get(name, version, cli); } } else if (args[0] == "rm") { if (args.length < 2) { @@ -430,11 +445,11 @@ If you find my software useful, consider donating ERR Package not found."); } else { - var depends = pkgInfo.dependencies ? pkgInfo.dependencies.join(" , ") : "None!"; var description = pkgInfo.description ? pkgInfo.description : "None!"; - cli.log(`${pkgInfo.name} - Description: ${description} - Dependencies: ${depends}`); + var vers = pkgInfo.versions ? pkgInfo.versions.join(", ") : "None!"; + cli.log(`${args[1]} +Description: ${description} +Versions: ${vers}`); } } catch (err) { cli.log("ERR Error while getting package info.\n" + err.stack); @@ -454,7 +469,7 @@ If you find my software useful, consider donating