@suronai/cli 0.1.41 → 0.1.43
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/package.json +1 -1
- package/src/commands.js +45 -14
package/package.json
CHANGED
package/src/commands.js
CHANGED
|
@@ -30,15 +30,14 @@ function openBrowser(url) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function
|
|
34
|
-
process.stdout.write(prompt);
|
|
33
|
+
function prompt(question) {
|
|
35
34
|
return new Promise(resolve => {
|
|
35
|
+
process.stdout.write(question);
|
|
36
36
|
const handler = (buf) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
37
|
+
const line = buf.toString().split("\n")[0].trim();
|
|
38
|
+
process.stdin.removeListener("data", handler);
|
|
39
|
+
process.stdin.pause();
|
|
40
|
+
resolve(line);
|
|
42
41
|
};
|
|
43
42
|
process.stdin.resume();
|
|
44
43
|
process.stdin.setEncoding("utf-8");
|
|
@@ -106,10 +105,21 @@ function installSdk(cwd) {
|
|
|
106
105
|
// ── Entry-point patching ──────────────────────────────────────────────────────
|
|
107
106
|
|
|
108
107
|
async function patchEntryPoint(cwd, isEsm) {
|
|
108
|
+
// Check package.json "main" first, then fall back to common names
|
|
109
|
+
let mainFromPkg = null;
|
|
110
|
+
try {
|
|
111
|
+
const pkg = JSON.parse(readFileSync(join(cwd, "package.json"), "utf-8"));
|
|
112
|
+
if (pkg.main) mainFromPkg = pkg.main;
|
|
113
|
+
} catch {}
|
|
114
|
+
|
|
109
115
|
const candidates = isEsm
|
|
110
116
|
? ["index.js", "index.mjs", "src/index.js", "src/index.mjs"]
|
|
111
117
|
: ["index.js", "index.cjs", "src/index.js", "src/index.cjs"];
|
|
112
118
|
|
|
119
|
+
if (mainFromPkg && !candidates.includes(mainFromPkg)) {
|
|
120
|
+
candidates.unshift(mainFromPkg);
|
|
121
|
+
}
|
|
122
|
+
|
|
113
123
|
let entryPath = null;
|
|
114
124
|
for (const rel of candidates) {
|
|
115
125
|
const abs = join(cwd, rel);
|
|
@@ -138,7 +148,18 @@ async function patchEntryPoint(cwd, isEsm) {
|
|
|
138
148
|
}
|
|
139
149
|
} else {
|
|
140
150
|
if (trimmed.includes("require")) {
|
|
141
|
-
|
|
151
|
+
// Handle: require("dotenv").config() → require("@suronai/sdk").config()
|
|
152
|
+
// Handle: require("dotenv/config") → require("@suronai/sdk").config()
|
|
153
|
+
// Handle: const x = require("dotenv") → const { config } = require("@suronai/sdk")\nawait config()
|
|
154
|
+
if (/require\(['"]dotenv['"]\)\.config/.test(trimmed)) {
|
|
155
|
+
replacement = indent + trimmed.replace(/require\(['"]dotenv['"]\)/, 'require("@suronai/sdk")');
|
|
156
|
+
// wrap the whole statement to be async-aware
|
|
157
|
+
replacement = indent + `await require("@suronai/sdk").config();`;
|
|
158
|
+
} else if (/require\(['"]dotenv\/config['"]\)/.test(trimmed)) {
|
|
159
|
+
replacement = indent + `await require("@suronai/sdk").config();`;
|
|
160
|
+
} else {
|
|
161
|
+
replacement = indent + `const { config: suronConfig } = require("@suronai/sdk");\n` + indent + `await suronConfig();`;
|
|
162
|
+
}
|
|
142
163
|
}
|
|
143
164
|
}
|
|
144
165
|
toReplace.push({ index: i, content: lines[i], replacement });
|
|
@@ -178,8 +199,7 @@ async function patchEntryPoint(cwd, isEsm) {
|
|
|
178
199
|
console.log(ui.blank());
|
|
179
200
|
}
|
|
180
201
|
|
|
181
|
-
await
|
|
182
|
-
const answer = "";
|
|
202
|
+
const answer = await prompt(ui.promptLine("apply patch? [Y/n]"));
|
|
183
203
|
const confirmed = answer === "" || /^y(es)?$/i.test(answer);
|
|
184
204
|
console.log(ui.blank());
|
|
185
205
|
console.log(ui.hr());
|
|
@@ -220,8 +240,7 @@ function printSnippet(isEsm) {
|
|
|
220
240
|
console.log(ui.INDENT + " " + ui.amber('import { config } from "@suronai/sdk"'));
|
|
221
241
|
console.log(ui.INDENT + " " + ui.amber("await config()"));
|
|
222
242
|
} else {
|
|
223
|
-
console.log(ui.INDENT + " " + ui.amber('
|
|
224
|
-
console.log(ui.INDENT + " " + ui.amber("await config()"));
|
|
243
|
+
console.log(ui.INDENT + " " + ui.amber('await require("@suronai/sdk").config()'));
|
|
225
244
|
}
|
|
226
245
|
console.log(ui.blank());
|
|
227
246
|
console.log(ui.hr());
|
|
@@ -263,7 +282,7 @@ export const loginCommand = new Command("login")
|
|
|
263
282
|
console.log(ui.kv("URL", loginUrl, 6));
|
|
264
283
|
console.log(ui.blank());
|
|
265
284
|
|
|
266
|
-
await
|
|
285
|
+
await prompt(ui.promptLine("open browser"));
|
|
267
286
|
openBrowser(loginUrl);
|
|
268
287
|
console.log(ui.blank());
|
|
269
288
|
|
|
@@ -494,6 +513,7 @@ export const whoamiCommand = new Command("whoami")
|
|
|
494
513
|
});
|
|
495
514
|
|
|
496
515
|
export const upCommand = new Command("up")
|
|
516
|
+
.description("Push a new version of .env")
|
|
497
517
|
.action(async () => {
|
|
498
518
|
requireToken();
|
|
499
519
|
const cwd = process.cwd();
|
|
@@ -502,9 +522,20 @@ export const upCommand = new Command("up")
|
|
|
502
522
|
if (!existsSync(join(cwd, ".env"))) cancel(".env not found");
|
|
503
523
|
|
|
504
524
|
const suronJson = JSON.parse(readFileSync(join(cwd, ".suron.json"), "utf-8"));
|
|
505
|
-
const { app_id }
|
|
525
|
+
const { app_id, version: currentVersion } = suronJson;
|
|
506
526
|
const env_plaintext = readFileSync(join(cwd, ".env"), "utf-8");
|
|
507
527
|
|
|
528
|
+
// ── Check if anything changed ─────────────────────────────────────────────
|
|
529
|
+
try {
|
|
530
|
+
const latest = await api(`/apps/${app_id}/versions/${currentVersion}`);
|
|
531
|
+
if (latest.env_plaintext?.trim() === env_plaintext.trim()) {
|
|
532
|
+
console.log(ui.blank());
|
|
533
|
+
console.log(ui.okBlock("nothing to push · .env unchanged since " + currentVersion));
|
|
534
|
+
console.log(ui.blank());
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
} catch { /* if fetch fails just proceed */ }
|
|
538
|
+
|
|
508
539
|
const s = spinner();
|
|
509
540
|
s.start("Pushing new version");
|
|
510
541
|
|