sprouts-cli 0.1.2 → 0.1.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 +16 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -73,13 +73,27 @@ async function pollToken(api, deviceCode, intervalSec) {
|
|
|
73
73
|
}
|
|
74
74
|
throw new Error("Timed out waiting for browser sign-in.");
|
|
75
75
|
}
|
|
76
|
+
const LOCAL_FALLBACK = "http://127.0.0.1:3000";
|
|
76
77
|
async function cmdLogin() {
|
|
77
|
-
|
|
78
|
+
let api = getApiBase();
|
|
78
79
|
console.log(`Using API: ${api}`);
|
|
79
|
-
|
|
80
|
+
let startRes = await fetch(`${api}/api/ide/device/start`, {
|
|
80
81
|
method: "POST",
|
|
81
82
|
headers: { "Content-Type": "application/json" },
|
|
82
83
|
});
|
|
84
|
+
if (!startRes.ok &&
|
|
85
|
+
api !== LOCAL_FALLBACK &&
|
|
86
|
+
(api.includes("api.getsprouts.io") || api.includes("getsprouts.io"))) {
|
|
87
|
+
const errPreview = await startRes.text();
|
|
88
|
+
const short = errPreview.length > 140 ? `${errPreview.slice(0, 140)}…` : errPreview;
|
|
89
|
+
console.warn(`\n${api} returned ${startRes.status}: ${short}\n` +
|
|
90
|
+
`Retrying local backend ${LOCAL_FALLBACK} — run \`cd backend && npm run dev\`, or set SPROUTS_API_URL to your API.\n`);
|
|
91
|
+
api = LOCAL_FALLBACK;
|
|
92
|
+
startRes = await fetch(`${api}/api/ide/device/start`, {
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: { "Content-Type": "application/json" },
|
|
95
|
+
});
|
|
96
|
+
}
|
|
83
97
|
if (!startRes.ok) {
|
|
84
98
|
const err = await startRes.text();
|
|
85
99
|
throw new Error(`device/start failed: ${startRes.status} ${err}`);
|