Skip to content

Commit

Permalink
chore(deps-dev): bump typedoc from 0.27.2 to 0.27.5 (#5282)
Browse files Browse the repository at this point in the history
* chore(deps-dev): bump typedoc from 0.27.2 to 0.27.5

Bumps [typedoc](https://github.com/TypeStrong/TypeDoc) from 0.27.2 to 0.27.5.
- [Release notes](https://github.com/TypeStrong/TypeDoc/releases)
- [Changelog](https://github.com/TypeStrong/typedoc/blob/master/CHANGELOG.md)
- [Commits](TypeStrong/typedoc@v0.27.2...v0.27.5)

---
updated-dependencies:
- dependency-name: typedoc
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps-dev): bump typedoc from 0.27.2 to 0.27.5 (#5280)

* chore(deps-dev): bump typedoc from 0.27.2 to 0.27.5

Bumps [typedoc](https://github.com/TypeStrong/TypeDoc) from 0.27.2 to 0.27.5.
- [Release notes](https://github.com/TypeStrong/TypeDoc/releases)
- [Changelog](https://github.com/TypeStrong/typedoc/blob/master/CHANGELOG.md)
- [Commits](TypeStrong/typedoc@v0.27.2...v0.27.5)

---
updated-dependencies:
- dependency-name: typedoc
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix: adapt compress and decompress mechanism

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Zhongpin Wang <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Zhongpin Wang <[email protected]>
  • Loading branch information
dependabot[bot] and ZhongpinWang authored Dec 17, 2024
1 parent 518cc59 commit c05c664
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"turbo": "^2.3.3",
"typedoc": "^0.27.2",
"typedoc": "^0.27.5",
"typescript": "~5.7.2"
},
"resolutions": {
Expand Down
71 changes: 40 additions & 31 deletions scripts/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { resolve, basename, extname } from 'path';
import execa from 'execa';
import { unixEOL } from '@sap-cloud-sdk/util';
import { transformFile } from './util';
import { gunzip, gzip } from 'zlib';
import { deflate } from 'zlib';
import { promisify } from 'util';

const gunzipP = promisify(gunzip);
const gzipP = promisify(gzip);
const deflateP = promisify(deflate);

const docPath = resolve(
JSON.parse(readFileSync('tsconfig.typedoc.json', 'utf8')).typedocOptions.out
Expand Down Expand Up @@ -36,8 +35,8 @@ const isNavigationJs = fileName => basename(fileName) === 'navigation.js';

const pipe =
(...fns) =>
start =>
fns.reduce((state, fn) => fn(state), start);
start =>
fns.reduce((state, fn) => fn(state), start);

async function adjustForGitHubPages() {
const documentationFilePaths = flatten(readDir(resolve(docPath)));
Expand All @@ -57,6 +56,34 @@ async function adjustForGitHubPages() {
htmlPaths.forEach(filePath => removeUnderlinePrefixFromFileName(filePath));
}

/**
* Decompresses Base64-encoded deflate compressed data and parses it into a JSON object.
* @link https://github.com/TypeStrong/typedoc/blob/82449253188582f6b63695fecf608d9887ba1761/src/lib/output/themes/default/assets/typedoc/utils/decompress.ts
*
* @param base64 - The Base64-encoded string representing the deflate-compressed JSON string.
* @returns A promise that resolves to the parsed JSON object.
*/
export async function decompressJson(base64: string) {
const binaryData = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
const blob = new Blob([binaryData]);
const decompressedStream = blob
.stream()
.pipeThrough(new DecompressionStream("deflate"));
const decompressedText = await new Response(decompressedStream).text();
return JSON.parse(decompressedText);
}

/**
* Compresses a JSON-serializable object into a Base64-encoded deflate string.
* @link https://github.com/TypeStrong/typedoc/blob/82449253188582f6b63695fecf608d9887ba1761/src/lib/utils/compress.ts
* @param data - The JSON-serializable object to compress.
* @returns A promise that resolves to a Base64-encoded string of the deflate-compressed data.
*/
export async function compressJson(data: any) {
const gz = await deflateP(Buffer.from(JSON.stringify(data)));
return gz.toString("base64");
}

async function adjustSearchJs(paths) {
const filtered = paths.filter(isSearchJs);
if (filtered.length !== 1) {
Expand All @@ -65,31 +92,22 @@ async function adjustSearchJs(paths) {

await transformFile(filtered[0], async file => {
const dataRegexResult =
/window.searchData = "data:application\/octet-stream;base64,(.*)"/.exec(
/window.searchData = "(.*)";/.exec(
file
);

if (!dataRegexResult) {
throw Error(
`Cannot adjust links in 'search.js'. File content did not match expected pattern.`
);
}

const encodedData = dataRegexResult[1];

const ungzipped = (
await gunzipP(Buffer.from(encodedData, 'base64'))
).toString('utf8');
const searchItems = JSON.parse(ungzipped);

const searchItems = await decompressJson(dataRegexResult[1]);
searchItems.rows.forEach(s => {
s.url = removeUnderlinePrefix(s.url);
});

const encodedAdjustedData = (
await gzipP(JSON.stringify(searchItems))
).toString('base64');
return `window.searchData = "data:application/octet-stream;base64,${encodedAdjustedData}"`;
const encodedAdjustedData = await compressJson(searchItems);
return `window.searchData = "${encodedAdjustedData}"`;
});
}

Expand All @@ -101,23 +119,16 @@ async function adjustNavigationJs(paths) {

await transformFile(filtered[0], async file => {
const dataRegexResult =
/window.navigationData = "data:application\/octet-stream;base64,(.*)"/.exec(
/window.navigationData = "(.*)"/.exec(
file
);

if (!dataRegexResult) {
throw Error(
`Cannot adjust links in 'navigation.js'. File content did not match expected pattern.`
);
}

const encodedData = dataRegexResult[1];

const ungzipped = (
await gunzipP(Buffer.from(encodedData, 'base64'))
).toString('utf8');
const navigationItems = JSON.parse(ungzipped);

const navigationItems = await decompressJson(dataRegexResult[1]);
navigationItems
.filter(n => n.path)
.forEach(n => {
Expand All @@ -127,10 +138,8 @@ async function adjustNavigationJs(paths) {
});
});

const encodedAdjustedData = (
await gzipP(JSON.stringify(navigationItems))
).toString('base64');
return `window.navigationData = "data:application/octet-stream;base64,${encodedAdjustedData}"`;
const encodedAdjustedData = await compressJson(navigationItems);
return `window.navigationData = "${encodedAdjustedData}"`;
});
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9616,10 +9616,10 @@ typedarray@^0.0.6:
resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==

typedoc@^0.27.2:
version "0.27.2"
resolved "https://registry.npmjs.org/typedoc/-/typedoc-0.27.2.tgz#8a4e0303f4c49174af21e981e0b60e8a637d8167"
integrity sha512-C2ima5TZJHU3ecnRIz50lKd1BsYck5LhYQIy7MRPmjuSEJreUEAt+uAVcZgY7wZsSORzEI7xW8miZIdxv/cbmw==
typedoc@^0.27.5:
version "0.27.5"
resolved "https://registry.npmjs.org/typedoc/-/typedoc-0.27.5.tgz#a86c89589213d7b36301eeafb4ddf6ad9dfd1ab3"
integrity sha512-x+fhKJtTg4ozXwKayh/ek4wxZQI/+2hmZUdO2i2NGDBRUflDble70z+ewHod3d4gRpXSO6fnlnjbDTnJk7HlkQ==
dependencies:
"@gerrit0/mini-shiki" "^1.24.0"
lunr "^2.3.9"
Expand Down

0 comments on commit c05c664

Please sign in to comment.