Skip to content

Commit 8e23e7f

Browse files
[DEV-2818] Update script to add synced data in s3 (#1696)
* Add synced responses for solutions and solution-list-page in s3 * Add synced responses for release notes in s3 * Add changeset * Add syncedResponses to improve constants menagement * Fix responseJson --------- Co-authored-by: marcobottaro <39835990+marcobottaro@users.noreply.github.com>
1 parent 19c9a9d commit 8e23e7f

File tree

5 files changed

+85
-9
lines changed

5 files changed

+85
-9
lines changed

.changeset/giant-pets-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook-docs": minor
3+
---
4+
5+
Update generate metadata script to add synced response in S3 for solutions and release note

packages/gitbook-docs/src/scripts/generateGuidesMetadata.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import {
1818
} from '../helpers/fetchFromStrapi';
1919
import { StrapiGuide, MetadataInfo } from '../helpers/guidesMetadataHelper';
2020
import { sitePathFromS3Path } from '../helpers/sitePathFromS3Path';
21+
import {
22+
getSyncedGuideListPagesResponseJsonPath,
23+
getSyncedGuidesResponseJsonPath,
24+
} from '../syncedResponses';
2125

2226
// Load environment variables from .env file
2327
dotenv.config();
@@ -27,11 +31,9 @@ const S3_PATH_TO_GITBOOK_DOCS =
2731
process.env.S3_PATH_TO_GITBOOK_DOCS || 'devportal-docs/docs';
2832
const S3_GUIDE_METADATA_JSON_PATH =
2933
process.env.S3_GUIDE_METADATA_JSON_PATH || 'guides-metadata.json';
30-
const SYNCED_GUIDES_RESPONSE_JSON_PATH =
31-
process.env.SYNCED_GUIDES_RESPONSE_JSON_PATH || 'synced-guides-response.json';
34+
const SYNCED_GUIDES_RESPONSE_JSON_PATH = getSyncedGuidesResponseJsonPath();
3235
const SYNCED_GUIDE_LIST_PAGES_RESPONSE_JSON_PATH =
33-
process.env.SYNCED_GUIDE_LIST_PAGES_RESPONSE_JSON_PATH ||
34-
'synced-guide-list-pages-response.json';
36+
getSyncedGuideListPagesResponseJsonPath();
3537

3638
const s3Client = makeS3Client();
3739

packages/gitbook-docs/src/scripts/generateReleaseNotesMetadata.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { extractTitleFromMarkdown } from '../helpers/extractTitle.helper';
1515
import { fetchFromStrapi } from '../helpers/fetchFromStrapi';
1616
import { sitePathFromS3Path } from '../helpers/sitePathFromS3Path';
1717
import { StrapiReleaseNote } from '../helpers/guidesMetadataHelper';
18+
import { getSyncedReleaseNotesResponseJsonPath } from '../syncedResponses';
1819

1920
// Load environment variables from .env file
2021
dotenv.config();
@@ -25,6 +26,8 @@ const S3_PATH_TO_GITBOOK_DOCS =
2526
const S3_RELEASE_NOTES_METADATA_JSON_PATH =
2627
process.env.S3_RELEASE_NOTES_METADATA_JSON_PATH ||
2728
'release-notes-metadata.json';
29+
const SYNCED_RELEASE_NOTES_RESPONSE_JSON_PATH =
30+
getSyncedReleaseNotesResponseJsonPath();
2831

2932
const s3Client = makeS3Client();
3033

@@ -98,11 +101,14 @@ async function main() {
98101

99102
// eslint-disable-next-line functional/no-let
100103
let strapiReleaseNotes;
104+
// eslint-disable-next-line functional/no-let
105+
let responseJson;
101106
try {
102-
const { data } = await fetchFromStrapi<StrapiReleaseNote>(
107+
const result = await fetchFromStrapi<StrapiReleaseNote>(
103108
'api/release-notes?populate[0]=product&pagination[pageSize]=1000&pagination[page]=1'
104109
);
105-
strapiReleaseNotes = data;
110+
strapiReleaseNotes = result.data;
111+
responseJson = result.responseJson;
106112
} catch (error) {
107113
console.error('Error fetching release notes from Strapi:', error);
108114
process.exit(1);
@@ -123,6 +129,14 @@ async function main() {
123129
`${S3_BUCKET_NAME}`,
124130
s3Client
125131
);
132+
133+
// TODO: remove when Strapi will manage Metadata
134+
await writeSitemapJson(
135+
responseJson,
136+
SYNCED_RELEASE_NOTES_RESPONSE_JSON_PATH,
137+
`${S3_BUCKET_NAME}`,
138+
s3Client
139+
);
126140
}
127141

128142
// Execute the function

packages/gitbook-docs/src/scripts/generateSolutionsMetadata.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ import {
1212
writeSitemapJson,
1313
} from '../helpers/s3Bucket.helper';
1414
import { extractTitleFromMarkdown } from '../helpers/extractTitle.helper';
15-
import { fetchFromStrapi } from '../helpers/fetchFromStrapi';
15+
import {
16+
fetchFromStrapi,
17+
getResponseFromStrapi,
18+
} from '../helpers/fetchFromStrapi';
1619
import { sitePathFromS3Path } from '../helpers/sitePathFromS3Path';
1720
import { StrapiSolution } from '../helpers/guidesMetadataHelper';
21+
import {
22+
getSyncedSolutionListPagesResponseJsonPath,
23+
getSyncedSolutionsResponseJsonPath,
24+
} from '../syncedResponses';
1825

1926
// Load environment variables from .env file
2027
dotenv.config();
@@ -24,6 +31,10 @@ const S3_PATH_TO_GITBOOK_DOCS =
2431
process.env.S3_PATH_TO_GITBOOK_DOCS || 'devportal-docs/docs';
2532
const S3_SOLUTIONS_METADATA_JSON_PATH =
2633
process.env.S3_SOLUTIONS_METADATA_JSON_PATH || 'solutions-metadata.json';
34+
const SYNCED_SOLUTIONS_RESPONSE_JSON_PATH =
35+
getSyncedSolutionsResponseJsonPath();
36+
const SYNCED_SOLUTION_LIST_PAGES_RESPONSE_JSON_PATH =
37+
getSyncedSolutionListPagesResponseJsonPath();
2738

2839
const s3Client = makeS3Client();
2940
function generateUrlPath(
@@ -92,13 +103,28 @@ async function convertSolutionToSitemapItems(
92103
async function main() {
93104
console.log('Starting to process Markdown files...');
94105

106+
// TODO: remove when Strapi will manage Metadata
107+
// eslint-disable-next-line functional/no-let
108+
let solutionListPagesResponse;
109+
try {
110+
solutionListPagesResponse = await getResponseFromStrapi(
111+
'api/solution-list-page/?populate%5Bsolutions%5D%5Bpopulate%5D%5B0%5D=bannerLinks&populate%5Bsolutions%5D%5Bpopulate%5D%5B1%5D=bannerLinks.icon&populate%5Bsolutions%5D%5Bpopulate%5D%5B2%5D=products.logo&populate%5Bsolutions%5D%5Bpopulate%5D%5B3%5D=icon&populate%5Bsolutions%5D%5Bpopulate%5D%5B4%5D=icon.name&populate%5Bsolutions%5D%5Bpopulate%5D%5B5%5D=stats&populate%5Bsolutions%5D%5Bpopulate%5D%5B6%5D=steps&populate%5Bsolutions%5D%5Bpopulate%5D%5B7%5D=steps.products&populate%5Bsolutions%5D%5Bpopulate%5D%5B8%5D=webinars&populate%5Bsolutions%5D%5Bpopulate%5D%5B9%5D=webinars.coverImage&populate%5Bsolutions%5D%5Bpopulate%5D%5B10%5D=caseHistories&populate%5Bsolutions%5D%5Bpopulate%5D%5B11%5D=caseHistories.case_histories&populate%5Bsolutions%5D%5Bpopulate%5D%5B12%5D=caseHistories.case_histories.image&populate%5BcaseHistories%5D%5Bpopulate%5D%5B0%5D=case_histories&populate%5BcaseHistories%5D%5Bpopulate%5D%5B1%5D=case_histories.image&populate%5Bfeatures%5D%5Bpopulate%5D%5B0%5D=items.icon&populate%5Bseo%5D%5Bpopulate%5D=%2A%2CmetaImage%2CmetaSocial.image'
112+
);
113+
} catch (error) {
114+
console.error('Error fetching solution list pages from Strapi:', error);
115+
process.exit(1);
116+
}
117+
95118
// eslint-disable-next-line functional/no-let
96119
let strapiSolutions;
120+
// eslint-disable-next-line functional/no-let
121+
let responseJson;
97122
try {
98-
const { data } = await fetchFromStrapi<StrapiSolution>(
123+
const result = await fetchFromStrapi<StrapiSolution>(
99124
'api/solutions?pagination[pageSize]=1000&pagination[page]=1'
100125
);
101-
strapiSolutions = data;
126+
strapiSolutions = result.data;
127+
responseJson = result.responseJson;
102128
} catch (error) {
103129
console.error('Error fetching solutions from Strapi:', error);
104130
process.exit(1);
@@ -115,6 +141,22 @@ async function main() {
115141
`${S3_BUCKET_NAME}`,
116142
s3Client
117143
);
144+
145+
// TODO: remove when Strapi will manage Metadata
146+
await writeSitemapJson(
147+
responseJson,
148+
SYNCED_SOLUTIONS_RESPONSE_JSON_PATH,
149+
`${S3_BUCKET_NAME}`,
150+
s3Client
151+
);
152+
153+
// TODO: remove when Strapi will manage Metadata
154+
await writeSitemapJson(
155+
solutionListPagesResponse,
156+
SYNCED_SOLUTION_LIST_PAGES_RESPONSE_JSON_PATH,
157+
`${S3_BUCKET_NAME}`,
158+
s3Client
159+
);
118160
}
119161

120162
// Execute the function
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const getSyncedGuidesResponseJsonPath = () =>
2+
process.env.SYNCED_GUIDES_RESPONSE_JSON_PATH || 'synced-guides-response.json';
3+
export const getSyncedGuideListPagesResponseJsonPath = () =>
4+
process.env.SYNCED_GUIDE_LIST_PAGES_RESPONSE_JSON_PATH ||
5+
'synced-guide-list-pages-response.json';
6+
7+
export const getSyncedSolutionsResponseJsonPath = () =>
8+
'synced-solutions-response.json';
9+
export const getSyncedSolutionListPagesResponseJsonPath = () =>
10+
'synced-solution-list-pages-response.json';
11+
12+
export const getSyncedReleaseNotesResponseJsonPath = () =>
13+
'synced-release-notes-response.json';

0 commit comments

Comments
 (0)