@better-auth/cli 1.2.12 → 1.3.0-beta.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 +41 -0
- package/dist/index.mjs +15 -5
- package/package.json +10 -2
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Better Auth CLI
|
|
2
|
+
|
|
3
|
+
Better Auth comes with a built-in CLI to help you manage the database schema needed for both core functionality and plugins.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### **Init**
|
|
7
|
+
|
|
8
|
+
The CLI includes an `init` command to add Better Auth to your project.
|
|
9
|
+
|
|
10
|
+
```bash title="terminal"
|
|
11
|
+
npx @better-auth/cli@latest init
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### **Generate**
|
|
15
|
+
|
|
16
|
+
The `generate` command creates the schema required by Better Auth. If you're using a database adapter like Prisma or Drizzle, this command will generate the right schema for your ORM. If you're using the built-in Kysely adapter, it will generate an SQL file you can run directly on your database.
|
|
17
|
+
|
|
18
|
+
```bash title="terminal"
|
|
19
|
+
npx @better-auth/cli@latest generate
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### **Migrate**
|
|
23
|
+
|
|
24
|
+
The `migrate` command applies the Better Auth schema directly to your database. This is available if you’re using the built-in Kysely adapter. For other adapters, you'll need to apply the schema using your ORM's migration tool.
|
|
25
|
+
|
|
26
|
+
```bash title="terminal"
|
|
27
|
+
npx @better-auth/cli@latest migrate
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### **Secret**
|
|
31
|
+
|
|
32
|
+
The CLI also provides a way to generate a secret key for your Better Auth instance.
|
|
33
|
+
|
|
34
|
+
```bash title="terminal"
|
|
35
|
+
npx @better-auth/cli@latest secret
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
MIT
|
package/dist/index.mjs
CHANGED
|
@@ -13,12 +13,12 @@ import babelPresetTypeScript from '@babel/preset-typescript';
|
|
|
13
13
|
import babelPresetReact from '@babel/preset-react';
|
|
14
14
|
import fs from 'fs-extra';
|
|
15
15
|
import fs$2 from 'fs/promises';
|
|
16
|
+
import prettier, { format } from 'prettier';
|
|
16
17
|
import { produceSchema } from '@mrleebo/prisma-ast';
|
|
17
18
|
import 'dotenv/config';
|
|
18
19
|
import Crypto from 'crypto';
|
|
19
20
|
import { parse } from 'dotenv';
|
|
20
21
|
import semver from 'semver';
|
|
21
|
-
import { format } from 'prettier';
|
|
22
22
|
import { intro, log, outro, confirm, isCancel, cancel, spinner, text, select, multiselect } from '@clack/prompts';
|
|
23
23
|
import { exec } from 'child_process';
|
|
24
24
|
|
|
@@ -415,7 +415,7 @@ const generateDrizzleSchema = async ({
|
|
|
415
415
|
);
|
|
416
416
|
}
|
|
417
417
|
const fileExist = existsSync(filePath);
|
|
418
|
-
let code = generateImport({ databaseType, tables });
|
|
418
|
+
let code = generateImport({ databaseType, tables, options });
|
|
419
419
|
for (const tableKey in tables) {
|
|
420
420
|
let getType = function(name, field) {
|
|
421
421
|
if (!databaseType) {
|
|
@@ -476,7 +476,11 @@ const generateDrizzleSchema = async ({
|
|
|
476
476
|
const fields = table.fields;
|
|
477
477
|
let id = "";
|
|
478
478
|
if (options.advanced?.database?.useNumberId) {
|
|
479
|
-
|
|
479
|
+
if (databaseType === "pg") {
|
|
480
|
+
id = `serial("id").primaryKey()`;
|
|
481
|
+
} else {
|
|
482
|
+
id = `int("id").autoincrement.primaryKey()`;
|
|
483
|
+
}
|
|
480
484
|
} else {
|
|
481
485
|
if (databaseType === "mysql") {
|
|
482
486
|
id = `varchar('id', { length: 36 }).primaryKey()`;
|
|
@@ -512,20 +516,25 @@ const generateDrizzleSchema = async ({
|
|
|
512
516
|
${schema}
|
|
513
517
|
`;
|
|
514
518
|
}
|
|
519
|
+
const formattedCode = await prettier.format(code, {
|
|
520
|
+
parser: "typescript"
|
|
521
|
+
});
|
|
515
522
|
return {
|
|
516
|
-
code,
|
|
523
|
+
code: formattedCode,
|
|
517
524
|
fileName: filePath,
|
|
518
525
|
overwrite: fileExist
|
|
519
526
|
};
|
|
520
527
|
};
|
|
521
528
|
function generateImport({
|
|
522
529
|
databaseType,
|
|
523
|
-
tables
|
|
530
|
+
tables,
|
|
531
|
+
options
|
|
524
532
|
}) {
|
|
525
533
|
let imports = [];
|
|
526
534
|
const hasBigint = Object.values(tables).some(
|
|
527
535
|
(table) => Object.values(table.fields).some((field) => field.bigint)
|
|
528
536
|
);
|
|
537
|
+
const useNumberId = options.advanced?.database?.useNumberId;
|
|
529
538
|
imports.push(`${databaseType}Table`);
|
|
530
539
|
imports.push(
|
|
531
540
|
databaseType === "mysql" ? "varchar, text" : databaseType === "pg" ? "text" : "text"
|
|
@@ -533,6 +542,7 @@ function generateImport({
|
|
|
533
542
|
imports.push(hasBigint ? databaseType !== "sqlite" ? "bigint" : "" : "");
|
|
534
543
|
imports.push(databaseType !== "sqlite" ? "timestamp, boolean" : "");
|
|
535
544
|
imports.push(databaseType === "mysql" ? "int" : "integer");
|
|
545
|
+
imports.push(useNumberId ? databaseType === "pg" ? "serial" : "" : "");
|
|
536
546
|
return `import { ${imports.map((x) => x.trim()).filter((x) => x !== "").join(", ")} } from "drizzle-orm/${databaseType}-core";
|
|
537
547
|
`;
|
|
538
548
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.4",
|
|
4
4
|
"description": "The CLI for Better Auth",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"repository": {
|
|
@@ -8,12 +8,20 @@
|
|
|
8
8
|
"url": "https://github.com/better-auth/better-auth",
|
|
9
9
|
"directory": "packages/cli"
|
|
10
10
|
},
|
|
11
|
+
"homepage": "https://www.better-auth.com/docs/concepts/cli",
|
|
11
12
|
"main": "./dist/index.mjs",
|
|
12
13
|
"publishConfig": {
|
|
13
14
|
"executableFiles": [
|
|
14
15
|
"./dist/index.mjs"
|
|
15
16
|
]
|
|
16
17
|
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"auth",
|
|
21
|
+
"cli",
|
|
22
|
+
"typescript",
|
|
23
|
+
"better-auth"
|
|
24
|
+
],
|
|
17
25
|
"exports": "./dist/index.mjs",
|
|
18
26
|
"bin": "./dist/index.mjs",
|
|
19
27
|
"devDependencies": {
|
|
@@ -47,7 +55,7 @@
|
|
|
47
55
|
"tinyexec": "^0.3.1",
|
|
48
56
|
"yocto-spinner": "^0.1.1",
|
|
49
57
|
"zod": "^3.23.8",
|
|
50
|
-
"better-auth": "1.
|
|
58
|
+
"better-auth": "1.3.0-beta.4"
|
|
51
59
|
},
|
|
52
60
|
"files": [
|
|
53
61
|
"dist"
|