@dhruv2mars/offdex 0.0.4 → 0.0.6

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
@@ -25,7 +25,9 @@ Supported targets:
25
25
  Common usage:
26
26
 
27
27
  ```bash
28
- offdex bridge --host 0.0.0.0 --port 42420
29
- offdex bridge --control-plane-url https://control.offdex.app
28
+ offdex start --host 0.0.0.0 --port 42420
29
+ offdex start --control-plane-url https://control.offdex.app
30
+ offdex status
31
+ offdex stop
30
32
  offdex --help
31
33
  ```
@@ -5,6 +5,7 @@ import http from "node:http";
5
5
  import https from "node:https";
6
6
  import { homedir } from "node:os";
7
7
  import { join } from "node:path";
8
+ import { gunzipSync } from "node:zlib";
8
9
 
9
10
  const REPO = "Dhruv2mars/offdex";
10
11
  const SUPPORTED_TARGETS = new Map([
@@ -58,6 +59,10 @@ export function checksumsAssetNameFor(platform = process.platform, arch = proces
58
59
  return `checksums-${platform}-${arch}.txt`;
59
60
  }
60
61
 
62
+ export function compressedAssetNameFor(platform = process.platform, arch = process.arch) {
63
+ return `${assetNameFor(platform, arch)}.gz`;
64
+ }
65
+
61
66
  export function resolveInstallRoot(env = process.env, home = homedir()) {
62
67
  return env.OFFDEX_INSTALL_ROOT || join(home, ".offdex");
63
68
  }
@@ -281,6 +286,7 @@ export async function installRuntime({
281
286
  const installBin = resolveInstalledBin(env, platform, home);
282
287
  const installMeta = resolveInstallMetaPath(env, home);
283
288
  const asset = assetNameFor(platform, arch);
289
+ const compressedAsset = compressedAssetNameFor(platform, arch);
284
290
  const checksumsAsset = checksumsAssetNameFor(platform, arch);
285
291
  const baseUrl = env.OFFDEX_RELEASE_BASE_URL
286
292
  || `https://github.com/${REPO}/releases/download/v${version}`;
@@ -293,21 +299,42 @@ export async function installRuntime({
293
299
  } catch {
294
300
  throw new Error(`failed_download:${checksumsAsset}`);
295
301
  }
296
- const expectedChecksum = parseChecksumForAsset(checksumsText, asset);
302
+ const expectedCompressedChecksum = parseChecksumForAsset(checksumsText, compressedAsset);
303
+ const expectedChecksum = expectedCompressedChecksum || parseChecksumForAsset(checksumsText, asset);
297
304
  if (!expectedChecksum) {
298
305
  throw new Error(`missing_checksum:${asset}`);
299
306
  }
300
307
 
301
308
  const tempPath = `${installBin}.download`;
302
309
  try {
303
- try {
304
- await downloadFn(`${baseUrl}/${asset}`, tempPath, 0, { onProgress });
305
- } catch {
306
- throw new Error(`failed_download:${asset}`);
307
- }
308
- const actualChecksum = createHash("sha256").update(readFileSync(tempPath)).digest("hex");
309
- if (actualChecksum !== expectedChecksum) {
310
- throw new Error(`checksum_mismatch:${asset}`);
310
+ if (expectedCompressedChecksum) {
311
+ const compressedPath = `${tempPath}.gz`;
312
+ try {
313
+ await downloadFn(`${baseUrl}/${compressedAsset}`, compressedPath, 0, { onProgress });
314
+ } catch {
315
+ throw new Error(`failed_download:${compressedAsset}`);
316
+ }
317
+ try {
318
+ const actualCompressedChecksum = createHash("sha256")
319
+ .update(readFileSync(compressedPath))
320
+ .digest("hex");
321
+ if (actualCompressedChecksum !== expectedCompressedChecksum) {
322
+ throw new Error(`checksum_mismatch:${compressedAsset}`);
323
+ }
324
+ await writeFile(tempPath, gunzipSync(readFileSync(compressedPath)));
325
+ } finally {
326
+ await rm(compressedPath, { force: true });
327
+ }
328
+ } else {
329
+ try {
330
+ await downloadFn(`${baseUrl}/${asset}`, tempPath, 0, { onProgress });
331
+ } catch {
332
+ throw new Error(`failed_download:${asset}`);
333
+ }
334
+ const actualChecksum = createHash("sha256").update(readFileSync(tempPath)).digest("hex");
335
+ if (actualChecksum !== expectedChecksum) {
336
+ throw new Error(`checksum_mismatch:${asset}`);
337
+ }
311
338
  }
312
339
  if (platform !== "win32") {
313
340
  await chmod(tempPath, 0o755);
package/bin/offdex.js CHANGED
@@ -13,11 +13,33 @@ import {
13
13
  } from "./offdex-lib.js";
14
14
 
15
15
  const args = process.argv.slice(2);
16
+ const ONBOARDING_TEXT = `Offdex
17
+ Codex from your phone.
18
+
19
+ Get started:
20
+ 1. Run offdex start
21
+ 2. Open Offdex on your phone
22
+ 3. Scan the QR from this terminal
23
+
24
+ Useful commands:
25
+ offdex start Start the Mac bridge
26
+ offdex status Check if Offdex is running
27
+ offdex stop Stop the local bridge
28
+ offdex --help Show all options
29
+ `;
16
30
  const HELP_TEXT = `Offdex CLI
17
31
 
18
32
  Usage:
19
- offdex bridge [options]
20
- offdex help
33
+ offdex
34
+ offdex start [options]
35
+ offdex status [options]
36
+ offdex stop [options]
37
+ offdex --help
38
+
39
+ Commands:
40
+ start Start the Mac bridge and show the pairing QR
41
+ status Check the local bridge
42
+ stop Stop the local bridge started by Offdex
21
43
 
22
44
  Options:
23
45
  --host <host> Bridge host. Default: 0.0.0.0
@@ -37,9 +59,14 @@ const packageVersion = readPackageVersion();
37
59
  const currentInstalledVersion = installedVersion(process.env);
38
60
  const workspaceBridgeCli = resolveWorkspaceBridgeCli();
39
61
 
62
+ if (!existsSync(installedBin) && args.length === 0) {
63
+ console.log(ONBOARDING_TEXT);
64
+ process.exit(0);
65
+ }
66
+
40
67
  if (
41
68
  !existsSync(installedBin) &&
42
- (args.length === 0 || args[0] === "help" || args[0] === "--help" || args[0] === "-h")
69
+ (args[0] === "help" || args[0] === "--help" || args[0] === "-h")
43
70
  ) {
44
71
  console.log(HELP_TEXT);
45
72
  process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhruv2mars/offdex",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Codex mobile bridge CLI for Offdex",
5
5
  "type": "module",
6
6
  "bin": {