@nativescript/cloudflare-cli 0.1.0-beta.0 → 0.1.0-beta.2
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 +1 -1
- package/dist/bin.js +29 -4
- package/dist/sync.d.ts +1 -1
- package/dist/sync.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Mirror a NativeScript project into an ns-edge project from a terminal or a Vite
|
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
npm i -D @nativescript/cloudflare-cli@beta
|
|
7
|
-
npx ns-edge create --server https://preview.nativescript.org --token <create token>
|
|
7
|
+
npx ns-edge create --server https://preview.nativescript.org --token <create token> # --template vue for nativescript-vue
|
|
8
8
|
npx ns-edge watch # push, then every save
|
|
9
9
|
npx ns-edge qr # print the pairing QR code again
|
|
10
10
|
```
|
package/dist/bin.js
CHANGED
|
@@ -2,23 +2,48 @@
|
|
|
2
2
|
import { watch } from 'node:fs';
|
|
3
3
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { join, sep } from 'node:path';
|
|
5
|
+
import { createInterface } from 'node:readline/promises';
|
|
5
6
|
import QRCode from 'qrcode';
|
|
6
7
|
import { applyChanges, collect, createProject, projectUrl, report, SYNCED } from './sync.js';
|
|
7
8
|
const CONFIG = '.ns-edge.json';
|
|
8
9
|
const DEBOUNCE_MS = 120;
|
|
9
10
|
const [cmd = 'help', ...args] = process.argv.slice(2);
|
|
11
|
+
/**
|
|
12
|
+
* Editors and tools write temp, swap and backup files next to the real one
|
|
13
|
+
* (sed -i's `.!123!file`, vim's `.file.swp`, `file~`). Skipped like collect()
|
|
14
|
+
* skips dotfiles: one such path in a batch makes the edge reject the whole batch.
|
|
15
|
+
*/
|
|
16
|
+
const isScratch = (rel) => rel.split('/').some((part) => part.startsWith('.')) || rel.endsWith('~');
|
|
10
17
|
const flag = (name) => {
|
|
11
18
|
const i = args.indexOf(`--${name}`);
|
|
12
19
|
return i >= 0 ? args[i + 1] : undefined;
|
|
13
20
|
};
|
|
14
21
|
const root = process.cwd();
|
|
15
22
|
async function loadRef() {
|
|
23
|
+
let ref;
|
|
16
24
|
try {
|
|
17
|
-
|
|
25
|
+
ref = JSON.parse(await readFile(join(root, CONFIG), 'utf8'));
|
|
18
26
|
}
|
|
19
27
|
catch {
|
|
20
28
|
throw new Error(`No ${CONFIG} here. Run \`ns-edge create --server <url>\` first.`);
|
|
21
29
|
}
|
|
30
|
+
// Copies meant to be shared (the IDE's StackBlitz export) leave the write key out of the file,
|
|
31
|
+
// so it is asked for here and kept in memory only.
|
|
32
|
+
ref.writeKey ||= process.env.NS_EDGE_WRITE_KEY || (await ask("Paste this project's write key (the IDE copied it to your clipboard): "));
|
|
33
|
+
if (!ref.writeKey)
|
|
34
|
+
throw new Error(`No write key: add it to ${CONFIG} or set NS_EDGE_WRITE_KEY.`);
|
|
35
|
+
return ref;
|
|
36
|
+
}
|
|
37
|
+
async function ask(question) {
|
|
38
|
+
if (!process.stdin.isTTY)
|
|
39
|
+
return '';
|
|
40
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
41
|
+
try {
|
|
42
|
+
return (await rl.question(question)).trim();
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
rl.close();
|
|
46
|
+
}
|
|
22
47
|
}
|
|
23
48
|
async function printPairing(ref) {
|
|
24
49
|
const url = projectUrl(ref);
|
|
@@ -30,7 +55,7 @@ async function printPairing(ref) {
|
|
|
30
55
|
const commands = {
|
|
31
56
|
async create() {
|
|
32
57
|
const server = flag('server') ?? 'http://localhost:5173';
|
|
33
|
-
const ref = await createProject(server, flag('token') ?? process.env.NS_EDGE_CREATE_TOKEN);
|
|
58
|
+
const ref = await createProject(server, flag('token') ?? process.env.NS_EDGE_CREATE_TOKEN, flag('template'));
|
|
34
59
|
await writeFile(join(root, CONFIG), JSON.stringify(ref, null, 2) + '\n');
|
|
35
60
|
console.log(`Created project ${ref.id} (saved to ${CONFIG}; it holds the project keys, keep it out of git)`);
|
|
36
61
|
await printPairing(ref);
|
|
@@ -74,7 +99,7 @@ const commands = {
|
|
|
74
99
|
if (!file)
|
|
75
100
|
return;
|
|
76
101
|
const rel = file.split(sep).join('/');
|
|
77
|
-
if (SYNCED.test(rel))
|
|
102
|
+
if (SYNCED.test(rel) && !isScratch(rel))
|
|
78
103
|
changed(rel);
|
|
79
104
|
});
|
|
80
105
|
}
|
|
@@ -100,7 +125,7 @@ const commands = {
|
|
|
100
125
|
async help() {
|
|
101
126
|
console.log(`ns-edge <command>
|
|
102
127
|
|
|
103
|
-
create [--server <url>] [--token <t>]
|
|
128
|
+
create [--server <url>] [--token <t>] [--template core|vue]
|
|
104
129
|
create an edge project and save .ns-edge.json
|
|
105
130
|
push upload app/ and server/ in one transaction
|
|
106
131
|
watch push, then stream every save to the edge
|
package/dist/sync.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface ApplyResult {
|
|
|
17
17
|
/** Project-relative paths that are mirrored to the edge. */
|
|
18
18
|
export declare const SYNCED: RegExp;
|
|
19
19
|
export declare function projectUrl(ref: ProjectRef): string;
|
|
20
|
-
export declare function createProject(server: string, token?: string): Promise<ProjectRef>;
|
|
20
|
+
export declare function createProject(server: string, token?: string, template?: string): Promise<ProjectRef>;
|
|
21
21
|
/** Sends a batch as one edge transaction, so devices see one consistent update. */
|
|
22
22
|
export declare function applyChanges(ref: ProjectRef, changes: {
|
|
23
23
|
path: string;
|
package/dist/sync.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
2
2
|
import { join, relative, sep } from 'node:path';
|
|
3
3
|
/** Project-relative paths that are mirrored to the edge. */
|
|
4
|
-
export const SYNCED = /^(app|server)\/.+\.(ts|mts|js|mjs|xml|css|json)$/;
|
|
4
|
+
export const SYNCED = /^(app|server)\/.+\.(ts|mts|js|mjs|vue|xml|css|json)$/;
|
|
5
5
|
export function projectUrl(ref) {
|
|
6
6
|
return `${ref.server.replace(/\/$/, '')}/p/${ref.id}`;
|
|
7
7
|
}
|
|
8
|
-
export async function createProject(server, token) {
|
|
9
|
-
const
|
|
8
|
+
export async function createProject(server, token, template) {
|
|
9
|
+
const query = template ? `?template=${encodeURIComponent(template)}` : '';
|
|
10
|
+
const res = await fetch(`${server.replace(/\/$/, '')}/api/projects${query}`, {
|
|
10
11
|
method: 'POST',
|
|
11
12
|
headers: token ? { authorization: `Bearer ${token}` } : {},
|
|
12
13
|
});
|
package/package.json
CHANGED