@@ -7,32 +7,46 @@ export const envVariablesInstaller: Installer = ({ projectDir, packages }) => {
7
7
const usingAuth = packages ?. nextAuth . inUse ;
8
8
const usingPrisma = packages ?. prisma . inUse ;
9
9
10
- const envAssetDir = path . join ( PKG_ROOT , "template/addons/env" ) ;
10
+ const envContent = getEnvContent ( ! ! usingAuth , ! ! usingPrisma ) ;
11
11
12
- let envSchemaFile = "" ;
13
- let envContent =
14
- "# When adding additional env variables, the schema in /env/schema.mjs should be updated accordingly\n" ;
12
+ const envSchemaFile =
13
+ usingAuth && usingPrisma
14
+ ? "with-auth-prisma.mjs"
15
+ : usingAuth
16
+ ? "with-auth.mjs"
17
+ : usingPrisma
18
+ ? "with-prisma.mjs"
19
+ : "" ;
15
20
16
- switch ( true ) {
17
- case usingAuth && usingPrisma :
18
- envSchemaFile = "auth-prisma-schema.mjs" ;
19
- break ;
20
- case usingAuth :
21
- envSchemaFile = "auth-schema.mjs" ;
22
- break ;
23
- case usingPrisma :
24
- envSchemaFile = "prisma-schema.mjs" ;
25
- break ;
21
+ if ( envSchemaFile !== "" ) {
22
+ const envSchemaSrc = path . join (
23
+ PKG_ROOT ,
24
+ "template/extras/src/env/schema" ,
25
+ envSchemaFile ,
26
+ ) ;
27
+ const envSchemaDest = path . join ( projectDir , "src/env/schema.mjs" ) ;
28
+ fs . copySync ( envSchemaSrc , envSchemaDest ) ;
26
29
}
27
30
28
- if ( usingPrisma ) {
29
- envContent += `
31
+ const envDest = path . join ( projectDir , ".env" ) ;
32
+ const envExampleDest = path . join ( projectDir , ".env.example" ) ;
33
+
34
+ fs . writeFileSync ( envDest , envContent , "utf-8" ) ;
35
+ fs . writeFileSync ( envExampleDest , exampleEnvContent + envContent , "utf-8" ) ;
36
+ } ;
37
+
38
+ const getEnvContent = ( usingAuth : boolean , usingPrisma : boolean ) => {
39
+ let content =
40
+ "# When adding additional env variables, the schema in /env/schema.mjs should be updated accordingly" ;
41
+
42
+ if ( usingPrisma )
43
+ content += `
30
44
# Prisma
31
45
DATABASE_URL=file:./db.sqlite
32
46
` ;
33
- }
34
- if ( usingAuth ) {
35
- envContent += `
47
+
48
+ if ( usingAuth )
49
+ content += `
36
50
# Next Auth
37
51
# You can generate the secret via 'openssl rand -base64 32' on Linux
38
52
# More info: https://next-auth.js.org/configuration/options#secret
@@ -43,34 +57,21 @@ NEXTAUTH_URL=http://localhost:3000
43
57
DISCORD_CLIENT_ID=
44
58
DISCORD_CLIENT_SECRET=
45
59
` ;
46
- }
47
60
48
- if ( ! envSchemaFile ) {
49
- envContent += `
61
+ if ( ! usingAuth && ! usingPrisma )
62
+ content += `
50
63
# Example:
51
64
# SERVERVAR=foo
52
65
# NEXT_PUBLIC_CLIENTVAR=bar
53
66
` ;
54
- }
55
67
56
- const envExampleContent =
57
- `# Since .env is gitignored, you can use .env.example to build a new \`.env\` file when you clone the repo.
68
+ return content ;
69
+ } ;
70
+
71
+ const exampleEnvContent = `# Since .env is gitignored, you can use .env.example to build a new \`.env\` file when you clone the repo.
58
72
# Keep this file up-to-date when you add new variables to \`.env\`.
59
73
60
74
# This file will be committed to version control, so make sure not to have any secrets in it.
61
75
# If you are cloning this repo, create a copy of this file named \`.env\` and populate it with your secrets.
62
76
63
- ` + envContent ;
64
-
65
- if ( envSchemaFile ) {
66
- const envSchemaSrc = path . join ( envAssetDir , envSchemaFile ) ;
67
- const envSchemaDest = path . join ( projectDir , "src/env/schema.mjs" ) ;
68
- fs . copySync ( envSchemaSrc , envSchemaDest ) ;
69
- }
70
-
71
- const envDest = path . join ( projectDir , ".env" ) ;
72
- const envExampleDest = path . join ( projectDir , ".env.example" ) ;
73
-
74
- fs . writeFileSync ( envDest , envContent , "utf-8" ) ;
75
- fs . writeFileSync ( envExampleDest , envExampleContent , "utf-8" ) ;
76
- } ;
77
+ ` ;
0 commit comments