@nativescript/cloudflare-cli 0.1.0-beta.0 → 0.1.0-beta.1
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/dist/bin.js +27 -2
- package/package.json +1 -1
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);
|
|
@@ -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
|
}
|
package/package.json
CHANGED