44 * Licensed under the BSD 3-Clause license.
55 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
7+ /* eslint-disable no-console */
8+ // import { Logger } from '@salesforce/core';
79import 'dotenv/config' ;
810
911export type ExperienceSiteConfig = {
1012 previewUser : string ;
1113 previewToken : string ;
1214 apiStaticMode : boolean ;
1315 apiBundlingGroups : boolean ;
14- apiVersion : string ;
1516 apiSiteVersion : string ;
17+ logLevel : string ;
18+ port : number ;
19+ openBrowser : boolean ;
20+ lwcConfigEnabled : boolean ;
21+ setupOnly : boolean ;
1622} ;
1723
24+ /**
25+ * Environment variables that are considered experimental
26+ */
27+ const EXPERIMENTAL_ENV_VARS = [
28+ 'PREVIEW_USER' ,
29+ 'SID_TOKEN' ,
30+ 'API_STATIC_MODE' ,
31+ 'API_BUNDLING_GROUPS' ,
32+ 'API_SITE_VERSION' ,
33+ 'SETUP_ONLY' ,
34+ 'LWC_CONFIG_ENABLED' ,
35+ ] ;
36+
37+ /**
38+ * Experimental configuration options for Experience Sites local development
39+ *
40+ */
1841export class ExperienceSiteConfigManager {
1942 private static instance : ExperienceSiteConfigManager ;
2043 private config : ExperienceSiteConfig ;
2144
2245 private constructor ( ) {
46+ // Show a warning
47+ checkExperimentalConfig ( ) ;
48+
2349 // Backwards Compat
2450 if ( process . env . SITE_GUEST_ACCESS === 'true' ) {
2551 process . env . PREVIEW_USER = 'Guest' ;
@@ -28,13 +54,29 @@ export class ExperienceSiteConfigManager {
2854 process . env . PREVIEW_USER = 'Custom' ;
2955 }
3056
57+ // Experimental configuration values
3158 this . config = {
32- previewUser : process . env . PREVIEW_USER ?? 'Admin' ,
33- previewToken : process . env . SID_TOKEN ?? '' ,
34- apiStaticMode : process . env . API_STATIC_MODE === 'true' ? true : false ,
35- apiBundlingGroups : process . env . API_BUNDLING_GROUPS === 'true' ? true : false ,
36- apiVersion : process . env . API_VERSION ?? 'v64.0' ,
37- apiSiteVersion : process . env . API_SITE_VERSION ?? 'published' ,
59+ // what user to preview site with
60+ previewUser : process . env . PREVIEW_USER ?? 'Admin' , // Default: Admin
61+ // Override the authentication token for this user
62+ previewToken : process . env . SID_TOKEN ?? '' , // Default: No Override (empty string)
63+ // download from static resources instead of the API
64+ apiStaticMode : process . env . API_STATIC_MODE === 'true' ? true : false , // Default: false
65+ // use bundling groups or not - testing purposes only
66+ apiBundlingGroups : process . env . API_BUNDLING_GROUPS === 'true' ? true : false , // Default: false
67+ // What version of the API to use
68+ apiSiteVersion : process . env . API_SITE_VERSION ?? 'published' , // Default: published
69+ // Log level supplied to the LWR server
70+ logLevel : process . env . LOG_LEVEL ?? 'error' , // Default: error
71+ // Port to run the LWR server
72+ port : parseInt ( process . env . PORT ?? '3000' , 10 ) , // Default: 3000
73+ // Should we automatically open the browser?
74+ openBrowser : process . env . OPEN_BROWSER === 'false' ? false : true , // Default: true
75+ // Enable lwc module resolution outside the context of SFDX
76+ lwcConfigEnabled : process . env . LWC_CONFIG_ENABLED === 'true' ? true : false , // Default: false
77+ // Skip running the server, just setup the site
78+ setupOnly : process . env . SETUP_ONLY === 'true' ? true : false , // Default: false
79+ // TODO Add option for running the site in preview only mode (no local changes included)
3880 } ;
3981 }
4082
@@ -80,3 +122,21 @@ export class ExperienceSiteConfigManager {
80122export function getExperienceSiteConfig ( ) : ExperienceSiteConfig {
81123 return ExperienceSiteConfigManager . getInstance ( ) . getConfig ( ) ;
82124}
125+
126+ /**
127+ * Checks if any experimental environment variables are set and logs a warning if so.
128+ * The warning is only shown once per command execution.
129+ */
130+ export function checkExperimentalConfig ( ) : void {
131+ // Check if any experimental env vars are set
132+ const usedEnvVars = EXPERIMENTAL_ENV_VARS . filter ( ( envVar ) => process . env [ envVar ] !== undefined ) ;
133+
134+ if ( usedEnvVars . length > 0 ) {
135+ // Log a warning
136+ console . warn ( '\x1b[33m%s\x1b[0m' , '⚠️ EXPERIMENTAL CONFIGURATION OPTIONS DETECTED ⚠️' ) ;
137+ console . warn (
138+ '\x1b[33m%s\x1b[0m' ,
139+ 'These configuration options are experimental and may change without notice. Please refer to the official documentation for supported options.'
140+ ) ;
141+ }
142+ }
0 commit comments