@nativescript/cloudflare-cli 0.1.0-beta.10 → 0.1.0-beta.11

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 +1 -1
  2. package/dist/bin.js +44 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -7,7 +7,7 @@ npx @nativescript/cloudflare-cli live --mac # a Mac app: opens the IDE and ru
7
7
  npx @nativescript/cloudflare-cli live --electron # an Electron app with native views, run the same way
8
8
  ```
9
9
 
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`. `--from <link>` starts from a copy of a shared project instead, such as a sample (its link, or a bare id on the same server). 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`. `--from <sample>` starts from a copy of a shared project instead: a sample's name (`--from expo-settings`; `samples` lists them), or any project's link or bare id. 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.
11
11
 
12
12
  ## Mirror a local project
13
13
 
package/dist/bin.js CHANGED
@@ -105,18 +105,23 @@ async function printPairing(ref) {
105
105
  }
106
106
  /** This folder's project, if it has one the server still knows. */
107
107
  /**
108
- * The project `--from` names: a link to it (its IDE, read-only or device link)
109
- * or a bare id on this CLI's server, with what it was made as.
108
+ * The project `--from` names: a link to it (its IDE, read-only or device link),
109
+ * a bare id, or a sample's name on this CLI's server, with what it was made as.
110
110
  */
111
111
  async function sourceProject(from) {
112
112
  let server = flag('server') ?? LIVE_SERVER;
113
113
  let id = from;
114
114
  if (!/^[0-9a-f]{32}$/.test(from)) {
115
- const match = URL.canParse(from) ? new URL(from).pathname.match(/^\/p\/([0-9a-f]{32})/) : null;
116
- if (!match)
117
- throw new Error(`--from takes a project link (https://…/p/<id>) or id, not '${from}'.`);
118
- server = new URL(from).origin;
119
- id = match[1];
115
+ if (URL.canParse(from) && /^https?:$/.test(new URL(from).protocol)) {
116
+ const link = new URL(from);
117
+ const match = link.pathname.match(/^\/p\/([0-9a-f]{32})(?:\/|$)/) ?? link.pathname.match(/^\/p\/([a-z0-9-]+)\/?$/);
118
+ if (!match)
119
+ throw new Error(`--from takes a sample's name, a project link (https://…/p/<id>) or its id, not '${from}'.`);
120
+ server = link.origin;
121
+ id = match[1];
122
+ }
123
+ if (!/^[0-9a-f]{32}$/.test(id))
124
+ id = await sampleId(server, id);
120
125
  }
121
126
  const res = await fetch(`${server}/p/${id}/details`).catch(() => null);
122
127
  if (!res?.ok)
@@ -124,6 +129,22 @@ async function sourceProject(from) {
124
129
  const { template, title } = (await res.json());
125
130
  return { server, id, template, title };
126
131
  }
132
+ async function listSamples(server) {
133
+ const res = await fetch(`${server}/api/samples`).catch(() => null);
134
+ if (!res?.ok || !res.headers.get('content-type')?.includes('json'))
135
+ return null;
136
+ return (await res.json());
137
+ }
138
+ async function sampleId(server, name) {
139
+ const res = await fetch(`${server}/api/samples/${encodeURIComponent(name)}`).catch(() => null);
140
+ if (!res)
141
+ throw new Error(`Couldn't reach ${server} to look up the sample '${name}'.`);
142
+ if (res.ok && res.headers.get('content-type')?.includes('json'))
143
+ return (await res.json()).id;
144
+ const names = (await listSamples(server))?.map((s) => s.name) ?? [];
145
+ const known = names.length ? ` Its samples: ${names.join(', ')}.` : '';
146
+ throw new Error(`There's no sample named '${name}' on ${server}.${known} --from also takes a project link or its full 32-character id.`);
147
+ }
127
148
  async function savedProject() {
128
149
  if (!existsSync(join(root, CONFIG)))
129
150
  return null;
@@ -314,22 +335,35 @@ const commands = {
314
335
  async qr() {
315
336
  await printPairing(await loadRef());
316
337
  },
338
+ async samples() {
339
+ const server = flag('server') ?? LIVE_SERVER;
340
+ const list = await listSamples(server);
341
+ if (!list)
342
+ throw new Error(`Couldn't list the samples on ${server}.`);
343
+ if (!list.length)
344
+ return console.log(`${server} has no named samples yet.`);
345
+ const width = Math.max(...list.map((s) => s.name.length));
346
+ for (const s of list)
347
+ console.log(` ${s.name.padEnd(width)} ${s.title}`);
348
+ console.log(`\nStart from one with: npx @nativescript/cloudflare-cli live --from <name>`);
349
+ },
317
350
  async help() {
318
351
  console.log(`ns-edge <command>
319
352
 
320
- live [--ng|--react|--vue|--svelte|--solid|--desktop|--electron|--expo] [--new] [--from <link>] [--no-open] [--allow-eval]
353
+ live [--ng|--react|--vue|--svelte|--solid|--desktop|--electron|--expo] [--new] [--from <sample>] [--no-open] [--allow-eval]
321
354
  create a project (or reopen this folder's), open its IDE, and print a QR code
322
355
  for your phone; --ng, --react, --vue, --svelte or --solid picks the framework
323
356
  (plain TypeScript with XML views otherwise); --desktop (or --mac, --windows)
324
357
  or --electron runs it on this Mac or Windows PC instead, with that OS's own
325
358
  controls; --expo runs an Expo Desktop app on this Mac or Windows x64 PC;
326
- --from starts from a copy of a shared project (a sample's link or id)
359
+ --from starts from a copy of a shared project: a sample's name, link or id
327
360
  create [--server <url>] [--token <t>] [--ng|--react|--vue|--svelte|--solid|--template <name>]
328
361
  create an edge project and save .ns-edge.json
329
362
  push upload app/ and server/ in one transaction
330
363
  watch push, then stream every save to the edge
331
364
  pull download the project's files here
332
- qr print the pairing QR code`);
365
+ qr print the pairing QR code
366
+ samples list the samples --from can start from by name`);
333
367
  },
334
368
  };
335
369
  const run = commands[cmd] ?? commands.help;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript/cloudflare-cli",
3
- "version": "0.1.0-beta.10",
3
+ "version": "0.1.0-beta.11",
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",