@@ -13,7 +13,7 @@ const blogPlaceholderValue = "{{SERVICE_BLOG_URI_PLACEHOLDER}}";
13
13
const cmsRegex = / S E R V I C E _ C M S _ U R I = " ( [ ^ " ] + ) " / ;
14
14
const cmsPlaceholderValue = "{{SERVICE_CMS_URI_PLACEHOLDER}}" ;
15
15
const aiEnableRegex = / A I _ E N A B L E _ C H A T = " ( [ ^ " ] + ) " / ;
16
- const aiEnablePlaceholderValue = "\" {{AI_ENABLE_CHAT_PLACEHOLDER}}\"" ;
16
+ const aiEnablePlaceholderValue = '" {{AI_ENABLE_CHAT_PLACEHOLDER}}"' ;
17
17
const aiChatApiRegex = / A I _ C H A T _ A P I _ U R I = " ( [ ^ " ] + ) " / ;
18
18
const aiChatApiPlaceholderValue = "{{AI_CHAT_API_URI_PLACEHOLDER}}" ;
19
19
const webPubSubUrlRegex = / S E R V I C E _ W E B _ P U B _ S U B _ U R L = " ( [ ^ " ] + ) " / ;
@@ -27,42 +27,49 @@ const distPath = resolve(__dirname, "../../../packages/portal/dist/contoso-app")
27
27
function replaceEnvURIs ( filePath ) {
28
28
const matchBlog = envVars . match ( blogRegex ) ;
29
29
const matchCms = envVars . match ( cmsRegex ) ;
30
- const webPubSubUrl = envVars . match ( webPubSubUrlRegex ) ;
31
- const webPubSubPath = envVars . match ( webPubSubPathRegex ) ;
30
+ const matchWebPubSubUrl = envVars . match ( webPubSubUrlRegex ) ;
31
+ const matchWebPubSubPath = envVars . match ( webPubSubPathRegex ) ;
32
32
33
- if ( matchBlog && matchCms ) {
34
- const blogValue = matchBlog [ 1 ] ;
35
- const cmsValue = matchCms [ 1 ] ;
36
- const fileContents = readFileSync ( filePath , "utf-8" ) ;
37
- const newFileContent = fileContents
38
- . replace ( blogPlaceholderValue , blogValue )
39
- . replace ( cmsPlaceholderValue , cmsValue )
40
- . replace ( webPubSubUrlPlaceholderValue , webPubSubUrl )
41
- . replace ( webPubSubPathPlaceholderValue , webPubSubPath )
42
- ;
43
-
44
- writeFileSync ( filePath , newFileContent ) ;
45
- } else {
46
- if ( ! matchBlog ) {
47
- console . log ( `No match found for ${ blogPlaceholderValue } . Skipping replacement.` ) ;
48
- process . exit ( 1 ) ;
49
- }
50
- if ( ! matchCms ) {
51
- console . log ( `No match found for ${ cmsPlaceholderValue } . Skipping replacement.` ) ;
52
- process . exit ( 1 ) ;
53
- }
33
+ if ( ! matchBlog ) {
34
+ console . log ( `No match found for ${ blogPlaceholderValue } . Skipping replacement.` ) ;
35
+ process . exit ( 1 ) ;
36
+ }
37
+ if ( ! matchCms ) {
38
+ console . log ( `No match found for ${ cmsPlaceholderValue } . Skipping replacement.` ) ;
39
+ process . exit ( 1 ) ;
40
+ }
41
+ if ( ! matchWebPubSubUrl ) {
42
+ console . log ( `No match found for ${ webPubSubUrlPlaceholderValue } . Skipping replacement.` ) ;
43
+ process . exit ( 1 ) ;
54
44
}
45
+ if ( ! matchWebPubSubPath ) {
46
+ console . log ( `No match found for ${ webPubSubPathPlaceholderValue } . Skipping replacement.` ) ;
47
+ process . exit ( 1 ) ;
48
+ }
49
+
50
+ const blogValue = matchBlog [ 1 ] ;
51
+ const cmsValue = matchCms [ 1 ] ;
52
+ const webPubSubUrlValue = matchWebPubSubUrl [ 1 ] ;
53
+ const webPubSubPathValue = matchWebPubSubPath [ 1 ] ;
54
+ const fileContents = readFileSync ( filePath , "utf-8" ) ;
55
55
56
+ // Replace the placeholder with the actual value
57
+ let newFileContent = fileContents
58
+ . replace ( blogPlaceholderValue , blogValue )
59
+ . replace ( cmsPlaceholderValue , cmsValue )
60
+ . replace ( webPubSubUrlPlaceholderValue , webPubSubUrlValue )
61
+ . replace ( webPubSubPathPlaceholderValue , webPubSubPathValue ) ;
62
+
63
+ // Special handling for AI chatbot
56
64
const matchAiEnable = envVars . match ( aiEnableRegex ) ;
57
65
const matchAiChatApi = envVars . match ( aiChatApiRegex ) ;
58
66
const aiEnableValue = matchAiEnable ? matchAiEnable [ 1 ] : false ;
59
- const aiChatApiValue = matchAiChatApi ? matchAiChatApi [ 1 ] : '' ;
67
+ const aiChatApiValue = matchAiChatApi ? matchAiChatApi [ 1 ] : "" ;
60
68
if ( matchAiEnable && matchAiChatApi ) {
61
69
console . log ( `AI chatbot is enabled. Chat API URI: ${ aiChatApiValue } ` ) ;
62
70
}
63
71
64
- const fileContents = readFileSync ( filePath , "utf-8" ) ;
65
- const newFileContent = fileContents
72
+ newFileContent = newFileContent
66
73
. replace ( aiEnablePlaceholderValue , aiEnableValue )
67
74
. replace ( aiChatApiPlaceholderValue , aiChatApiValue ) ;
68
75
0 commit comments