runcloud 0.2.235 → 0.2.237

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.
@@ -1,12 +1,50 @@
1
1
  import { execFile } from 'node:child_process';
2
2
  import { promisify } from 'node:util';
3
+ import { dirname } from 'node:path';
4
+ import { Option } from 'commander';
3
5
  import { CLI_VERSION } from '../version.js';
4
6
  export const PACKAGE_NAME = '@newly/cli';
5
- export const UPDATE_COMMAND = `npm install -g ${PACKAGE_NAME}@latest`;
7
+ export const UPDATE_COMMAND = npmSource(PACKAGE_NAME).manualCommand;
6
8
  const defaultExec = async (file, args) => {
7
9
  const { stdout } = await promisify(execFile)(file, args, { encoding: 'utf8' });
8
10
  return { stdout };
9
11
  };
12
+ export function npmSource(packageName) {
13
+ return {
14
+ name: packageName,
15
+ manualCommand: `npm install -g ${packageName}@latest`,
16
+ latest: async (exec) => (await exec('npm', ['view', `${packageName}@latest`, 'version'])).stdout.trim(),
17
+ install: async (exec) => {
18
+ await exec('npm', ['install', '-g', `${packageName}@latest`]);
19
+ },
20
+ };
21
+ }
22
+ export const RUNCLOUD_INSTALLER_URL = 'https://run.cloud/install';
23
+ export const RUNCLOUD_LATEST_URL = 'https://dl.run.cloud/latest.json';
24
+ export function runCloudBinarySource(binaryPath) {
25
+ const installDir = dirname(binaryPath);
26
+ return {
27
+ name: 'runcloud',
28
+ manualCommand: `curl -fsSL ${RUNCLOUD_INSTALLER_URL} | RUNCLOUD_INSTALL_DIR=${installDir} sh`,
29
+ latest: async (exec) => {
30
+ const { stdout } = await exec('curl', ['-fsSL', RUNCLOUD_LATEST_URL]);
31
+ const version = JSON.parse(stdout).version;
32
+ return typeof version === 'string' ? version.trim() : '';
33
+ },
34
+ install: async (exec) => {
35
+ await exec('sh', [
36
+ '-c',
37
+ 'curl -fsSL "$1" | RUNCLOUD_INSTALL_DIR="$2" RUNCLOUD_NO_LOGIN=1 sh',
38
+ 'sh',
39
+ RUNCLOUD_INSTALLER_URL,
40
+ installDir,
41
+ ]);
42
+ },
43
+ };
44
+ }
45
+ export function runCloudSource() {
46
+ return process.versions.bun ? runCloudBinarySource(process.execPath) : npmSource('runcloud');
47
+ }
10
48
  function errorText(error) {
11
49
  if (error && typeof error === 'object') {
12
50
  const stderr = error.stderr;
@@ -15,48 +53,46 @@ function errorText(error) {
15
53
  }
16
54
  return error instanceof Error ? error.message : String(error);
17
55
  }
18
- export async function latestPublishedVersion(exec) {
19
- const { stdout } = await exec('npm', ['view', `${PACKAGE_NAME}@latest`, 'version']);
20
- return stdout.trim();
21
- }
22
56
  export async function updateCli(deps = {}) {
23
57
  const exec = deps.exec ?? defaultExec;
24
58
  const log = deps.log ?? ((message) => console.log(message));
25
59
  const current = deps.currentVersion ?? CLI_VERSION;
60
+ const source = deps.source ?? npmSource(PACKAGE_NAME);
61
+ const byHand = `Run \`${source.manualCommand}\` to update by hand.`;
26
62
  let latest;
27
63
  try {
28
- latest = await latestPublishedVersion(exec);
64
+ latest = await source.latest(exec);
29
65
  }
30
66
  catch (error) {
31
- throw new Error(`Could not reach the npm registry to check for updates: ${errorText(error)}\n` +
32
- `Run \`${UPDATE_COMMAND}\` to update by hand.`);
67
+ throw new Error(`Could not check for updates: ${errorText(error)}\n${byHand}`);
33
68
  }
34
69
  if (!latest) {
35
- throw new Error(`The npm registry did not report a version for ${PACKAGE_NAME}.\n` +
36
- `Run \`${UPDATE_COMMAND}\` to update by hand.`);
70
+ throw new Error(`The release source did not report a version for ${source.name}.\n${byHand}`);
37
71
  }
38
72
  if (latest === current) {
39
73
  log(`Already on the latest version (${current}).`);
40
74
  return;
41
75
  }
42
- log(`Updating ${PACKAGE_NAME} ${current} → ${latest}…`);
76
+ log(`Updating ${source.name} ${current} → ${latest}…`);
43
77
  try {
44
- await exec('npm', ['install', '-g', `${PACKAGE_NAME}@latest`]);
78
+ await source.install(exec);
45
79
  }
46
80
  catch (error) {
47
- throw new Error(`Update failed: ${errorText(error)}\n` + `Run \`${UPDATE_COMMAND}\` to update by hand.`);
81
+ throw new Error(`Update failed: ${errorText(error)}\n${byHand}`);
48
82
  }
49
83
  log(`Updated to ${latest}.`);
50
84
  }
51
- export function registerUpdate(program) {
85
+ export function registerUpdate(program, source) {
52
86
  program.option('-u, --update', 'update this CLI to the latest published version');
87
+ program.addOption(new Option('-U', 'same as --update').hideHelp());
53
88
  program.action(async () => {
54
- if (program.opts().update !== true) {
89
+ const opts = program.opts();
90
+ if (opts.update !== true && opts.U !== true) {
55
91
  program.help();
56
92
  return;
57
93
  }
58
94
  try {
59
- await updateCli();
95
+ await updateCli({ source });
60
96
  }
61
97
  catch (error) {
62
98
  console.error(error instanceof Error ? error.message : String(error));
@@ -88,7 +88,7 @@ function beforeDelimiter(argv) {
88
88
  return delimiter < 0 ? argv : argv.slice(0, delimiter);
89
89
  }
90
90
  function suppressInteractive(argv) {
91
- return beforeDelimiter(argv).some(arg => ['--json', '--help', '-h', '--version', '-V'].includes(arg) || arg.startsWith('--json='))
91
+ return beforeDelimiter(argv).some(arg => ['--json', '--help', '-h', '--version', '-V', '--update', '-u', '-U'].includes(arg) || arg.startsWith('--json='))
92
92
  || argv[0] === 'help';
93
93
  }
94
94
  function quoted(value) {
package/dist/run-cloud.js CHANGED
@@ -7,6 +7,7 @@ import { registerRunCloudFleet } from './commands/run-cloud-fleet.js';
7
7
  import { registerSandbox } from './commands/sandbox.js';
8
8
  import { registerSecrets } from './commands/secrets.js';
9
9
  import { registerToken } from './commands/token.js';
10
+ import { registerUpdate, runCloudSource } from './commands/update.js';
10
11
  import { registerXcode } from './commands/xcode.js';
11
12
  import { CLI_VERSION } from './version.js';
12
13
  import { runCloudCli } from './run-cloud-interactive.js';
@@ -28,4 +29,5 @@ registerSecrets(program);
28
29
  registerToken(program);
29
30
  registerXcode(program);
30
31
  registerImage(program);
32
+ registerUpdate(program, runCloudSource());
31
33
  await runCloudCli(program);
@@ -25,6 +25,7 @@ async function post(apiUrl, path, body, token) {
25
25
  method: 'POST',
26
26
  headers: {
27
27
  'content-type': 'application/json',
28
+ origin: new URL(apiUrl).origin,
28
29
  ...(token ? { authorization: `Bearer ${token}` } : {}),
29
30
  },
30
31
  body: JSON.stringify(body),
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = '0.2.235';
1
+ export const CLI_VERSION = '0.2.237';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runcloud",
3
- "version": "0.2.235",
3
+ "version": "0.2.237",
4
4
  "description": "Create and control run.cloud remote mobile simulators and cloud sandboxes",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
Binary file
Binary file