@getrouter/getrouter-cli 0.1.7 → 0.1.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.
- package/dist/bin.mjs +21 -14
- package/package.json +1 -1
- package/src/core/auth/device.ts +30 -15
package/dist/bin.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { randomInt } from "node:crypto";
|
|
|
8
8
|
import prompts from "prompts";
|
|
9
9
|
|
|
10
10
|
//#region package.json
|
|
11
|
-
var version = "0.1.
|
|
11
|
+
var version = "0.1.8";
|
|
12
12
|
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/generated/router/dashboard/v1/index.ts
|
|
@@ -446,31 +446,38 @@ const generateAuthCode = () => {
|
|
|
446
446
|
return out;
|
|
447
447
|
};
|
|
448
448
|
const buildLoginUrl = (authCode) => `https://getrouter.dev/auth/${authCode}`;
|
|
449
|
+
const spawnBrowser = (command, args) => {
|
|
450
|
+
try {
|
|
451
|
+
const child = spawn(command, args, {
|
|
452
|
+
stdio: "ignore",
|
|
453
|
+
detached: true
|
|
454
|
+
});
|
|
455
|
+
child.on("error", (err) => {
|
|
456
|
+
const code = typeof err === "object" && err !== null && "code" in err ? err.code : void 0;
|
|
457
|
+
const reason = code === "ENOENT" ? ` (${command} not found)` : code ? ` (${code})` : "";
|
|
458
|
+
console.log(`⚠️ Unable to open browser${reason}. Please open the URL manually.`);
|
|
459
|
+
});
|
|
460
|
+
child.unref();
|
|
461
|
+
} catch {
|
|
462
|
+
console.log("⚠️ Unable to open browser. Please open the URL manually.");
|
|
463
|
+
}
|
|
464
|
+
};
|
|
449
465
|
const openLoginUrl = async (url) => {
|
|
450
466
|
try {
|
|
451
467
|
if (process.platform === "darwin") {
|
|
452
|
-
|
|
453
|
-
stdio: "ignore",
|
|
454
|
-
detached: true
|
|
455
|
-
}).unref();
|
|
468
|
+
spawnBrowser("open", [url]);
|
|
456
469
|
return;
|
|
457
470
|
}
|
|
458
471
|
if (process.platform === "win32") {
|
|
459
|
-
|
|
472
|
+
spawnBrowser("cmd", [
|
|
460
473
|
"/c",
|
|
461
474
|
"start",
|
|
462
475
|
"",
|
|
463
476
|
url
|
|
464
|
-
]
|
|
465
|
-
stdio: "ignore",
|
|
466
|
-
detached: true
|
|
467
|
-
}).unref();
|
|
477
|
+
]);
|
|
468
478
|
return;
|
|
469
479
|
}
|
|
470
|
-
|
|
471
|
-
stdio: "ignore",
|
|
472
|
-
detached: true
|
|
473
|
-
}).unref();
|
|
480
|
+
spawnBrowser("xdg-open", [url]);
|
|
474
481
|
} catch {}
|
|
475
482
|
};
|
|
476
483
|
const pollAuthorize = async ({ authorize, code, timeoutMs = 300 * 1e3, initialDelayMs = 1e3, maxDelayMs = 1e4, sleep = (ms) => new Promise((r) => setTimeout(r, ms)), now = () => Date.now(), onRetry }) => {
|
package/package.json
CHANGED
package/src/core/auth/device.ts
CHANGED
|
@@ -33,29 +33,44 @@ export const generateAuthCode = () => {
|
|
|
33
33
|
export const buildLoginUrl = (authCode: string) =>
|
|
34
34
|
`https://getrouter.dev/auth/${authCode}`;
|
|
35
35
|
|
|
36
|
+
const spawnBrowser = (command: string, args: string[]) => {
|
|
37
|
+
try {
|
|
38
|
+
const child = spawn(command, args, {
|
|
39
|
+
stdio: "ignore",
|
|
40
|
+
detached: true,
|
|
41
|
+
});
|
|
42
|
+
child.on("error", (err) => {
|
|
43
|
+
const code =
|
|
44
|
+
typeof err === "object" && err !== null && "code" in err
|
|
45
|
+
? (err as { code?: string }).code
|
|
46
|
+
: undefined;
|
|
47
|
+
const reason =
|
|
48
|
+
code === "ENOENT"
|
|
49
|
+
? ` (${command} not found)`
|
|
50
|
+
: code
|
|
51
|
+
? ` (${code})`
|
|
52
|
+
: "";
|
|
53
|
+
console.log(
|
|
54
|
+
`⚠️ Unable to open browser${reason}. Please open the URL manually.`,
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
child.unref();
|
|
58
|
+
} catch {
|
|
59
|
+
console.log("⚠️ Unable to open browser. Please open the URL manually.");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
36
63
|
export const openLoginUrl = async (url: string) => {
|
|
37
64
|
try {
|
|
38
65
|
if (process.platform === "darwin") {
|
|
39
|
-
|
|
40
|
-
stdio: "ignore",
|
|
41
|
-
detached: true,
|
|
42
|
-
});
|
|
43
|
-
child.unref();
|
|
66
|
+
spawnBrowser("open", [url]);
|
|
44
67
|
return;
|
|
45
68
|
}
|
|
46
69
|
if (process.platform === "win32") {
|
|
47
|
-
|
|
48
|
-
stdio: "ignore",
|
|
49
|
-
detached: true,
|
|
50
|
-
});
|
|
51
|
-
child.unref();
|
|
70
|
+
spawnBrowser("cmd", ["/c", "start", "", url]);
|
|
52
71
|
return;
|
|
53
72
|
}
|
|
54
|
-
|
|
55
|
-
stdio: "ignore",
|
|
56
|
-
detached: true,
|
|
57
|
-
});
|
|
58
|
-
child.unref();
|
|
73
|
+
spawnBrowser("xdg-open", [url]);
|
|
59
74
|
} catch {
|
|
60
75
|
// best effort
|
|
61
76
|
}
|