@baclet/cli 0.1.2 → 0.1.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/README.md +2 -1
- package/package.json +1 -1
- package/src/commands/auth.js +2 -2
- package/src/commands/project.js +29 -2
- package/src/index.js +8 -4
package/README.md
CHANGED
|
@@ -26,12 +26,13 @@ Node.js 18 or later is required.
|
|
|
26
26
|
| --- | --- |
|
|
27
27
|
| `baclet login [--qr\|--link]` | Authorize this machine with a QR code, a link, or both. |
|
|
28
28
|
| `baclet logout` | Remove local credentials and revoke the CLI token. |
|
|
29
|
-
| `baclet whoami` | Show the authorized
|
|
29
|
+
| `baclet whoami` | Show the authorized user's name and email. |
|
|
30
30
|
| `baclet init [--publishable-key KEY]` | Create `baclet.config.ts`, selecting a project when logged in. |
|
|
31
31
|
| `baclet projects list` | List projects you can access. |
|
|
32
32
|
| `baclet db status` | Print the schema diff without applying it. |
|
|
33
33
|
| `baclet db push [--yes]` | Apply the schema diff after confirmation. |
|
|
34
34
|
| `baclet db migrate [--yes]` | Alias for `db push`. |
|
|
35
|
+
| `baclet --version` | Print the CLI version. |
|
|
35
36
|
|
|
36
37
|
## Login
|
|
37
38
|
|
package/package.json
CHANGED
package/src/commands/auth.js
CHANGED
|
@@ -74,6 +74,6 @@ export async function whoami() {
|
|
|
74
74
|
const creds = await requireCredentials();
|
|
75
75
|
const payload = await request({ method: "GET", path: "/api/v1/me", token: creds.accessToken });
|
|
76
76
|
const profile = payload.user || payload;
|
|
77
|
-
|
|
78
|
-
console.log(
|
|
77
|
+
const name = profile.full_name || profile.fullName || profile.email;
|
|
78
|
+
console.log(name === profile.email ? profile.email : `${name} <${profile.email}>`);
|
|
79
79
|
}
|
package/src/commands/project.js
CHANGED
|
@@ -70,6 +70,32 @@ export async function listProjects() {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
function normalizeModels(models) {
|
|
74
|
+
return models.map((model) => ({
|
|
75
|
+
...model,
|
|
76
|
+
fields: Object.fromEntries(
|
|
77
|
+
Object.entries(model.fields).map(([name, field]) => [
|
|
78
|
+
name,
|
|
79
|
+
{
|
|
80
|
+
type: field.type,
|
|
81
|
+
required: field.required ?? false,
|
|
82
|
+
default: field.default ?? null,
|
|
83
|
+
unique: field.unique ?? false,
|
|
84
|
+
index: field.index ?? false,
|
|
85
|
+
values: field.values ?? [],
|
|
86
|
+
precision: field.precision ?? 0,
|
|
87
|
+
scale: field.scale ?? 0,
|
|
88
|
+
reference: {
|
|
89
|
+
model: field.reference?.model ?? "",
|
|
90
|
+
field: field.reference?.field ?? "",
|
|
91
|
+
onDelete: field.reference?.onDelete ?? "",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
]),
|
|
95
|
+
),
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
|
|
73
99
|
function printDiff(result) {
|
|
74
100
|
const statements = result?.diff?.statements || [];
|
|
75
101
|
const warnings = result?.diff?.warnings || [];
|
|
@@ -86,13 +112,14 @@ function printDiff(result) {
|
|
|
86
112
|
async function push(args, apply) {
|
|
87
113
|
const creds = await requireCredentials();
|
|
88
114
|
const { models, projectId } = await loadProject();
|
|
115
|
+
const payloadModels = normalizeModels(models);
|
|
89
116
|
console.log(`Loaded ${models.length} model${models.length === 1 ? "" : "s"} from project ${projectId}.`);
|
|
90
117
|
|
|
91
118
|
const result = await request({
|
|
92
119
|
method: "POST",
|
|
93
120
|
path: `/api/v1/cli/schema/${apply ? "push" : "status"}`,
|
|
94
121
|
token: creds.accessToken,
|
|
95
|
-
body: { projectId, models },
|
|
122
|
+
body: { projectId, models: payloadModels, apply: false },
|
|
96
123
|
});
|
|
97
124
|
printDiff(result);
|
|
98
125
|
|
|
@@ -109,7 +136,7 @@ async function push(args, apply) {
|
|
|
109
136
|
method: "POST",
|
|
110
137
|
path: "/api/v1/cli/schema/push",
|
|
111
138
|
token: creds.accessToken,
|
|
112
|
-
body: { projectId, models, apply: true },
|
|
139
|
+
body: { projectId, models: payloadModels, apply: true },
|
|
113
140
|
});
|
|
114
141
|
console.log(`\nSchema applied. Version ${applied.version} saved.`);
|
|
115
142
|
}
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
2
3
|
import { login, logout, whoami } from "./commands/auth.js";
|
|
3
4
|
import { init, listProjects, dbStatus, dbPush } from "./commands/project.js";
|
|
4
5
|
|
|
6
|
+
const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
7
|
+
|
|
5
8
|
const help = `BACLET CLI
|
|
6
9
|
|
|
7
10
|
Usage:
|
|
@@ -13,11 +16,8 @@ Usage:
|
|
|
13
16
|
baclet db status Show the schema diff without applying it
|
|
14
17
|
baclet db push [--yes] Apply the schema to your project database
|
|
15
18
|
baclet db migrate [--yes] Alias for db push
|
|
19
|
+
baclet --version Print the CLI version
|
|
16
20
|
baclet --help Show this message
|
|
17
|
-
|
|
18
|
-
Environment:
|
|
19
|
-
BACLET_API_URL API base URL (default https://api.baclet.app)
|
|
20
|
-
BACLET_DASHBOARD_URL Dashboard URL (default https://baclet.app)
|
|
21
21
|
`;
|
|
22
22
|
|
|
23
23
|
async function main() {
|
|
@@ -34,6 +34,10 @@ async function main() {
|
|
|
34
34
|
if (args[0] === "status") return dbStatus();
|
|
35
35
|
if (args[0] === "push" || args[0] === "migrate") return dbPush(args.slice(1));
|
|
36
36
|
throw new Error("Usage: baclet db status|push|migrate");
|
|
37
|
+
case "--version":
|
|
38
|
+
case "-v":
|
|
39
|
+
process.stdout.write(`${version}\n`);
|
|
40
|
+
return;
|
|
37
41
|
case "--help":
|
|
38
42
|
case "-h":
|
|
39
43
|
case undefined:
|