chofex-cli 0.1.146 → 0.1.147

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.
Files changed (2) hide show
  1. package/dist/index.js +86 -28
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -59464,7 +59464,9 @@ If the browser did not open automatically, open that URL yourself.`);
59464
59464
  redirect_uri: redirectUri,
59465
59465
  code_verifier: verifier
59466
59466
  });
59467
- await saveCredentials(credentialsFromToken(body));
59467
+ const credentials = credentialsFromToken(body);
59468
+ await saveCredentials(credentials);
59469
+ return credentials.accessToken;
59468
59470
  } finally {
59469
59471
  clearTimeout(timeout3);
59470
59472
  server.close();
@@ -62460,7 +62462,7 @@ var uploadPicture = exports_Effect.fn("uploadPicture")(function* (options, path4
62460
62462
  import { spawn as spawn3 } from "node:child_process";
62461
62463
  import { mkdtemp as mkdtemp2, rm as rm2 } from "node:fs/promises";
62462
62464
  import { tmpdir as tmpdir2 } from "node:os";
62463
- import { join as join3 } from "node:path";
62465
+ import { dirname as dirname2, join as join3 } from "node:path";
62464
62466
  var cliPackageName = "chofex-cli";
62465
62467
  var upgradeVersion = "latest";
62466
62468
  var npmUpgradeArguments = (cacheDirectory) => [
@@ -62471,31 +62473,81 @@ var npmUpgradeArguments = (cacheDirectory) => [
62471
62473
  "--prefer-online",
62472
62474
  `--cache=${cacheDirectory}`
62473
62475
  ];
62474
- var runNpm = (arguments_) => new Promise((resolve4, reject) => {
62475
- const executable = process.platform === "win32" ? "npm.cmd" : "npm";
62476
+ var runProcess = (executable, arguments_, input) => new Promise((resolve4, reject) => {
62477
+ const stdin = input === undefined ? "ignore" : "pipe";
62476
62478
  const child = spawn3(executable, arguments_, {
62477
- stdio: ["ignore", "ignore", "pipe"]
62479
+ stdio: [stdin, "ignore", "pipe"]
62478
62480
  });
62479
62481
  let stderr = "";
62480
- child.stderr.setEncoding("utf8");
62481
- child.stderr.on("data", (chunk) => {
62482
+ const stderrStream = child.stderr;
62483
+ if (stderrStream === null) {
62484
+ child.kill();
62485
+ reject(new Error(`Could not capture stderr from ${executable}`));
62486
+ return;
62487
+ }
62488
+ stderrStream.setEncoding("utf8");
62489
+ stderrStream.on("data", (chunk) => {
62482
62490
  stderr += chunk;
62483
62491
  });
62484
62492
  child.on("error", reject);
62485
62493
  child.on("close", (exitCode) => {
62486
62494
  resolve4({ exitCode: exitCode ?? 1, stderr: stderr.trim() });
62487
62495
  });
62496
+ if (input !== undefined) {
62497
+ const stdinStream = child.stdin;
62498
+ if (stdinStream === null) {
62499
+ child.kill();
62500
+ reject(new Error(`Could not send input to ${executable}`));
62501
+ return;
62502
+ }
62503
+ stdinStream.end(input);
62504
+ }
62488
62505
  });
62489
- var upgradeCli = async (runner = runNpm) => {
62506
+ var runNpm = (arguments_) => {
62507
+ const executable = process.platform === "win32" ? "npm.cmd" : "npm";
62508
+ return runProcess(executable, arguments_);
62509
+ };
62510
+ var installerUrl = "https://hacktheandes.com/install";
62511
+ var runInstaller = async (installDirectory) => {
62512
+ const response = await fetch(installerUrl);
62513
+ if (!response.ok) {
62514
+ throw new Error(`installer download returned HTTP ${response.status}`);
62515
+ }
62516
+ const script = await response.text();
62517
+ const arguments_ = [
62518
+ "-s",
62519
+ "--",
62520
+ "--install-dir",
62521
+ installDirectory,
62522
+ "--no-modify-path"
62523
+ ];
62524
+ if (process.platform === "win32") {
62525
+ arguments_.push("--defer-until-pid", String(process.pid));
62526
+ }
62527
+ return runProcess("bash", arguments_, script);
62528
+ };
62529
+ var isStandaloneExecutable = () => typeof Bun !== "undefined" && Bun.isStandaloneExecutable;
62530
+ var assertSuccessful = (result3, program) => {
62531
+ if (result3.exitCode === 0)
62532
+ return;
62533
+ let detail = "";
62534
+ if (result3.stderr)
62535
+ detail = `: ${result3.stderr}`;
62536
+ throw new Error(`${program} exited with code ${result3.exitCode}${detail}`);
62537
+ };
62538
+ var upgradeCli = async (options = {}) => {
62539
+ const standalone = options.standalone ?? isStandaloneExecutable();
62540
+ if (standalone) {
62541
+ const runner2 = options.installerRunner ?? runInstaller;
62542
+ const result3 = await runner2(dirname2(process.execPath));
62543
+ assertSuccessful(result3, "installer");
62544
+ return;
62545
+ }
62546
+ const runner = options.npmRunner ?? runNpm;
62490
62547
  const cacheDirectory = await mkdtemp2(join3(tmpdir2(), "chofex-npm-cache-"));
62491
62548
  try {
62492
62549
  const result3 = await runner(npmUpgradeArguments(cacheDirectory));
62493
- if (result3.exitCode === 0)
62494
- return;
62495
- let detail = "";
62496
- if (result3.stderr)
62497
- detail = `: ${result3.stderr}`;
62498
- throw new Error(`npm exited with code ${result3.exitCode}${detail}`);
62550
+ assertSuccessful(result3, "npm");
62499
62551
  } finally {
62500
62552
  await rm2(cacheDirectory, { recursive: true, force: true });
62501
62553
  }
@@ -62633,17 +62685,18 @@ var confirmCommand = exports_Command.make("confirm", {
62633
62685
  ]));
62634
62686
  var loginCommand = exports_Command.make("login", {}, exports_Effect.fn("loginCommand")(function* () {
62635
62687
  const options = yield* root;
62636
- const operation = exports_Effect.tryPromise({
62637
- try: async () => {
62638
- await login();
62639
- return {
62640
- version: 1,
62641
- ok: true,
62642
- requestId: crypto.randomUUID(),
62643
- data: { authenticated: true }
62644
- };
62645
- },
62646
- catch: (error2) => cliError("LOGIN_FAILED", String(error2))
62688
+ const operation = exports_Effect.gen(function* () {
62689
+ const token = yield* exports_Effect.tryPromise({
62690
+ try: () => login(),
62691
+ catch: (error2) => cliError("LOGIN_FAILED", String(error2))
62692
+ });
62693
+ yield* getCurrentUser({ apiUrl: options.apiUrl, token }).pipe(exports_Effect.catch(() => exports_Effect.succeed(undefined)));
62694
+ return {
62695
+ version: 1,
62696
+ ok: true,
62697
+ requestId: crypto.randomUUID(),
62698
+ data: { authenticated: true }
62699
+ };
62647
62700
  });
62648
62701
  yield* execute(options.output, operation, () => "Signed in successfully.");
62649
62702
  })).pipe(exports_Command.withDescription("Sign in through Clerk OAuth in your browser"));
@@ -62693,7 +62746,7 @@ var makeUpgradeCommand = (name) => exports_Command.make(name, {}, exports_Effect
62693
62746
  }
62694
62747
  };
62695
62748
  },
62696
- catch: (error2) => cliError("UPGRADE_FAILED", `npm could not update ${cliPackageName}`, false, String(error2))
62749
+ catch: (error2) => cliError("UPGRADE_FAILED", `Could not update ${cliPackageName}`, false, String(error2))
62697
62750
  });
62698
62751
  yield* execute(options.output, operation, () => `Updated ${cliPackageName} to the ${upgradeVersion} version.`);
62699
62752
  })).pipe(exports_Command.withDescription("Update chofex-cli to the latest version"));
@@ -62929,8 +62982,13 @@ ${shortcuts.flatMap((line) => wrap(line, width)).join(`
62929
62982
  };
62930
62983
 
62931
62984
  // src/index.ts
62932
- var packageMetadata = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
62933
- var cliVersion = packageMetadata.version;
62985
+ var readCliVersion = () => {
62986
+ if (typeof CHOFEX_VERSION !== "undefined")
62987
+ return CHOFEX_VERSION;
62988
+ const packageMetadata = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
62989
+ return packageMetadata.version;
62990
+ };
62991
+ var cliVersion = readCliVersion();
62934
62992
  var arguments_ = process.argv.slice(2);
62935
62993
  var jsonOutputRequested = (arguments_2) => {
62936
62994
  if (arguments_2.includes("--output=json"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chofex-cli",
3
- "version": "0.1.146",
3
+ "version": "0.1.147",
4
4
  "description": "Command-line client for Hack the Andes",
5
5
  "type": "module",
6
6
  "bin": {