sprouts-cli 0.1.0 → 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/README.md +7 -2
- package/dist/index.js +49 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,9 +8,14 @@ Terminal helper for **Sprouts IDE pairing**: starts a device session, opens the
|
|
|
8
8
|
npx sprouts-cli login
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## API URL
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Default is **`http://127.0.0.1:3000`** (local Sprouts backend). Override if your API is elsewhere:
|
|
14
|
+
|
|
15
|
+
- **Env:** `SPROUTS_API_URL=https://your-tunnel.example.ngrok-free.dev npx sprouts-cli login`
|
|
16
|
+
- **File:** `~/.sprouts/config.json` → `{ "apiUrl": "https://..." }` (no trailing slash)
|
|
17
|
+
|
|
18
|
+
When production is live at `https://api.getsprouts.io`, set one of the above or export `SPROUTS_API_URL` before running.
|
|
14
19
|
|
|
15
20
|
## Publish
|
|
16
21
|
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,34 @@
|
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
-
|
|
5
|
+
/** Local backend default — production API is not always deployed at api.getsprouts.io yet. */
|
|
6
|
+
const DEFAULT_API = "http://127.0.0.1:3000";
|
|
7
|
+
function configPath() {
|
|
8
|
+
const home = process.env.HOME || process.env.USERPROFILE || ".";
|
|
9
|
+
return path.join(home, ".sprouts", "config.json");
|
|
10
|
+
}
|
|
11
|
+
function readConfigApiUrl() {
|
|
12
|
+
try {
|
|
13
|
+
const p = configPath();
|
|
14
|
+
if (!fs.existsSync(p))
|
|
15
|
+
return undefined;
|
|
16
|
+
const raw = fs.readFileSync(p, "utf8");
|
|
17
|
+
const j = JSON.parse(raw);
|
|
18
|
+
const u = j.apiUrl?.trim().replace(/\/$/, "");
|
|
19
|
+
return u || undefined;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
6
25
|
function getApiBase() {
|
|
7
|
-
const
|
|
8
|
-
|
|
26
|
+
const fromEnv = process.env.SPROUTS_API_URL?.trim().replace(/\/$/, "");
|
|
27
|
+
if (fromEnv)
|
|
28
|
+
return fromEnv;
|
|
29
|
+
const fromFile = readConfigApiUrl();
|
|
30
|
+
if (fromFile)
|
|
31
|
+
return fromFile;
|
|
32
|
+
return DEFAULT_API;
|
|
9
33
|
}
|
|
10
34
|
function openUrl(url) {
|
|
11
35
|
const platform = process.platform;
|
|
@@ -49,13 +73,27 @@ async function pollToken(api, deviceCode, intervalSec) {
|
|
|
49
73
|
}
|
|
50
74
|
throw new Error("Timed out waiting for browser sign-in.");
|
|
51
75
|
}
|
|
76
|
+
const LOCAL_FALLBACK = "http://127.0.0.1:3000";
|
|
52
77
|
async function cmdLogin() {
|
|
53
|
-
|
|
78
|
+
let api = getApiBase();
|
|
54
79
|
console.log(`Using API: ${api}`);
|
|
55
|
-
|
|
80
|
+
let startRes = await fetch(`${api}/api/ide/device/start`, {
|
|
56
81
|
method: "POST",
|
|
57
82
|
headers: { "Content-Type": "application/json" },
|
|
58
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
|
+
}
|
|
59
97
|
if (!startRes.ok) {
|
|
60
98
|
const err = await startRes.text();
|
|
61
99
|
throw new Error(`device/start failed: ${startRes.status} ${err}`);
|
|
@@ -71,7 +109,8 @@ async function cmdLogin() {
|
|
|
71
109
|
fs.mkdirSync(dir, { recursive: true });
|
|
72
110
|
fs.writeFileSync(tokenPath(), JSON.stringify({ access_token: access_token, savedAt: new Date().toISOString() }, null, 2), "utf8");
|
|
73
111
|
console.log("\nDone. Token saved to:", tokenPath());
|
|
74
|
-
console.log("
|
|
112
|
+
console.log("In Cursor/VS Code: open the Sprouts sidebar (activity bar) → click Refresh, or run “Sprouts: Refresh panel”.\n" +
|
|
113
|
+
"The extension loads this token automatically when its secret store is empty.\n");
|
|
75
114
|
}
|
|
76
115
|
function printHelp() {
|
|
77
116
|
console.log(`
|
|
@@ -80,8 +119,10 @@ Sprouts CLI — pair your editor session
|
|
|
80
119
|
Usage:
|
|
81
120
|
npx sprouts-cli login Start browser sign-in and save IDE token to ~/.sprouts/ide-token.json
|
|
82
121
|
|
|
83
|
-
Environment:
|
|
84
|
-
SPROUTS_API_URL
|
|
122
|
+
Environment & config:
|
|
123
|
+
SPROUTS_API_URL Backend base URL (overrides everything if set)
|
|
124
|
+
~/.sprouts/config.json Optional: { "apiUrl": "https://your-ngrok-url.ngrok-free.dev" }
|
|
125
|
+
Default API: ${DEFAULT_API} (local backend; set env or config for a public URL)
|
|
85
126
|
`);
|
|
86
127
|
}
|
|
87
128
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprouts-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Sprouts CLI — IDE pairing (opens browser to sign in)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"sprouts": "
|
|
7
|
+
"sprouts": "dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|