Skip to content

Commit

Permalink
Merge branch 'tech/doc-generation' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Dec 13, 2024
2 parents 1b16129 + ad05514 commit 88821e4
Show file tree
Hide file tree
Showing 79 changed files with 1,433 additions and 258 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ packages/wallet/next-env.d.ts

# Turbo tmp stuff
.turbo

generated-docs/
Binary file modified bun.lockb
Binary file not shown.
67 changes: 67 additions & 0 deletions docs/replace-external.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
/**
* The external symbol map we want to replace
*/
const symbolMap = {
viem: {
home: "https://viem.sh/docs/getting-started.html",
Address: "https://viem.sh/docs/glossary/types#address",
Hex: "https://viem.sh/docs/glossary/types#hex",
SiweMessage: "https://eips.ethereum.org/EIPS/eip-4361",
},
"@tanstack/react-query": {
home: "https://tanstack.com/query/latest",
useQuery:
"https://tanstack.com/query/v4/docs/framework/react/reference/useQuery",
UseQueryResult:
"https://tanstack.com/query/v4/docs/framework/react/reference/useQuery",
QueryClientProvider:
"https://tanstack.com/query/v4/docs/framework/react/reference/QueryClientProvider",
useMutation:
"https://tanstack.com/query/v4/docs/framework/react/reference/useMutation",
UseMutationResult:
"https://tanstack.com/query/v4/docs/framework/react/reference/useMutation",
},
};

/**
* Add some symbol converter (for viem / tanstack specially)
*/
app.converter.addUnknownSymbolResolver((ref) => {
if (
ref.moduleSource !== "viem" &&
ref.moduleSource !== "@tanstack/react-query"
) {
return;
}
const knownSymbols = symbolMap[ref.moduleSource];

// If someone did {@link viem!} or {@link @tanstack/react-query!}, link them directly to the home page.
if (!ref.symbolReference) {
console.log("Returning home", ref);
return knownSymbols.home;
}

// Otherwise, we need to navigate through the symbol reference to
// determine where they meant to link to. Since the symbols we know
// about are all a single "level" deep, this is pretty simple.
if (!ref.symbolReference.path) {
console.log("No path", ref);
// Someone included a meaning, but not a path.
// https://typedoc.org/guides/declaration-references/#meaning
return;
}

if (ref.symbolReference.path.length === 1) {
const name = ref.symbolReference.path[0].path;
const output = knownSymbols[name];
if (!output) {
console.log("No output", ref, name, knownSymbols[name]);
}
return output;
}
});
}
40 changes: 40 additions & 0 deletions docs/vocs-frontmatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @ts-check
import { ReflectionKind } from "typedoc";
import { MarkdownPageEvent } from "typedoc-plugin-markdown";

/**
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
// Get the generation data that will be pushed in the header (year-month-day)
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const dateStr = `${year}-${month}-${day}`;

// The modal kind we want
const targetModelKink = [
ReflectionKind.Variable,
ReflectionKind.TypeAlias,
ReflectionKind.Function,
];

app.renderer.on(
MarkdownPageEvent.BEGIN,
/** @param {import('typedoc-plugin-markdown').MarkdownPageEvent} page */
(page) => {
// Set the frontmatter options depending on the model kind
if (targetModelKink.includes(page.model?.kind)) {
// Set custom front matter options here
page.frontmatter = {
// Add a few options to the frontmatter section
title: `${page.group} - ${page.model?.name}`,
date: dateStr,
// spread the existing frontmatter
...page.frontmatter,
};
}
}
);
}
114 changes: 114 additions & 0 deletions docs/vocs-sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { writeFileSync } from "node:fs";
import path from "node:path";
import { MarkdownPageEvent } from "typedoc-plugin-markdown";

/**
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
/**
* Slugify each anchor reference in the final markdown generated
*/
app.renderer.on(MarkdownPageEvent.END, (page) => {
page.contents = page.contents?.replace(
/\[([^\]]+)\]\((?!https?:|\/|\.)([^)]*#?[^)]*)\)/g,
(_match, text, url) => {
const urlWithAnchor = url.split("#");
if (urlWithAnchor.length > 1) {
const anchorPart = slugifyAnchor(urlWithAnchor[1]);
return `[${text}](${encodeURI(`${urlWithAnchor[0]}#${anchorPart}`)})`;
}
return `[${text}](${encodeURI(url)})`;
}
);
});

/**
* Generate the sidebar ts file
*/
app.renderer.postRenderAsyncJobs.push(async (output) => {
if (!output.navigation) return;

const outDir = app.options.getValue("out");
const basePath = app.options.getValue("publicPath");
const sidebarPath = path.resolve(outDir, "references-sidebar.json");

const sidebar = output.navigation.map((navigationItem) =>
getNavigationItem(navigationItem, basePath)
);
writeFileSync(sidebarPath, JSON.stringify(sidebar, null, 4));
});
}

/**
* Helper to slugify the anchor
* - From https://github.com/typedoc2md/typedoc-plugin-markdown/blob/5bd12c8670969726095417413bac5ab69efd12b5/packages/typedoc-vitepress-theme/src/utils/utils.ts#L6
* @param str
*/
export const slugifyAnchor = (str) =>
str
.normalize("NFKD")
// Remove accents
// biome-ignore lint/suspicious/noMisleadingCharacterClass: False positive
.replace(/[\u0300-\u036F]/g, "")
// Remove control characters
// biome-ignore lint/suspicious/noControlCharactersInRegex: Exactly what we want to do, remove control char from the text
.replace(/[\u0000-\u001f]/g, "")
// Replace special characters
.replace(/[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g, "-")
// Remove continuos separators
.replace(/-{2,}/g, "-")
// Remove prefixing and trailing separators
.replace(/^-+|-+$/g, "")
// ensure it doesn't start with a number (#121)
.replace(/^(\d)/, "_$1")
// lowercase
.toLowerCase();

/**
* @param {import('typedoc-plugin-markdown').NavigationItem} navigationItem
* @param {string} basePath
*/
function getNavigationItem(navigationItem, basePath) {
const hasChildren = navigationItem?.children?.length;

const linkParts = [];

if (navigationItem?.path) {
if (basePath.length) {
linkParts.push(basePath);
}
linkParts.push(
getParsedUrl(navigationItem.path)
.replace(/\\/g, "/")
.replace(".mdx", "")
);
}

// Get all the childrens of the navigation item
let items = navigationItem.children?.map((group) =>
getNavigationItem(group, basePath)
);

// If it only has one items, and this items has sub items, directly use the sub items
if (items?.length === 1 && items[0].items) {
items = items[0].items;
}

return {
text: navigationItem.title,
...(linkParts.length && {
link: `${linkParts.join("/")}`,
}),
items,
// All navigation are collapsed by default
...(hasChildren && { collapsed: true }),
};
}

function getParsedUrl(url) {
if (path.basename(url) === "index.md") {
return `${path.dirname(url)}/`;
}
return url;
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@
"@changesets/changelog-git": "^0.2.0",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.7",
"@pulumi/aws": "^6.60.0",
"@pulumi/pulumi": "^3.141.0",
"@types/node": "^22.0.0",
"knip": "^5.27.0",
"npm-check-updates": "^16.14.20",
"rimraf": "^6.0.1",
"sst": "3.3.28",
"typescript": "^5.6.2",
"@pulumi/aws": "^6.60.0",
"@pulumi/pulumi": "^3.141.0"
"typedoc": "^0.27.4",
"typedoc-plugin-frontmatter": "^1.1.2",
"typedoc-plugin-inline-sources": "^1.2.0",
"typedoc-plugin-markdown": "^4.3.2",
"typescript": "^5.6.2"
},
"workspaces": [
"packages/*",
Expand Down
2 changes: 1 addition & 1 deletion sdk/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"keywords": [
"frak-labs",
"nexus-wallet",
"erc-4337",
"erc-frak",
"eip-4337",
"smart-wallet",
"components",
Expand Down
44 changes: 43 additions & 1 deletion sdk/components/src/ButtonShare/ButtonShare.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { useCallback, useEffect, useState } from "preact/hooks";
import { getModalBuilderSteps, onClientReady } from "../utils";

/**
* The props type for {@link ButtonShare}.
* @inline
*/
type ButtonShareProps = {
text: string;
/** Text to display on the button */
text?: string;
/** Classname to apply to the button */
classname?: string;
};

/**
* Open the share modal
*
* @description
* This function will open the share modal with the configuration provided in the `window.FrakSetup.modalShareConfig` object.
*/
function modalShare() {
const modalBuilderSteps = getModalBuilderSteps();

Expand All @@ -19,6 +31,36 @@ function modalShare() {
.display();
}

/**
* Button to share the current page
*
* @param args
* @param args.text - Text to display on the button
* @param args.classname - Classname to apply to the button
* @returns The share button with `<button>` tag
*
* @group components
*
* @example
* Basic usage:
* ```html
* <frak-button-share></frak-button-share>
* ```
*
* @example
* Using a custom text:
* ```html
* <frak-button-share text="Share and earn!"></frak-button-share>
* ```
*
* @example
* Using a custom class:
* ```html
* <frak-button-share classname="button button-primary"></frak-button-share>
* ```
*
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the underlying action
*/
export function ButtonShare({
text = "Share and earn!",
classname = "",
Expand Down
2 changes: 1 addition & 1 deletion sdk/components/src/components.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupClient } from "@core/utils";
import { setupClient } from "@core/clients";
import { onDocumentReady } from "@module/utils/onDocumentReady";
import {
dispatchClientReadyEvent,
Expand Down
5 changes: 3 additions & 2 deletions sdk/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
This SDK help any dApps, or gated content provider, use the [Frak Wallet](https://wallet.frak.id/) as a regular wallet, with smoother UX for your end-users (pay for his gas fees, check the paywall options, track his consumption etc.)

Checkout our documentation for more information's about the usage:
- [React client usage](https://docs.frak.id/wallet-sdk/react/start)
- [Core client usage](https://docs.frak.id/wallet-sdk/js/start)
- [React client usage](https://docs.frak.id/wallet-sdk/getting-started/react)
- [Core client usage](https://docs.frak.id/wallet-sdk/getting-started/javascript)
- [CDN / Browser usage](https://docs.frak.id/wallet-sdk/getting-started/cdn)
2 changes: 1 addition & 1 deletion sdk/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"homepage": "https://docs.frak.id/wallet-sdk/overview",
"keywords": [
"frak-labs",
"nexus-wallet",
"frak-wallet",
"erc-4337",
"eip-4337",
"smart-wallet"
Expand Down
Loading

0 comments on commit 88821e4

Please sign in to comment.