| 
									
										
										
										
											2021-05-05 10:48:27 +02:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							|  |  |  | const dotenv = require('dotenv'); | 
					
						
							|  |  |  | const fs = require('fs-extra'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const dotenvFilePath = path.resolve(process.cwd(), '.env'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (fs.existsSync(dotenvFilePath)) { | 
					
						
							|  |  |  |   dotenv.config({ path: dotenvFilePath }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const STRAPI_ADMIN = /^STRAPI_ADMIN_/i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  | const getClientEnvironment = (options) => { | 
					
						
							| 
									
										
										
										
											2021-05-05 10:48:27 +02:00
										 |  |  |   const raw = Object.keys(process.env) | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     .filter((key) => STRAPI_ADMIN.test(key)) | 
					
						
							| 
									
										
										
										
											2021-05-05 10:48:27 +02:00
										 |  |  |     .reduce( | 
					
						
							|  |  |  |       (acc, current) => { | 
					
						
							|  |  |  |         acc[current] = process.env[current]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return acc; | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         ADMIN_PATH: options.adminPath, | 
					
						
							| 
									
										
										
										
											2021-05-12 10:28:20 +02:00
										 |  |  |         NODE_ENV: options.env || 'development', | 
					
						
							| 
									
										
										
										
											2021-05-05 17:52:41 +02:00
										 |  |  |         STRAPI_ADMIN_BACKEND_URL: options.backend, | 
					
						
							| 
									
										
										
										
											2022-07-27 23:32:26 +02:00
										 |  |  |         STRAPI_TELEMETRY_DISABLED: options.telemetryDisabled, | 
					
						
							| 
									
										
										
										
											2021-05-05 10:48:27 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 17:52:41 +02:00
										 |  |  |   const stringified = { | 
					
						
							|  |  |  |     'process.env': Object.keys(raw).reduce((env, key) => { | 
					
						
							|  |  |  |       env[key] = JSON.stringify(raw[key]); | 
					
						
							|  |  |  |       return env; | 
					
						
							|  |  |  |     }, {}), | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2021-05-05 10:48:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 15:41:23 +02:00
										 |  |  |   return stringified; | 
					
						
							| 
									
										
										
										
											2021-05-05 10:48:27 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = getClientEnvironment; |