-
Notifications
You must be signed in to change notification settings - Fork 991
/
config.ts
221 lines (205 loc) · 4.9 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import fs from 'fs'
import toml from '@iarna/toml'
import merge from 'deepmerge'
import { env as envInterpolation } from 'string-env-interpolation'
import { getConfigPath } from './configPath'
export enum TargetEnum {
NODE = 'node',
BROWSER = 'browser',
REACT_NATIVE = 'react-native',
ELECTRON = 'electron',
}
export enum BundlerEnum {
WEBPACK = 'webpack',
VITE = 'vite',
}
export interface NodeTargetConfig {
title: string
name?: string
host: string
port: number
path: string
target: TargetEnum.NODE
schemaPath: string
serverConfig: string
debugPort?: number
}
interface BrowserTargetConfig {
title: string
name?: string
host: string
port: number
path: string
target: TargetEnum.BROWSER
bundler: BundlerEnum
includeEnvironmentVariables: string[]
/**
* Specify the URL to your api-server.
* This can be an absolute path proxied on the current domain (`/.netlify/functions`),
* or a fully qualified URL (`https://api.example.org:8911/functions`).
*
* Note: This should not include the path to the GraphQL Server.
**/
apiUrl: string
/**
* Optional: FQDN or absolute path to the GraphQL serverless function, without the trailing slash.
* This will override the apiUrl configuration just for the graphql function
* Example: `./redwood/functions/graphql` or `https://api.redwoodjs.com/graphql`
*/
apiGraphQLUrl?: string
fastRefresh: boolean
a11y: boolean
sourceMap: boolean
}
interface GraphiQLStudioConfig {
endpoint?: string
authImpersonation?: AuthImpersonationConfig
}
type SupportedAuthImpersonationProviders = 'dbAuth' | 'netlify' | 'supabase'
interface AuthImpersonationConfig {
authProvider?: SupportedAuthImpersonationProviders
jwtSecret?: string
userId?: string
email?: string
roles?: string[]
}
interface StudioConfig {
inMemory: boolean
graphiql?: GraphiQLStudioConfig
}
export interface Config {
web: BrowserTargetConfig
api: NodeTargetConfig
browser: {
open: boolean | string
}
generate: {
tests: boolean
stories: boolean
nestScaffoldByModel: boolean
}
notifications: {
versionUpdates: string[]
}
experimental: {
opentelemetry: {
enabled: boolean
apiSdk?: string
}
studio: StudioConfig
cli: {
autoInstall: boolean
plugins: CLIPlugin[]
}
useSDLCodeGenForGraphQLTypes: boolean
streamingSsr: {
enabled: boolean
}
rsc: {
enabled: boolean
}
}
}
export interface CLIPlugin {
package: string
enabled?: boolean
}
// Note that web's includeEnvironmentVariables is handled in `webpack.common.js`
// https://github.com/redwoodjs/redwood/blob/d51ade08118c17459cebcdb496197ea52485364a/packages/core/config/webpack.common.js#L19
const DEFAULT_CONFIG: Config = {
web: {
title: 'Redwood App',
host: 'localhost',
port: 8910,
path: './web',
target: TargetEnum.BROWSER,
bundler: BundlerEnum.VITE,
includeEnvironmentVariables: [],
apiUrl: '/.redwood/functions',
fastRefresh: true,
a11y: true,
sourceMap: false,
},
api: {
title: 'Redwood App',
host: 'localhost',
port: 8911,
path: './api',
target: TargetEnum.NODE,
schemaPath: './api/db/schema.prisma',
serverConfig: './api/server.config.js',
debugPort: 18911,
},
browser: {
open: false,
},
generate: {
tests: true,
stories: true,
nestScaffoldByModel: true,
},
notifications: {
versionUpdates: [],
},
experimental: {
opentelemetry: {
enabled: false,
apiSdk: undefined,
},
studio: {
inMemory: false,
graphiql: {
endpoint: 'graphql',
authImpersonation: {
authProvider: undefined,
userId: undefined,
email: undefined,
roles: undefined,
jwtSecret: 'secret',
},
},
},
cli: {
autoInstall: true,
plugins: [
{
package: '@redwoodjs/cli-storybook',
},
{
package: '@redwoodjs/cli-data-migrate',
},
],
},
useSDLCodeGenForGraphQLTypes: false,
streamingSsr: {
enabled: false,
},
rsc: {
enabled: false,
},
},
}
/**
* These configuration options are modified by the user via the Redwood
* config file.
*/
export const getConfig = (configPath = getConfigPath()): Config => {
try {
return merge(DEFAULT_CONFIG, getRawConfig(configPath))
} catch (e) {
throw new Error(`Could not parse "${configPath}": ${e}`)
}
}
/**
* Returns the JSON parse of the config file without any default values.
*
* @param configPath Path to the config file, defaults to automatically find the project `redwood.toml` file
* @returns A JSON object from the parsed toml values
*/
export function getRawConfig(configPath = getConfigPath()) {
try {
return toml.parse(envInterpolation(fs.readFileSync(configPath, 'utf8')))
} catch (e) {
throw new Error(`Could not parse "${configPath}": ${e}`)
}
}