@nativescript/cloudflare-cli 0.1.0-beta.7 → 0.1.0-beta.8

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 +49 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,11 +2,12 @@
2
2
 
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
+ npx @nativescript/cloudflare-cli live --react # the same with a framework: --ng (Angular), --react, --vue, --svelte or --solid
5
6
  npx @nativescript/cloudflare-cli live --mac # a Mac app: opens the IDE and runs the app on this Mac, streamed into the IDE
6
7
  npx @nativescript/cloudflare-cli live --electron # an Electron app with native views, run the same way
7
8
  ```
8
9
 
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 (no platform flag needed), or add `--new` for another. While `live` runs a Mac app it restarts the app if it crashes, unless it crashes three times in a minute. 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.
10
+ `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. The framework flags are `ns create`'s (`--ng`/`--angular`, `--react`, `--vue`, `--svelte`, `--solid`, `--ts`); without one a phone project is plain TypeScript with XML views. Run it again in the same folder to reopen that project (no flag needed), or add `--new` for another; a flag for a different kind of project than the folder's asks for `--new`. While `live` runs a Mac app it restarts the app if it crashes, unless it crashes three times in a minute. 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.
10
11
 
11
12
  ## Mirror a local project
12
13
 
package/dist/bin.js CHANGED
@@ -17,6 +17,26 @@ const DESKTOP_HOSTS = {
17
17
  };
18
18
  const DESKTOP_TEMPLATES = new Set(['macos', 'electron', 'expo']);
19
19
  const DESKTOP_FLAGS = { macos: 'mac', electron: 'electron', expo: 'expo' };
20
+ /** The NativeScript CLI's `ns create` framework flags, so `live` and `create` take the same ones. */
21
+ const FRAMEWORK_FLAGS = {
22
+ angular: ['ng', 'angular'],
23
+ react: ['react', 'reactjs'],
24
+ vue: ['vue', 'vuejs'],
25
+ svelte: ['svelte'],
26
+ solid: ['solid', 'solidjs'],
27
+ core: ['ts', 'tsc', 'typescript'],
28
+ };
29
+ const TEMPLATE_KINDS = {
30
+ core: 'a phone',
31
+ angular: 'an Angular phone',
32
+ react: 'a React phone',
33
+ vue: 'a Vue phone',
34
+ svelte: 'a Svelte phone',
35
+ solid: 'a Solid phone',
36
+ macos: 'a Mac',
37
+ electron: 'an Electron',
38
+ expo: 'an Expo Desktop',
39
+ };
20
40
  const MAX_CRASHES = 3;
21
41
  const CRASH_WINDOW_MS = 60_000;
22
42
  const RESTART_DELAY_MS = 1000;
@@ -32,6 +52,22 @@ const flag = (name) => {
32
52
  return i >= 0 ? args[i + 1] : undefined;
33
53
  };
34
54
  const has = (name) => args.includes(`--${name}`);
55
+ /** The template --template, a framework flag or a desktop flag asks for, if any; asking for two is an error. */
56
+ function requestedTemplate() {
57
+ const asked = new Set();
58
+ const named = flag('template');
59
+ if (named)
60
+ asked.add(named);
61
+ for (const [template, names] of Object.entries(FRAMEWORK_FLAGS))
62
+ if (names.some((name) => has(name)))
63
+ asked.add(template);
64
+ for (const [template, name] of Object.entries(DESKTOP_FLAGS))
65
+ if (has(name))
66
+ asked.add(template);
67
+ if (asked.size > 1)
68
+ throw new Error(`Pick one kind of project: this asked for ${[...asked].join(' and ')}.`);
69
+ return [...asked][0];
70
+ }
35
71
  const root = process.cwd();
36
72
  async function loadRef() {
37
73
  let ref;
@@ -130,14 +166,13 @@ const commands = {
130
166
  throw new Error(`--${later} isn't available yet. Run \`live\` for a phone app, or \`live --mac\`, \`--electron\` or \`--expo\` for a Mac app.`);
131
167
  }
132
168
  let ref = has('new') ? null : await savedProject();
133
- // Without a platform flag, this folder's project runs as whatever it was made as.
134
- const template = flag('template') ?? Object.entries(DESKTOP_FLAGS).find(([, name]) => has(name))?.[0] ?? ref?.template ?? 'core';
169
+ const requested = requestedTemplate();
170
+ // Without a template flag, this folder's project runs as whatever it was made as.
171
+ const template = requested ?? ref?.template ?? 'core';
135
172
  const desktop = DESKTOP_TEMPLATES.has(template);
136
- if (ref && DESKTOP_TEMPLATES.has(ref.template ?? 'core') !== desktop) {
137
- 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.`);
138
- }
139
- if (ref && desktop && ref.template !== template) {
140
- throw new Error(`This folder's project (${CONFIG}) is a ${ref.template} project. Add --new to replace it, or run this in another folder.`);
173
+ if (ref && requested && (ref.template ?? 'core') !== requested) {
174
+ const current = TEMPLATE_KINDS[ref.template ?? 'core'] ?? `a ${ref.template}`;
175
+ throw new Error(`This folder's project (${CONFIG}) is ${current} project. Add --new to start ${TEMPLATE_KINDS[requested] ?? `a ${requested}`} one, or run this in another folder.`);
141
176
  }
142
177
  if (ref) {
143
178
  console.log(`Opening this folder's project ${ref.id} (${CONFIG})`);
@@ -145,8 +180,7 @@ const commands = {
145
180
  else {
146
181
  ref = await createProject(flag('server') ?? LIVE_SERVER, flag('token') ?? process.env.NS_EDGE_CREATE_TOKEN, template);
147
182
  await writeFile(join(root, CONFIG), JSON.stringify(ref, null, 2) + '\n');
148
- const kind = template === 'electron' ? 'an Electron' : template === 'expo' ? 'an Expo Desktop' : desktop ? 'a Mac' : 'a phone';
149
- console.log(`Created ${kind} project, saved to ${CONFIG} (it holds the project's keys: keep it private and out of git).`);
183
+ console.log(`Created ${TEMPLATE_KINDS[template] ?? `a ${template}`} project, saved to ${CONFIG} (it holds the project's keys: keep it private and out of git).`);
150
184
  if (ref.free) {
151
185
  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. ` +
152
186
  'For an unlimited agent, add your own API key in the agent panel or connect Claude Code from Connect agent.');
@@ -168,7 +202,7 @@ const commands = {
168
202
  },
169
203
  async create() {
170
204
  const server = flag('server') ?? 'http://localhost:5173';
171
- const ref = await createProject(server, flag('token') ?? process.env.NS_EDGE_CREATE_TOKEN, flag('template'));
205
+ const ref = await createProject(server, flag('token') ?? process.env.NS_EDGE_CREATE_TOKEN, requestedTemplate());
172
206
  await writeFile(join(root, CONFIG), JSON.stringify(ref, null, 2) + '\n');
173
207
  console.log(`Created project ${ref.id} (saved to ${CONFIG}; it holds the project keys, keep it out of git)`);
174
208
  await printPairing(ref);
@@ -238,10 +272,12 @@ const commands = {
238
272
  async help() {
239
273
  console.log(`ns-edge <command>
240
274
 
241
- live [--mac|--electron|--expo] [--new] [--no-open] [--allow-eval]
275
+ live [--ng|--react|--vue|--svelte|--solid|--mac|--electron|--expo] [--new] [--no-open] [--allow-eval]
242
276
  create a project (or reopen this folder's), open its IDE, and print a QR code
243
- for your phone; --mac, --electron or --expo runs it on this Mac instead
244
- create [--server <url>] [--token <t>] [--template core|vue|react|solid|svelte|angular]
277
+ for your phone; --ng, --react, --vue, --svelte or --solid picks the framework
278
+ (plain TypeScript with XML views otherwise); --mac, --electron or --expo runs it
279
+ on this Mac instead
280
+ create [--server <url>] [--token <t>] [--ng|--react|--vue|--svelte|--solid|--template <name>]
245
281
  create an edge project and save .ns-edge.json
246
282
  push upload app/ and server/ in one transaction
247
283
  watch push, then stream every save to the edge
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript/cloudflare-cli",
3
- "version": "0.1.0-beta.7",
3
+ "version": "0.1.0-beta.8",
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",