sagacloud 0.3.2 → 0.3.3
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/index.js +59 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import pc8 from "picocolors";
|
|
|
8
8
|
import crypto from "crypto";
|
|
9
9
|
import http from "http";
|
|
10
10
|
import os2 from "os";
|
|
11
|
+
import readline from "readline/promises";
|
|
11
12
|
import * as p from "@clack/prompts";
|
|
12
13
|
import Table from "cli-table3";
|
|
13
14
|
import pc from "picocolors";
|
|
@@ -519,7 +520,7 @@ function registerAuthCommands(program2) {
|
|
|
519
520
|
await authenticateWithToken(opts.token, apiUrl, opts.panelUrl);
|
|
520
521
|
return;
|
|
521
522
|
}
|
|
522
|
-
if (opts.manual
|
|
523
|
+
if (opts.manual) {
|
|
523
524
|
await promptManualLogin(apiUrl, panelBase, Boolean(opts.browser !== false && !isHeadlessOrRemoteShell()));
|
|
524
525
|
return;
|
|
525
526
|
}
|
|
@@ -535,18 +536,24 @@ function registerAuthCommands(program2) {
|
|
|
535
536
|
authUrl.searchParams.set("callback", callbackUrl);
|
|
536
537
|
authUrl.searchParams.set("state", state);
|
|
537
538
|
authUrl.searchParams.set("device", os2.hostname());
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
539
|
+
const shouldTryOpen = opts.browser !== false && !isHeadlessOrRemoteShell();
|
|
540
|
+
const manualUrl = new URL(`${panelBase}/hosting/cli-auth`);
|
|
541
|
+
manualUrl.searchParams.set("mode", "manual");
|
|
542
|
+
manualUrl.searchParams.set("device", os2.hostname());
|
|
543
|
+
console.log(pc.bold("Authenticate SagaCloud CLI (Browser OR Manual Paste):"));
|
|
544
|
+
console.log(`\u2022 ${pc.bold("Browser auto-login:")} ${pc.cyan(authUrl.toString())}`);
|
|
545
|
+
console.log(`\u2022 ${pc.bold("Remote / SSH / Copy code:")} ${pc.cyan(manualUrl.toString())}
|
|
541
546
|
`);
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
return;
|
|
547
|
+
if (shouldTryOpen) {
|
|
548
|
+
const opened = await openBrowser(authUrl.toString());
|
|
549
|
+
if (!opened) {
|
|
550
|
+
console.log(pc.yellow("No local browser opener found \u2014 open either URL above and paste your code/token below.\n"));
|
|
551
|
+
}
|
|
548
552
|
}
|
|
549
|
-
const
|
|
553
|
+
const ac = new AbortController();
|
|
554
|
+
let settled = false;
|
|
555
|
+
const rl = process.stdin.isTTY ? readline.createInterface({ input: process.stdin, output: process.stdout }) : null;
|
|
556
|
+
const serverPromise = new Promise((resolve, reject) => {
|
|
550
557
|
const timeout = setTimeout(() => {
|
|
551
558
|
server.close();
|
|
552
559
|
reject(new Error("Login timed out after 3 minutes."));
|
|
@@ -596,12 +603,50 @@ function registerAuthCommands(program2) {
|
|
|
596
603
|
})
|
|
597
604
|
);
|
|
598
605
|
server.close();
|
|
599
|
-
resolve(recvCode);
|
|
606
|
+
resolve({ kind: "code", value: recvCode });
|
|
600
607
|
});
|
|
601
608
|
});
|
|
609
|
+
const pastePromise = rl ? (async () => {
|
|
610
|
+
rl.on("SIGINT", () => {
|
|
611
|
+
server.close();
|
|
612
|
+
rl.close();
|
|
613
|
+
console.log("\nLogin cancelled.");
|
|
614
|
+
process.exit(1);
|
|
615
|
+
});
|
|
616
|
+
while (!settled) {
|
|
617
|
+
const ans = (await rl.question(
|
|
618
|
+
pc.dim("Waiting for browser approval \u2014 or paste code / sc_live_... token: "),
|
|
619
|
+
{ signal: ac.signal }
|
|
620
|
+
)).trim();
|
|
621
|
+
if (!ans) continue;
|
|
622
|
+
return {
|
|
623
|
+
kind: ans.startsWith("sc_live_") ? "token" : "code",
|
|
624
|
+
value: ans
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
return await new Promise(() => {
|
|
628
|
+
});
|
|
629
|
+
})() : new Promise(() => {
|
|
630
|
+
});
|
|
631
|
+
let authResult;
|
|
632
|
+
try {
|
|
633
|
+
authResult = await Promise.race([serverPromise, pastePromise]);
|
|
634
|
+
} finally {
|
|
635
|
+
settled = true;
|
|
636
|
+
ac.abort();
|
|
637
|
+
if (rl) {
|
|
638
|
+
rl.close();
|
|
639
|
+
process.stdout.write("\n");
|
|
640
|
+
}
|
|
641
|
+
server.close();
|
|
642
|
+
}
|
|
643
|
+
if (authResult.kind === "token") {
|
|
644
|
+
await authenticateWithToken(authResult.value, apiUrl, panelBase);
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
602
647
|
const spin = p.spinner();
|
|
603
648
|
spin.start("Exchanging one-time authorization code...");
|
|
604
|
-
const exchanged = await exchangeCliCode(apiUrl,
|
|
649
|
+
const exchanged = await exchangeCliCode(apiUrl, authResult.value);
|
|
605
650
|
writeAuthProfile({
|
|
606
651
|
token: exchanged.token,
|
|
607
652
|
apiUrl,
|
|
@@ -2052,7 +2097,7 @@ function registerSkillCommands(program2) {
|
|
|
2052
2097
|
|
|
2053
2098
|
// src/index.ts
|
|
2054
2099
|
var program = new Command();
|
|
2055
|
-
program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.3.
|
|
2100
|
+
program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.3.3");
|
|
2056
2101
|
registerAuthCommands(program);
|
|
2057
2102
|
registerProjectCommands(program);
|
|
2058
2103
|
registerDeployCommands(program);
|