@await-widget/runtime 0.0.21 → 0.0.23
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/bin/await-widget.js +22 -2
- package/package.json +1 -1
package/bin/await-widget.js
CHANGED
|
@@ -23,6 +23,10 @@ function main() {
|
|
|
23
23
|
function startDevServer(args) {
|
|
24
24
|
const options = parseDevArgs(args);
|
|
25
25
|
const root = path.resolve(options.root);
|
|
26
|
+
if (!isSubdirectory(root)) {
|
|
27
|
+
printHelp();
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
26
30
|
const stats = fs.statSync(root);
|
|
27
31
|
if (!stats.isDirectory()) {
|
|
28
32
|
throw new Error(`${root} is not a directory`);
|
|
@@ -42,7 +46,7 @@ function startDevServer(args) {
|
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
function parseDevArgs(args) {
|
|
45
|
-
let root
|
|
49
|
+
let root;
|
|
46
50
|
let port = defaultPort;
|
|
47
51
|
for (let index = 0; index < args.length; index += 1) {
|
|
48
52
|
const arg = args[index];
|
|
@@ -57,9 +61,18 @@ function parseDevArgs(args) {
|
|
|
57
61
|
}
|
|
58
62
|
root = arg;
|
|
59
63
|
}
|
|
64
|
+
if (!root) {
|
|
65
|
+
printHelp();
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
60
68
|
return {root, port};
|
|
61
69
|
}
|
|
62
70
|
|
|
71
|
+
function isSubdirectory(root) {
|
|
72
|
+
const relativePath = path.relative(process.cwd(), root);
|
|
73
|
+
return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
|
|
74
|
+
}
|
|
75
|
+
|
|
63
76
|
function handleRequest({request, response, root, token}) {
|
|
64
77
|
const url = new URL(request.url ?? "/", "http://localhost");
|
|
65
78
|
if (url.pathname === "/") {
|
|
@@ -249,7 +262,9 @@ function printServerUrls(port, token) {
|
|
|
249
262
|
const recommended = networkUrls.find(({address}) => isPrivateIPv4(address)) ?? networkUrls[0];
|
|
250
263
|
if (recommended) {
|
|
251
264
|
console.log("Paste this URL into Await on iPhone:");
|
|
265
|
+
console.log("");
|
|
252
266
|
console.log(recommended.url);
|
|
267
|
+
console.log("");
|
|
253
268
|
}
|
|
254
269
|
const otherUrls = [
|
|
255
270
|
{url: `http://127.0.0.1:${port}?token=${token}`},
|
|
@@ -295,7 +310,12 @@ function urlForRequest(request, token) {
|
|
|
295
310
|
|
|
296
311
|
function printHelp() {
|
|
297
312
|
console.log(`Usage:
|
|
298
|
-
await-widget dev
|
|
313
|
+
await-widget dev <widget-directory> [--port ${defaultPort}]
|
|
314
|
+
|
|
315
|
+
Example:
|
|
316
|
+
await-widget dev MyWidget
|
|
317
|
+
|
|
318
|
+
Pass a widget subdirectory, not the current package directory.
|
|
299
319
|
`);
|
|
300
320
|
}
|
|
301
321
|
|