@nativescript/cloudflare-cli 0.1.0-beta.3 → 0.1.0-beta.4

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 (3) hide show
  1. package/README.md +2 -1
  2. package/dist/bin.js +16 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3,9 +3,10 @@
3
3
  ```sh
4
4
  npx @nativescript/cloudflare-cli live # a phone app: opens the IDE and prints a QR code for NativeScript Preview
5
5
  npx @nativescript/cloudflare-cli live --mac # a Mac app: opens the IDE and runs the app on this Mac, streamed into the IDE
6
+ npx @nativescript/cloudflare-cli live --electron # an Electron app with native views, run the same way
6
7
  ```
7
8
 
8
- `live` creates a project on preview.nativescript.org (`--server` or `NS_EDGE_SERVER` for another edge), saves it to `.ns-edge.json` and opens its IDE. Run it again in the same folder to reopen that project, or add `--new` for another. Without a create token the project is free: a few hosted agent turns a day, no backend, deleted after 30 days unused. `--no-open` skips the browser; with `--mac`, `--allow-eval` lets the agent run code on this Mac.
9
+ `live` creates a project on preview.nativescript.org (`--server` or `NS_EDGE_SERVER` for another edge), saves it to `.ns-edge.json` and opens its IDE. Run it again in the same folder to reopen that project, or add `--new` for another. Without a create token the project is free: a few hosted agent turns a day, no backend, deleted after 30 days unused. `--no-open` skips the browser; with `--mac` or `--electron`, `--allow-eval` lets the agent run code on this Mac.
9
10
 
10
11
  ## Mirror a local project
11
12
 
package/dist/bin.js CHANGED
@@ -9,8 +9,11 @@ import { applyChanges, collect, createProject, projectUrl, report, SYNCED } from
9
9
  const CONFIG = '.ns-edge.json';
10
10
  const DEBOUNCE_MS = 120;
11
11
  const LIVE_SERVER = process.env.NS_EDGE_SERVER ?? 'https://preview.nativescript.org';
12
- /** The desktop host `live --mac` runs; bump it with each host release this CLI is tested against. */
13
- const DESKTOP_HOST = '@nativescript/cloudflare-desktop@0.1.0-alpha.2';
12
+ /** The hosts `live --mac` and `live --electron` run; bump them with each host release this CLI is tested against. */
13
+ const DESKTOP_HOSTS = {
14
+ macos: '@nativescript/cloudflare-desktop@0.1.0-alpha.3',
15
+ electron: '@nativescript/cloudflare-electron@0.1.0-alpha.0',
16
+ };
14
17
  const DESKTOP_TEMPLATES = new Set(['macos', 'electron']);
15
18
  const [cmd = 'help', ...args] = process.argv.slice(2);
16
19
  /**
@@ -72,14 +75,15 @@ function openInBrowser(url) {
72
75
  const [command, ...rest] = process.platform === 'darwin' ? ['open', url] : process.platform === 'win32' ? ['cmd', '/c', 'start', '""', url.replace(/&/g, '^&')] : ['xdg-open', url];
73
76
  spawn(command, rest, { stdio: 'ignore', detached: true }).on('error', () => { }).unref();
74
77
  }
75
- /** Runs the Mac host for a desktop project until it exits; the host prints what joining allows. */
78
+ /** Runs the Mac host for a desktop project until it exits; the host says what joining allows. */
76
79
  function runDesktopHost(ref) {
77
80
  if (process.platform !== 'darwin' || process.arch !== 'arm64') {
78
81
  throw new Error('Mac projects run on an Apple Silicon Mac (macOS 14.4 or later). Run the same command there.');
79
82
  }
80
83
  const device = `${projectUrl(ref)}#${ref.deviceKey}`;
81
84
  const extra = has('allow-eval') ? ['--allow-eval'] : [];
82
- const child = spawn('npx', ['-y', DESKTOP_HOST, device, '--yes', ...extra], { stdio: 'inherit' });
85
+ const host = DESKTOP_HOSTS[ref.template ?? 'macos'] ?? DESKTOP_HOSTS.macos;
86
+ const child = spawn('npx', ['-y', host, device, '--yes', ...extra], { stdio: 'inherit' });
83
87
  for (const signal of ['SIGINT', 'SIGTERM'])
84
88
  process.on(signal, () => child.kill(signal));
85
89
  return new Promise((resolve, reject) => {
@@ -93,19 +97,22 @@ const commands = {
93
97
  if (has(later))
94
98
  throw new Error(`--${later} isn't available yet. Run \`live\` for a phone app or \`live --mac\` for a Mac app.`);
95
99
  }
96
- const template = flag('template') ?? (has('mac') ? 'macos' : 'core');
100
+ const template = flag('template') ?? (has('electron') ? 'electron' : has('mac') ? 'macos' : 'core');
97
101
  const desktop = DESKTOP_TEMPLATES.has(template);
98
102
  let ref = has('new') ? null : await savedProject();
99
103
  if (ref && DESKTOP_TEMPLATES.has(ref.template ?? 'core') !== desktop) {
100
104
  throw new Error(`This folder's project (${CONFIG}) is a ${desktop ? 'phone' : 'Mac'} project. Add --new to replace it, or run this in another folder.`);
101
105
  }
106
+ if (ref && desktop && ref.template !== template) {
107
+ throw new Error(`This folder's project (${CONFIG}) is a ${ref.template} project. Add --new to replace it, or run this in another folder.`);
108
+ }
102
109
  if (ref) {
103
110
  console.log(`Opening this folder's project ${ref.id} (${CONFIG})`);
104
111
  }
105
112
  else {
106
113
  ref = await createProject(flag('server') ?? LIVE_SERVER, flag('token') ?? process.env.NS_EDGE_CREATE_TOKEN, template);
107
114
  await writeFile(join(root, CONFIG), JSON.stringify(ref, null, 2) + '\n');
108
- console.log(`Created a ${desktop ? 'Mac' : 'phone'} project, saved to ${CONFIG} (it holds the project's keys: keep it private and out of git).`);
115
+ console.log(`Created ${template === 'electron' ? 'an Electron' : desktop ? 'a Mac' : 'a phone'} project, saved to ${CONFIG} (it holds the project's keys: keep it private and out of git).`);
109
116
  if (ref.free) {
110
117
  console.log(`It's a free project: ${ref.free.agentTurnsPerDay} hosted agent turn${ref.free.agentTurnsPerDay === 1 ? '' : 's'} a day, deleted after ${ref.free.idleDays} days unused. ` +
111
118
  'For an unlimited agent, add your own API key in the agent panel or connect Claude Code from Connect agent.');
@@ -116,7 +123,7 @@ const commands = {
116
123
  if (!has('no-open'))
117
124
  openInBrowser(ide);
118
125
  if (desktop) {
119
- console.log('Starting the app on this Mac. Its window streams to the IDE\'s Device pane. Press Ctrl+C to stop.\n');
126
+ console.log(`Starting the app on this Mac${template === 'electron' ? ' (the first run downloads Electron)' : ''}. Its window streams to the IDE's Device pane. Press Ctrl+C to stop.\n`);
120
127
  return runDesktopHost(ref);
121
128
  }
122
129
  const device = `${projectUrl(ref)}#${ref.deviceKey}`;
@@ -196,9 +203,9 @@ const commands = {
196
203
  async help() {
197
204
  console.log(`ns-edge <command>
198
205
 
199
- live [--mac] [--new] [--no-open] [--allow-eval]
206
+ live [--mac|--electron] [--new] [--no-open] [--allow-eval]
200
207
  create a project (or reopen this folder's), open its IDE, and print a QR code
201
- for your phone; --mac runs it on this Mac instead
208
+ for your phone; --mac or --electron runs it on this Mac instead
202
209
  create [--server <url>] [--token <t>] [--template core|vue|react|solid|svelte|angular]
203
210
  create an edge project and save .ns-edge.json
204
211
  push upload app/ and server/ in one transaction
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript/cloudflare-cli",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "Mirror a NativeScript project into an ns-edge project from a terminal or a Vite dev server",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",