sagacloud 0.3.1 → 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.
Files changed (2) hide show
  1. package/dist/index.js +70 -15
  2. 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 || opts.browser === false || isHeadlessOrRemoteShell()) {
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
- console.log(pc.bold("Opening SagaCloud browser login..."));
539
- console.log(`If your browser doesn't open, visit:
540
- ${pc.cyan(authUrl.toString())}
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
- const opened = await openBrowser(authUrl.toString());
543
- if (!opened) {
544
- server.close();
545
- console.log(pc.yellow("No working local browser opener detected; switching to manual authorization mode.\n"));
546
- await promptManualLogin(apiUrl, panelBase, false);
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 code = await new Promise((resolve, reject) => {
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 });
607
+ });
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(() => {
600
628
  });
629
+ })() : new Promise(() => {
601
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, code);
649
+ const exchanged = await exchangeCliCode(apiUrl, authResult.value);
605
650
  writeAuthProfile({
606
651
  token: exchanged.token,
607
652
  apiUrl,
@@ -954,6 +999,10 @@ var STATIC_NON_WEB_IGNORES = [
954
999
  ".editorconfig",
955
1000
  ".gitignore",
956
1001
  ".gitattributes",
1002
+ ".gitkeep",
1003
+ "**/.gitkeep",
1004
+ ".keep",
1005
+ "**/.keep",
957
1006
  ".browserslistrc",
958
1007
  ".npmrc",
959
1008
  ".prettierrc",
@@ -1234,7 +1283,13 @@ function registerDeployCommands(program2) {
1234
1283
  const uploadSpin = p2.spinner();
1235
1284
  uploadSpin.start("Uploading bundle to SagaCloud...");
1236
1285
  const zipName = `${(jsonc?.app_name || jsonc?.name || path4.basename(cwd) || "bundle").replace(/[^a-z0-9-]+/gi, "-")}.zip`;
1237
- const uploaded = await client.uploadBundle(archive.buffer, zipName, siteType);
1286
+ let uploaded;
1287
+ try {
1288
+ uploaded = await client.uploadBundle(archive.buffer, zipName, siteType);
1289
+ } catch (err) {
1290
+ uploadSpin.stop("Upload failed");
1291
+ throw err;
1292
+ }
1238
1293
  uploadSpin.stop(`Uploaded (${uploaded.detected_entry})`);
1239
1294
  const mergedVars = /* @__PURE__ */ new Map();
1240
1295
  if (jsonc?.vars) {
@@ -2042,7 +2097,7 @@ function registerSkillCommands(program2) {
2042
2097
 
2043
2098
  // src/index.ts
2044
2099
  var program = new Command();
2045
- program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.3.1");
2100
+ program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.3.3");
2046
2101
  registerAuthCommands(program);
2047
2102
  registerProjectCommands(program);
2048
2103
  registerDeployCommands(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sagacloud",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Official CLI for SagaCloud Web & App Hosting",
5
5
  "license": "MIT",
6
6
  "author": "SagaSoft",