Skip to content

Commit c4aa415

Browse files
committed
(#133) Add a token map for widgets
Closes #133
1 parent 380511a commit c4aa415

File tree

6 files changed

+259
-209
lines changed

6 files changed

+259
-209
lines changed

.github/workflows/deploy.yml

+42-5
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,50 @@ jobs:
3333
# Sets up our deployment
3434
- uses: "./.github/workflows/composite/setup"
3535

36+
37+
########## Widget Package ##########
38+
39+
# Update widget tokens
40+
# Our own solution instead of --tokenMap because we need to replace values inside a JSON object
41+
# and Akumina's solution only supports string values
42+
- name: Update widget tokens
43+
id: tokens
44+
if: inputs.deploy-widgets
45+
shell: pwsh
46+
env:
47+
WIDGET_TOKENS: ${{ vars.WIDGET_TOKENS }}
48+
run: |
49+
$mappingJson = $env:WIDGET_TOKENS
50+
$mapping = $mappingJson | ConvertFrom-Json
51+
52+
$TargetDirectory = "src/js/widgets"
53+
$files = Get-ChildItem -Path $TargetDirectory -Recurse -Filter "*.json"
54+
55+
foreach ($file in $files) {
56+
$content = Get-Content $file.FullName -Raw
57+
$fileReplacements = 0
58+
foreach ($key in $mapping.PSObject.Properties.Name) {
59+
$searchKey = "GHA_$key"
60+
$value = $mapping.$key
61+
if ($content -match [regex]::Escape($searchKey)) {
62+
$content = $content -replace [regex]::Escape($searchKey), $value
63+
$fileReplacements++
64+
}
65+
}
66+
if ($fileReplacements -gt 0) {
67+
Set-Content -Path $file.FullName -Value $content
68+
Write-Host "$fileReplacements token(s) replaced with values from GHA environment in $($file.FullName)."
69+
}
70+
}
71+
3672
# Package the widgets (must run before build)
37-
- name: Package Widgets
73+
- name: Package widgets
3874
if: inputs.deploy-widgets
39-
# TO-DO: Implement tokenMap
40-
#run: npm run package ${{ inputs.widget_name }} -- --tokenMap ${{ inputs.token_map }}
75+
# npm run package -- --tokenMap "${{ steps.tokens.outputs.WIDGET_TOKEN_STRING }}"
4176
run: npm run package
4277

78+
########## Build ##########
79+
4380
# Runs webpack to copy the source to the build folder
4481
- name: Build
4582
run: npm run build${{ inputs.environment == 'Prod' && '-prod-ci' || ''}}
@@ -54,7 +91,7 @@ jobs:
5491
deployment_type: "cdnassets"
5592

5693
# Runs akumina-widget-builder with the cdnpackage option to prep widgets for deployment
57-
- name: Package Widgets for CDN
94+
- name: Package widgets for CDN
5895
if: inputs.deploy-widgets
5996
run: npm run cdnpackage
6097

@@ -80,7 +117,7 @@ jobs:
80117
deployment_type: "widgets"
81118

82119
# Runs site deployer
83-
- name: Deploy Widgets
120+
- name: Deploy widgets
84121
if: inputs.deploy-widgets
85122
run: npm run deploy
86123
env:

site/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# Exclude things copied in via webpack
33
build/sitedefinitions/Client/Branding/*
44
build/sitedefinitions/Client/CDNAssets/*
5+
build/sitedefinitions/Client/WidgetPackages/*
56

67
# Exclude the distribution widgets
7-
dist/widgets/*
8+
dist/*
89

910
# Exclude the tools
1011
tools/*

site/src/js/widgets/BlogsWidget/config/config.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{
1717
"Name": "blogslatesthomeversion",
1818
"Path": "/{AssetLibraryName}/DigitalWorkPlace/Content/Templates/BlogsWidget/blogslatesthomeversion.html",
19-
"Id":"03b63f18-957c-49b2-af66-595d85eb0639"
19+
"Id": "03b63f18-957c-49b2-af66-595d85eb0639"
2020
}
2121
],
2222
"JS": {
@@ -57,26 +57,26 @@
5757
{
5858
"name": "searchrefiners",
5959
"value": {
60-
"termStoreId": "9f6b3be8-ba1a-4111-ae41-3d7d6617b251",
60+
"termStoreId": "{GHA_termsetCategoryToken}",
6161
"terms": [
6262
{
6363
"managedPropertyName": "SPTags",
6464
"displayName": "common.tags",
65-
"id": "f7fece51-494f-48df-824d-f21cdd9a0146",
65+
"id": "{GHA_termTagsToken}",
6666
"taxonomyIsTermSet": false,
6767
"termSetName": "Category"
6868
},
6969
{
7070
"managedPropertyName": "Departments",
7171
"displayName": "common.departments",
72-
"id": "ef90fc48-1b8a-4242-bbda-df722c8b3a47",
72+
"id": "{GHA_termLocationsToken}",
7373
"taxonomyIsTermSet": false,
7474
"termSetName": "Category"
7575
},
7676
{
7777
"managedPropertyName": "Region",
7878
"displayName": "common.regions",
79-
"id": "5b1272bd-6012-4a2a-a5c7-8b718ec23521",
79+
"id": "{GHA_termDepartmentsToken}",
8080
"taxonomyIsTermSet": false,
8181
"termSetName": "Category"
8282
}
@@ -173,26 +173,26 @@
173173
{
174174
"name": "searchrefiners",
175175
"value": {
176-
"termStoreId": "",
176+
"termStoreId": "{GHA_termsetCategoryToken}",
177177
"terms": [
178178
{
179179
"managedPropertyName": "SPTags",
180180
"displayName": "common.tags",
181-
"id": "f7fece51-494f-48df-824d-f21cdd9a0146",
181+
"id": "{GHA_termTagsToken}",
182182
"taxonomyIsTermSet": false,
183183
"termSetName": "Category"
184184
},
185185
{
186186
"managedPropertyName": "Departments",
187187
"displayName": "common.departments",
188-
"id": "ef90fc48-1b8a-4242-bbda-df722c8b3a47",
188+
"id": "{GHA_termLocationsToken}",
189189
"taxonomyIsTermSet": false,
190190
"termSetName": "Category"
191191
},
192192
{
193193
"managedPropertyName": "Region",
194194
"displayName": "common.regions",
195-
"id": "5b1272bd-6012-4a2a-a5c7-8b718ec23521",
195+
"id": "{GHA_termDepartmentsToken}",
196196
"taxonomyIsTermSet": false,
197197
"termSetName": "Category"
198198
}
@@ -262,4 +262,4 @@
262262
"IsDashboardWidget": false,
263263
"IsAppManagerWidget": false
264264
}
265-
}
265+
}

site/src/js/widgets/LaunchPadWidget/config/config.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
{
3737
"name": "groupby",
3838
"value": {
39-
"termStoreId": "9f6b3be8-ba1a-4111-ae41-3d7d6617b251",
39+
"termStoreId": "{GHA_termsetCategoryToken}",
4040
"termSetName": "Category",
4141
"terms": {
4242
"name": "Departments",
4343
"displayName": "Departments",
4444
"columnName": "Departments",
45-
"id": "19b184fe-a269-44fc-a939-b590dd9379ea"
45+
"id": "{GHA_termDepartmentsToken}"
4646
}
4747
}
4848
},
@@ -85,4 +85,4 @@
8585
"IsDashboardWidget": false,
8686
"IsAppManagerWidget": false
8787
}
88-
}
88+
}

0 commit comments

Comments
 (0)