@better-auth/cli 0.0.1 → 0.4.9-beta.13
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/index.mjs +17 -599
- package/dist/index.mjs.map +1 -0
- package/package.json +16 -3
package/dist/index.mjs
CHANGED
|
@@ -1,610 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// src/commands/migrate.ts
|
|
7
|
-
import { Command } from "commander";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
import { existsSync } from "fs";
|
|
10
|
-
import path2 from "path";
|
|
11
|
-
import yoctoSpinner from "yocto-spinner";
|
|
12
|
-
import chalk from "chalk";
|
|
13
|
-
import prompts from "prompts";
|
|
14
|
-
import { logger as logger2 } from "better-auth";
|
|
15
|
-
import { getAdapter, getMigrations } from "better-auth/db";
|
|
16
|
-
|
|
17
|
-
// src/utils/get-config.ts
|
|
18
|
-
import { loadConfig } from "c12";
|
|
19
|
-
import { logger } from "better-auth";
|
|
20
|
-
import path from "path";
|
|
21
|
-
import babelPresetTypescript from "@babel/preset-typescript";
|
|
22
|
-
import babelPresetReact from "@babel/preset-react";
|
|
23
|
-
import fs from "fs";
|
|
24
|
-
import { BetterAuthError } from "better-auth";
|
|
25
|
-
|
|
26
|
-
// src/utils/add-svelte-kit-env-modules.ts
|
|
27
|
-
function addSvelteKitEnvModules(aliases) {
|
|
28
|
-
aliases["$env/dynamic/private"] = createDataUriModule(
|
|
29
|
-
createDynamicEnvModule()
|
|
30
|
-
);
|
|
31
|
-
aliases["$env/dynamic/public"] = createDataUriModule(
|
|
32
|
-
createDynamicEnvModule()
|
|
33
|
-
);
|
|
34
|
-
aliases["$env/static/private"] = createDataUriModule(
|
|
35
|
-
createStaticEnvModule(filterPrivateEnv("PUBLIC_", ""))
|
|
36
|
-
);
|
|
37
|
-
aliases["$env/static/public"] = createDataUriModule(
|
|
38
|
-
createStaticEnvModule(filterPublicEnv("PUBLIC_", ""))
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
function createDataUriModule(module) {
|
|
42
|
-
return `data:text/javascript;charset=utf-8,${encodeURIComponent(module)}`;
|
|
43
|
-
}
|
|
44
|
-
function createStaticEnvModule(env) {
|
|
45
|
-
const declarations = Object.keys(env).filter((k) => validIdentifier.test(k) && !reserved.has(k)).map((k) => `export const ${k} = ${JSON.stringify(env[k])};`);
|
|
46
|
-
return `
|
|
47
|
-
${declarations.join("\n")}
|
|
2
|
+
import{Command as Ct}from"commander";import{Command as ct}from"commander";import{z as O}from"zod";import{existsSync as pt}from"fs";import ft from"path";import B from"yocto-spinner";import z from"chalk";import E from"prompts";import{logger as v}from"better-auth";import{getAdapter as mt,getMigrations as lt}from"better-auth/db";import{loadConfig as q}from"c12";import{logger as $}from"better-auth";import R from"path";import rt from"@babel/preset-typescript";import it from"@babel/preset-react";import D from"fs";import{BetterAuthError as nt}from"better-auth";function F(e){e["$env/dynamic/private"]=k(P()),e["$env/dynamic/public"]=k(P()),e["$env/static/private"]=k(M(V("PUBLIC_",""))),e["$env/static/public"]=k(M(tt("PUBLIC_","")))}function k(e){return`data:text/javascript;charset=utf-8,${encodeURIComponent(e)}`}function M(e){return`
|
|
3
|
+
${Object.keys(e).filter(t=>et.test(t)&&!ot.has(t)).map(t=>`export const ${t} = ${JSON.stringify(e[t])};`).join(`
|
|
4
|
+
`)}
|
|
48
5
|
// jiti dirty hack: .unknown
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
function createDynamicEnvModule() {
|
|
52
|
-
return `
|
|
6
|
+
`}function P(){return`
|
|
53
7
|
export const env = process.env;
|
|
54
8
|
// jiti dirty hack: .unknown
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
function filterPrivateEnv(publicPrefix, privatePrefix) {
|
|
58
|
-
return Object.fromEntries(
|
|
59
|
-
Object.entries(process.env).filter(
|
|
60
|
-
([k]) => k.startsWith(privatePrefix) && (publicPrefix === "" || !k.startsWith(publicPrefix))
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
function filterPublicEnv(publicPrefix, privatePrefix) {
|
|
65
|
-
return Object.fromEntries(
|
|
66
|
-
Object.entries(process.env).filter(
|
|
67
|
-
([k]) => k.startsWith(publicPrefix) && (privatePrefix === "" || !k.startsWith(privatePrefix))
|
|
68
|
-
)
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
var validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
72
|
-
var reserved = /* @__PURE__ */ new Set([
|
|
73
|
-
"do",
|
|
74
|
-
"if",
|
|
75
|
-
"in",
|
|
76
|
-
"for",
|
|
77
|
-
"let",
|
|
78
|
-
"new",
|
|
79
|
-
"try",
|
|
80
|
-
"var",
|
|
81
|
-
"case",
|
|
82
|
-
"else",
|
|
83
|
-
"enum",
|
|
84
|
-
"eval",
|
|
85
|
-
"null",
|
|
86
|
-
"this",
|
|
87
|
-
"true",
|
|
88
|
-
"void",
|
|
89
|
-
"with",
|
|
90
|
-
"await",
|
|
91
|
-
"break",
|
|
92
|
-
"catch",
|
|
93
|
-
"class",
|
|
94
|
-
"const",
|
|
95
|
-
"false",
|
|
96
|
-
"super",
|
|
97
|
-
"throw",
|
|
98
|
-
"while",
|
|
99
|
-
"yield",
|
|
100
|
-
"delete",
|
|
101
|
-
"export",
|
|
102
|
-
"import",
|
|
103
|
-
"public",
|
|
104
|
-
"return",
|
|
105
|
-
"static",
|
|
106
|
-
"switch",
|
|
107
|
-
"typeof",
|
|
108
|
-
"default",
|
|
109
|
-
"extends",
|
|
110
|
-
"finally",
|
|
111
|
-
"package",
|
|
112
|
-
"private",
|
|
113
|
-
"continue",
|
|
114
|
-
"debugger",
|
|
115
|
-
"function",
|
|
116
|
-
"arguments",
|
|
117
|
-
"interface",
|
|
118
|
-
"protected",
|
|
119
|
-
"implements",
|
|
120
|
-
"instanceof"
|
|
121
|
-
]);
|
|
122
|
-
|
|
123
|
-
// src/utils/get-config.ts
|
|
124
|
-
var possiblePaths = ["auth.ts", "auth.tsx"];
|
|
125
|
-
possiblePaths = [
|
|
126
|
-
...possiblePaths,
|
|
127
|
-
...possiblePaths.map((it) => `lib/server${it}`),
|
|
128
|
-
...possiblePaths.map((it) => `lib/${it}`),
|
|
129
|
-
...possiblePaths.map((it) => `utils/${it}`)
|
|
130
|
-
];
|
|
131
|
-
possiblePaths = [
|
|
132
|
-
...possiblePaths,
|
|
133
|
-
...possiblePaths.map((it) => `src/${it}`),
|
|
134
|
-
...possiblePaths.map((it) => `app/${it}`)
|
|
135
|
-
];
|
|
136
|
-
function stripJsonComments(jsonString) {
|
|
137
|
-
return jsonString.replace(
|
|
138
|
-
/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,
|
|
139
|
-
(m, g) => g ? "" : m
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
function getPathAliases(cwd) {
|
|
143
|
-
const tsConfigPath = path.join(cwd, "tsconfig.json");
|
|
144
|
-
if (!fs.existsSync(tsConfigPath)) {
|
|
145
|
-
logger.warn("[#better-auth]: tsconfig.json not found.");
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
try {
|
|
149
|
-
const tsConfigContent = fs.readFileSync(tsConfigPath, "utf8");
|
|
150
|
-
const strippedTsConfigContent = stripJsonComments(tsConfigContent);
|
|
151
|
-
const tsConfig = JSON.parse(strippedTsConfigContent);
|
|
152
|
-
const { paths = {} } = tsConfig.compilerOptions || {};
|
|
153
|
-
const result = {};
|
|
154
|
-
const obj = Object.entries(paths);
|
|
155
|
-
for (const [alias, aliasPaths] of obj) {
|
|
156
|
-
for (const _ of aliasPaths) {
|
|
157
|
-
result[alias[0] || ""] = "../";
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
addSvelteKitEnvModules(result);
|
|
161
|
-
return result;
|
|
162
|
-
} catch (error) {
|
|
163
|
-
console.error(error);
|
|
164
|
-
throw new BetterAuthError("Error parsing tsconfig.json");
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
var jitiOptions = (cwd) => {
|
|
168
|
-
const alias = getPathAliases(cwd) || {};
|
|
169
|
-
return {
|
|
170
|
-
transformOptions: {
|
|
171
|
-
babel: {
|
|
172
|
-
presets: [
|
|
173
|
-
[
|
|
174
|
-
babelPresetTypescript,
|
|
175
|
-
{
|
|
176
|
-
isTSX: true,
|
|
177
|
-
allExtensions: true
|
|
178
|
-
}
|
|
179
|
-
],
|
|
180
|
-
[babelPresetReact, { runtime: "automatic" }]
|
|
181
|
-
]
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
185
|
-
alias
|
|
186
|
-
};
|
|
187
|
-
};
|
|
188
|
-
async function getConfig({
|
|
189
|
-
cwd,
|
|
190
|
-
configPath
|
|
191
|
-
}) {
|
|
192
|
-
try {
|
|
193
|
-
let configFile = null;
|
|
194
|
-
if (configPath) {
|
|
195
|
-
const { config } = await loadConfig({
|
|
196
|
-
configFile: path.join(cwd, configPath),
|
|
197
|
-
dotenv: true,
|
|
198
|
-
jitiOptions: jitiOptions(cwd)
|
|
199
|
-
});
|
|
200
|
-
if (!config.auth && !config.default) {
|
|
201
|
-
logger.error(
|
|
202
|
-
"[#better-auth]: Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth."
|
|
203
|
-
);
|
|
204
|
-
process.exit(1);
|
|
205
|
-
}
|
|
206
|
-
configFile = config.auth?.options || config.default?.options || null;
|
|
207
|
-
}
|
|
208
|
-
if (!configFile) {
|
|
209
|
-
for (const possiblePath of possiblePaths) {
|
|
210
|
-
try {
|
|
211
|
-
const { config } = await loadConfig({
|
|
212
|
-
configFile: possiblePath,
|
|
213
|
-
jitiOptions: jitiOptions(cwd)
|
|
214
|
-
});
|
|
215
|
-
const hasConfig = Object.keys(config).length > 0;
|
|
216
|
-
if (hasConfig) {
|
|
217
|
-
configFile = config.auth?.options || config.default?.options || null;
|
|
218
|
-
if (!configFile) {
|
|
219
|
-
logger.error("[#better-auth]: Couldn't read your auth config.");
|
|
220
|
-
logger.break();
|
|
221
|
-
logger.info(
|
|
222
|
-
"[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth."
|
|
223
|
-
);
|
|
224
|
-
process.exit(1);
|
|
225
|
-
}
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
} catch (e) {
|
|
229
|
-
logger.error("[#better-auth]: Couldn't read your auth config.", e);
|
|
230
|
-
process.exit(1);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return configFile;
|
|
235
|
-
} catch (e) {
|
|
236
|
-
logger.error("Couldn't read your auth config.");
|
|
237
|
-
process.exit(1);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// src/commands/migrate.ts
|
|
242
|
-
var migrate = new Command("migrate").option(
|
|
243
|
-
"-c, --cwd <cwd>",
|
|
244
|
-
"the working directory. defaults to the current directory.",
|
|
245
|
-
process.cwd()
|
|
246
|
-
).option(
|
|
247
|
-
"--config <config>",
|
|
248
|
-
"the path to the configuration file. defaults to the first configuration file found."
|
|
249
|
-
).option("--y", "").action(async (opts) => {
|
|
250
|
-
const options = z.object({
|
|
251
|
-
cwd: z.string(),
|
|
252
|
-
config: z.string().optional()
|
|
253
|
-
}).parse(opts);
|
|
254
|
-
const cwd = path2.resolve(options.cwd);
|
|
255
|
-
if (!existsSync(cwd)) {
|
|
256
|
-
logger2.error(`The directory "${cwd}" does not exist.`);
|
|
257
|
-
process.exit(1);
|
|
258
|
-
}
|
|
259
|
-
const config = await getConfig({
|
|
260
|
-
cwd,
|
|
261
|
-
configPath: options.config
|
|
262
|
-
});
|
|
263
|
-
if (!config) {
|
|
264
|
-
logger2.error(
|
|
265
|
-
"No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag."
|
|
266
|
-
);
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
const db = await getAdapter(config, true);
|
|
270
|
-
if (!db) {
|
|
271
|
-
logger2.error(
|
|
272
|
-
"Invalid database configuration. Make sure you're not using adapters. Migrate command only works with built-in Kysely adapter."
|
|
273
|
-
);
|
|
274
|
-
process.exit(1);
|
|
275
|
-
}
|
|
276
|
-
if (db.id !== "kysely") {
|
|
277
|
-
logger2.error("Migrate command only works with built-in Kysely adapter.");
|
|
278
|
-
process.exit(1);
|
|
279
|
-
}
|
|
280
|
-
const spinner = yoctoSpinner({ text: "preparing migration..." }).start();
|
|
281
|
-
const { toBeAdded, toBeCreated, runMigrations } = await getMigrations(config);
|
|
282
|
-
if (!toBeAdded.length && !toBeCreated.length) {
|
|
283
|
-
spinner.stop();
|
|
284
|
-
logger2.success("\u{1F680} No migrations needed.");
|
|
285
|
-
process.exit(0);
|
|
286
|
-
}
|
|
287
|
-
spinner.stop();
|
|
288
|
-
logger2.info(`\u{1F511} The migration will affect the following:`);
|
|
289
|
-
for (const table of [...toBeCreated, ...toBeAdded]) {
|
|
290
|
-
console.log(
|
|
291
|
-
"->",
|
|
292
|
-
chalk.magenta(Object.keys(table.fields).join(", ")),
|
|
293
|
-
chalk.white("fields on"),
|
|
294
|
-
chalk.yellow(`${table.table}`),
|
|
295
|
-
chalk.white("table.")
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
const { migrate: migrate2 } = await prompts({
|
|
299
|
-
type: "confirm",
|
|
300
|
-
name: "migrate",
|
|
301
|
-
message: "Are you sure you want to run these migrations?",
|
|
302
|
-
initial: false
|
|
303
|
-
});
|
|
304
|
-
if (!migrate2) {
|
|
305
|
-
logger2.info("Migration cancelled.");
|
|
306
|
-
process.exit(0);
|
|
307
|
-
}
|
|
308
|
-
spinner?.start("migrating...");
|
|
309
|
-
await runMigrations();
|
|
310
|
-
spinner.stop();
|
|
311
|
-
logger2.success("\u{1F680} migration was completed successfully!");
|
|
312
|
-
process.exit(0);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
// src/commands/generate.ts
|
|
316
|
-
import { Command as Command2 } from "commander";
|
|
317
|
-
import { z as z2 } from "zod";
|
|
318
|
-
import { existsSync as existsSync4 } from "fs";
|
|
319
|
-
import path4 from "path";
|
|
320
|
-
import { logger as logger4 } from "better-auth";
|
|
321
|
-
import yoctoSpinner2 from "yocto-spinner";
|
|
322
|
-
import prompts2 from "prompts";
|
|
323
|
-
import fs3 from "fs/promises";
|
|
324
|
-
import chalk2 from "chalk";
|
|
325
|
-
import { getAdapter as getAdapter2 } from "better-auth/db";
|
|
326
|
-
|
|
327
|
-
// src/generators/index.ts
|
|
328
|
-
import { logger as logger3 } from "better-auth";
|
|
329
|
-
|
|
330
|
-
// src/generators/drizzle.ts
|
|
331
|
-
import { getAuthTables } from "better-auth/db";
|
|
332
|
-
import { existsSync as existsSync2 } from "fs";
|
|
333
|
-
var generateDrizzleSchema = async ({
|
|
334
|
-
options,
|
|
335
|
-
file,
|
|
336
|
-
adapter
|
|
337
|
-
}) => {
|
|
338
|
-
const tables = getAuthTables(options);
|
|
339
|
-
const filePath = file || "./auth-schema.ts";
|
|
340
|
-
const databaseType = adapter.options?.provider;
|
|
341
|
-
const timestampAndBoolean = databaseType !== "sqlite" ? "timestamp, boolean" : "";
|
|
342
|
-
const int = databaseType === "mysql" ? "int" : "integer";
|
|
343
|
-
let code = `import { ${databaseType}Table, text, ${int}, ${timestampAndBoolean} } from "drizzle-orm/${databaseType}-core";
|
|
344
|
-
`;
|
|
345
|
-
const fileExist = existsSync2(filePath);
|
|
346
|
-
for (const table in tables) {
|
|
347
|
-
let getType2 = function(name, type) {
|
|
348
|
-
if (type === "string") {
|
|
349
|
-
return `text('${name}')`;
|
|
350
|
-
}
|
|
351
|
-
if (type === "number") {
|
|
352
|
-
return `${int}('${name}')`;
|
|
353
|
-
}
|
|
354
|
-
if (type === "boolean") {
|
|
355
|
-
if (databaseType === "sqlite") {
|
|
356
|
-
return `integer('${name}', {
|
|
9
|
+
`}function V(e,r){return Object.fromEntries(Object.entries(process.env).filter(([t])=>t.startsWith(r)&&(e===""||!t.startsWith(e))))}function tt(e,r){return Object.fromEntries(Object.entries(process.env).filter(([t])=>t.startsWith(e)&&(r===""||!t.startsWith(r))))}var et=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,ot=new Set(["do","if","in","for","let","new","try","var","case","else","enum","eval","null","this","true","void","with","await","break","catch","class","const","false","super","throw","while","yield","delete","export","import","public","return","static","switch","typeof","default","extends","finally","package","private","continue","debugger","function","arguments","interface","protected","implements","instanceof"]);var w=["auth.ts","auth.tsx"];w=[...w,...w.map(e=>`lib/server${e}`),...w.map(e=>`lib/${e}`),...w.map(e=>`utils/${e}`)];w=[...w,...w.map(e=>`src/${e}`),...w.map(e=>`app/${e}`)];function st(e){return e.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,(r,t)=>t?"":r)}function at(e){let r=R.join(e,"tsconfig.json");if(!D.existsSync(r))return $.warn("[#better-auth]: tsconfig.json not found."),null;try{let t=D.readFileSync(r,"utf8"),i=st(t),n=JSON.parse(i),{paths:s={}}=n.compilerOptions||{},o={},m=Object.entries(s);for(let[p,c]of m)for(let d of c)o[p[0]||""]="../";return F(o),o}catch(t){throw console.error(t),new nt("Error parsing tsconfig.json")}}var I=e=>{let r=at(e)||{};return{transformOptions:{babel:{presets:[[rt,{isTSX:!0,allExtensions:!0}],[it,{runtime:"automatic"}]]}},extensions:[".ts",".tsx",".js",".jsx"],alias:r}};async function T({cwd:e,configPath:r}){try{let t=null;if(r){let{config:i}=await q({configFile:R.join(e,r),dotenv:!0,jitiOptions:I(e)});!i.auth&&!i.default&&($.error("[#better-auth]: Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth."),process.exit(1)),t=i.auth?.options||i.default?.options||null}if(!t)for(let i of w)try{let{config:n}=await q({configFile:i,jitiOptions:I(e)});if(Object.keys(n).length>0){t=n.auth?.options||n.default?.options||null,t||($.error("[#better-auth]: Couldn't read your auth config."),$.break(),$.info("[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth."),process.exit(1));break}}catch(n){$.error("[#better-auth]: Couldn't read your auth config.",n),process.exit(1)}return t}catch{$.error("Couldn't read your auth config."),process.exit(1)}}import{exec as G}from"tinyexec";async function ut(e){let r=O.object({cwd:O.string(),config:O.string().optional(),y:O.boolean().optional()}).parse(e),t=ft.resolve(r.cwd);pt(t)||(v.error(`The directory "${t}" does not exist.`),process.exit(1));let i=await T({cwd:t,configPath:r.config});if(!i){v.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");return}let n=await mt(i,!0);if(n||(v.error("Invalid database configuration. Make sure you're not using adapters. Migrate command only works with built-in Kysely adapter."),process.exit(1)),n.id!=="kysely"){if(n.id==="prisma"){let{confirm:d}=await E({type:"confirm",name:"confirm",message:"Do you want to run prisma migrate dev?",initial:!1});if(d){let g=B({text:"running prisma migrate dev..."});await G("npx",["prisma","migrate","dev"]),g.stop(),process.exit(0)}process.exit(0)}if(n.id==="drizzle"){let{confirm:d}=await E({type:"confirm",name:"confirm",message:"Do you want to run drizzle migrate?",initial:!1});if(d){let g=B({text:"running drizzle migrate..."}).start();await G("npx",["drizzle-kit","migrate"]),g.stop(),process.exit(0)}process.exit(1)}v.error("Migrate command only works isn't supported for this adapter."),process.exit(1)}let s=B({text:"preparing migration..."}).start(),{toBeAdded:o,toBeCreated:m,runMigrations:p}=await lt(i);!o.length&&!m.length&&(s.stop(),v.success("\u{1F680} No migrations needed."),process.exit(0)),s.stop(),v.info("\u{1F511} The migration will affect the following:");for(let d of[...m,...o])console.log("->",z.magenta(Object.keys(d.fields).join(", ")),z.white("fields on"),z.yellow(`${d.table}`),z.white("table."));let c=r.y;c||(c=(await E({type:"confirm",name:"migrate",message:"Are you sure you want to run these migrations?",initial:!1})).migrate),c||(v.info("Migration cancelled."),process.exit(0)),s?.start("migrating..."),await p(),s.stop(),v.success("\u{1F680} migration was completed successfully!"),process.exit(0)}var _=new ct("migrate").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("--config <config>","the path to the configuration file. defaults to the first configuration file found.").option("-y, --y","automatically accept and run migrations without prompting",!1).action(ut);import{Command as jt}from"commander";import{z as S}from"zod";import{existsSync as A}from"fs";import a from"path";import{logger as x}from"better-auth";import St from"yocto-spinner";import Y from"prompts";import b from"fs/promises";import H from"chalk";import{getAdapter as At}from"better-auth/db";import{logger as $t}from"better-auth";import{getAuthTables as dt}from"better-auth/db";import{existsSync as gt}from"fs";var L=async({options:e,file:r,adapter:t})=>{let i=dt(e),n=r||"./auth-schema.ts",s=t.options?.provider,o=s!=="sqlite"?"timestamp, boolean":"",m=s==="mysql"?"int":"integer",p=`import { ${s}Table, text, ${m}, ${o} } from "drizzle-orm/${s}-core";
|
|
10
|
+
`,c=gt(n);for(let g in i){let h=function(f,l){if(l==="string")return`text('${f}')`;if(l==="number")return`${m}('${f}')`;if(l==="boolean")return s==="sqlite"?`integer('${f}', {
|
|
357
11
|
mode: "boolean"
|
|
358
|
-
})`;
|
|
359
|
-
}
|
|
360
|
-
return `boolean('${name}')`;
|
|
361
|
-
}
|
|
362
|
-
if (type === "date") {
|
|
363
|
-
if (databaseType === "sqlite") {
|
|
364
|
-
return `integer('${name}', {
|
|
12
|
+
})`:`boolean('${f}')`;if(l==="date")return s==="sqlite"?`integer('${f}', {
|
|
365
13
|
mode: "timestamp"
|
|
366
|
-
})
|
|
367
|
-
}
|
|
368
|
-
return `timestamp('${name}')`;
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
var getType = getType2;
|
|
372
|
-
const tableName = tables[table].tableName;
|
|
373
|
-
const fields = tables[table].fields;
|
|
374
|
-
const schema = `export const ${table} = ${databaseType}Table("${tableName}", {
|
|
14
|
+
})`:`timestamp('${f}')`};var d=h;let N=i[g].tableName,j=i[g].fields,C=`export const ${g} = ${s}Table("${N}", {
|
|
375
15
|
id: text("id").primaryKey(),
|
|
376
|
-
${Object.keys(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
code += `
|
|
382
|
-
${schema}
|
|
383
|
-
`;
|
|
384
|
-
}
|
|
385
|
-
return {
|
|
386
|
-
code,
|
|
387
|
-
fileName: filePath,
|
|
388
|
-
overwrite: fileExist
|
|
389
|
-
};
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
// src/generators/prisma.ts
|
|
393
|
-
import { getAuthTables as getAuthTables2 } from "better-auth/db";
|
|
394
|
-
import { produceSchema } from "@mrleebo/prisma-ast";
|
|
395
|
-
import { existsSync as existsSync3 } from "fs";
|
|
396
|
-
import path3 from "path";
|
|
397
|
-
import fs2 from "fs/promises";
|
|
398
|
-
import { capitalizeFirstLetter } from "better-auth";
|
|
399
|
-
var generatePrismaSchema = async ({
|
|
400
|
-
adapter,
|
|
401
|
-
options,
|
|
402
|
-
file
|
|
403
|
-
}) => {
|
|
404
|
-
const provider = adapter.options?.provider || "pg";
|
|
405
|
-
const tables = getAuthTables2(options);
|
|
406
|
-
const filePath = file || "./prisma/schema.prisma";
|
|
407
|
-
const schemaPrismaExist = existsSync3(path3.join(process.cwd(), filePath));
|
|
408
|
-
let schemaPrisma = "";
|
|
409
|
-
if (schemaPrismaExist) {
|
|
410
|
-
schemaPrisma = await fs2.readFile(
|
|
411
|
-
path3.join(process.cwd(), filePath),
|
|
412
|
-
"utf-8"
|
|
413
|
-
);
|
|
414
|
-
} else {
|
|
415
|
-
schemaPrisma = getNewPrisma(provider);
|
|
416
|
-
}
|
|
417
|
-
const schema = produceSchema(schemaPrisma, (builder) => {
|
|
418
|
-
for (const table in tables) {
|
|
419
|
-
let getType2 = function(type, isOptional) {
|
|
420
|
-
if (type === "string") {
|
|
421
|
-
return isOptional ? "String?" : "String";
|
|
422
|
-
}
|
|
423
|
-
if (type === "number") {
|
|
424
|
-
return isOptional ? "Int?" : "Int";
|
|
425
|
-
}
|
|
426
|
-
if (type === "boolean") {
|
|
427
|
-
return isOptional ? "Boolean?" : "Boolean";
|
|
428
|
-
}
|
|
429
|
-
if (type === "date") {
|
|
430
|
-
return isOptional ? "DateTime?" : "DateTime";
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
var getType = getType2;
|
|
434
|
-
const fields = tables[table]?.fields;
|
|
435
|
-
const originalTable = tables[table]?.tableName;
|
|
436
|
-
const tableName = capitalizeFirstLetter(originalTable || "");
|
|
437
|
-
const prismaModel = builder.findByType("model", {
|
|
438
|
-
name: tableName
|
|
439
|
-
});
|
|
440
|
-
!prismaModel && builder.model(tableName).field("id", "String").attribute("id");
|
|
441
|
-
for (const field in fields) {
|
|
442
|
-
const attr = fields[field];
|
|
443
|
-
if (prismaModel) {
|
|
444
|
-
const isAlreadyExist = builder.findByType("field", {
|
|
445
|
-
name: field,
|
|
446
|
-
within: prismaModel.properties
|
|
447
|
-
});
|
|
448
|
-
if (isAlreadyExist) {
|
|
449
|
-
continue;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
builder.model(tableName).field(field, getType2(attr.type, !attr?.required));
|
|
453
|
-
if (attr.unique) {
|
|
454
|
-
builder.model(tableName).blockAttribute(`unique([${field}])`);
|
|
455
|
-
}
|
|
456
|
-
if (attr.references) {
|
|
457
|
-
builder.model(tableName).field(
|
|
458
|
-
`${attr.references.model.toLowerCase()}`,
|
|
459
|
-
capitalizeFirstLetter(attr.references.model)
|
|
460
|
-
).attribute(
|
|
461
|
-
`relation(fields: [${field}], references: [${attr.references.field}], onDelete: Cascade)`
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
const hasAttribute = builder.findByType("attribute", {
|
|
466
|
-
name: "map",
|
|
467
|
-
within: prismaModel?.properties
|
|
468
|
-
});
|
|
469
|
-
if (originalTable !== tableName && !hasAttribute) {
|
|
470
|
-
builder.model(tableName).blockAttribute("map", originalTable);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
return {
|
|
475
|
-
code: schema.trim() === schemaPrisma.trim() ? "" : schema,
|
|
476
|
-
fileName: filePath
|
|
477
|
-
};
|
|
478
|
-
};
|
|
479
|
-
var getNewPrisma = (provider) => `generator client {
|
|
16
|
+
${Object.keys(j).map(f=>{let l=j[f];return`${f}: ${h(f,l.type)}${l.required?".notNull()":""}${l.unique?".unique()":""}${l.references?`.references(()=> ${l.references.model}.${l.references.field})`:""}`}).join(`,
|
|
17
|
+
`)}
|
|
18
|
+
});`;p+=`
|
|
19
|
+
${C}
|
|
20
|
+
`}return{code:p,fileName:n,overwrite:c}};import{getAuthTables as ht}from"better-auth/db";import{produceSchema as yt}from"@mrleebo/prisma-ast";import{existsSync as wt}from"fs";import U from"path";import xt from"fs/promises";import{capitalizeFirstLetter as K}from"better-auth";var W=async({adapter:e,options:r,file:t})=>{let i=e.options?.provider||"postgresql",n=ht(r),s=t||"./prisma/schema.prisma",o=wt(U.join(process.cwd(),s)),m="";o?m=await xt.readFile(U.join(process.cwd(),s),"utf-8"):m=bt(i);let p=yt(m,c=>{for(let g in n){let C=function(y,u){if(y==="string")return u?"String?":"String";if(y==="number")return u?"Int?":"Int";if(y==="boolean")return u?"Boolean?":"Boolean";if(y==="date")return u?"DateTime?":"DateTime"};var d=C;let N=n[g]?.fields,j=n[g]?.tableName,h=K(j||""),f=c.findByType("model",{name:h});!f&&c.model(h).field("id","String").attribute("id");for(let y in N){let u=N[y];f&&c.findByType("field",{name:y,within:f.properties})||(c.model(h).field(y,C(u.type,!u?.required)),u.unique&&c.model(h).blockAttribute(`unique([${y}])`),u.references&&c.model(h).field(`${u.references.model.toLowerCase()}`,K(u.references.model)).attribute(`relation(fields: [${y}], references: [${u.references.field}], onDelete: Cascade)`))}let l=c.findByType("attribute",{name:"map",within:f?.properties});j!==h&&!l&&c.model(h).blockAttribute("map",j)}});return{code:p.trim()===m.trim()?"":p,fileName:s}},bt=e=>`generator client {
|
|
480
21
|
provider = "prisma-client-js"
|
|
481
22
|
}
|
|
482
23
|
|
|
483
24
|
datasource db {
|
|
484
|
-
provider = "${
|
|
485
|
-
url = ${
|
|
486
|
-
}`;
|
|
487
|
-
|
|
488
|
-
// src/generators/index.ts
|
|
489
|
-
var adapters = {
|
|
490
|
-
prisma: generatePrismaSchema,
|
|
491
|
-
drizzle: generateDrizzleSchema
|
|
492
|
-
};
|
|
493
|
-
var getGenerator = (opts) => {
|
|
494
|
-
const adapter = opts.adapter;
|
|
495
|
-
const generator = adapter.id in adapters ? adapters[adapter.id] : null;
|
|
496
|
-
if (!generator) {
|
|
497
|
-
logger3.error(`${adapter.id} is not supported.`);
|
|
498
|
-
process.exit(1);
|
|
499
|
-
}
|
|
500
|
-
return generator(opts);
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
// src/commands/generate.ts
|
|
504
|
-
var generate = new Command2("generate").option(
|
|
505
|
-
"-c, --cwd <cwd>",
|
|
506
|
-
"the working directory. defaults to the current directory.",
|
|
507
|
-
process.cwd()
|
|
508
|
-
).option(
|
|
509
|
-
"--config <config>",
|
|
510
|
-
"the path to the configuration file. defaults to the first configuration file found."
|
|
511
|
-
).option("--output <output>", "the file to output to the generated schema").option("--y", "").action(async (opts) => {
|
|
512
|
-
const options = z2.object({
|
|
513
|
-
cwd: z2.string(),
|
|
514
|
-
config: z2.string().optional(),
|
|
515
|
-
output: z2.string().optional()
|
|
516
|
-
}).parse(opts);
|
|
517
|
-
const cwd = path4.resolve(options.cwd);
|
|
518
|
-
if (!existsSync4(cwd)) {
|
|
519
|
-
logger4.error(`The directory "${cwd}" does not exist.`);
|
|
520
|
-
process.exit(1);
|
|
521
|
-
}
|
|
522
|
-
const config = await getConfig({
|
|
523
|
-
cwd,
|
|
524
|
-
configPath: options.config
|
|
525
|
-
});
|
|
526
|
-
if (!config) {
|
|
527
|
-
logger4.error(
|
|
528
|
-
"No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag."
|
|
529
|
-
);
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
const spinner = yoctoSpinner2({ text: "preparing schema..." }).start();
|
|
533
|
-
const adapter = await getAdapter2(config, true).catch((e) => {
|
|
534
|
-
logger4.error(e.message);
|
|
535
|
-
process.exit(1);
|
|
536
|
-
});
|
|
537
|
-
const schema = await getGenerator({
|
|
538
|
-
adapter,
|
|
539
|
-
file: options.output,
|
|
540
|
-
options: config
|
|
541
|
-
});
|
|
542
|
-
spinner.stop();
|
|
543
|
-
if (!schema.code) {
|
|
544
|
-
logger4.success("Your schema is already up to date.");
|
|
545
|
-
process.exit(0);
|
|
546
|
-
}
|
|
547
|
-
if (schema.append || schema.overwrite) {
|
|
548
|
-
const { confirm: confirm2 } = await prompts2({
|
|
549
|
-
type: "confirm",
|
|
550
|
-
name: "confirm",
|
|
551
|
-
message: `The file ${schema.fileName} already exists. Do you want to ${chalk2.yellow(
|
|
552
|
-
`${schema.overwrite ? "overwrite" : "append"}`
|
|
553
|
-
)} the schema to the file?`
|
|
554
|
-
});
|
|
555
|
-
if (confirm2) {
|
|
556
|
-
const exist = existsSync4(path4.join(cwd, schema.fileName));
|
|
557
|
-
if (!exist) {
|
|
558
|
-
await fs3.mkdir(path4.dirname(path4.join(cwd, schema.fileName)), {
|
|
559
|
-
recursive: true
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
if (schema.overwrite) {
|
|
563
|
-
await fs3.writeFile(path4.join(cwd, schema.fileName), schema.code);
|
|
564
|
-
} else {
|
|
565
|
-
await fs3.appendFile(path4.join(cwd, schema.fileName), schema.code);
|
|
566
|
-
}
|
|
567
|
-
logger4.success(`\u{1F680} schema was appended successfully!`);
|
|
568
|
-
process.exit(0);
|
|
569
|
-
} else {
|
|
570
|
-
logger4.error("Schema generation aborted.");
|
|
571
|
-
process.exit(1);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
const { confirm } = await prompts2({
|
|
575
|
-
type: "confirm",
|
|
576
|
-
name: "confirm",
|
|
577
|
-
message: `Do you want to generate the schema to ${chalk2.yellow(
|
|
578
|
-
schema.fileName
|
|
579
|
-
)}?`
|
|
580
|
-
});
|
|
581
|
-
if (!confirm) {
|
|
582
|
-
logger4.error("Schema generation aborted.");
|
|
583
|
-
process.exit(1);
|
|
584
|
-
}
|
|
585
|
-
if (!options.output) {
|
|
586
|
-
const dirExist = existsSync4(
|
|
587
|
-
path4.dirname(path4.join(cwd, schema.fileName))
|
|
588
|
-
);
|
|
589
|
-
if (!dirExist) {
|
|
590
|
-
await fs3.mkdir(path4.dirname(path4.join(cwd, schema.fileName)), {
|
|
591
|
-
recursive: true
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
await fs3.writeFile(
|
|
596
|
-
options.output || path4.join(cwd, schema.fileName),
|
|
597
|
-
schema.code
|
|
598
|
-
);
|
|
599
|
-
logger4.success(`\u{1F680} schema was generated successfully!`);
|
|
600
|
-
process.exit(0);
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
// src/index.ts
|
|
604
|
-
import "dotenv/config";
|
|
605
|
-
async function main() {
|
|
606
|
-
const program = new Command3();
|
|
607
|
-
program.name("better-auth").addCommand(migrate).addCommand(generate).version("0.0.1").description("Better Auth CLI");
|
|
608
|
-
program.parse();
|
|
609
|
-
}
|
|
610
|
-
main();
|
|
25
|
+
provider = "${e}"
|
|
26
|
+
url = ${e==="sqlite"?'"file:./dev.db"':'env("DATABASE_URL")'}
|
|
27
|
+
}`;import{getMigrations as vt}from"better-auth/db";var J=async({options:e})=>{let{compileMigrations:r}=await vt(e);return{code:await r(),fileName:`./better-auth_migrations/${new Date().toISOString().replace(/:/g,"-")}.sql`}};var Z={prisma:W,drizzle:L,kysely:J},X=e=>{let r=e.adapter,t=r.id in Z?Z[r.id]:null;return t||($t.error(`${r.id} is not supported.`),process.exit(1)),t(e)};async function Nt(e){let r=S.object({cwd:S.string(),config:S.string().optional(),output:S.string().optional(),y:S.boolean().optional()}).parse(e),t=a.resolve(r.cwd);A(t)||(x.error(`The directory "${t}" does not exist.`),process.exit(1));let i=await T({cwd:t,configPath:r.config});if(!i){x.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");return}let n=await At(i,!0).catch(p=>{x.error(p.message),process.exit(1)}),s=St({text:"preparing schema..."}).start(),o=await X({adapter:n,file:r.output,options:i});if(s.stop(),o.code||(x.success("Your schema is already up to date."),process.exit(0)),o.append||o.overwrite){r.y&&(A(a.join(t,o.fileName))||await b.mkdir(a.dirname(a.join(t,o.fileName)),{recursive:!0}),o.overwrite?await b.writeFile(a.join(t,o.fileName),o.code):await b.appendFile(a.join(t,o.fileName),o.code),x.success(`\u{1F680} Schema was ${o.overwrite?"overwritten":"appended"} successfully!`),process.exit(0));let{confirm:p}=await Y({type:"confirm",name:"confirm",message:`The file ${o.fileName} already exists. Do you want to ${H.yellow(`${o.overwrite?"overwrite":"append"}`)} the schema to the file?`});p?(A(a.join(t,o.fileName))||await b.mkdir(a.dirname(a.join(t,o.fileName)),{recursive:!0}),o.overwrite?await b.writeFile(a.join(t,o.fileName),o.code):await b.appendFile(a.join(t,o.fileName),o.code),x.success(`\u{1F680} Schema was ${o.overwrite?"overwritten":"appended"} successfully!`),process.exit(0)):(x.error("Schema generation aborted."),process.exit(1))}r.y&&(r.output||A(a.dirname(a.join(t,o.fileName)))||await b.mkdir(a.dirname(a.join(t,o.fileName)),{recursive:!0}),await b.writeFile(r.output||a.join(t,o.fileName),o.code),x.success("\u{1F680} Schema was generated successfully!"),process.exit(0));let{confirm:m}=await Y({type:"confirm",name:"confirm",message:`Do you want to generate the schema to ${H.yellow(o.fileName)}?`});m||(x.error("Schema generation aborted."),process.exit(1)),r.output||A(a.dirname(a.join(t,o.fileName)))||await b.mkdir(a.dirname(a.join(t,o.fileName)),{recursive:!0}),await b.writeFile(r.output||a.join(t,o.fileName),o.code),x.success("\u{1F680} Schema was generated successfully!"),process.exit(0)}var Q=new jt("generate").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("--config <config>","the path to the configuration file. defaults to the first configuration file found.").option("--output <output>","the file to output to the generated schema").option("-y, --yes","automatically answer yes to all prompts").action(Nt);import"dotenv/config";async function kt(){let e=new Ct;e.addCommand(_).addCommand(Q).version("0.0.1").description("Better Auth CLI"),e.parse()}kt();
|
|
28
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/commands/migrate.ts","../src/utils/get-config.ts","../src/utils/add-svelte-kit-env-modules.ts","../src/commands/generate.ts","../src/generators/index.ts","../src/generators/drizzle.ts","../src/generators/prisma.ts","../src/generators/kysely.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Command } from \"commander\";\nimport { migrate } from \"./commands/migrate\";\nimport { generate } from \"./commands/generate\";\nimport \"dotenv/config\";\n\nasync function main() {\n\tconst program = new Command();\n\tprogram\n\t\t.addCommand(migrate)\n\t\t.addCommand(generate)\n\t\t.version(\"0.0.1\")\n\t\t.description(\"Better Auth CLI\");\n\tprogram.parse();\n}\n\nmain();\n","import { Command } from \"commander\";\nimport { z } from \"zod\";\nimport { existsSync } from \"fs\";\nimport path from \"path\";\nimport yoctoSpinner from \"yocto-spinner\";\nimport chalk from \"chalk\";\nimport prompts from \"prompts\";\nimport { logger } from \"better-auth\";\nimport { getAdapter, getMigrations } from \"better-auth/db\";\nimport { getConfig } from \"../utils/get-config\";\nimport { exec } from \"tinyexec\";\n\nexport async function migrateAction(opts: any) {\n\tconst options = z\n\t\t.object({\n\t\t\tcwd: z.string(),\n\t\t\tconfig: z.string().optional(),\n\t\t\ty: z.boolean().optional(),\n\t\t})\n\t\t.parse(opts);\n\tconst cwd = path.resolve(options.cwd);\n\tif (!existsSync(cwd)) {\n\t\tlogger.error(`The directory \"${cwd}\" does not exist.`);\n\t\tprocess.exit(1);\n\t}\n\tconst config = await getConfig({\n\t\tcwd,\n\t\tconfigPath: options.config,\n\t});\n\tif (!config) {\n\t\tlogger.error(\n\t\t\t\"No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.\",\n\t\t);\n\t\treturn;\n\t}\n\n\tconst db = await getAdapter(config, true);\n\n\tif (!db) {\n\t\tlogger.error(\n\t\t\t\"Invalid database configuration. Make sure you're not using adapters. Migrate command only works with built-in Kysely adapter.\",\n\t\t);\n\t\tprocess.exit(1);\n\t}\n\n\tif (db.id !== \"kysely\") {\n\t\tif (db.id === \"prisma\") {\n\t\t\tconst { confirm } = await prompts({\n\t\t\t\ttype: \"confirm\",\n\t\t\t\tname: \"confirm\",\n\t\t\t\tmessage: \"Do you want to run prisma migrate dev?\",\n\t\t\t\tinitial: false,\n\t\t\t});\n\t\t\tif (confirm) {\n\t\t\t\tconst spinner = yoctoSpinner({\n\t\t\t\t\ttext: \"running prisma migrate dev...\",\n\t\t\t\t});\n\t\t\t\tawait exec(\"npx\", [\"prisma\", \"migrate\", \"dev\"]);\n\t\t\t\tspinner.stop();\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tif (db.id === \"drizzle\") {\n\t\t\tconst { confirm } = await prompts({\n\t\t\t\ttype: \"confirm\",\n\t\t\t\tname: \"confirm\",\n\t\t\t\tmessage: \"Do you want to run drizzle migrate?\",\n\t\t\t\tinitial: false,\n\t\t\t});\n\t\t\tif (confirm) {\n\t\t\t\tconst spinner = yoctoSpinner({\n\t\t\t\t\ttext: \"running drizzle migrate...\",\n\t\t\t\t}).start();\n\t\t\t\tawait exec(\"npx\", [\"drizzle-kit\", \"migrate\"]);\n\t\t\t\tspinner.stop();\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tlogger.error(\n\t\t\t\"Migrate command only works isn't supported for this adapter.\",\n\t\t);\n\t\tprocess.exit(1);\n\t}\n\n\tconst spinner = yoctoSpinner({ text: \"preparing migration...\" }).start();\n\n\tconst { toBeAdded, toBeCreated, runMigrations } = await getMigrations(config);\n\n\tif (!toBeAdded.length && !toBeCreated.length) {\n\t\tspinner.stop();\n\t\tlogger.success(\"🚀 No migrations needed.\");\n\t\tprocess.exit(0);\n\t}\n\n\tspinner.stop();\n\tlogger.info(`🔑 The migration will affect the following:`);\n\n\tfor (const table of [...toBeCreated, ...toBeAdded]) {\n\t\tconsole.log(\n\t\t\t\"->\",\n\t\t\tchalk.magenta(Object.keys(table.fields).join(\", \")),\n\t\t\tchalk.white(\"fields on\"),\n\t\t\tchalk.yellow(`${table.table}`),\n\t\t\tchalk.white(\"table.\"),\n\t\t);\n\t}\n\n\tlet migrate = options.y;\n\tif (!migrate) {\n\t\tconst response = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"migrate\",\n\t\t\tmessage: \"Are you sure you want to run these migrations?\",\n\t\t\tinitial: false,\n\t\t});\n\t\tmigrate = response.migrate;\n\t}\n\n\tif (!migrate) {\n\t\tlogger.info(\"Migration cancelled.\");\n\t\tprocess.exit(0);\n\t}\n\n\tspinner?.start(\"migrating...\");\n\tawait runMigrations();\n\tspinner.stop();\n\tlogger.success(\"🚀 migration was completed successfully!\");\n\tprocess.exit(0);\n}\n\nexport const migrate = new Command(\"migrate\")\n\t.option(\n\t\t\"-c, --cwd <cwd>\",\n\t\t\"the working directory. defaults to the current directory.\",\n\t\tprocess.cwd(),\n\t)\n\t.option(\n\t\t\"--config <config>\",\n\t\t\"the path to the configuration file. defaults to the first configuration file found.\",\n\t)\n\t.option(\n\t\t\"-y, --y\",\n\t\t\"automatically accept and run migrations without prompting\",\n\t\tfalse,\n\t)\n\t.action(migrateAction);\n","import { loadConfig } from \"c12\";\nimport type { BetterAuthOptions } from \"better-auth\";\nimport { logger } from \"better-auth\";\nimport path from \"path\";\n// @ts-ignore\nimport babelPresetTypescript from \"@babel/preset-typescript\";\n// @ts-ignore\nimport babelPresetReact from \"@babel/preset-react\";\nimport fs from \"fs\";\nimport { BetterAuthError } from \"better-auth\";\nimport { addSvelteKitEnvModules } from \"./add-svelte-kit-env-modules\";\n\nlet possiblePaths = [\"auth.ts\", \"auth.tsx\"];\n\npossiblePaths = [\n\t...possiblePaths,\n\t...possiblePaths.map((it) => `lib/server${it}`),\n\t...possiblePaths.map((it) => `lib/${it}`),\n\t...possiblePaths.map((it) => `utils/${it}`),\n];\npossiblePaths = [\n\t...possiblePaths,\n\t...possiblePaths.map((it) => `src/${it}`),\n\t...possiblePaths.map((it) => `app/${it}`),\n];\n\nfunction stripJsonComments(jsonString: string): string {\n\treturn jsonString.replace(\n\t\t/\\\\\"|\"(?:\\\\\"|[^\"])*\"|(\\/\\/.*|\\/\\*[\\s\\S]*?\\*\\/)/g,\n\t\t(m, g) => (g ? \"\" : m),\n\t);\n}\n\nfunction getPathAliases(cwd: string): Record<string, string> | null {\n\tconst tsConfigPath = path.join(cwd, \"tsconfig.json\");\n\tif (!fs.existsSync(tsConfigPath)) {\n\t\tlogger.warn(\"[#better-auth]: tsconfig.json not found.\");\n\t\treturn null;\n\t}\n\ttry {\n\t\tconst tsConfigContent = fs.readFileSync(tsConfigPath, \"utf8\");\n\t\tconst strippedTsConfigContent = stripJsonComments(tsConfigContent);\n\t\tconst tsConfig = JSON.parse(strippedTsConfigContent);\n\t\tconst { paths = {} } = tsConfig.compilerOptions || {};\n\n\t\tconst result: Record<string, string> = {};\n\t\tconst obj = Object.entries(paths) as [string, string[]][];\n\t\tfor (const [alias, aliasPaths] of obj) {\n\t\t\tfor (const _ of aliasPaths) {\n\t\t\t\tresult[alias[0] || \"\"] = \"../\";\n\t\t\t}\n\t\t}\n\t\taddSvelteKitEnvModules(result);\n\t\treturn result;\n\t} catch (error) {\n\t\tconsole.error(error);\n\t\tthrow new BetterAuthError(\"Error parsing tsconfig.json\");\n\t}\n}\n/**\n * .tsx files are not supported by Jiti.\n */\nconst jitiOptions = (cwd: string) => {\n\tconst alias = getPathAliases(cwd) || {};\n\treturn {\n\t\ttransformOptions: {\n\t\t\tbabel: {\n\t\t\t\tpresets: [\n\t\t\t\t\t[\n\t\t\t\t\t\tbabelPresetTypescript,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tisTSX: true,\n\t\t\t\t\t\t\tallExtensions: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\t[babelPresetReact, { runtime: \"automatic\" }],\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\textensions: [\".ts\", \".tsx\", \".js\", \".jsx\"],\n\t\talias,\n\t};\n};\nexport async function getConfig({\n\tcwd,\n\tconfigPath,\n}: {\n\tcwd: string;\n\tconfigPath?: string;\n}) {\n\ttry {\n\t\tlet configFile: BetterAuthOptions | null = null;\n\t\tif (configPath) {\n\t\t\tconst { config } = await loadConfig<{\n\t\t\t\tauth: {\n\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t};\n\t\t\t\tdefault?: {\n\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t};\n\t\t\t}>({\n\t\t\t\tconfigFile: path.join(cwd, configPath),\n\t\t\t\tdotenv: true,\n\t\t\t\tjitiOptions: jitiOptions(cwd),\n\t\t\t});\n\t\t\tif (!config.auth && !config.default) {\n\t\t\t\tlogger.error(\n\t\t\t\t\t\"[#better-auth]: Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth.\",\n\t\t\t\t);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\tconfigFile = config.auth?.options || config.default?.options || null;\n\t\t}\n\n\t\tif (!configFile) {\n\t\t\tfor (const possiblePath of possiblePaths) {\n\t\t\t\ttry {\n\t\t\t\t\tconst { config } = await loadConfig<{\n\t\t\t\t\t\tauth: {\n\t\t\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t\t\t};\n\t\t\t\t\t\tdefault?: {\n\t\t\t\t\t\t\toptions: BetterAuthOptions;\n\t\t\t\t\t\t};\n\t\t\t\t\t}>({\n\t\t\t\t\t\tconfigFile: possiblePath,\n\t\t\t\t\t\tjitiOptions: jitiOptions(cwd),\n\t\t\t\t\t});\n\t\t\t\t\tconst hasConfig = Object.keys(config).length > 0;\n\t\t\t\t\tif (hasConfig) {\n\t\t\t\t\t\tconfigFile =\n\t\t\t\t\t\t\tconfig.auth?.options || config.default?.options || null;\n\t\t\t\t\t\tif (!configFile) {\n\t\t\t\t\t\t\tlogger.error(\"[#better-auth]: Couldn't read your auth config.\");\n\t\t\t\t\t\t\tlogger.break();\n\t\t\t\t\t\t\tlogger.info(\n\t\t\t\t\t\t\t\t\"[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth.\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tprocess.exit(1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\tlogger.error(\"[#better-auth]: Couldn't read your auth config.\", e);\n\t\t\t\t\tprocess.exit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn configFile;\n\t} catch (e) {\n\t\tlogger.error(\"Couldn't read your auth config.\");\n\t\tprocess.exit(1);\n\t}\n}\n\nexport { possiblePaths };\n","export function addSvelteKitEnvModules(aliases: Record<string, string>) {\n\taliases[\"$env/dynamic/private\"] = createDataUriModule(\n\t\tcreateDynamicEnvModule(),\n\t);\n\taliases[\"$env/dynamic/public\"] = createDataUriModule(\n\t\tcreateDynamicEnvModule(),\n\t);\n\taliases[\"$env/static/private\"] = createDataUriModule(\n\t\tcreateStaticEnvModule(filterPrivateEnv(\"PUBLIC_\", \"\")),\n\t);\n\taliases[\"$env/static/public\"] = createDataUriModule(\n\t\tcreateStaticEnvModule(filterPublicEnv(\"PUBLIC_\", \"\")),\n\t);\n}\n\nfunction createDataUriModule(module: string) {\n\treturn `data:text/javascript;charset=utf-8,${encodeURIComponent(module)}`;\n}\n\nfunction createStaticEnvModule(env: Record<string, string>) {\n\tconst declarations = Object.keys(env)\n\t\t.filter((k) => validIdentifier.test(k) && !reserved.has(k))\n\t\t.map((k) => `export const ${k} = ${JSON.stringify(env[k])};`);\n\n\treturn `\n ${declarations.join(\"\\n\")}\n // jiti dirty hack: .unknown\n `;\n}\n\nfunction createDynamicEnvModule() {\n\treturn `\n export const env = process.env;\n // jiti dirty hack: .unknown\n `;\n}\n\nexport function filterPrivateEnv(publicPrefix: string, privatePrefix: string) {\n\treturn Object.fromEntries(\n\t\tObject.entries(process.env).filter(\n\t\t\t([k]) =>\n\t\t\t\tk.startsWith(privatePrefix) &&\n\t\t\t\t(publicPrefix === \"\" || !k.startsWith(publicPrefix)),\n\t\t),\n\t) as Record<string, string>;\n}\n\nexport function filterPublicEnv(publicPrefix: string, privatePrefix: string) {\n\treturn Object.fromEntries(\n\t\tObject.entries(process.env).filter(\n\t\t\t([k]) =>\n\t\t\t\tk.startsWith(publicPrefix) &&\n\t\t\t\t(privatePrefix === \"\" || !k.startsWith(privatePrefix)),\n\t\t),\n\t) as Record<string, string>;\n}\n\nconst validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\nconst reserved = new Set([\n\t\"do\",\n\t\"if\",\n\t\"in\",\n\t\"for\",\n\t\"let\",\n\t\"new\",\n\t\"try\",\n\t\"var\",\n\t\"case\",\n\t\"else\",\n\t\"enum\",\n\t\"eval\",\n\t\"null\",\n\t\"this\",\n\t\"true\",\n\t\"void\",\n\t\"with\",\n\t\"await\",\n\t\"break\",\n\t\"catch\",\n\t\"class\",\n\t\"const\",\n\t\"false\",\n\t\"super\",\n\t\"throw\",\n\t\"while\",\n\t\"yield\",\n\t\"delete\",\n\t\"export\",\n\t\"import\",\n\t\"public\",\n\t\"return\",\n\t\"static\",\n\t\"switch\",\n\t\"typeof\",\n\t\"default\",\n\t\"extends\",\n\t\"finally\",\n\t\"package\",\n\t\"private\",\n\t\"continue\",\n\t\"debugger\",\n\t\"function\",\n\t\"arguments\",\n\t\"interface\",\n\t\"protected\",\n\t\"implements\",\n\t\"instanceof\",\n]);\n","import { Command } from \"commander\";\nimport { getConfig } from \"../utils/get-config\";\nimport { z } from \"zod\";\nimport { existsSync } from \"fs\";\nimport path from \"path\";\nimport { logger } from \"better-auth\";\nimport yoctoSpinner from \"yocto-spinner\";\nimport prompts from \"prompts\";\nimport fs from \"fs/promises\";\nimport chalk from \"chalk\";\nimport { getAdapter } from \"better-auth/db\";\nimport { getGenerator } from \"../generators\";\n\nexport async function generateAction(opts: any) {\n\tconst options = z\n\t\t.object({\n\t\t\tcwd: z.string(),\n\t\t\tconfig: z.string().optional(),\n\t\t\toutput: z.string().optional(),\n\t\t\ty: z.boolean().optional(),\n\t\t})\n\t\t.parse(opts);\n\n\tconst cwd = path.resolve(options.cwd);\n\tif (!existsSync(cwd)) {\n\t\tlogger.error(`The directory \"${cwd}\" does not exist.`);\n\t\tprocess.exit(1);\n\t}\n\tconst config = await getConfig({\n\t\tcwd,\n\t\tconfigPath: options.config,\n\t});\n\tif (!config) {\n\t\tlogger.error(\n\t\t\t\"No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.\",\n\t\t);\n\t\treturn;\n\t}\n\n\tconst adapter = await getAdapter(config, true).catch((e) => {\n\t\tlogger.error(e.message);\n\t\tprocess.exit(1);\n\t});\n\n\tconst spinner = yoctoSpinner({ text: \"preparing schema...\" }).start();\n\n\tconst schema = await getGenerator({\n\t\tadapter,\n\t\tfile: options.output,\n\t\toptions: config,\n\t});\n\n\tspinner.stop();\n\tif (!schema.code) {\n\t\tlogger.success(\"Your schema is already up to date.\");\n\t\tprocess.exit(0);\n\t}\n\tif (schema.append || schema.overwrite) {\n\t\tif (options.y) {\n\t\t\tconst exist = existsSync(path.join(cwd, schema.fileName));\n\t\t\tif (!exist) {\n\t\t\t\tawait fs.mkdir(path.dirname(path.join(cwd, schema.fileName)), {\n\t\t\t\t\trecursive: true,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (schema.overwrite) {\n\t\t\t\tawait fs.writeFile(path.join(cwd, schema.fileName), schema.code);\n\t\t\t} else {\n\t\t\t\tawait fs.appendFile(path.join(cwd, schema.fileName), schema.code);\n\t\t\t}\n\t\t\tlogger.success(\n\t\t\t\t`🚀 Schema was ${\n\t\t\t\t\tschema.overwrite ? \"overwritten\" : \"appended\"\n\t\t\t\t} successfully!`,\n\t\t\t);\n\t\t\tprocess.exit(0);\n\t\t}\n\n\t\tconst { confirm } = await prompts({\n\t\t\ttype: \"confirm\",\n\t\t\tname: \"confirm\",\n\t\t\tmessage: `The file ${\n\t\t\t\tschema.fileName\n\t\t\t} already exists. Do you want to ${chalk.yellow(\n\t\t\t\t`${schema.overwrite ? \"overwrite\" : \"append\"}`,\n\t\t\t)} the schema to the file?`,\n\t\t});\n\t\tif (confirm) {\n\t\t\tconst exist = existsSync(path.join(cwd, schema.fileName));\n\t\t\tif (!exist) {\n\t\t\t\tawait fs.mkdir(path.dirname(path.join(cwd, schema.fileName)), {\n\t\t\t\t\trecursive: true,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (schema.overwrite) {\n\t\t\t\tawait fs.writeFile(path.join(cwd, schema.fileName), schema.code);\n\t\t\t} else {\n\t\t\t\tawait fs.appendFile(path.join(cwd, schema.fileName), schema.code);\n\t\t\t}\n\t\t\tlogger.success(\n\t\t\t\t`🚀 Schema was ${\n\t\t\t\t\tschema.overwrite ? \"overwritten\" : \"appended\"\n\t\t\t\t} successfully!`,\n\t\t\t);\n\t\t\tprocess.exit(0);\n\t\t} else {\n\t\t\tlogger.error(\"Schema generation aborted.\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tif (options.y) {\n\t\tif (!options.output) {\n\t\t\tconst dirExist = existsSync(\n\t\t\t\tpath.dirname(path.join(cwd, schema.fileName)),\n\t\t\t);\n\t\t\tif (!dirExist) {\n\t\t\t\tawait fs.mkdir(path.dirname(path.join(cwd, schema.fileName)), {\n\t\t\t\t\trecursive: true,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tawait fs.writeFile(\n\t\t\toptions.output || path.join(cwd, schema.fileName),\n\t\t\tschema.code,\n\t\t);\n\t\tlogger.success(`🚀 Schema was generated successfully!`);\n\t\tprocess.exit(0);\n\t}\n\n\tconst { confirm } = await prompts({\n\t\ttype: \"confirm\",\n\t\tname: \"confirm\",\n\t\tmessage: `Do you want to generate the schema to ${chalk.yellow(\n\t\t\tschema.fileName,\n\t\t)}?`,\n\t});\n\tif (!confirm) {\n\t\tlogger.error(\"Schema generation aborted.\");\n\t\tprocess.exit(1);\n\t}\n\n\tif (!options.output) {\n\t\tconst dirExist = existsSync(path.dirname(path.join(cwd, schema.fileName)));\n\t\tif (!dirExist) {\n\t\t\tawait fs.mkdir(path.dirname(path.join(cwd, schema.fileName)), {\n\t\t\t\trecursive: true,\n\t\t\t});\n\t\t}\n\t}\n\tawait fs.writeFile(\n\t\toptions.output || path.join(cwd, schema.fileName),\n\t\tschema.code,\n\t);\n\tlogger.success(`🚀 Schema was generated successfully!`);\n\tprocess.exit(0);\n}\n\nexport const generate = new Command(\"generate\")\n\t.option(\n\t\t\"-c, --cwd <cwd>\",\n\t\t\"the working directory. defaults to the current directory.\",\n\t\tprocess.cwd(),\n\t)\n\t.option(\n\t\t\"--config <config>\",\n\t\t\"the path to the configuration file. defaults to the first configuration file found.\",\n\t)\n\t.option(\"--output <output>\", \"the file to output to the generated schema\")\n\t.option(\"-y, --yes\", \"automatically answer yes to all prompts\")\n\t.action(generateAction);\n","import { logger, type Adapter, type BetterAuthOptions } from \"better-auth\";\nimport { generateDrizzleSchema } from \"./drizzle\";\nimport { generatePrismaSchema } from \"./prisma\";\nimport { generateMigrations } from \"./kysely\";\n\nexport const adapters = {\n\tprisma: generatePrismaSchema,\n\tdrizzle: generateDrizzleSchema,\n\tkysely: generateMigrations,\n};\n\nexport const getGenerator = (opts: {\n\tadapter: Adapter;\n\tfile?: string;\n\toptions: BetterAuthOptions;\n}) => {\n\tconst adapter = opts.adapter;\n\tconst generator =\n\t\tadapter.id in adapters\n\t\t\t? adapters[adapter.id as keyof typeof adapters]\n\t\t\t: null;\n\tif (!generator) {\n\t\tlogger.error(`${adapter.id} is not supported.`);\n\t\tprocess.exit(1);\n\t}\n\treturn generator(opts);\n};\n","import { getAuthTables, type FieldType } from \"better-auth/db\";\nimport { existsSync } from \"fs\";\nimport type { SchemaGenerator } from \"./types\";\n\nexport const generateDrizzleSchema: SchemaGenerator = async ({\n\toptions,\n\tfile,\n\tadapter,\n}) => {\n\tconst tables = getAuthTables(options);\n\tconst filePath = file || \"./auth-schema.ts\";\n\tconst databaseType = adapter.options?.provider;\n\tconst timestampAndBoolean =\n\t\tdatabaseType !== \"sqlite\" ? \"timestamp, boolean\" : \"\";\n\tconst int = databaseType === \"mysql\" ? \"int\" : \"integer\";\n\tlet code = `import { ${databaseType}Table, text, ${int}, ${timestampAndBoolean} } from \"drizzle-orm/${databaseType}-core\";\n\t\t\t`;\n\n\tconst fileExist = existsSync(filePath);\n\n\tfor (const table in tables) {\n\t\tconst tableName = tables[table].tableName;\n\t\tconst fields = tables[table].fields;\n\t\tfunction getType(name: string, type: FieldType) {\n\t\t\tif (type === \"string\") {\n\t\t\t\treturn `text('${name}')`;\n\t\t\t}\n\t\t\tif (type === \"number\") {\n\t\t\t\treturn `${int}('${name}')`;\n\t\t\t}\n\t\t\tif (type === \"boolean\") {\n\t\t\t\tif (databaseType === \"sqlite\") {\n\t\t\t\t\treturn `integer('${name}', {\n\t\t\t\t\t\t\t\tmode: \"boolean\"\n\t\t\t\t\t\t\t})`;\n\t\t\t\t}\n\t\t\t\treturn `boolean('${name}')`;\n\t\t\t}\n\t\t\tif (type === \"date\") {\n\t\t\t\tif (databaseType === \"sqlite\") {\n\t\t\t\t\treturn `integer('${name}', {\n\t\t\t\t\t\t\t\tmode: \"timestamp\"\n\t\t\t\t\t\t\t})`;\n\t\t\t\t}\n\t\t\t\treturn `timestamp('${name}')`;\n\t\t\t}\n\t\t}\n\t\tconst schema = `export const ${table} = ${databaseType}Table(\"${tableName}\", {\n\t\t\t\t\tid: text(\"id\").primaryKey(),\n\t\t\t\t\t${Object.keys(fields)\n\t\t\t\t\t\t.map((field) => {\n\t\t\t\t\t\t\tconst attr = fields[field];\n\t\t\t\t\t\t\treturn `${field}: ${getType(field, attr.type)}${\n\t\t\t\t\t\t\t\tattr.required ? \".notNull()\" : \"\"\n\t\t\t\t\t\t\t}${attr.unique ? \".unique()\" : \"\"}${\n\t\t\t\t\t\t\t\tattr.references\n\t\t\t\t\t\t\t\t\t? `.references(()=> ${attr.references.model}.${attr.references.field})`\n\t\t\t\t\t\t\t\t\t: \"\"\n\t\t\t\t\t\t\t}`;\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join(\",\\n \")}\n\t\t\t\t});`;\n\t\tcode += `\\n${schema}\\n`;\n\t}\n\n\treturn {\n\t\tcode: code,\n\t\tfileName: filePath,\n\t\toverwrite: fileExist,\n\t};\n};\n","import { getAuthTables, type FieldType } from \"better-auth/db\";\nimport { produceSchema } from \"@mrleebo/prisma-ast\";\nimport { existsSync } from \"fs\";\nimport path from \"path\";\nimport fs from \"fs/promises\";\nimport { capitalizeFirstLetter } from \"better-auth\";\nimport type { SchemaGenerator } from \"./types\";\n\nexport const generatePrismaSchema: SchemaGenerator = async ({\n\tadapter,\n\toptions,\n\tfile,\n}) => {\n\tconst provider = adapter.options?.provider || \"postgresql\";\n\tconst tables = getAuthTables(options);\n\tconst filePath = file || \"./prisma/schema.prisma\";\n\tconst schemaPrismaExist = existsSync(path.join(process.cwd(), filePath));\n\tlet schemaPrisma = \"\";\n\tif (schemaPrismaExist) {\n\t\tschemaPrisma = await fs.readFile(\n\t\t\tpath.join(process.cwd(), filePath),\n\t\t\t\"utf-8\",\n\t\t);\n\t} else {\n\t\tschemaPrisma = getNewPrisma(provider);\n\t}\n\n\tconst schema = produceSchema(schemaPrisma, (builder) => {\n\t\tfor (const table in tables) {\n\t\t\tconst fields = tables[table]?.fields;\n\t\t\tconst originalTable = tables[table]?.tableName;\n\t\t\tconst tableName = capitalizeFirstLetter(originalTable || \"\");\n\t\t\tfunction getType(type: FieldType, isOptional: boolean) {\n\t\t\t\tif (type === \"string\") {\n\t\t\t\t\treturn isOptional ? \"String?\" : \"String\";\n\t\t\t\t}\n\t\t\t\tif (type === \"number\") {\n\t\t\t\t\treturn isOptional ? \"Int?\" : \"Int\";\n\t\t\t\t}\n\t\t\t\tif (type === \"boolean\") {\n\t\t\t\t\treturn isOptional ? \"Boolean?\" : \"Boolean\";\n\t\t\t\t}\n\t\t\t\tif (type === \"date\") {\n\t\t\t\t\treturn isOptional ? \"DateTime?\" : \"DateTime\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst prismaModel = builder.findByType(\"model\", {\n\t\t\t\tname: tableName,\n\t\t\t});\n\t\t\t!prismaModel &&\n\t\t\t\tbuilder.model(tableName).field(\"id\", \"String\").attribute(\"id\");\n\n\t\t\tfor (const field in fields) {\n\t\t\t\tconst attr = fields[field]!;\n\n\t\t\t\tif (prismaModel) {\n\t\t\t\t\tconst isAlreadyExist = builder.findByType(\"field\", {\n\t\t\t\t\t\tname: field,\n\t\t\t\t\t\twithin: prismaModel.properties,\n\t\t\t\t\t});\n\t\t\t\t\tif (isAlreadyExist) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tbuilder\n\t\t\t\t\t.model(tableName)\n\t\t\t\t\t.field(field, getType(attr.type, !attr?.required));\n\t\t\t\tif (attr.unique) {\n\t\t\t\t\tbuilder.model(tableName).blockAttribute(`unique([${field}])`);\n\t\t\t\t}\n\t\t\t\tif (attr.references) {\n\t\t\t\t\tbuilder\n\t\t\t\t\t\t.model(tableName)\n\t\t\t\t\t\t.field(\n\t\t\t\t\t\t\t`${attr.references.model.toLowerCase()}`,\n\t\t\t\t\t\t\tcapitalizeFirstLetter(attr.references.model),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.attribute(\n\t\t\t\t\t\t\t`relation(fields: [${field}], references: [${attr.references.field}], onDelete: Cascade)`,\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst hasAttribute = builder.findByType(\"attribute\", {\n\t\t\t\tname: \"map\",\n\t\t\t\twithin: prismaModel?.properties,\n\t\t\t});\n\t\t\tif (originalTable !== tableName && !hasAttribute) {\n\t\t\t\tbuilder.model(tableName).blockAttribute(\"map\", originalTable);\n\t\t\t}\n\t\t}\n\t});\n\treturn {\n\t\tcode: schema.trim() === schemaPrisma.trim() ? \"\" : schema,\n\t\tfileName: filePath,\n\t};\n};\n\nconst getNewPrisma = (provider: string) => `generator client {\n provider = \"prisma-client-js\"\n }\n \n datasource db {\n provider = \"${provider}\"\n url = ${\n\t\t\tprovider === \"sqlite\" ? `\"file:./dev.db\"` : `env(\"DATABASE_URL\")`\n\t\t}\n }`;\n","import { getMigrations } from \"better-auth/db\";\nimport type { SchemaGenerator } from \"./types\";\n\nexport const generateMigrations: SchemaGenerator = async ({ options }) => {\n\tconst { compileMigrations } = await getMigrations(options);\n\tconst migrations = await compileMigrations();\n\treturn {\n\t\tcode: migrations,\n\t\tfileName: `./better-auth_migrations/${new Date()\n\t\t\t.toISOString()\n\t\t\t.replace(/:/g, \"-\")}.sql`,\n\t};\n};\n"],"mappings":";AAEA,OAAS,WAAAA,OAAe,YCFxB,OAAS,WAAAC,OAAe,YACxB,OAAS,KAAAC,MAAS,MAClB,OAAS,cAAAC,OAAkB,KAC3B,OAAOC,OAAU,OACjB,OAAOC,MAAkB,gBACzB,OAAOC,MAAW,QAClB,OAAOC,MAAa,UACpB,OAAS,UAAAC,MAAc,cACvB,OAAS,cAAAC,GAAY,iBAAAC,OAAqB,iBCR1C,OAAS,cAAAC,MAAkB,MAE3B,OAAS,UAAAC,MAAc,cACvB,OAAOC,MAAU,OAEjB,OAAOC,OAA2B,2BAElC,OAAOC,OAAsB,sBAC7B,OAAOC,MAAQ,KACf,OAAS,mBAAAC,OAAuB,cCTzB,SAASC,EAAuBC,EAAiC,CACvEA,EAAQ,sBAAsB,EAAIC,EACjCC,EAAuB,CACxB,EACAF,EAAQ,qBAAqB,EAAIC,EAChC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EACZ,CAAC,EAGH,MAAME,EAAG,UACRf,EAAQ,QAAUG,EAAK,KAAKD,EAAKW,EAAO,QAAQ,EAChDA,EAAO,IACR,EACAR,EAAO,QAAQ,8CAAuC,EACtD,QAAQ,KAAK,CAAC,GAGf,GAAM,CAAE,QAAAW,CAAQ,EAAI,MAAMC,EAAQ,CACjC,KAAM,UACN,KAAM,UACN,QAAS,yCAAyCC,EAAM,OACvDL,EAAO,QACR,CAAC,GACF,CAAC,EACIG,IACJX,EAAO,MAAM,4BAA4B,EACzC,QAAQ,KAAK,CAAC,GAGVL,EAAQ,QACKI,EAAWD,EAAK,QAAQA,EAAK,KAAKD,EAAKW,EAAO,QAAQ,CAAC,CAAC,GAExE,MAAME,EAAG,MAAMZ,EAAK,QAAQA,EAAK,KAAKD,EAAKW,EAAO,QAAQ,CAAC,EAAG,CAC7D,UAAW,EACZ,CAAC,EAGH,MAAME,EAAG,UACRf,EAAQ,QAAUG,EAAK,KAAKD,EAAKW,EAAO,QAAQ,EAChDA,EAAO,IACR,EACAR,EAAO,QAAQ,8CAAuC,EACtD,QAAQ,KAAK,CAAC,CACf,CAEO,IAAMc,EAAW,IAAIC,GAAQ,UAAU,EAC5C,OACA,kBACA,4DACA,QAAQ,IAAI,CACb,EACC,OACA,oBACA,qFACD,EACC,OAAO,oBAAqB,4CAA4C,EACxE,OAAO,YAAa,yCAAyC,EAC7D,OAAOtB,EAAc,EJrKvB,MAAO,gBAEP,eAAeuB,IAAO,CACrB,IAAMC,EAAU,IAAIC,GACpBD,EACE,WAAWE,CAAO,EAClB,WAAWC,CAAQ,EACnB,QAAQ,OAAO,EACf,YAAY,iBAAiB,EAC/BH,EAAQ,MAAM,CACf,CAEAD,GAAK","names":["Command","Command","z","existsSync","path","yoctoSpinner","chalk","prompts","logger","getAdapter","getMigrations","loadConfig","logger","path","babelPresetTypescript","babelPresetReact","fs","BetterAuthError","addSvelteKitEnvModules","aliases","createDataUriModule","createDynamicEnvModule","createStaticEnvModule","filterPrivateEnv","filterPublicEnv","module","env","k","validIdentifier","reserved","publicPrefix","privatePrefix","possiblePaths","it","stripJsonComments","jsonString","m","g","getPathAliases","cwd","tsConfigPath","path","fs","logger","tsConfigContent","strippedTsConfigContent","tsConfig","paths","result","obj","alias","aliasPaths","_","addSvelteKitEnvModules","error","BetterAuthError","jitiOptions","babelPresetTypescript","babelPresetReact","getConfig","configPath","configFile","config","loadConfig","possiblePath","e","exec","migrateAction","opts","options","z","cwd","path","existsSync","logger","config","getConfig","db","getAdapter","confirm","prompts","spinner","yoctoSpinner","toBeAdded","toBeCreated","runMigrations","getMigrations","table","chalk","migrate","Command","Command","z","existsSync","path","logger","yoctoSpinner","prompts","fs","chalk","getAdapter","logger","getAuthTables","existsSync","generateDrizzleSchema","options","file","adapter","tables","filePath","databaseType","timestampAndBoolean","int","code","fileExist","table","getType","name","type","tableName","fields","schema","field","attr","getAuthTables","produceSchema","existsSync","path","fs","capitalizeFirstLetter","generatePrismaSchema","adapter","options","file","provider","tables","filePath","schemaPrismaExist","schemaPrisma","getNewPrisma","schema","builder","table","getType","type","isOptional","fields","originalTable","tableName","prismaModel","field","attr","hasAttribute","getMigrations","generateMigrations","options","compileMigrations","adapters","generatePrismaSchema","generateDrizzleSchema","generateMigrations","getGenerator","opts","adapter","generator","logger","generateAction","opts","options","z","cwd","path","existsSync","logger","config","getConfig","adapter","getAdapter","e","spinner","yoctoSpinner","schema","getGenerator","fs","confirm","prompts","chalk","generate","Command","main","program","Command","migrate","generate"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.9-beta.13",
|
|
4
4
|
"description": "The CLI for BetterAuth",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"repository": {
|
|
@@ -9,31 +9,44 @@
|
|
|
9
9
|
"directory": "packages/cli"
|
|
10
10
|
},
|
|
11
11
|
"main": "./dist/index.mjs",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"executableFiles": [
|
|
14
|
+
"./dist/index.mjs"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"exports": "./dist/index.mjs",
|
|
12
18
|
"bin": "./dist/index.mjs",
|
|
13
19
|
"devDependencies": {
|
|
14
20
|
"tsup": "^8.2.4",
|
|
15
|
-
"typescript": "^5.6.3"
|
|
21
|
+
"typescript": "^5.6.3",
|
|
22
|
+
"vitest": "^1.6.0"
|
|
16
23
|
},
|
|
17
24
|
"dependencies": {
|
|
18
25
|
"@babel/preset-react": "^7.24.7",
|
|
19
26
|
"@babel/preset-typescript": "^7.24.7",
|
|
20
27
|
"@mrleebo/prisma-ast": "^0.12.0",
|
|
28
|
+
"@prisma/client": "^5.19.1",
|
|
29
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
21
30
|
"@types/prompts": "^2.4.9",
|
|
31
|
+
"better-sqlite3": "^11.3.0",
|
|
22
32
|
"c12": "^2.0.1",
|
|
23
33
|
"chalk": "^5.3.0",
|
|
24
34
|
"commander": "^12.1.0",
|
|
25
35
|
"dotenv": "^16.4.5",
|
|
36
|
+
"drizzle-orm": "^0.33.0",
|
|
37
|
+
"prisma": "^5.19.1",
|
|
26
38
|
"prompts": "^2.4.2",
|
|
27
39
|
"tinyexec": "^0.3.0",
|
|
28
40
|
"yocto-spinner": "^0.1.1",
|
|
29
41
|
"zod": "^3.23.8",
|
|
30
|
-
"better-auth": "0.4.9-beta.
|
|
42
|
+
"better-auth": "0.4.9-beta.13"
|
|
31
43
|
},
|
|
32
44
|
"files": [
|
|
33
45
|
"dist"
|
|
34
46
|
],
|
|
35
47
|
"scripts": {
|
|
36
48
|
"dev": "tsup --watch --sourcemap",
|
|
49
|
+
"test": "vitest",
|
|
37
50
|
"build": "tsup --clean"
|
|
38
51
|
}
|
|
39
52
|
}
|