@uetuluk/create-cli 0.0.2 → 0.0.4
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/cli.js +18 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -25,11 +25,27 @@ async function api(serverUrl2, path, init = {}) {
|
|
|
25
25
|
} catch {
|
|
26
26
|
}
|
|
27
27
|
if (!r.ok) {
|
|
28
|
-
const msg =
|
|
28
|
+
const msg = formatErrorMessage(body, r.status);
|
|
29
29
|
throw new ApiError(r.status, msg, body);
|
|
30
30
|
}
|
|
31
31
|
return body;
|
|
32
32
|
}
|
|
33
|
+
function formatErrorMessage(body, status) {
|
|
34
|
+
if (!body || typeof body !== "object") return `HTTP ${status}`;
|
|
35
|
+
const b = body;
|
|
36
|
+
const outer = typeof b.error === "string" && b.error || typeof b.message === "string" && b.message || "";
|
|
37
|
+
const inner = innerDetail(b.data);
|
|
38
|
+
if (outer && inner && inner !== outer) return `${outer}: ${inner}`;
|
|
39
|
+
return outer || inner || `HTTP ${status}`;
|
|
40
|
+
}
|
|
41
|
+
function innerDetail(data) {
|
|
42
|
+
if (!data || typeof data !== "object") return "";
|
|
43
|
+
const d = data;
|
|
44
|
+
for (const v of [d.error, d.detail, d.message]) {
|
|
45
|
+
if (typeof v === "string" && v) return v;
|
|
46
|
+
}
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
33
49
|
|
|
34
50
|
// src/store.ts
|
|
35
51
|
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -265,7 +281,7 @@ cli.command("deploy <name>", "push schema + migrations to your instance").option
|
|
|
265
281
|
const r = await api(inst.url, "/api/v1/migrations", {
|
|
266
282
|
method: "POST",
|
|
267
283
|
token: inst.adminToken,
|
|
268
|
-
body: JSON.stringify({
|
|
284
|
+
body: JSON.stringify({ settings, generate: true })
|
|
269
285
|
});
|
|
270
286
|
console.log(colors.green(`deployed to ${inst.url}`));
|
|
271
287
|
if (r.applied?.length) console.log(` applied: ${r.applied.join(", ")}`);
|