authverse 1.1.3 → 1.1.5
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 +0 -1
- package/dist/index.cjs +595 -445
- package/dist/index.js +588 -438
- package/dist/template/TanstackState/components/LoginComponent.tsx +0 -1
- package/dist/template/components/LoginComponent.tsx +18 -15
- package/dist/template/components/SingUpComponent.tsx +20 -20
- package/package.json +7 -13
- package/dist/template/components/Logout.tsx +0 -21
- package/dist/template/server/user.ts +0 -49
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var getPackageManager = () => {
|
|
|
32
32
|
if (ua.includes("bun")) return "bun";
|
|
33
33
|
if (ua.includes("pnpm")) return "pnpm";
|
|
34
34
|
if (ua.includes("yarn")) return "yarn";
|
|
35
|
-
return "
|
|
35
|
+
return "pnpm";
|
|
36
36
|
};
|
|
37
37
|
var pm = getPackageManager();
|
|
38
38
|
var packageManager = (pkg, dev = false) => {
|
|
@@ -62,14 +62,47 @@ var runCommand = (cmd) => {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
// script/authUi.ts
|
|
65
|
-
var
|
|
65
|
+
var shadcnComponents = [
|
|
66
|
+
"button.tsx",
|
|
67
|
+
"card.tsx",
|
|
68
|
+
"field.tsx",
|
|
69
|
+
"input.tsx",
|
|
70
|
+
"label.tsx",
|
|
71
|
+
"separator.tsx",
|
|
72
|
+
"sonner.tsx"
|
|
73
|
+
];
|
|
74
|
+
var authUiRun = async ({
|
|
75
|
+
folder,
|
|
76
|
+
packageJson: packageJson2,
|
|
77
|
+
cmd
|
|
78
|
+
}) => {
|
|
66
79
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
const projectDir = process.cwd();
|
|
81
|
+
const shadcnPath = path.join(projectDir, folder, "components", "ui");
|
|
82
|
+
const shadcnConfigPath = path.join(projectDir, "components.json");
|
|
83
|
+
if (!fs.existsSync(shadcnPath) || !fs.existsSync(shadcnConfigPath)) {
|
|
84
|
+
console.log(chalk.yellow("\n Installing shadcn ui Components\n"));
|
|
85
|
+
if (cmd == true) {
|
|
86
|
+
runCommand("shadcn@latest init --base-color zinc --yes");
|
|
87
|
+
runCommand("shadcn@latest add button sonner card field input");
|
|
88
|
+
} else {
|
|
89
|
+
runCommand("shadcn@latest add button sonner card field input");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const shadcnFiles = fs.readdirSync(shadcnPath);
|
|
93
|
+
const missingComponents = shadcnComponents.filter(
|
|
94
|
+
(component) => !shadcnFiles.includes(component)
|
|
95
|
+
);
|
|
96
|
+
if (missingComponents.length > 0) {
|
|
97
|
+
console.log(chalk.yellow("\n Installing shadcn ui Components\n"));
|
|
98
|
+
const install = missingComponents.map((components) => components.split(".")[0]).join(" ");
|
|
99
|
+
runCommand(`shadcn@latest add ${install}`);
|
|
100
|
+
}
|
|
101
|
+
if (!packageJson2.dependencies?.["react-hook-form"] || !packageJson2.dependencies?.["@hookform/resolvers"] || !packageJson2.dependencies?.["zod"]) {
|
|
102
|
+
packageManager("react-hook-form @hookform/resolvers zod");
|
|
103
|
+
}
|
|
70
104
|
const __filename = fileURLToPath(import.meta.url);
|
|
71
105
|
const __dirname = path.dirname(__filename);
|
|
72
|
-
const projectDir = process.cwd();
|
|
73
106
|
const componentPath = path.resolve(__dirname, "./template/components");
|
|
74
107
|
const destinationPath = path.join(
|
|
75
108
|
projectDir,
|
|
@@ -96,8 +129,6 @@ var authUiRun = async ({ folder }) => {
|
|
|
96
129
|
`${componentPath}/SingUpComponent.tsx`,
|
|
97
130
|
SignUpDestinationPath
|
|
98
131
|
);
|
|
99
|
-
const LogoutDestinationPath = path.join(destinationPath, "Logout.tsx");
|
|
100
|
-
fs.copyFileSync(`${componentPath}/Logout.tsx`, LogoutDestinationPath);
|
|
101
132
|
const authTemplatePath = path.resolve(
|
|
102
133
|
__dirname,
|
|
103
134
|
"./template/app-auth-uiDesign"
|
|
@@ -152,14 +183,14 @@ ${layoutContent}`;
|
|
|
152
183
|
|
|
153
184
|
// script/prisma.ts
|
|
154
185
|
import inquirer from "inquirer";
|
|
155
|
-
var prismaRun = async ({ authUi, database }) => {
|
|
186
|
+
var prismaRun = async ({ authUi, database, cmd }) => {
|
|
156
187
|
try {
|
|
157
188
|
const projectDir = process.cwd();
|
|
158
189
|
const __filename = fileURLToPath2(import.meta.url);
|
|
159
190
|
const __dirname = path2.dirname(__filename);
|
|
160
191
|
const packageJsonPath = path2.join(projectDir, "package.json");
|
|
161
192
|
const packageJson2 = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
|
|
162
|
-
if (!packageJson2.devDependencies?.prisma
|
|
193
|
+
if (!packageJson2.devDependencies?.prisma || !packageJson2.dependencies?.["@prisma/client"]) {
|
|
163
194
|
console.log(chalk2.cyan("\n\u2699\uFE0F Initializing Prisma...\n"));
|
|
164
195
|
if (database !== "Mongodb") {
|
|
165
196
|
packageManager("prisma", true);
|
|
@@ -199,7 +230,7 @@ var prismaRun = async ({ authUi, database }) => {
|
|
|
199
230
|
} else {
|
|
200
231
|
const schemaPath = path2.join(prismaDir, "schema.prisma");
|
|
201
232
|
const schemaContent = fs2.readFileSync(schemaPath, "utf-8");
|
|
202
|
-
if (!schemaContent.includes("User")
|
|
233
|
+
if (!schemaContent.includes("User") || !schemaContent.includes("Session") || !schemaContent.includes("Account") || !schemaContent.includes("Verification")) {
|
|
203
234
|
const templatePath = path2.resolve(
|
|
204
235
|
__dirname,
|
|
205
236
|
`./template/prisma/${database}/schema.prisma_copy`
|
|
@@ -232,16 +263,48 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
232
263
|
}
|
|
233
264
|
const authPath = path2.join(libPath, "auth.ts");
|
|
234
265
|
const authClientPath = path2.join(libPath, "auth-client.ts");
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
266
|
+
if (cmd !== true) {
|
|
267
|
+
if (fs2.existsSync(authPath) || fs2.existsSync(authClientPath)) {
|
|
268
|
+
const answers = await inquirer.prompt([
|
|
269
|
+
{
|
|
270
|
+
type: "confirm",
|
|
271
|
+
name: "overwrite",
|
|
272
|
+
message: "Do you want to overwrite existing auth lib/auth.ts or lib/auth-client.ts",
|
|
273
|
+
default: false
|
|
274
|
+
}
|
|
275
|
+
]);
|
|
276
|
+
if (answers.overwrite) {
|
|
277
|
+
const authTemplatePath = path2.resolve(
|
|
278
|
+
__dirname,
|
|
279
|
+
`./template/lib/${database}/auth.ts`
|
|
280
|
+
);
|
|
281
|
+
const authDestinationPath = path2.join(libPath, "auth.ts");
|
|
282
|
+
fs2.copyFileSync(authTemplatePath, authDestinationPath);
|
|
283
|
+
const authClientTemplatePath = path2.resolve(
|
|
284
|
+
__dirname,
|
|
285
|
+
"./template/lib/auth-client.ts"
|
|
286
|
+
);
|
|
287
|
+
const authClientDestinationPath = path2.join(
|
|
288
|
+
libPath,
|
|
289
|
+
"auth-client.ts"
|
|
290
|
+
);
|
|
291
|
+
fs2.copyFileSync(authClientTemplatePath, authClientDestinationPath);
|
|
292
|
+
if (srcFolder === "src") {
|
|
293
|
+
const authContextPath = path2.join(libPath, "auth.ts");
|
|
294
|
+
const authContextContent = fs2.readFileSync(
|
|
295
|
+
authContextPath,
|
|
296
|
+
"utf-8"
|
|
297
|
+
);
|
|
298
|
+
fs2.writeFileSync(
|
|
299
|
+
authContextPath,
|
|
300
|
+
authContextContent.replace(
|
|
301
|
+
'import { PrismaClient } from "@/generated/prisma/client";',
|
|
302
|
+
'import { PrismaClient } from "../../generated/prisma/client";'
|
|
303
|
+
)
|
|
304
|
+
);
|
|
305
|
+
}
|
|
242
306
|
}
|
|
243
|
-
|
|
244
|
-
if (answers.overwrite) {
|
|
307
|
+
} else {
|
|
245
308
|
const authTemplatePath = path2.resolve(
|
|
246
309
|
__dirname,
|
|
247
310
|
`./template/lib/${database}/auth.ts`
|
|
@@ -266,41 +329,7 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
266
329
|
);
|
|
267
330
|
}
|
|
268
331
|
}
|
|
269
|
-
} else {
|
|
270
|
-
const authTemplatePath = path2.resolve(
|
|
271
|
-
__dirname,
|
|
272
|
-
`./template/lib/${database}/auth.ts`
|
|
273
|
-
);
|
|
274
|
-
const authDestinationPath = path2.join(libPath, "auth.ts");
|
|
275
|
-
fs2.copyFileSync(authTemplatePath, authDestinationPath);
|
|
276
|
-
const authClientTemplatePath = path2.resolve(
|
|
277
|
-
__dirname,
|
|
278
|
-
"./template/lib/auth-client.ts"
|
|
279
|
-
);
|
|
280
|
-
const authClientDestinationPath = path2.join(libPath, "auth-client.ts");
|
|
281
|
-
fs2.copyFileSync(authClientTemplatePath, authClientDestinationPath);
|
|
282
|
-
if (srcFolder === "src") {
|
|
283
|
-
const authContextPath = path2.join(libPath, "auth.ts");
|
|
284
|
-
const authContextContent = fs2.readFileSync(authContextPath, "utf-8");
|
|
285
|
-
fs2.writeFileSync(
|
|
286
|
-
authContextPath,
|
|
287
|
-
authContextContent.replace(
|
|
288
|
-
'import { PrismaClient } from "@/generated/prisma/client";',
|
|
289
|
-
'import { PrismaClient } from "../../generated/prisma/client";'
|
|
290
|
-
)
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
332
|
}
|
|
294
|
-
const serverPath = path2.join(projectDir, srcFolder, "server");
|
|
295
|
-
if (!fs2.existsSync(serverPath)) {
|
|
296
|
-
fs2.mkdirSync(serverPath, { recursive: true });
|
|
297
|
-
}
|
|
298
|
-
const userTemplatePath = path2.resolve(
|
|
299
|
-
__dirname,
|
|
300
|
-
"./template/server/user.ts"
|
|
301
|
-
);
|
|
302
|
-
const userDestinationPath = path2.join(serverPath, "user.ts");
|
|
303
|
-
fs2.copyFileSync(userTemplatePath, userDestinationPath);
|
|
304
333
|
const routeTemplatePath = path2.resolve(
|
|
305
334
|
__dirname,
|
|
306
335
|
"./template/api/route.ts"
|
|
@@ -339,7 +368,11 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
339
368
|
);
|
|
340
369
|
}
|
|
341
370
|
if (authUi) {
|
|
342
|
-
await authUiRun({
|
|
371
|
+
await authUiRun({
|
|
372
|
+
folder: srcFolder,
|
|
373
|
+
packageJson: packageJson2,
|
|
374
|
+
cmd
|
|
375
|
+
});
|
|
343
376
|
} else {
|
|
344
377
|
console.log(
|
|
345
378
|
chalk2.green(
|
|
@@ -358,7 +391,7 @@ import path3 from "path";
|
|
|
358
391
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
359
392
|
import fs3 from "fs";
|
|
360
393
|
import inquirer2 from "inquirer";
|
|
361
|
-
var drizzleRun = async (authUi) => {
|
|
394
|
+
var drizzleRun = async ({ authUi, cmd }) => {
|
|
362
395
|
try {
|
|
363
396
|
const projectDir = process.cwd();
|
|
364
397
|
const packageJsonPath = path3.join(projectDir, "package.json");
|
|
@@ -481,16 +514,6 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
481
514
|
);
|
|
482
515
|
fs3.copyFileSync(drizzleConfigTemplatePath, drizzleConfigDestinationPath);
|
|
483
516
|
}
|
|
484
|
-
const serverPath = path3.join(projectDir, srcFolder, "server");
|
|
485
|
-
if (!fs3.existsSync(serverPath)) {
|
|
486
|
-
fs3.mkdirSync(serverPath, { recursive: true });
|
|
487
|
-
}
|
|
488
|
-
const userTemplatePath = path3.resolve(
|
|
489
|
-
__dirname,
|
|
490
|
-
"./template/server/user.ts"
|
|
491
|
-
);
|
|
492
|
-
const userDestinationPath = path3.join(serverPath, "user.ts");
|
|
493
|
-
fs3.copyFileSync(userTemplatePath, userDestinationPath);
|
|
494
517
|
const routeTemplatePath = path3.resolve(
|
|
495
518
|
__dirname,
|
|
496
519
|
"./template/api/route.ts"
|
|
@@ -516,7 +539,11 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
516
539
|
const proxyDestinationPath = path3.join(proxyDestinationDir, "proxy.ts");
|
|
517
540
|
fs3.copyFileSync(proxyTemplatePath, proxyDestinationPath);
|
|
518
541
|
if (authUi) {
|
|
519
|
-
await authUiRun({
|
|
542
|
+
await authUiRun({
|
|
543
|
+
folder: srcFolder,
|
|
544
|
+
packageJson: packageJson2,
|
|
545
|
+
cmd
|
|
546
|
+
});
|
|
520
547
|
} else {
|
|
521
548
|
console.log(
|
|
522
549
|
chalk3.green(
|
|
@@ -529,10 +556,6 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
529
556
|
}
|
|
530
557
|
};
|
|
531
558
|
|
|
532
|
-
// cli/init.ts
|
|
533
|
-
import path7 from "path";
|
|
534
|
-
import fs7 from "fs";
|
|
535
|
-
|
|
536
559
|
// script/prismaRunTanstackState.ts
|
|
537
560
|
import chalk5 from "chalk";
|
|
538
561
|
import path5 from "path";
|
|
@@ -544,14 +567,46 @@ import chalk4 from "chalk";
|
|
|
544
567
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
545
568
|
import path4 from "path";
|
|
546
569
|
import fs4 from "fs";
|
|
547
|
-
var
|
|
570
|
+
var shadcnComponents2 = [
|
|
571
|
+
"button.tsx",
|
|
572
|
+
"card.tsx",
|
|
573
|
+
"field.tsx",
|
|
574
|
+
"input.tsx",
|
|
575
|
+
"label.tsx",
|
|
576
|
+
"separator.tsx",
|
|
577
|
+
"sonner.tsx"
|
|
578
|
+
];
|
|
579
|
+
var authUiTanstackState = async ({
|
|
580
|
+
packageJson: packageJson2,
|
|
581
|
+
cmd
|
|
582
|
+
}) => {
|
|
548
583
|
try {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
584
|
+
const projectDir = process.cwd();
|
|
585
|
+
const shadcnPath = path4.join(projectDir, "src", "components", "ui");
|
|
586
|
+
const shadcnConfigPath = path4.join(projectDir, "components.json");
|
|
587
|
+
if (!fs4.existsSync(shadcnPath) || !fs4.existsSync(shadcnConfigPath)) {
|
|
588
|
+
console.log(chalk4.yellow("\n Installing shadcn ui Components\n"));
|
|
589
|
+
if (cmd == true) {
|
|
590
|
+
runCommand("shadcn@latest init --base-color zinc --yes");
|
|
591
|
+
runCommand("shadcn@latest add button sonner card field input");
|
|
592
|
+
} else {
|
|
593
|
+
runCommand("shadcn@latest add button sonner card field input");
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
const shadcnFiles = fs4.readdirSync(shadcnPath);
|
|
597
|
+
const missingComponents = shadcnComponents2.filter(
|
|
598
|
+
(component) => !shadcnFiles.includes(component)
|
|
599
|
+
);
|
|
600
|
+
if (missingComponents.length > 0) {
|
|
601
|
+
console.log(chalk4.yellow("\n Installing shadcn ui Components\n"));
|
|
602
|
+
const install = missingComponents.map((components) => components.split(".")[0]).join(" ");
|
|
603
|
+
runCommand(`shadcn@latest add ${install}`);
|
|
604
|
+
}
|
|
605
|
+
if (!packageJson2.dependencies?.["@tanstack/react-form"] || !packageJson2.dependencies?.["zod"]) {
|
|
606
|
+
packageManager("@tanstack/react-form zod");
|
|
607
|
+
}
|
|
552
608
|
const __filename = fileURLToPath4(import.meta.url);
|
|
553
609
|
const __dirname = path4.dirname(__filename);
|
|
554
|
-
const projectDir = process.cwd();
|
|
555
610
|
const srcPath = path4.join(projectDir, "src");
|
|
556
611
|
const componentPath = path4.resolve(
|
|
557
612
|
__dirname,
|
|
@@ -613,7 +668,8 @@ ${rootContent}`;
|
|
|
613
668
|
// script/prismaRunTanstackState.ts
|
|
614
669
|
var prismaRunTanstackState = async ({
|
|
615
670
|
authUi,
|
|
616
|
-
database
|
|
671
|
+
database,
|
|
672
|
+
cmd
|
|
617
673
|
}) => {
|
|
618
674
|
try {
|
|
619
675
|
const projectDir = process.cwd();
|
|
@@ -621,7 +677,7 @@ var prismaRunTanstackState = async ({
|
|
|
621
677
|
const __dirname = path5.dirname(__filename);
|
|
622
678
|
const packageJsonPath = path5.join(projectDir, "package.json");
|
|
623
679
|
const packageJson2 = JSON.parse(fs5.readFileSync(packageJsonPath, "utf-8"));
|
|
624
|
-
if (!packageJson2.devDependencies?.prisma
|
|
680
|
+
if (!packageJson2.devDependencies?.prisma || !packageJson2.dependencies?.["@prisma/client"]) {
|
|
625
681
|
console.log(chalk5.cyan("\n\u2699\uFE0F Initializing Prisma...\n"));
|
|
626
682
|
if (database !== "Mongodb") {
|
|
627
683
|
packageManager("prisma", true);
|
|
@@ -661,7 +717,7 @@ var prismaRunTanstackState = async ({
|
|
|
661
717
|
} else {
|
|
662
718
|
const schemaPath = path5.join(prismaDir, "schema.prisma");
|
|
663
719
|
const schemaContent = fs5.readFileSync(schemaPath, "utf-8");
|
|
664
|
-
if (!schemaContent.includes("User")
|
|
720
|
+
if (!schemaContent.includes("User") || !schemaContent.includes("Session") || !schemaContent.includes("Account") || !schemaContent.includes("Verification")) {
|
|
665
721
|
const templatePath = path5.resolve(
|
|
666
722
|
__dirname,
|
|
667
723
|
`./template/prisma/${database}/schema.prisma_copy`
|
|
@@ -730,7 +786,10 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
730
786
|
const apiDestinationPath = path5.join(fileRouteDestinationPath, "$.ts");
|
|
731
787
|
fs5.copyFileSync(fileRouteTemplatePath, apiDestinationPath);
|
|
732
788
|
if (authUi) {
|
|
733
|
-
await authUiTanstackState(
|
|
789
|
+
await authUiTanstackState({
|
|
790
|
+
packageJson: packageJson2,
|
|
791
|
+
cmd
|
|
792
|
+
});
|
|
734
793
|
} else {
|
|
735
794
|
console.log(
|
|
736
795
|
chalk5.green(
|
|
@@ -748,7 +807,10 @@ import chalk6 from "chalk";
|
|
|
748
807
|
import path6 from "path";
|
|
749
808
|
import fs6 from "fs";
|
|
750
809
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
751
|
-
var drizzleRunTanstackState = async (
|
|
810
|
+
var drizzleRunTanstackState = async ({
|
|
811
|
+
authUi,
|
|
812
|
+
cmd
|
|
813
|
+
}) => {
|
|
752
814
|
try {
|
|
753
815
|
const projectDir = process.cwd();
|
|
754
816
|
const packageJsonPath = path6.join(projectDir, "package.json");
|
|
@@ -841,7 +903,10 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
841
903
|
const apiDestinationPath = path6.join(fileRouteDestinationPath, "$.ts");
|
|
842
904
|
fs6.copyFileSync(fileRouteTemplatePath, apiDestinationPath);
|
|
843
905
|
if (authUi) {
|
|
844
|
-
await authUiTanstackState(
|
|
906
|
+
await authUiTanstackState({
|
|
907
|
+
packageJson: packageJson2,
|
|
908
|
+
cmd
|
|
909
|
+
});
|
|
845
910
|
} else {
|
|
846
911
|
console.log(
|
|
847
912
|
chalk6.green(
|
|
@@ -854,15 +919,47 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
854
919
|
}
|
|
855
920
|
};
|
|
856
921
|
|
|
922
|
+
// utils/framework.ts
|
|
923
|
+
import path7 from "path";
|
|
924
|
+
import fs7 from "fs";
|
|
925
|
+
var getFramework = async () => {
|
|
926
|
+
const projectDir = process.cwd();
|
|
927
|
+
if (!fs7.existsSync(path7.join(projectDir, "package.json"))) {
|
|
928
|
+
return {
|
|
929
|
+
framework: null,
|
|
930
|
+
error: "No framework detected"
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
const packageJson2 = JSON.parse(
|
|
934
|
+
fs7.readFileSync(path7.join(projectDir, "package.json"), "utf-8")
|
|
935
|
+
);
|
|
936
|
+
const hasNext = packageJson2?.dependencies?.["next"] || packageJson2?.devDependencies?.["next"];
|
|
937
|
+
if (hasNext) {
|
|
938
|
+
return {
|
|
939
|
+
framework: "Next js",
|
|
940
|
+
error: null
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
const hasTanstackState = packageJson2?.devDependencies?.["@tanstack/devtools-vite"] || packageJson2?.devDependencies?.["@tanstack/eslint-config"] || packageJson2?.devDependencies?.["@tanstack/react-start"];
|
|
944
|
+
if (hasTanstackState) {
|
|
945
|
+
return {
|
|
946
|
+
framework: "tanstack state",
|
|
947
|
+
error: null
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
return {
|
|
951
|
+
framework: null,
|
|
952
|
+
error: "No framework supported authverse"
|
|
953
|
+
};
|
|
954
|
+
};
|
|
955
|
+
|
|
857
956
|
// cli/init.ts
|
|
957
|
+
import chalk7 from "chalk";
|
|
858
958
|
var initAnswer = async () => {
|
|
859
|
-
const
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
const packageJson2 = JSON.parse(fs7.readFileSync(packageJsonPath, "utf-8"));
|
|
864
|
-
const hasNext = packageJson2?.dependencies?.["next"] || packageJson2?.devDependencies?.["next"];
|
|
865
|
-
framework = hasNext ? "Next js" : "tanstack state";
|
|
959
|
+
const { framework, error } = await getFramework();
|
|
960
|
+
if (error) {
|
|
961
|
+
console.log(chalk7.red(error));
|
|
962
|
+
return;
|
|
866
963
|
}
|
|
867
964
|
console.log(`\u2714 Detected framework: ${framework}`);
|
|
868
965
|
const answers = await inquirer3.prompt([
|
|
@@ -889,20 +986,28 @@ var initAnswer = async () => {
|
|
|
889
986
|
if (framework === "Next js" && answers.orm === "Prisma") {
|
|
890
987
|
await prismaRun({
|
|
891
988
|
authUi: answers.authUi,
|
|
892
|
-
database: answers.database
|
|
989
|
+
database: answers.database,
|
|
990
|
+
cmd: false
|
|
893
991
|
});
|
|
894
992
|
}
|
|
895
993
|
if (framework === "Next js" && answers.orm === "Drizzle") {
|
|
896
|
-
await drizzleRun(
|
|
994
|
+
await drizzleRun({
|
|
995
|
+
authUi: answers.authUi,
|
|
996
|
+
cmd: false
|
|
997
|
+
});
|
|
897
998
|
}
|
|
898
999
|
if (framework === "tanstack state" && answers.orm === "Prisma") {
|
|
899
1000
|
await prismaRunTanstackState({
|
|
900
1001
|
authUi: answers.authUi,
|
|
901
|
-
database: answers.database
|
|
1002
|
+
database: answers.database,
|
|
1003
|
+
cmd: false
|
|
902
1004
|
});
|
|
903
1005
|
}
|
|
904
1006
|
if (framework === "tanstack state" && answers.orm === "Drizzle") {
|
|
905
|
-
await drizzleRunTanstackState(
|
|
1007
|
+
await drizzleRunTanstackState({
|
|
1008
|
+
authUi: answers.authUi,
|
|
1009
|
+
cmd: false
|
|
1010
|
+
});
|
|
906
1011
|
}
|
|
907
1012
|
};
|
|
908
1013
|
|
|
@@ -910,10 +1015,10 @@ var initAnswer = async () => {
|
|
|
910
1015
|
import { readFileSync } from "fs";
|
|
911
1016
|
|
|
912
1017
|
// cli/provider.ts
|
|
913
|
-
import
|
|
1018
|
+
import chalk12 from "chalk";
|
|
914
1019
|
|
|
915
1020
|
// script/googleRun.ts
|
|
916
|
-
import
|
|
1021
|
+
import chalk8 from "chalk";
|
|
917
1022
|
import fs8 from "fs";
|
|
918
1023
|
import path8 from "path";
|
|
919
1024
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
@@ -926,16 +1031,16 @@ var googleRun = async () => {
|
|
|
926
1031
|
const folder = fs8.existsSync(srcPath) ? "src" : "";
|
|
927
1032
|
const authFilePath = path8.join(projectDir, folder, "lib", "auth.ts");
|
|
928
1033
|
if (!fs8.existsSync(authFilePath)) {
|
|
929
|
-
console.log(
|
|
1034
|
+
console.log(chalk8.red("\u274C auth.ts file not found"));
|
|
930
1035
|
return;
|
|
931
1036
|
}
|
|
932
1037
|
let content = fs8.readFileSync(authFilePath, "utf8");
|
|
933
1038
|
if (!content.includes("betterAuth({")) {
|
|
934
|
-
console.log(
|
|
1039
|
+
console.log(chalk8.red("betterAuth({}) block not found"));
|
|
935
1040
|
return;
|
|
936
1041
|
}
|
|
937
1042
|
if (content.includes("socialProviders") && content.includes("google:")) {
|
|
938
|
-
console.log(
|
|
1043
|
+
console.log(chalk8.yellow("Google provider already exists"));
|
|
939
1044
|
return;
|
|
940
1045
|
}
|
|
941
1046
|
const googleProviderEntry = `
|
|
@@ -958,7 +1063,7 @@ var googleRun = async () => {
|
|
|
958
1063
|
}
|
|
959
1064
|
}
|
|
960
1065
|
if (insertPos === -1) {
|
|
961
|
-
console.log(
|
|
1066
|
+
console.log(chalk8.red("Failed to parse socialProviders block"));
|
|
962
1067
|
return;
|
|
963
1068
|
}
|
|
964
1069
|
content = content.slice(0, insertPos) + googleProviderEntry + "\n " + content.slice(insertPos);
|
|
@@ -966,7 +1071,7 @@ var googleRun = async () => {
|
|
|
966
1071
|
const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
|
|
967
1072
|
if (!databaseRegex.test(content)) {
|
|
968
1073
|
console.log(
|
|
969
|
-
|
|
1074
|
+
chalk8.red(
|
|
970
1075
|
"Could not find database adapter (prismaAdapter or drizzleAdapter)"
|
|
971
1076
|
)
|
|
972
1077
|
);
|
|
@@ -1015,14 +1120,14 @@ GOOGLE_CLIENT_SECRET=
|
|
|
1015
1120
|
if (fs8.existsSync(componentTemplate)) {
|
|
1016
1121
|
fs8.copyFileSync(componentTemplate, componentDest);
|
|
1017
1122
|
}
|
|
1018
|
-
console.log(
|
|
1123
|
+
console.log(chalk8.green("Google provider added & merged successfully"));
|
|
1019
1124
|
} catch (error) {
|
|
1020
|
-
console.log(
|
|
1125
|
+
console.log(chalk8.red("googleRun error:"), error);
|
|
1021
1126
|
}
|
|
1022
1127
|
};
|
|
1023
1128
|
|
|
1024
1129
|
// script/githubRun.ts
|
|
1025
|
-
import
|
|
1130
|
+
import chalk9 from "chalk";
|
|
1026
1131
|
import fs9 from "fs";
|
|
1027
1132
|
import path9 from "path";
|
|
1028
1133
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
@@ -1035,16 +1140,16 @@ var githubRun = async () => {
|
|
|
1035
1140
|
const folder = fs9.existsSync(srcPath) ? "src" : "";
|
|
1036
1141
|
const authFilePath = path9.join(projectDir, folder, "lib", "auth.ts");
|
|
1037
1142
|
if (!fs9.existsSync(authFilePath)) {
|
|
1038
|
-
console.log(
|
|
1143
|
+
console.log(chalk9.red("auth.ts file not found"));
|
|
1039
1144
|
return;
|
|
1040
1145
|
}
|
|
1041
1146
|
let content = fs9.readFileSync(authFilePath, "utf8");
|
|
1042
1147
|
if (!content.includes("betterAuth({")) {
|
|
1043
|
-
console.log(
|
|
1148
|
+
console.log(chalk9.red("betterAuth({}) block not found"));
|
|
1044
1149
|
return;
|
|
1045
1150
|
}
|
|
1046
1151
|
if (content.includes("socialProviders") && content.includes("github:")) {
|
|
1047
|
-
console.log(
|
|
1152
|
+
console.log(chalk9.yellow("GitHub provider already exists"));
|
|
1048
1153
|
return;
|
|
1049
1154
|
}
|
|
1050
1155
|
const githubProviderEntry = `
|
|
@@ -1067,7 +1172,7 @@ var githubRun = async () => {
|
|
|
1067
1172
|
}
|
|
1068
1173
|
}
|
|
1069
1174
|
if (insertPos === -1) {
|
|
1070
|
-
console.log(
|
|
1175
|
+
console.log(chalk9.red("Failed to parse socialProviders block"));
|
|
1071
1176
|
return;
|
|
1072
1177
|
}
|
|
1073
1178
|
content = content.slice(0, insertPos) + githubProviderEntry + "\n " + content.slice(insertPos);
|
|
@@ -1075,7 +1180,7 @@ var githubRun = async () => {
|
|
|
1075
1180
|
const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
|
|
1076
1181
|
if (!databaseRegex.test(content)) {
|
|
1077
1182
|
console.log(
|
|
1078
|
-
|
|
1183
|
+
chalk9.red(
|
|
1079
1184
|
"Could not find database adapter (prismaAdapter or drizzleAdapter)"
|
|
1080
1185
|
)
|
|
1081
1186
|
);
|
|
@@ -1124,18 +1229,14 @@ GITHUB_CLIENT_SECRET=
|
|
|
1124
1229
|
if (fs9.existsSync(componentTemplate)) {
|
|
1125
1230
|
fs9.copyFileSync(componentTemplate, componentDest);
|
|
1126
1231
|
}
|
|
1127
|
-
console.log(
|
|
1232
|
+
console.log(chalk9.green("GitHub provider added & merged successfully"));
|
|
1128
1233
|
} catch (error) {
|
|
1129
|
-
console.log(
|
|
1234
|
+
console.log(chalk9.red("githubRun error:"), error);
|
|
1130
1235
|
}
|
|
1131
1236
|
};
|
|
1132
1237
|
|
|
1133
|
-
// cli/provider.ts
|
|
1134
|
-
import path12 from "path";
|
|
1135
|
-
import fs12 from "fs";
|
|
1136
|
-
|
|
1137
1238
|
// script/googleRunTanstackState.ts
|
|
1138
|
-
import
|
|
1239
|
+
import chalk10 from "chalk";
|
|
1139
1240
|
import fs10 from "fs";
|
|
1140
1241
|
import path10 from "path";
|
|
1141
1242
|
import { fileURLToPath as fileURLToPath9 } from "url";
|
|
@@ -1147,16 +1248,16 @@ var googleRunTanstackState = async () => {
|
|
|
1147
1248
|
const srcPath = path10.join(projectDir, "src");
|
|
1148
1249
|
const authFilePath = path10.join(srcPath, "lib", "auth.ts");
|
|
1149
1250
|
if (!fs10.existsSync(authFilePath)) {
|
|
1150
|
-
console.log(
|
|
1251
|
+
console.log(chalk10.red("auth.ts file not found"));
|
|
1151
1252
|
return;
|
|
1152
1253
|
}
|
|
1153
1254
|
let content = fs10.readFileSync(authFilePath, "utf8");
|
|
1154
1255
|
if (!content.includes("betterAuth({")) {
|
|
1155
|
-
console.log(
|
|
1256
|
+
console.log(chalk10.red("betterAuth({}) block not found"));
|
|
1156
1257
|
return;
|
|
1157
1258
|
}
|
|
1158
1259
|
if (content.includes("socialProviders") && content.includes("google:")) {
|
|
1159
|
-
console.log(
|
|
1260
|
+
console.log(chalk10.yellow("Google provider already exists"));
|
|
1160
1261
|
return;
|
|
1161
1262
|
}
|
|
1162
1263
|
const googleProviderEntry = `
|
|
@@ -1179,7 +1280,7 @@ var googleRunTanstackState = async () => {
|
|
|
1179
1280
|
}
|
|
1180
1281
|
}
|
|
1181
1282
|
if (insertPos === -1) {
|
|
1182
|
-
console.log(
|
|
1283
|
+
console.log(chalk10.red("Failed to parse socialProviders block"));
|
|
1183
1284
|
return;
|
|
1184
1285
|
}
|
|
1185
1286
|
content = content.slice(0, insertPos) + googleProviderEntry + "\n " + content.slice(insertPos);
|
|
@@ -1187,7 +1288,7 @@ var googleRunTanstackState = async () => {
|
|
|
1187
1288
|
const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
|
|
1188
1289
|
if (!databaseRegex.test(content)) {
|
|
1189
1290
|
console.log(
|
|
1190
|
-
|
|
1291
|
+
chalk10.red(
|
|
1191
1292
|
"Could not find database adapter (prismaAdapter or drizzleAdapter)"
|
|
1192
1293
|
)
|
|
1193
1294
|
);
|
|
@@ -1231,14 +1332,14 @@ GOOGLE_CLIENT_SECRET=
|
|
|
1231
1332
|
if (fs10.existsSync(componentTemplate)) {
|
|
1232
1333
|
fs10.copyFileSync(componentTemplate, componentDest);
|
|
1233
1334
|
}
|
|
1234
|
-
console.log(
|
|
1335
|
+
console.log(chalk10.green("Google provider added & merged successfully"));
|
|
1235
1336
|
} catch (error) {
|
|
1236
|
-
console.log(
|
|
1337
|
+
console.log(chalk10.red("googleRunTanstackState error:"), error);
|
|
1237
1338
|
}
|
|
1238
1339
|
};
|
|
1239
1340
|
|
|
1240
1341
|
// script/githubRunTanstackState.ts
|
|
1241
|
-
import
|
|
1342
|
+
import chalk11 from "chalk";
|
|
1242
1343
|
import fs11 from "fs";
|
|
1243
1344
|
import path11 from "path";
|
|
1244
1345
|
import { fileURLToPath as fileURLToPath10 } from "url";
|
|
@@ -1250,16 +1351,16 @@ var githubRunTanstackState = async () => {
|
|
|
1250
1351
|
const srcPath = path11.join(projectDir, "src");
|
|
1251
1352
|
const authFilePath = path11.join(srcPath, "lib", "auth.ts");
|
|
1252
1353
|
if (!fs11.existsSync(authFilePath)) {
|
|
1253
|
-
console.log(
|
|
1354
|
+
console.log(chalk11.red("auth.ts file not found"));
|
|
1254
1355
|
return;
|
|
1255
1356
|
}
|
|
1256
1357
|
let content = fs11.readFileSync(authFilePath, "utf8");
|
|
1257
1358
|
if (!content.includes("betterAuth({")) {
|
|
1258
|
-
console.log(
|
|
1359
|
+
console.log(chalk11.red("betterAuth({}) block not found"));
|
|
1259
1360
|
return;
|
|
1260
1361
|
}
|
|
1261
1362
|
if (content.includes("socialProviders") && content.includes("github:")) {
|
|
1262
|
-
console.log(
|
|
1363
|
+
console.log(chalk11.yellow("Github provider already exists"));
|
|
1263
1364
|
return;
|
|
1264
1365
|
}
|
|
1265
1366
|
const githubProviderEntry = `
|
|
@@ -1282,7 +1383,7 @@ var githubRunTanstackState = async () => {
|
|
|
1282
1383
|
}
|
|
1283
1384
|
}
|
|
1284
1385
|
if (insertPos === -1) {
|
|
1285
|
-
console.log(
|
|
1386
|
+
console.log(chalk11.red("Failed to parse socialProviders block"));
|
|
1286
1387
|
return;
|
|
1287
1388
|
}
|
|
1288
1389
|
content = content.slice(0, insertPos) + githubProviderEntry + "\n " + content.slice(insertPos);
|
|
@@ -1290,7 +1391,7 @@ var githubRunTanstackState = async () => {
|
|
|
1290
1391
|
const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
|
|
1291
1392
|
if (!databaseRegex.test(content)) {
|
|
1292
1393
|
console.log(
|
|
1293
|
-
|
|
1394
|
+
chalk11.red(
|
|
1294
1395
|
"Could not find database adapter (prismaAdapter or drizzleAdapter)"
|
|
1295
1396
|
)
|
|
1296
1397
|
);
|
|
@@ -1334,22 +1435,19 @@ GITHUB_CLIENT_SECRET=
|
|
|
1334
1435
|
if (fs11.existsSync(componentTemplate)) {
|
|
1335
1436
|
fs11.copyFileSync(componentTemplate, componentDest);
|
|
1336
1437
|
}
|
|
1337
|
-
console.log(
|
|
1438
|
+
console.log(chalk11.green("Github provider added & merged successfully"));
|
|
1338
1439
|
} catch (error) {
|
|
1339
|
-
console.log(
|
|
1440
|
+
console.log(chalk11.red("githubRunTanstackState error:"), error);
|
|
1340
1441
|
}
|
|
1341
1442
|
};
|
|
1342
1443
|
|
|
1343
1444
|
// cli/provider.ts
|
|
1344
1445
|
var providers = async ({ provider }) => {
|
|
1345
1446
|
try {
|
|
1346
|
-
const
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
const packageJson2 = JSON.parse(fs12.readFileSync(packageJsonPath, "utf-8"));
|
|
1351
|
-
const hasNext = packageJson2?.dependencies?.["next"] || packageJson2?.devDependencies?.["next"];
|
|
1352
|
-
framework = hasNext ? "Next js" : "tanstack state";
|
|
1447
|
+
const { framework, error } = await getFramework();
|
|
1448
|
+
if (error) {
|
|
1449
|
+
console.log(chalk12.red(error));
|
|
1450
|
+
return;
|
|
1353
1451
|
}
|
|
1354
1452
|
if (framework === "Next js" && provider == "google") {
|
|
1355
1453
|
await googleRun();
|
|
@@ -1362,45 +1460,96 @@ var providers = async ({ provider }) => {
|
|
|
1362
1460
|
await githubRunTanstackState();
|
|
1363
1461
|
}
|
|
1364
1462
|
} catch (error) {
|
|
1365
|
-
console.log(
|
|
1463
|
+
console.log(chalk12.red("Error adding provider:"), error);
|
|
1366
1464
|
}
|
|
1367
1465
|
};
|
|
1368
1466
|
|
|
1369
|
-
// cli/forget.ts
|
|
1370
|
-
import path22 from "path";
|
|
1371
|
-
import fs22 from "fs";
|
|
1372
|
-
|
|
1373
1467
|
// script/forgetNext.ts
|
|
1374
|
-
import
|
|
1375
|
-
import
|
|
1468
|
+
import chalk20 from "chalk";
|
|
1469
|
+
import path19 from "path";
|
|
1376
1470
|
import { fileURLToPath as fileURLToPath17 } from "url";
|
|
1377
|
-
import
|
|
1471
|
+
import fs19 from "fs";
|
|
1378
1472
|
|
|
1379
1473
|
// cli/email.ts
|
|
1380
|
-
import
|
|
1381
|
-
import
|
|
1474
|
+
import path18 from "path";
|
|
1475
|
+
import fs18 from "fs";
|
|
1382
1476
|
import inquirer4 from "inquirer";
|
|
1383
1477
|
|
|
1384
1478
|
// email/gmailRun.ts
|
|
1385
|
-
import
|
|
1386
|
-
import
|
|
1387
|
-
import
|
|
1479
|
+
import chalk13 from "chalk";
|
|
1480
|
+
import path12 from "path";
|
|
1481
|
+
import fs12 from "fs";
|
|
1388
1482
|
import { fileURLToPath as fileURLToPath11 } from "url";
|
|
1389
1483
|
var gmailRun = async () => {
|
|
1484
|
+
try {
|
|
1485
|
+
const projectDir = process.cwd();
|
|
1486
|
+
const packageJsonPath = path12.join(projectDir, "package.json");
|
|
1487
|
+
const packageJson2 = JSON.parse(fs12.readFileSync(packageJsonPath, "utf-8"));
|
|
1488
|
+
const srcFolder = fs12.existsSync(path12.join(projectDir, "src")) ? "src" : "";
|
|
1489
|
+
const __filename = fileURLToPath11(import.meta.url);
|
|
1490
|
+
const __dirname = path12.dirname(__filename);
|
|
1491
|
+
if (!packageJson2.dependencies?.nodemailer || !packageJson2.devDependencies?.["@types/nodemailer"]) {
|
|
1492
|
+
console.log(chalk13.cyan("\n\u2699\uFE0F Installing nodemailer...\n"));
|
|
1493
|
+
packageManager("nodemailer");
|
|
1494
|
+
packageManager("@types/nodemailer", true);
|
|
1495
|
+
}
|
|
1496
|
+
if (!packageJson2.dependencies?.["@react-email/components"]) {
|
|
1497
|
+
console.log(chalk13.cyan("\n\u2699\uFE0F Installing @react-email/components...\n"));
|
|
1498
|
+
packageManager("@react-email/components");
|
|
1499
|
+
}
|
|
1500
|
+
const envPath = path12.join(projectDir, ".env");
|
|
1501
|
+
const envContent = fs12.readFileSync(envPath, "utf8");
|
|
1502
|
+
if (!envContent.includes("GMAIL_HOST") && !envContent.includes("GMAIL_PORT") && !envContent.includes("GMAIL_SERVICE") && !envContent.includes("GMAIL_MAIL") && !envContent.includes("GMAIL_NAME") && !envContent.includes("GMAIL_PASSWORD")) {
|
|
1503
|
+
fs12.appendFileSync(envPath, `
|
|
1504
|
+
|
|
1505
|
+
# Gmail API Key for sending emails`);
|
|
1506
|
+
fs12.appendFileSync(envPath, `
|
|
1507
|
+
GMAIL_HOST=`);
|
|
1508
|
+
fs12.appendFileSync(envPath, `
|
|
1509
|
+
GMAIL_PORT=`);
|
|
1510
|
+
fs12.appendFileSync(envPath, `
|
|
1511
|
+
GMAIL_SERVICE=`);
|
|
1512
|
+
fs12.appendFileSync(envPath, `
|
|
1513
|
+
GMAIL_MAIL=`);
|
|
1514
|
+
fs12.appendFileSync(envPath, `
|
|
1515
|
+
GMAIL_NAME=`);
|
|
1516
|
+
fs12.appendFileSync(envPath, `
|
|
1517
|
+
GMAIL_PASSWORD=`);
|
|
1518
|
+
}
|
|
1519
|
+
const templatePath = path12.resolve(
|
|
1520
|
+
__dirname,
|
|
1521
|
+
"./template/email/emailGmail.ts"
|
|
1522
|
+
);
|
|
1523
|
+
const libPath = path12.join(projectDir, srcFolder, "lib");
|
|
1524
|
+
if (!fs12.existsSync(libPath)) {
|
|
1525
|
+
fs12.mkdirSync(libPath, { recursive: true });
|
|
1526
|
+
}
|
|
1527
|
+
const libDestinationPath = path12.join(libPath, "email.ts");
|
|
1528
|
+
fs12.copyFileSync(templatePath, libDestinationPath);
|
|
1529
|
+
} catch (error) {
|
|
1530
|
+
console.log(chalk13.red(error));
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
|
|
1534
|
+
// email/gmailRunTanstackState.ts
|
|
1535
|
+
import chalk14 from "chalk";
|
|
1536
|
+
import path13 from "path";
|
|
1537
|
+
import fs13 from "fs";
|
|
1538
|
+
import { fileURLToPath as fileURLToPath12 } from "url";
|
|
1539
|
+
var gmailRunTanstackState = async () => {
|
|
1390
1540
|
try {
|
|
1391
1541
|
const projectDir = process.cwd();
|
|
1392
1542
|
const packageJsonPath = path13.join(projectDir, "package.json");
|
|
1393
1543
|
const packageJson2 = JSON.parse(fs13.readFileSync(packageJsonPath, "utf-8"));
|
|
1394
|
-
const
|
|
1395
|
-
const __filename = fileURLToPath11(import.meta.url);
|
|
1544
|
+
const __filename = fileURLToPath12(import.meta.url);
|
|
1396
1545
|
const __dirname = path13.dirname(__filename);
|
|
1397
1546
|
if (!packageJson2.dependencies?.nodemailer || !packageJson2.devDependencies?.["@types/nodemailer"]) {
|
|
1398
|
-
console.log(
|
|
1547
|
+
console.log(chalk14.cyan("\n\u2699\uFE0F Installing nodemailer...\n"));
|
|
1399
1548
|
packageManager("nodemailer");
|
|
1400
1549
|
packageManager("@types/nodemailer", true);
|
|
1401
1550
|
}
|
|
1402
1551
|
if (!packageJson2.dependencies?.["@react-email/components"]) {
|
|
1403
|
-
console.log(
|
|
1552
|
+
console.log(chalk14.cyan("\n\u2699\uFE0F Installing @react-email/components...\n"));
|
|
1404
1553
|
packageManager("@react-email/components");
|
|
1405
1554
|
}
|
|
1406
1555
|
const envPath = path13.join(projectDir, ".env");
|
|
@@ -1426,92 +1575,92 @@ GMAIL_PASSWORD=`);
|
|
|
1426
1575
|
__dirname,
|
|
1427
1576
|
"./template/email/emailGmail.ts"
|
|
1428
1577
|
);
|
|
1429
|
-
const libPath = path13.join(projectDir,
|
|
1578
|
+
const libPath = path13.join(projectDir, "src", "lib");
|
|
1430
1579
|
if (!fs13.existsSync(libPath)) {
|
|
1431
1580
|
fs13.mkdirSync(libPath, { recursive: true });
|
|
1432
1581
|
}
|
|
1433
1582
|
const libDestinationPath = path13.join(libPath, "email.ts");
|
|
1434
1583
|
fs13.copyFileSync(templatePath, libDestinationPath);
|
|
1435
1584
|
} catch (error) {
|
|
1436
|
-
console.log(
|
|
1585
|
+
console.log(chalk14.red(error));
|
|
1437
1586
|
}
|
|
1438
1587
|
};
|
|
1439
1588
|
|
|
1440
|
-
// email/
|
|
1441
|
-
import
|
|
1589
|
+
// email/awsSesRun.ts
|
|
1590
|
+
import chalk15 from "chalk";
|
|
1442
1591
|
import path14 from "path";
|
|
1443
1592
|
import fs14 from "fs";
|
|
1444
|
-
import { fileURLToPath as
|
|
1445
|
-
var
|
|
1593
|
+
import { fileURLToPath as fileURLToPath13 } from "url";
|
|
1594
|
+
var awsSesRun = async () => {
|
|
1446
1595
|
try {
|
|
1447
1596
|
const projectDir = process.cwd();
|
|
1448
1597
|
const packageJsonPath = path14.join(projectDir, "package.json");
|
|
1449
1598
|
const packageJson2 = JSON.parse(fs14.readFileSync(packageJsonPath, "utf-8"));
|
|
1450
|
-
const
|
|
1599
|
+
const srcFolder = fs14.existsSync(path14.join(projectDir, "src")) ? "src" : "";
|
|
1600
|
+
const __filename = fileURLToPath13(import.meta.url);
|
|
1451
1601
|
const __dirname = path14.dirname(__filename);
|
|
1452
1602
|
if (!packageJson2.dependencies?.nodemailer || !packageJson2.devDependencies?.["@types/nodemailer"]) {
|
|
1453
|
-
console.log(
|
|
1603
|
+
console.log(chalk15.cyan("\n\u2699\uFE0F Installing nodemailer...\n"));
|
|
1454
1604
|
packageManager("nodemailer");
|
|
1455
1605
|
packageManager("@types/nodemailer", true);
|
|
1456
1606
|
}
|
|
1457
1607
|
if (!packageJson2.dependencies?.["@react-email/components"]) {
|
|
1458
|
-
console.log(
|
|
1608
|
+
console.log(chalk15.cyan("\n\u2699\uFE0F Installing @react-email/components...\n"));
|
|
1459
1609
|
packageManager("@react-email/components");
|
|
1460
1610
|
}
|
|
1461
1611
|
const envPath = path14.join(projectDir, ".env");
|
|
1462
1612
|
const envContent = fs14.readFileSync(envPath, "utf8");
|
|
1463
|
-
if (!envContent.includes("
|
|
1613
|
+
if (!envContent.includes("AWS_SES_HOST") && !envContent.includes("AWS_SES_PORT") && !envContent.includes("AWS_SES_SERVICE") && !envContent.includes("AWS_SES_USER") && !envContent.includes("AWS_SES_PASS") && !envContent.includes("AWS_SES_FROM")) {
|
|
1464
1614
|
fs14.appendFileSync(envPath, `
|
|
1465
1615
|
|
|
1466
|
-
#
|
|
1616
|
+
# AWS SES API Key for sending emails`);
|
|
1467
1617
|
fs14.appendFileSync(envPath, `
|
|
1468
|
-
|
|
1618
|
+
AWS_SES_HOST=`);
|
|
1469
1619
|
fs14.appendFileSync(envPath, `
|
|
1470
|
-
|
|
1620
|
+
AWS_SES_PORT=`);
|
|
1471
1621
|
fs14.appendFileSync(envPath, `
|
|
1472
|
-
|
|
1622
|
+
AWS_SES_SERVICE=`);
|
|
1473
1623
|
fs14.appendFileSync(envPath, `
|
|
1474
|
-
|
|
1624
|
+
AWS_SES_USER=`);
|
|
1475
1625
|
fs14.appendFileSync(envPath, `
|
|
1476
|
-
|
|
1626
|
+
AWS_SES_PASS=`);
|
|
1477
1627
|
fs14.appendFileSync(envPath, `
|
|
1478
|
-
|
|
1628
|
+
AWS_SES_FROM=`);
|
|
1479
1629
|
}
|
|
1480
1630
|
const templatePath = path14.resolve(
|
|
1481
1631
|
__dirname,
|
|
1482
|
-
"./template/email/
|
|
1632
|
+
"./template/email/emailAwsSes.ts"
|
|
1483
1633
|
);
|
|
1484
|
-
const libPath = path14.join(projectDir,
|
|
1634
|
+
const libPath = path14.join(projectDir, srcFolder, "lib");
|
|
1485
1635
|
if (!fs14.existsSync(libPath)) {
|
|
1486
1636
|
fs14.mkdirSync(libPath, { recursive: true });
|
|
1487
1637
|
}
|
|
1488
1638
|
const libDestinationPath = path14.join(libPath, "email.ts");
|
|
1489
1639
|
fs14.copyFileSync(templatePath, libDestinationPath);
|
|
1490
1640
|
} catch (error) {
|
|
1491
|
-
console.log(
|
|
1641
|
+
console.log(chalk15.red(error));
|
|
1492
1642
|
}
|
|
1493
1643
|
};
|
|
1494
1644
|
|
|
1495
|
-
// email/
|
|
1496
|
-
import
|
|
1645
|
+
// email/awsSesRunTanstackState.ts
|
|
1646
|
+
import chalk16 from "chalk";
|
|
1497
1647
|
import path15 from "path";
|
|
1498
1648
|
import fs15 from "fs";
|
|
1499
|
-
import { fileURLToPath as
|
|
1500
|
-
var
|
|
1649
|
+
import { fileURLToPath as fileURLToPath14 } from "url";
|
|
1650
|
+
var awsSesRunTanstackState = async () => {
|
|
1501
1651
|
try {
|
|
1502
1652
|
const projectDir = process.cwd();
|
|
1503
1653
|
const packageJsonPath = path15.join(projectDir, "package.json");
|
|
1504
1654
|
const packageJson2 = JSON.parse(fs15.readFileSync(packageJsonPath, "utf-8"));
|
|
1505
|
-
const
|
|
1506
|
-
const __filename = fileURLToPath13(import.meta.url);
|
|
1655
|
+
const __filename = fileURLToPath14(import.meta.url);
|
|
1507
1656
|
const __dirname = path15.dirname(__filename);
|
|
1508
1657
|
if (!packageJson2.dependencies?.nodemailer || !packageJson2.devDependencies?.["@types/nodemailer"]) {
|
|
1509
|
-
console.log(
|
|
1658
|
+
console.log(chalk16.cyan("\n\u2699\uFE0F Installing nodemailer...\n"));
|
|
1510
1659
|
packageManager("nodemailer");
|
|
1511
1660
|
packageManager("@types/nodemailer", true);
|
|
1512
1661
|
}
|
|
1513
1662
|
if (!packageJson2.dependencies?.["@react-email/components"]) {
|
|
1514
|
-
console.log(
|
|
1663
|
+
console.log(chalk16.cyan("\n\u2699\uFE0F Installing @react-email/components...\n"));
|
|
1515
1664
|
packageManager("@react-email/components");
|
|
1516
1665
|
}
|
|
1517
1666
|
const envPath = path15.join(projectDir, ".env");
|
|
@@ -1537,91 +1686,84 @@ AWS_SES_FROM=`);
|
|
|
1537
1686
|
__dirname,
|
|
1538
1687
|
"./template/email/emailAwsSes.ts"
|
|
1539
1688
|
);
|
|
1540
|
-
const libPath = path15.join(projectDir,
|
|
1689
|
+
const libPath = path15.join(projectDir, "src", "lib");
|
|
1541
1690
|
if (!fs15.existsSync(libPath)) {
|
|
1542
1691
|
fs15.mkdirSync(libPath, { recursive: true });
|
|
1543
1692
|
}
|
|
1544
1693
|
const libDestinationPath = path15.join(libPath, "email.ts");
|
|
1545
1694
|
fs15.copyFileSync(templatePath, libDestinationPath);
|
|
1546
1695
|
} catch (error) {
|
|
1547
|
-
console.log(
|
|
1696
|
+
console.log(chalk16.red(error));
|
|
1548
1697
|
}
|
|
1549
1698
|
};
|
|
1550
1699
|
|
|
1551
|
-
// email/
|
|
1552
|
-
import
|
|
1700
|
+
// email/resendRun.ts
|
|
1701
|
+
import chalk17 from "chalk";
|
|
1553
1702
|
import path16 from "path";
|
|
1554
1703
|
import fs16 from "fs";
|
|
1555
|
-
import { fileURLToPath as
|
|
1556
|
-
var
|
|
1704
|
+
import { fileURLToPath as fileURLToPath15 } from "url";
|
|
1705
|
+
var resendRun = async () => {
|
|
1557
1706
|
try {
|
|
1558
1707
|
const projectDir = process.cwd();
|
|
1559
1708
|
const packageJsonPath = path16.join(projectDir, "package.json");
|
|
1560
1709
|
const packageJson2 = JSON.parse(fs16.readFileSync(packageJsonPath, "utf-8"));
|
|
1561
|
-
const
|
|
1710
|
+
const srcFolder = fs16.existsSync(path16.join(projectDir, "src")) ? "src" : "";
|
|
1711
|
+
const __filename = fileURLToPath15(import.meta.url);
|
|
1562
1712
|
const __dirname = path16.dirname(__filename);
|
|
1563
|
-
if (!packageJson2.dependencies?.
|
|
1564
|
-
console.log(
|
|
1565
|
-
packageManager("
|
|
1566
|
-
packageManager("@types/nodemailer", true);
|
|
1713
|
+
if (!packageJson2.dependencies?.resend) {
|
|
1714
|
+
console.log(chalk17.cyan("\n\u2699\uFE0F Installing Resend...\n"));
|
|
1715
|
+
packageManager("resend");
|
|
1567
1716
|
}
|
|
1568
1717
|
if (!packageJson2.dependencies?.["@react-email/components"]) {
|
|
1569
|
-
console.log(
|
|
1718
|
+
console.log(chalk17.cyan("\n\u2699\uFE0F Installing @react-email/components...\n"));
|
|
1570
1719
|
packageManager("@react-email/components");
|
|
1571
1720
|
}
|
|
1572
1721
|
const envPath = path16.join(projectDir, ".env");
|
|
1573
1722
|
const envContent = fs16.readFileSync(envPath, "utf8");
|
|
1574
|
-
if (!envContent.includes("
|
|
1723
|
+
if (!envContent.includes("RESEND_API_KEY") && !envContent.includes("EMAIL_SENDER_NAME") && !envContent.includes("EMAIL_SENDER_ADDRESS")) {
|
|
1575
1724
|
fs16.appendFileSync(envPath, `
|
|
1576
1725
|
|
|
1577
|
-
#
|
|
1578
|
-
fs16.appendFileSync(envPath, `
|
|
1579
|
-
AWS_SES_HOST=`);
|
|
1580
|
-
fs16.appendFileSync(envPath, `
|
|
1581
|
-
AWS_SES_PORT=`);
|
|
1582
|
-
fs16.appendFileSync(envPath, `
|
|
1583
|
-
AWS_SES_SERVICE=`);
|
|
1726
|
+
# Resend API Key for sending emails`);
|
|
1584
1727
|
fs16.appendFileSync(envPath, `
|
|
1585
|
-
|
|
1728
|
+
RESEND_API_KEY=`);
|
|
1586
1729
|
fs16.appendFileSync(envPath, `
|
|
1587
|
-
|
|
1730
|
+
EMAIL_SENDER_NAME=Your Name`);
|
|
1588
1731
|
fs16.appendFileSync(envPath, `
|
|
1589
|
-
|
|
1732
|
+
EMAIL_SENDER_ADDRESS=`);
|
|
1590
1733
|
}
|
|
1591
1734
|
const templatePath = path16.resolve(
|
|
1592
1735
|
__dirname,
|
|
1593
|
-
"./template/email/
|
|
1736
|
+
"./template/email/emailResend.ts"
|
|
1594
1737
|
);
|
|
1595
|
-
const libPath = path16.join(projectDir,
|
|
1738
|
+
const libPath = path16.join(projectDir, srcFolder, "lib");
|
|
1596
1739
|
if (!fs16.existsSync(libPath)) {
|
|
1597
1740
|
fs16.mkdirSync(libPath, { recursive: true });
|
|
1598
1741
|
}
|
|
1599
1742
|
const libDestinationPath = path16.join(libPath, "email.ts");
|
|
1600
1743
|
fs16.copyFileSync(templatePath, libDestinationPath);
|
|
1601
1744
|
} catch (error) {
|
|
1602
|
-
console.log(
|
|
1745
|
+
console.log(chalk17.red(error));
|
|
1603
1746
|
}
|
|
1604
1747
|
};
|
|
1605
1748
|
|
|
1606
|
-
// email/
|
|
1607
|
-
import
|
|
1749
|
+
// email/resendRunTanstackState.ts
|
|
1750
|
+
import chalk18 from "chalk";
|
|
1608
1751
|
import path17 from "path";
|
|
1609
1752
|
import fs17 from "fs";
|
|
1610
|
-
import { fileURLToPath as
|
|
1611
|
-
var
|
|
1753
|
+
import { fileURLToPath as fileURLToPath16 } from "url";
|
|
1754
|
+
var resendRunTanstackState = async () => {
|
|
1612
1755
|
try {
|
|
1613
1756
|
const projectDir = process.cwd();
|
|
1614
1757
|
const packageJsonPath = path17.join(projectDir, "package.json");
|
|
1615
1758
|
const packageJson2 = JSON.parse(fs17.readFileSync(packageJsonPath, "utf-8"));
|
|
1616
|
-
const
|
|
1617
|
-
const __filename = fileURLToPath15(import.meta.url);
|
|
1759
|
+
const __filename = fileURLToPath16(import.meta.url);
|
|
1618
1760
|
const __dirname = path17.dirname(__filename);
|
|
1619
1761
|
if (!packageJson2.dependencies?.resend) {
|
|
1620
|
-
console.log(
|
|
1762
|
+
console.log(chalk18.cyan("\n\u2699\uFE0F Installing Resend...\n"));
|
|
1621
1763
|
packageManager("resend");
|
|
1622
1764
|
}
|
|
1623
1765
|
if (!packageJson2.dependencies?.["@react-email/components"]) {
|
|
1624
|
-
console.log(
|
|
1766
|
+
console.log(chalk18.cyan("\n\u2699\uFE0F Installing @react-email/components...\n"));
|
|
1625
1767
|
packageManager("@react-email/components");
|
|
1626
1768
|
}
|
|
1627
1769
|
const envPath = path17.join(projectDir, ".env");
|
|
@@ -1641,79 +1783,30 @@ EMAIL_SENDER_ADDRESS=`);
|
|
|
1641
1783
|
__dirname,
|
|
1642
1784
|
"./template/email/emailResend.ts"
|
|
1643
1785
|
);
|
|
1644
|
-
const libPath = path17.join(projectDir,
|
|
1786
|
+
const libPath = path17.join(projectDir, "src", "lib");
|
|
1645
1787
|
if (!fs17.existsSync(libPath)) {
|
|
1646
1788
|
fs17.mkdirSync(libPath, { recursive: true });
|
|
1647
1789
|
}
|
|
1648
1790
|
const libDestinationPath = path17.join(libPath, "email.ts");
|
|
1649
1791
|
fs17.copyFileSync(templatePath, libDestinationPath);
|
|
1650
1792
|
} catch (error) {
|
|
1651
|
-
console.log(
|
|
1652
|
-
}
|
|
1653
|
-
};
|
|
1654
|
-
|
|
1655
|
-
// email/resendRunTanstackState.ts
|
|
1656
|
-
import chalk17 from "chalk";
|
|
1657
|
-
import path18 from "path";
|
|
1658
|
-
import fs18 from "fs";
|
|
1659
|
-
import { fileURLToPath as fileURLToPath16 } from "url";
|
|
1660
|
-
var resendRunTanstackState = async () => {
|
|
1661
|
-
try {
|
|
1662
|
-
const projectDir = process.cwd();
|
|
1663
|
-
const packageJsonPath = path18.join(projectDir, "package.json");
|
|
1664
|
-
const packageJson2 = JSON.parse(fs18.readFileSync(packageJsonPath, "utf-8"));
|
|
1665
|
-
const __filename = fileURLToPath16(import.meta.url);
|
|
1666
|
-
const __dirname = path18.dirname(__filename);
|
|
1667
|
-
if (!packageJson2.dependencies?.resend) {
|
|
1668
|
-
console.log(chalk17.cyan("\n\u2699\uFE0F Installing Resend...\n"));
|
|
1669
|
-
packageManager("resend");
|
|
1670
|
-
}
|
|
1671
|
-
if (!packageJson2.dependencies?.["@react-email/components"]) {
|
|
1672
|
-
console.log(chalk17.cyan("\n\u2699\uFE0F Installing @react-email/components...\n"));
|
|
1673
|
-
packageManager("@react-email/components");
|
|
1674
|
-
}
|
|
1675
|
-
const envPath = path18.join(projectDir, ".env");
|
|
1676
|
-
const envContent = fs18.readFileSync(envPath, "utf8");
|
|
1677
|
-
if (!envContent.includes("RESEND_API_KEY") && !envContent.includes("EMAIL_SENDER_NAME") && !envContent.includes("EMAIL_SENDER_ADDRESS")) {
|
|
1678
|
-
fs18.appendFileSync(envPath, `
|
|
1679
|
-
|
|
1680
|
-
# Resend API Key for sending emails`);
|
|
1681
|
-
fs18.appendFileSync(envPath, `
|
|
1682
|
-
RESEND_API_KEY=`);
|
|
1683
|
-
fs18.appendFileSync(envPath, `
|
|
1684
|
-
EMAIL_SENDER_NAME=Your Name`);
|
|
1685
|
-
fs18.appendFileSync(envPath, `
|
|
1686
|
-
EMAIL_SENDER_ADDRESS=`);
|
|
1687
|
-
}
|
|
1688
|
-
const templatePath = path18.resolve(
|
|
1689
|
-
__dirname,
|
|
1690
|
-
"./template/email/emailResend.ts"
|
|
1691
|
-
);
|
|
1692
|
-
const libPath = path18.join(projectDir, "src", "lib");
|
|
1693
|
-
if (!fs18.existsSync(libPath)) {
|
|
1694
|
-
fs18.mkdirSync(libPath, { recursive: true });
|
|
1695
|
-
}
|
|
1696
|
-
const libDestinationPath = path18.join(libPath, "email.ts");
|
|
1697
|
-
fs18.copyFileSync(templatePath, libDestinationPath);
|
|
1698
|
-
} catch (error) {
|
|
1699
|
-
console.log(chalk17.red(error));
|
|
1793
|
+
console.log(chalk18.red(error));
|
|
1700
1794
|
}
|
|
1701
1795
|
};
|
|
1702
1796
|
|
|
1703
1797
|
// cli/email.ts
|
|
1798
|
+
import chalk19 from "chalk";
|
|
1704
1799
|
var email = async () => {
|
|
1705
1800
|
const projectDir = process.cwd();
|
|
1706
|
-
const
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
const hasNext = packageJson2?.dependencies?.["next"] || packageJson2?.devDependencies?.["next"];
|
|
1711
|
-
framework = hasNext ? "Next js" : "tanstack state";
|
|
1801
|
+
const { framework, error } = await getFramework();
|
|
1802
|
+
if (error) {
|
|
1803
|
+
console.log(chalk19.red(error));
|
|
1804
|
+
return;
|
|
1712
1805
|
}
|
|
1713
1806
|
if (framework === "Next js") {
|
|
1714
|
-
const srcFolder =
|
|
1715
|
-
const emailPath =
|
|
1716
|
-
if (
|
|
1807
|
+
const srcFolder = fs18.existsSync(path18.join(projectDir, "src")) ? "src" : "";
|
|
1808
|
+
const emailPath = path18.join(projectDir, srcFolder, "lib", "email.ts");
|
|
1809
|
+
if (fs18.existsSync(emailPath)) {
|
|
1717
1810
|
const answers2 = await inquirer4.prompt([
|
|
1718
1811
|
{
|
|
1719
1812
|
type: "confirm",
|
|
@@ -1728,12 +1821,12 @@ var email = async () => {
|
|
|
1728
1821
|
}
|
|
1729
1822
|
}
|
|
1730
1823
|
if (framework === "tanstack state") {
|
|
1731
|
-
const srcFolderTanstackState =
|
|
1732
|
-
const libPathTanstackState =
|
|
1824
|
+
const srcFolderTanstackState = path18.join(projectDir, "src");
|
|
1825
|
+
const libPathTanstackState = path18.join(
|
|
1733
1826
|
srcFolderTanstackState,
|
|
1734
1827
|
"lib/email.ts"
|
|
1735
1828
|
);
|
|
1736
|
-
if (
|
|
1829
|
+
if (fs18.existsSync(libPathTanstackState)) {
|
|
1737
1830
|
const answers2 = await inquirer4.prompt([
|
|
1738
1831
|
{
|
|
1739
1832
|
type: "confirm",
|
|
@@ -1780,19 +1873,19 @@ var forgetNext = async () => {
|
|
|
1780
1873
|
try {
|
|
1781
1874
|
const projectDir = process.cwd();
|
|
1782
1875
|
const __filename = fileURLToPath17(import.meta.url);
|
|
1783
|
-
const __dirname =
|
|
1784
|
-
const srcPath =
|
|
1785
|
-
const folder =
|
|
1786
|
-
const emailFilePath =
|
|
1787
|
-
if (!
|
|
1876
|
+
const __dirname = path19.dirname(__filename);
|
|
1877
|
+
const srcPath = path19.join(projectDir, "src");
|
|
1878
|
+
const folder = fs19.existsSync(srcPath) ? "src" : "";
|
|
1879
|
+
const emailFilePath = path19.join(projectDir, folder, "lib", "email.ts");
|
|
1880
|
+
if (!fs19.existsSync(emailFilePath)) {
|
|
1788
1881
|
await email();
|
|
1789
1882
|
}
|
|
1790
|
-
const authFilePath =
|
|
1791
|
-
if (!
|
|
1792
|
-
console.log(
|
|
1883
|
+
const authFilePath = path19.join(projectDir, folder, "lib", "auth.ts");
|
|
1884
|
+
if (!fs19.existsSync(authFilePath)) {
|
|
1885
|
+
console.log(chalk20.red("auth.ts file not found."));
|
|
1793
1886
|
return;
|
|
1794
1887
|
}
|
|
1795
|
-
let content =
|
|
1888
|
+
let content = fs19.readFileSync(authFilePath, "utf8");
|
|
1796
1889
|
const codeAdded = ` sendResetPassword: async ({ user, url, token }) => {
|
|
1797
1890
|
await sendEmail({
|
|
1798
1891
|
email: user.email!,
|
|
@@ -1836,7 +1929,7 @@ var forgetNext = async () => {
|
|
|
1836
1929
|
content = before + `
|
|
1837
1930
|
${codeAdded}` + after;
|
|
1838
1931
|
}
|
|
1839
|
-
|
|
1932
|
+
fs19.writeFileSync(authFilePath, content, "utf8");
|
|
1840
1933
|
if (!content.includes("import { sendEmail }")) {
|
|
1841
1934
|
const lastImportIndex = content.lastIndexOf("import");
|
|
1842
1935
|
const nextLineAfterLastImport = content.indexOf("\n", lastImportIndex) + 1;
|
|
@@ -1846,128 +1939,128 @@ var forgetNext = async () => {
|
|
|
1846
1939
|
import { sendEmail } from "./email";
|
|
1847
1940
|
`;
|
|
1848
1941
|
content = beforeImports + newImports + afterImports;
|
|
1849
|
-
|
|
1942
|
+
fs19.writeFileSync(authFilePath, content, "utf8");
|
|
1850
1943
|
}
|
|
1851
|
-
const componentPath =
|
|
1944
|
+
const componentPath = path19.resolve(
|
|
1852
1945
|
__dirname,
|
|
1853
1946
|
"./template/email/reset-password.tsx"
|
|
1854
1947
|
);
|
|
1855
|
-
const destinationPath =
|
|
1948
|
+
const destinationPath = path19.join(
|
|
1856
1949
|
projectDir,
|
|
1857
1950
|
folder,
|
|
1858
1951
|
"components",
|
|
1859
1952
|
"email"
|
|
1860
1953
|
);
|
|
1861
|
-
if (!
|
|
1862
|
-
|
|
1954
|
+
if (!fs19.existsSync(destinationPath)) {
|
|
1955
|
+
fs19.mkdirSync(destinationPath, { recursive: true });
|
|
1863
1956
|
}
|
|
1864
|
-
const emailDestinationPath =
|
|
1957
|
+
const emailDestinationPath = path19.join(
|
|
1865
1958
|
destinationPath,
|
|
1866
1959
|
"reset-password.tsx"
|
|
1867
1960
|
);
|
|
1868
|
-
if (
|
|
1869
|
-
|
|
1961
|
+
if (fs19.existsSync(componentPath)) {
|
|
1962
|
+
fs19.copyFileSync(componentPath, emailDestinationPath);
|
|
1870
1963
|
}
|
|
1871
|
-
const forgetComponentPath =
|
|
1964
|
+
const forgetComponentPath = path19.resolve(
|
|
1872
1965
|
__dirname,
|
|
1873
1966
|
"./template/components/ForgetComponent.tsx"
|
|
1874
1967
|
);
|
|
1875
|
-
const componentsDestinationPath =
|
|
1968
|
+
const componentsDestinationPath = path19.join(
|
|
1876
1969
|
projectDir,
|
|
1877
1970
|
folder,
|
|
1878
1971
|
"components",
|
|
1879
1972
|
"authverse"
|
|
1880
1973
|
);
|
|
1881
|
-
if (!
|
|
1882
|
-
|
|
1974
|
+
if (!fs19.existsSync(componentsDestinationPath)) {
|
|
1975
|
+
fs19.mkdirSync(componentsDestinationPath, { recursive: true });
|
|
1883
1976
|
}
|
|
1884
|
-
const forgetDestinationPath =
|
|
1977
|
+
const forgetDestinationPath = path19.join(
|
|
1885
1978
|
componentsDestinationPath,
|
|
1886
1979
|
"ForgetComponent.tsx"
|
|
1887
1980
|
);
|
|
1888
|
-
if (
|
|
1889
|
-
|
|
1981
|
+
if (fs19.existsSync(forgetComponentPath)) {
|
|
1982
|
+
fs19.copyFileSync(forgetComponentPath, forgetDestinationPath);
|
|
1890
1983
|
}
|
|
1891
|
-
const resetComponentPath =
|
|
1984
|
+
const resetComponentPath = path19.resolve(
|
|
1892
1985
|
__dirname,
|
|
1893
1986
|
"./template/components/ResetComponent.tsx"
|
|
1894
1987
|
);
|
|
1895
|
-
const resetDestinationPath =
|
|
1988
|
+
const resetDestinationPath = path19.join(
|
|
1896
1989
|
componentsDestinationPath,
|
|
1897
1990
|
"ResetComponent.tsx"
|
|
1898
1991
|
);
|
|
1899
|
-
if (
|
|
1900
|
-
|
|
1992
|
+
if (fs19.existsSync(resetComponentPath)) {
|
|
1993
|
+
fs19.copyFileSync(resetComponentPath, resetDestinationPath);
|
|
1901
1994
|
}
|
|
1902
|
-
const authTemplatePath =
|
|
1995
|
+
const authTemplatePath = path19.resolve(
|
|
1903
1996
|
__dirname,
|
|
1904
1997
|
"./template/app-auth-uiDesign"
|
|
1905
1998
|
);
|
|
1906
|
-
const appDestinationPath =
|
|
1907
|
-
if (!
|
|
1908
|
-
|
|
1999
|
+
const appDestinationPath = path19.join(projectDir, folder, "app", "auth");
|
|
2000
|
+
if (!fs19.existsSync(appDestinationPath)) {
|
|
2001
|
+
fs19.mkdirSync(appDestinationPath, { recursive: true });
|
|
1909
2002
|
}
|
|
1910
|
-
const forgetDestinationDir =
|
|
1911
|
-
if (!
|
|
1912
|
-
|
|
2003
|
+
const forgetDestinationDir = path19.join(appDestinationPath, "forget");
|
|
2004
|
+
if (!fs19.existsSync(forgetDestinationDir)) {
|
|
2005
|
+
fs19.mkdirSync(forgetDestinationDir, { recursive: true });
|
|
1913
2006
|
}
|
|
1914
|
-
const forgetPageDestinationPath =
|
|
2007
|
+
const forgetPageDestinationPath = path19.join(
|
|
1915
2008
|
forgetDestinationDir,
|
|
1916
2009
|
"page.tsx"
|
|
1917
2010
|
);
|
|
1918
|
-
|
|
2011
|
+
fs19.copyFileSync(
|
|
1919
2012
|
`${authTemplatePath}/forget/page.tsx`,
|
|
1920
2013
|
forgetPageDestinationPath
|
|
1921
2014
|
);
|
|
1922
|
-
const resetDestinationDir =
|
|
2015
|
+
const resetDestinationDir = path19.join(
|
|
1923
2016
|
appDestinationPath,
|
|
1924
2017
|
"reset-password"
|
|
1925
2018
|
);
|
|
1926
|
-
if (!
|
|
1927
|
-
|
|
2019
|
+
if (!fs19.existsSync(resetDestinationDir)) {
|
|
2020
|
+
fs19.mkdirSync(resetDestinationDir, { recursive: true });
|
|
1928
2021
|
}
|
|
1929
|
-
const resetPageDestinationPath =
|
|
2022
|
+
const resetPageDestinationPath = path19.join(
|
|
1930
2023
|
resetDestinationDir,
|
|
1931
2024
|
"page.tsx"
|
|
1932
2025
|
);
|
|
1933
|
-
|
|
2026
|
+
fs19.copyFileSync(
|
|
1934
2027
|
`${authTemplatePath}/reset-password/page.tsx`,
|
|
1935
2028
|
resetPageDestinationPath
|
|
1936
2029
|
);
|
|
1937
2030
|
console.log(
|
|
1938
|
-
|
|
2031
|
+
chalk20.green("Successfully added forget and reset-password pages")
|
|
1939
2032
|
);
|
|
1940
2033
|
} else {
|
|
1941
2034
|
console.log(
|
|
1942
|
-
|
|
2035
|
+
chalk20.red("Could not find emailAndPassword configuration in auth.ts")
|
|
1943
2036
|
);
|
|
1944
2037
|
}
|
|
1945
2038
|
} catch (error) {
|
|
1946
|
-
console.log(
|
|
2039
|
+
console.log(chalk20.red("Error adding sendResetPassword:"), error);
|
|
1947
2040
|
}
|
|
1948
2041
|
};
|
|
1949
2042
|
|
|
1950
2043
|
// script/forgetTanstack.ts
|
|
1951
|
-
import
|
|
1952
|
-
import
|
|
2044
|
+
import chalk21 from "chalk";
|
|
2045
|
+
import path20 from "path";
|
|
1953
2046
|
import { fileURLToPath as fileURLToPath18 } from "url";
|
|
1954
|
-
import
|
|
2047
|
+
import fs20 from "fs";
|
|
1955
2048
|
var forgetTanstack = async () => {
|
|
1956
2049
|
try {
|
|
1957
2050
|
const projectDir = process.cwd();
|
|
1958
2051
|
const __filename = fileURLToPath18(import.meta.url);
|
|
1959
|
-
const __dirname =
|
|
1960
|
-
const srcPath =
|
|
1961
|
-
const emailFilePath =
|
|
1962
|
-
if (!
|
|
2052
|
+
const __dirname = path20.dirname(__filename);
|
|
2053
|
+
const srcPath = path20.join(projectDir, "src");
|
|
2054
|
+
const emailFilePath = path20.join(srcPath, "lib", "email.ts");
|
|
2055
|
+
if (!fs20.existsSync(emailFilePath)) {
|
|
1963
2056
|
await email();
|
|
1964
2057
|
}
|
|
1965
|
-
const authFilePath =
|
|
1966
|
-
if (!
|
|
1967
|
-
console.log(
|
|
2058
|
+
const authFilePath = path20.join(srcPath, "lib", "auth.ts");
|
|
2059
|
+
if (!fs20.existsSync(authFilePath)) {
|
|
2060
|
+
console.log(chalk21.red("auth.ts file not found."));
|
|
1968
2061
|
return;
|
|
1969
2062
|
}
|
|
1970
|
-
let content =
|
|
2063
|
+
let content = fs20.readFileSync(authFilePath, "utf8");
|
|
1971
2064
|
const codeAdded = `sendResetPassword: async ({ user, url, token }) => {
|
|
1972
2065
|
await sendEmail({
|
|
1973
2066
|
email: user.email!,
|
|
@@ -2011,7 +2104,7 @@ var forgetTanstack = async () => {
|
|
|
2011
2104
|
content = before + `
|
|
2012
2105
|
${codeAdded}` + after;
|
|
2013
2106
|
}
|
|
2014
|
-
|
|
2107
|
+
fs20.writeFileSync(authFilePath, content, "utf8");
|
|
2015
2108
|
if (!content.includes("import { sendEmail }")) {
|
|
2016
2109
|
const lastImportIndex = content.lastIndexOf("import");
|
|
2017
2110
|
const nextLineAfterLastImport = content.indexOf("\n", lastImportIndex) + 1;
|
|
@@ -2021,99 +2114,97 @@ var forgetTanstack = async () => {
|
|
|
2021
2114
|
import { sendEmail } from "./email";
|
|
2022
2115
|
`;
|
|
2023
2116
|
content = beforeImports + newImports + afterImports;
|
|
2024
|
-
|
|
2117
|
+
fs20.writeFileSync(authFilePath, content, "utf8");
|
|
2025
2118
|
}
|
|
2026
|
-
const componentPath =
|
|
2119
|
+
const componentPath = path20.resolve(
|
|
2027
2120
|
__dirname,
|
|
2028
2121
|
"./template/email/reset-password.tsx"
|
|
2029
2122
|
);
|
|
2030
|
-
const destinationPath =
|
|
2031
|
-
if (!
|
|
2032
|
-
|
|
2123
|
+
const destinationPath = path20.join(srcPath, "components", "email");
|
|
2124
|
+
if (!fs20.existsSync(destinationPath)) {
|
|
2125
|
+
fs20.mkdirSync(destinationPath, { recursive: true });
|
|
2033
2126
|
}
|
|
2034
|
-
const emailDestinationPath =
|
|
2127
|
+
const emailDestinationPath = path20.join(
|
|
2035
2128
|
destinationPath,
|
|
2036
2129
|
"reset-password.tsx"
|
|
2037
2130
|
);
|
|
2038
|
-
if (
|
|
2039
|
-
|
|
2131
|
+
if (fs20.existsSync(componentPath)) {
|
|
2132
|
+
fs20.copyFileSync(componentPath, emailDestinationPath);
|
|
2040
2133
|
}
|
|
2041
|
-
const forgetComponentPath =
|
|
2134
|
+
const forgetComponentPath = path20.resolve(
|
|
2042
2135
|
__dirname,
|
|
2043
2136
|
"./template/TanstackState/components/ForgetComponent.tsx"
|
|
2044
2137
|
);
|
|
2045
|
-
const componentsDestinationPath =
|
|
2138
|
+
const componentsDestinationPath = path20.join(
|
|
2046
2139
|
srcPath,
|
|
2047
2140
|
"components",
|
|
2048
2141
|
"authverse"
|
|
2049
2142
|
);
|
|
2050
|
-
if (!
|
|
2051
|
-
|
|
2143
|
+
if (!fs20.existsSync(componentsDestinationPath)) {
|
|
2144
|
+
fs20.mkdirSync(componentsDestinationPath, { recursive: true });
|
|
2052
2145
|
}
|
|
2053
|
-
const forgetDestinationPath =
|
|
2146
|
+
const forgetDestinationPath = path20.join(
|
|
2054
2147
|
componentsDestinationPath,
|
|
2055
2148
|
"ForgetComponent.tsx"
|
|
2056
2149
|
);
|
|
2057
|
-
if (
|
|
2058
|
-
|
|
2150
|
+
if (fs20.existsSync(forgetComponentPath)) {
|
|
2151
|
+
fs20.copyFileSync(forgetComponentPath, forgetDestinationPath);
|
|
2059
2152
|
}
|
|
2060
|
-
const resetComponentPath =
|
|
2153
|
+
const resetComponentPath = path20.resolve(
|
|
2061
2154
|
__dirname,
|
|
2062
2155
|
"./template/TanstackState/components/ResetComponent.tsx"
|
|
2063
2156
|
);
|
|
2064
|
-
const resetDestinationPath =
|
|
2157
|
+
const resetDestinationPath = path20.join(
|
|
2065
2158
|
componentsDestinationPath,
|
|
2066
2159
|
"ResetComponent.tsx"
|
|
2067
2160
|
);
|
|
2068
|
-
if (
|
|
2069
|
-
|
|
2161
|
+
if (fs20.existsSync(resetComponentPath)) {
|
|
2162
|
+
fs20.copyFileSync(resetComponentPath, resetDestinationPath);
|
|
2070
2163
|
}
|
|
2071
|
-
const authTemplatePath =
|
|
2164
|
+
const authTemplatePath = path20.resolve(
|
|
2072
2165
|
__dirname,
|
|
2073
2166
|
"./template/TanstackState/routes/auth"
|
|
2074
2167
|
);
|
|
2075
|
-
const routesDestinationPath =
|
|
2076
|
-
if (!
|
|
2077
|
-
|
|
2168
|
+
const routesDestinationPath = path20.join(srcPath, "routes", "auth");
|
|
2169
|
+
if (!fs20.existsSync(routesDestinationPath)) {
|
|
2170
|
+
fs20.mkdirSync(routesDestinationPath, { recursive: true });
|
|
2078
2171
|
}
|
|
2079
|
-
const forgetPageDestinationPath =
|
|
2172
|
+
const forgetPageDestinationPath = path20.join(
|
|
2080
2173
|
routesDestinationPath,
|
|
2081
2174
|
"forget.tsx"
|
|
2082
2175
|
);
|
|
2083
|
-
|
|
2176
|
+
fs20.copyFileSync(
|
|
2084
2177
|
`${authTemplatePath}/forget.tsx`,
|
|
2085
2178
|
forgetPageDestinationPath
|
|
2086
2179
|
);
|
|
2087
|
-
const resetPageDestinationPath =
|
|
2180
|
+
const resetPageDestinationPath = path20.join(
|
|
2088
2181
|
routesDestinationPath,
|
|
2089
2182
|
"reset-password.tsx"
|
|
2090
2183
|
);
|
|
2091
|
-
|
|
2184
|
+
fs20.copyFileSync(
|
|
2092
2185
|
`${authTemplatePath}/reset-password.tsx`,
|
|
2093
2186
|
resetPageDestinationPath
|
|
2094
2187
|
);
|
|
2095
2188
|
console.log(
|
|
2096
|
-
|
|
2189
|
+
chalk21.green("Successfully added forget and reset-password pages")
|
|
2097
2190
|
);
|
|
2098
2191
|
} else {
|
|
2099
2192
|
console.log(
|
|
2100
|
-
|
|
2193
|
+
chalk21.red("Could not find emailAndPassword configuration in auth.ts")
|
|
2101
2194
|
);
|
|
2102
2195
|
}
|
|
2103
2196
|
} catch (error) {
|
|
2104
|
-
console.log(
|
|
2197
|
+
console.log(chalk21.red("Error adding sendResetPassword:"), error);
|
|
2105
2198
|
}
|
|
2106
2199
|
};
|
|
2107
2200
|
|
|
2108
2201
|
// cli/forget.ts
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
const
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
const hasNext = packageJson2?.dependencies?.["next"] || packageJson2?.devDependencies?.["next"];
|
|
2116
|
-
framework = hasNext ? "Next js" : "tanstack state";
|
|
2202
|
+
import chalk22 from "chalk";
|
|
2203
|
+
var forget = async () => {
|
|
2204
|
+
const { framework, error } = await getFramework();
|
|
2205
|
+
if (error) {
|
|
2206
|
+
console.log(chalk22.red(error));
|
|
2207
|
+
return;
|
|
2117
2208
|
}
|
|
2118
2209
|
if (framework === "Next js") {
|
|
2119
2210
|
return forgetNext();
|
|
@@ -2124,32 +2215,30 @@ var forget = () => {
|
|
|
2124
2215
|
};
|
|
2125
2216
|
|
|
2126
2217
|
// cli/verification.ts
|
|
2127
|
-
import
|
|
2128
|
-
import fs25 from "fs";
|
|
2129
|
-
import path25 from "path";
|
|
2218
|
+
import chalk25 from "chalk";
|
|
2130
2219
|
|
|
2131
2220
|
// script/verifyNext.ts
|
|
2132
|
-
import
|
|
2133
|
-
import
|
|
2134
|
-
import
|
|
2221
|
+
import chalk23 from "chalk";
|
|
2222
|
+
import fs21 from "fs";
|
|
2223
|
+
import path21 from "path";
|
|
2135
2224
|
import { fileURLToPath as fileURLToPath19 } from "url";
|
|
2136
2225
|
var verifyNext = async () => {
|
|
2137
2226
|
try {
|
|
2138
2227
|
const projectDir = process.cwd();
|
|
2139
2228
|
const __filename = fileURLToPath19(import.meta.url);
|
|
2140
|
-
const __dirname =
|
|
2141
|
-
const srcPath =
|
|
2142
|
-
const folder =
|
|
2143
|
-
const emailFilePath =
|
|
2144
|
-
if (!
|
|
2229
|
+
const __dirname = path21.dirname(__filename);
|
|
2230
|
+
const srcPath = path21.join(projectDir, "src");
|
|
2231
|
+
const folder = fs21.existsSync(srcPath) ? "src" : "";
|
|
2232
|
+
const emailFilePath = path21.join(projectDir, folder, "lib", "email.ts");
|
|
2233
|
+
if (!fs21.existsSync(emailFilePath)) {
|
|
2145
2234
|
await email();
|
|
2146
2235
|
}
|
|
2147
|
-
const authFilePath =
|
|
2148
|
-
if (!
|
|
2149
|
-
console.log(
|
|
2236
|
+
const authFilePath = path21.join(projectDir, folder, "lib", "auth.ts");
|
|
2237
|
+
if (!fs21.existsSync(authFilePath)) {
|
|
2238
|
+
console.log(chalk23.red("auth.ts file not found."));
|
|
2150
2239
|
return;
|
|
2151
2240
|
}
|
|
2152
|
-
let content =
|
|
2241
|
+
let content = fs21.readFileSync(authFilePath, "utf8");
|
|
2153
2242
|
if (content.includes("emailAndPassword: {")) {
|
|
2154
2243
|
const start = content.indexOf("emailAndPassword: {");
|
|
2155
2244
|
let end = start;
|
|
@@ -2195,54 +2284,60 @@ var verifyNext = async () => {
|
|
|
2195
2284
|
`;
|
|
2196
2285
|
content = content.slice(0, insertAt + 2) + emailVerificationBlock + content.slice(insertAt + 2);
|
|
2197
2286
|
}
|
|
2198
|
-
if (!content.includes("EmailVerification")) {
|
|
2287
|
+
if (!content.includes("import EmailVerification")) {
|
|
2199
2288
|
const lastImport = content.lastIndexOf("import");
|
|
2200
2289
|
const nextLine = content.indexOf("\n", lastImport) + 1;
|
|
2201
2290
|
const imports = `import EmailVerification from "@/components/email/EmailVerification";
|
|
2202
|
-
import { sendEmail } from "./email";
|
|
2203
2291
|
`;
|
|
2204
2292
|
content = content.slice(0, nextLine) + imports + content.slice(nextLine);
|
|
2205
2293
|
}
|
|
2206
|
-
|
|
2207
|
-
|
|
2294
|
+
if (!content.includes("import { sendEmail }")) {
|
|
2295
|
+
const lastImport = content.lastIndexOf("import");
|
|
2296
|
+
const nextLine = content.indexOf("\n", lastImport) + 1;
|
|
2297
|
+
const imports = `import { sendEmail } from "./email";
|
|
2298
|
+
`;
|
|
2299
|
+
content = content.slice(0, nextLine) + imports + content.slice(nextLine);
|
|
2300
|
+
}
|
|
2301
|
+
fs21.writeFileSync(authFilePath, content, "utf8");
|
|
2302
|
+
const templatePath = path21.resolve(
|
|
2208
2303
|
__dirname,
|
|
2209
2304
|
"./template/email/EmailVerification.tsx"
|
|
2210
2305
|
);
|
|
2211
|
-
const componentsDir =
|
|
2212
|
-
if (!
|
|
2213
|
-
|
|
2306
|
+
const componentsDir = path21.join(projectDir, folder, "components", "email");
|
|
2307
|
+
if (!fs21.existsSync(componentsDir)) {
|
|
2308
|
+
fs21.mkdirSync(componentsDir, { recursive: true });
|
|
2214
2309
|
}
|
|
2215
|
-
const destFile =
|
|
2216
|
-
if (
|
|
2217
|
-
|
|
2310
|
+
const destFile = path21.join(componentsDir, "EmailVerification.tsx");
|
|
2311
|
+
if (fs21.existsSync(templatePath) && !fs21.existsSync(destFile)) {
|
|
2312
|
+
fs21.copyFileSync(templatePath, destFile);
|
|
2218
2313
|
}
|
|
2219
|
-
console.log(
|
|
2314
|
+
console.log(chalk23.green("Email verification successfully configured"));
|
|
2220
2315
|
} catch (error) {
|
|
2221
|
-
console.log(
|
|
2316
|
+
console.log(chalk23.red(String(error)));
|
|
2222
2317
|
}
|
|
2223
2318
|
};
|
|
2224
2319
|
|
|
2225
2320
|
// script/verifyTanstack.ts
|
|
2226
|
-
import
|
|
2227
|
-
import
|
|
2228
|
-
import
|
|
2321
|
+
import chalk24 from "chalk";
|
|
2322
|
+
import fs22 from "fs";
|
|
2323
|
+
import path22 from "path";
|
|
2229
2324
|
import { fileURLToPath as fileURLToPath20 } from "url";
|
|
2230
2325
|
var verifyTanstack = async () => {
|
|
2231
2326
|
try {
|
|
2232
2327
|
const projectDir = process.cwd();
|
|
2233
2328
|
const __filename = fileURLToPath20(import.meta.url);
|
|
2234
|
-
const __dirname =
|
|
2235
|
-
const srcPath =
|
|
2236
|
-
const emailFilePath =
|
|
2237
|
-
if (!
|
|
2329
|
+
const __dirname = path22.dirname(__filename);
|
|
2330
|
+
const srcPath = path22.join(projectDir, "src");
|
|
2331
|
+
const emailFilePath = path22.join(srcPath, "lib", "email.ts");
|
|
2332
|
+
if (!fs22.existsSync(emailFilePath)) {
|
|
2238
2333
|
await email();
|
|
2239
2334
|
}
|
|
2240
|
-
const authFilePath =
|
|
2241
|
-
if (!
|
|
2242
|
-
console.log(
|
|
2335
|
+
const authFilePath = path22.join(srcPath, "lib", "auth.ts");
|
|
2336
|
+
if (!fs22.existsSync(authFilePath)) {
|
|
2337
|
+
console.log(chalk24.red("auth.ts file not found."));
|
|
2243
2338
|
return;
|
|
2244
2339
|
}
|
|
2245
|
-
let content =
|
|
2340
|
+
let content = fs22.readFileSync(authFilePath, "utf8");
|
|
2246
2341
|
if (content.includes("emailAndPassword: {")) {
|
|
2247
2342
|
const start = content.indexOf("emailAndPassword: {");
|
|
2248
2343
|
let end = start;
|
|
@@ -2288,43 +2383,46 @@ var verifyTanstack = async () => {
|
|
|
2288
2383
|
`;
|
|
2289
2384
|
content = content.slice(0, insertAt + 2) + emailVerificationBlock + content.slice(insertAt + 2);
|
|
2290
2385
|
}
|
|
2291
|
-
if (!content.includes("EmailVerification")) {
|
|
2386
|
+
if (!content.includes("import EmailVerification")) {
|
|
2292
2387
|
const lastImport = content.lastIndexOf("import");
|
|
2293
2388
|
const nextLine = content.indexOf("\n", lastImport) + 1;
|
|
2294
2389
|
const imports = `import EmailVerification from "@/components/email/EmailVerification";
|
|
2295
|
-
import { sendEmail } from "./email";
|
|
2296
2390
|
`;
|
|
2297
2391
|
content = content.slice(0, nextLine) + imports + content.slice(nextLine);
|
|
2298
2392
|
}
|
|
2299
|
-
|
|
2300
|
-
|
|
2393
|
+
if (!content.includes("import { sendEmail }")) {
|
|
2394
|
+
const lastImport = content.lastIndexOf("import");
|
|
2395
|
+
const nextLine = content.indexOf("\n", lastImport) + 1;
|
|
2396
|
+
const imports = `import { sendEmail } from "./email";
|
|
2397
|
+
`;
|
|
2398
|
+
content = content.slice(0, nextLine) + imports + content.slice(nextLine);
|
|
2399
|
+
}
|
|
2400
|
+
fs22.writeFileSync(authFilePath, content, "utf8");
|
|
2401
|
+
const templatePath = path22.resolve(
|
|
2301
2402
|
__dirname,
|
|
2302
2403
|
"./template/email/EmailVerification.tsx"
|
|
2303
2404
|
);
|
|
2304
|
-
const componentsDir =
|
|
2305
|
-
if (!
|
|
2306
|
-
|
|
2405
|
+
const componentsDir = path22.join(srcPath, "components", "email");
|
|
2406
|
+
if (!fs22.existsSync(componentsDir)) {
|
|
2407
|
+
fs22.mkdirSync(componentsDir, { recursive: true });
|
|
2307
2408
|
}
|
|
2308
|
-
const destFile =
|
|
2309
|
-
if (
|
|
2310
|
-
|
|
2409
|
+
const destFile = path22.join(componentsDir, "EmailVerification.tsx");
|
|
2410
|
+
if (fs22.existsSync(templatePath) && !fs22.existsSync(destFile)) {
|
|
2411
|
+
fs22.copyFileSync(templatePath, destFile);
|
|
2311
2412
|
}
|
|
2312
|
-
console.log(
|
|
2413
|
+
console.log(chalk24.green("Email verification successfully configured"));
|
|
2313
2414
|
} catch (error) {
|
|
2314
|
-
console.log(
|
|
2415
|
+
console.log(chalk24.red(String(error)));
|
|
2315
2416
|
}
|
|
2316
2417
|
};
|
|
2317
2418
|
|
|
2318
2419
|
// cli/verification.ts
|
|
2319
2420
|
var verification = async () => {
|
|
2320
2421
|
try {
|
|
2321
|
-
const
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
const packageJson2 = JSON.parse(fs25.readFileSync(packageJsonPath, "utf-8"));
|
|
2326
|
-
const hasNext = packageJson2?.dependencies?.["next"] || packageJson2?.devDependencies?.["next"];
|
|
2327
|
-
framework = hasNext ? "Next js" : "tanstack state";
|
|
2422
|
+
const { framework, error } = await getFramework();
|
|
2423
|
+
if (error) {
|
|
2424
|
+
console.log(chalk25.red(error));
|
|
2425
|
+
return;
|
|
2328
2426
|
}
|
|
2329
2427
|
if (framework === "Next js") {
|
|
2330
2428
|
await verifyNext();
|
|
@@ -2333,7 +2431,47 @@ var verification = async () => {
|
|
|
2333
2431
|
await verifyTanstack();
|
|
2334
2432
|
}
|
|
2335
2433
|
} catch (error) {
|
|
2336
|
-
console.log(
|
|
2434
|
+
console.log(chalk25.red(error.message));
|
|
2435
|
+
}
|
|
2436
|
+
};
|
|
2437
|
+
|
|
2438
|
+
// cli/initCmd.ts
|
|
2439
|
+
import chalk26 from "chalk";
|
|
2440
|
+
var initCmd = async (cmd) => {
|
|
2441
|
+
try {
|
|
2442
|
+
const { framework, error } = await getFramework();
|
|
2443
|
+
if (error) {
|
|
2444
|
+
console.log(chalk26.red(error));
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
if (framework === "Next js" && cmd.orm === "prisma") {
|
|
2448
|
+
await prismaRun({
|
|
2449
|
+
database: cmd.db,
|
|
2450
|
+
authUi: cmd.authUi === "yes" ? true : false,
|
|
2451
|
+
cmd: true
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
if (framework === "Next js" && cmd.orm === "drizzle") {
|
|
2455
|
+
await drizzleRun({
|
|
2456
|
+
authUi: cmd.authUi === "yes" ? true : false,
|
|
2457
|
+
cmd: true
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
if (framework === "tanstack state" && cmd.orm === "prisma") {
|
|
2461
|
+
await prismaRunTanstackState({
|
|
2462
|
+
authUi: cmd.authUi === "yes" ? true : false,
|
|
2463
|
+
database: cmd.db,
|
|
2464
|
+
cmd: true
|
|
2465
|
+
});
|
|
2466
|
+
}
|
|
2467
|
+
if (framework === "tanstack state" && cmd.orm === "drizzle") {
|
|
2468
|
+
await drizzleRunTanstackState({
|
|
2469
|
+
authUi: cmd.authUi === "yes" ? true : false,
|
|
2470
|
+
cmd: true
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
} catch (error) {
|
|
2474
|
+
console.log(chalk26.red(error));
|
|
2337
2475
|
}
|
|
2338
2476
|
};
|
|
2339
2477
|
|
|
@@ -2345,11 +2483,23 @@ program.name("authverse").description("CLI tool for creating authverse projects"
|
|
|
2345
2483
|
"-v, --version",
|
|
2346
2484
|
"display the version number"
|
|
2347
2485
|
);
|
|
2348
|
-
program.command("init").description("Select project template and configuration").action(async () => {
|
|
2349
|
-
|
|
2486
|
+
program.command("init").description("Select project template and configuration").option("--orm <type>", "Select ORM (prisma, drizzle)").option("--db <type>", "Select database (mysql, postgres, mongodb)").option("--authUi <value>", "Include auth UI (yes/no)").action(async (cmd) => {
|
|
2487
|
+
if (!cmd.orm || !cmd.db || !cmd.authUi) {
|
|
2488
|
+
await initAnswer();
|
|
2489
|
+
} else {
|
|
2490
|
+
await initCmd(cmd);
|
|
2491
|
+
}
|
|
2492
|
+
});
|
|
2493
|
+
program.command("add <provider>").description("Add a new authentication provider").action(async (provider) => {
|
|
2494
|
+
await providers({ provider });
|
|
2495
|
+
});
|
|
2496
|
+
program.command("forget").description("Forget stored configurations").action(async () => {
|
|
2497
|
+
await forget();
|
|
2498
|
+
});
|
|
2499
|
+
program.command("email").description("Configure email settings").action(async () => {
|
|
2500
|
+
await email();
|
|
2501
|
+
});
|
|
2502
|
+
program.command("verify").description("Verify authentication setup").action(async () => {
|
|
2503
|
+
await verification();
|
|
2350
2504
|
});
|
|
2351
|
-
program.command("add <provider>").description("Add a new authentication provider").action((provider) => providers({ provider }));
|
|
2352
|
-
program.command("forget").description("Forget stored configurations").action(forget);
|
|
2353
|
-
program.command("email").description("Configure email settings").action(email);
|
|
2354
|
-
program.command("verify").description("Verify authentication setup").action(verification);
|
|
2355
2505
|
program.parse(process.argv);
|