unreleased-cli 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,6 +26,8 @@ sudo add-apt-repository ppa:saint-duckworth/ppa
26
26
  sudo apt install unreleased-cli
27
27
  ```
28
28
 
29
+ To update later, run `unreleased update` (or `update` inside the shell). It checks for a newer version and installs it if you installed from npm; `update -c` only checks.
30
+
29
31
  From source:
30
32
 
31
33
  ```
@@ -82,7 +82,7 @@ function saveSettings(settings) {
82
82
 
83
83
  // src/api.ts
84
84
  var DEFAULT_API = "https://juicewrldapi.com/juicewrld";
85
- var VERSION = "0.1.2";
85
+ var VERSION = "0.1.3";
86
86
  function apiBase() {
87
87
  return (process.env.UNRELEASED_API || loadConfig().api || DEFAULT_API).replace(/\/+$/, "");
88
88
  }
@@ -4416,6 +4416,82 @@ var SETTINGS_COMMANDS = [
4416
4416
  }
4417
4417
  ];
4418
4418
 
4419
+ // src/update.ts
4420
+ import { spawn as spawn2 } from "node:child_process";
4421
+ import { realpathSync } from "node:fs";
4422
+ var PACKAGE = "unreleased-cli";
4423
+ async function latestVersion() {
4424
+ let res;
4425
+ try {
4426
+ res = await fetch(`https://registry.npmjs.org/${PACKAGE}/latest`, { signal: AbortSignal.timeout(1e4) });
4427
+ } catch {
4428
+ return fail("couldn't reach npm to check for updates (are you online?)");
4429
+ }
4430
+ if (!res.ok) fail(`npm answered ${res.status} when checking for updates`);
4431
+ const { version } = await res.json();
4432
+ return version ?? fail("npm sent no version number");
4433
+ }
4434
+ function compare(a, b) {
4435
+ const pa = a.split(".").map((n) => parseInt(n, 10) || 0);
4436
+ const pb = b.split(".").map((n) => parseInt(n, 10) || 0);
4437
+ for (let i = 0; i < 3; i++) if ((pa[i] ?? 0) !== (pb[i] ?? 0)) return (pa[i] ?? 0) - (pb[i] ?? 0);
4438
+ return 0;
4439
+ }
4440
+ function installKind() {
4441
+ let file = process.argv[1] ?? "";
4442
+ try {
4443
+ file = realpathSync(file);
4444
+ } catch {
4445
+ }
4446
+ const p = file.replace(/\\/g, "/");
4447
+ if (p.startsWith("/usr/lib/unreleased-cli/")) return "apt";
4448
+ if (p.includes("/node_modules/")) return "npm";
4449
+ return "source";
4450
+ }
4451
+ function runNpmInstall() {
4452
+ return new Promise((resolve3) => {
4453
+ const child = spawn2("npm", ["install", "-g", `${PACKAGE}@latest`], { stdio: "inherit", shell: process.platform === "win32" });
4454
+ child.on("error", () => resolve3(1));
4455
+ child.on("close", (code2) => resolve3(code2 ?? 1));
4456
+ });
4457
+ }
4458
+ var UPDATE_COMMANDS = [
4459
+ {
4460
+ name: "update",
4461
+ aliases: ["upgrade"],
4462
+ group: "Shell",
4463
+ usage: "update [-c]",
4464
+ description: "Check for a newer version and install it. -c only checks",
4465
+ run: async (arg, sh) => {
4466
+ const checkOnly = /^-c$|^--check$/.test(arg.trim());
4467
+ if (arg.trim() && !checkOnly) fail("usage: update [-c]");
4468
+ const latest = await latestVersion();
4469
+ if (compare(latest, VERSION) <= 0) {
4470
+ sh.print(`you're up to date (v${VERSION})`, "ok");
4471
+ return;
4472
+ }
4473
+ sh.print(`new version: v${latest} (you have v${VERSION})`);
4474
+ if (checkOnly) {
4475
+ sh.print("run update to install it", "dim");
4476
+ return;
4477
+ }
4478
+ const kind = installKind();
4479
+ if (kind === "apt") {
4480
+ sh.print("this copy came from the Ubuntu PPA, so update it with:\n sudo apt update && sudo apt install --only-upgrade unreleased-cli");
4481
+ return;
4482
+ }
4483
+ if (kind === "source") {
4484
+ sh.print("this copy runs from a source checkout, so update it with:\n git pull && npm install && npm run build");
4485
+ return;
4486
+ }
4487
+ sh.print(`installing v${latest}\u2026`, "dim");
4488
+ const code2 = await runNpmInstall();
4489
+ if (code2 !== 0) fail(`the install failed (npm exit code ${code2}). If it says permission denied, run it with sudo: sudo npm install -g ${PACKAGE}@latest`);
4490
+ sh.print(`updated to v${latest} - leave and start unreleased again to use it`, "ok");
4491
+ }
4492
+ }
4493
+ ];
4494
+
4419
4495
  // src/karaoke.ts
4420
4496
  var TIME = /\[(\d{1,2}):(\d{2})[.:](\d{2,3})\]/g;
4421
4497
  function parseLrc(lrc) {
@@ -4547,7 +4623,7 @@ var KARAOKE_COMMANDS = [
4547
4623
  ];
4548
4624
 
4549
4625
  // src/visualizer.ts
4550
- import { spawn as spawn2 } from "node:child_process";
4626
+ import { spawn as spawn3 } from "node:child_process";
4551
4627
  import { closeSync, fstatSync, openSync, readSync, rmSync as rmSync2 } from "node:fs";
4552
4628
  import { tmpdir as tmpdir2 } from "node:os";
4553
4629
  import { join as join5 } from "node:path";
@@ -4564,7 +4640,7 @@ var Decoder = class {
4564
4640
  finished = false;
4565
4641
  failed = false;
4566
4642
  constructor(binary, url) {
4567
- this.proc = spawn2(binary, [
4643
+ this.proc = spawn3(binary, [
4568
4644
  "--no-config",
4569
4645
  "--no-video",
4570
4646
  "--no-terminal",
@@ -4986,6 +5062,7 @@ ${color.dim(`local ${sh.localDir}`)}`)
4986
5062
  ...KARAOKE_COMMANDS,
4987
5063
  ...GAME_COMMANDS,
4988
5064
  ...SETTINGS_COMMANDS,
5065
+ ...UPDATE_COMMANDS,
4989
5066
  {
4990
5067
  name: "source",
4991
5068
  aliases: ["."],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unreleased-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "The Unreleased site terminal as a command-line shell",
5
5
  "keywords": [
6
6
  "juice-wrld",