Skip to content

Commit

Permalink
Add api
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaitanLyss committed Sep 19, 2024
1 parent 7082829 commit 124b42a
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dist/

tmp/
src/content/docs/api/
src/content/docs/developper/api/

# dependencies
node_modules/
Expand Down
150 changes: 126 additions & 24 deletions astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import { loadEnv, type Plugin } from "vite";
import starlightTypeDoc, { typeDocSidebarGroup } from "starlight-typedoc";
import starlightTypeDoc, {
createStarlightTypeDocPlugin,
typeDocSidebarGroup,
type StarlightTypeDocOptions,
} from "starlight-typedoc";
import {} from 'typedoc'
import { execSync } from "child_process";
import fs from "fs";
import type { StarlightPlugin } from "@astrojs/starlight/types";
const {
SITE_ORIGIN,
BASE_PATH = "/",
Expand All @@ -18,28 +24,85 @@ console.log("BASE_PATH", BASE_PATH);
console.log("SIMPLIFIED_URL", SIMPLIFIED_URL);
const dev = import.meta.env.MODE === "development";

const [testStarlightTypeDoc, testTypeDocSidebarGroup] =
createStarlightTypeDocPlugin();
const [commonsStarlightTypeDoc, commonsTypeDocSidebarGroup] =
createStarlightTypeDocPlugin();
const [graphEditorStarlightTypeDoc, graphEditorTypeDocSidebarGroup] =
createStarlightTypeDocPlugin();

function getRepo({ repoUrl, output }: { repoUrl: string; output: string }) {
const dir = `tmp/${output}`;
console.log("Getting sources from", repoUrl, "into", dir);
if (fs.existsSync(dir)) {
execSync("git pull", { cwd: dir });
} else
execSync(
`git clone ${repoUrl} ${dir}`
);
execSync(`cd ${dir} && bun install`);
}
function typedocRepo({
repoUrl,
output,
options
}: {
repoUrl: string;
output: string;
options?: Partial<StarlightTypeDocOptions>
}): StarlightPlugin {
getRepo({ repoUrl, output });
return createStarlightTypeDocPlugin()[0]({
entryPoints: [`tmp/${output}/src/lib`],
tsconfig: `tmp/${output}/tsconfig.json`,
// watch: true,
output: `developper/api/${output}`,
pagination: true,
typeDoc: {
entryPointStrategy: "expand",
plugin: [
"typedoc-plugin-mdn-links",
"typedoc-plugin-frontmatter",
"./src/plugins/frontmatter.js",
],
// entryFileName: "@selenite/commons",
// navigation: {
// excludeReferences: true,
// },
exclude: ["**/*.test.ts"],
skipErrorChecking: true,
outputFileStrategy: "modules",
categorizeByGroup: true,
useCodeBlocks: true,
},
sidebar: {
collapsed: true,
label: "Commons",
},
...options,
});
}
// https://astro.build/config
export default defineConfig({
site: SITE_ORIGIN,
base: BASE_PATH,
integrations: [
{
name: "get-selenite-sources",
hooks: {
"astro:config:setup": () => {
console.log("yo");
if (fs.existsSync("tmp/commons")) {
execSync('git pull', {cwd: 'tmp/commons'});
console.log('pull');
}
else
execSync(
"git clone https://github.com/Selenite-GEOS/commons.git tmp/commons"
);
execSync("cd tmp/commons && bun install");
},
},
},
// {
// name: "get-selenite-sources",
// hooks: {
// "astro:config:setup": () => {
// console.log("yo");
// if (fs.existsSync("tmp/commons")) {
// execSync("git pull", { cwd: "tmp/commons" });
// console.log("pull");
// } else
// execSync(
// "git clone https://github.com/Selenite-GEOS/commons.git tmp/commons"
// );
// execSync("cd tmp/commons && bun install");
// },
// },
// },
starlight({
title: "Selenite Docs",
logo: {
Expand All @@ -48,11 +111,38 @@ export default defineConfig({
},
plugins: [
// Generate the documentation.
starlightTypeDoc({
entryPoints: ["tmp/commons/src/lib/index.ts"],
tsconfig: "tmp/commons/tsconfig.json",
output: 'api/commons'
typedocRepo({
repoUrl: "https://github.com/Selenite-GEOS/commons.git",
output: "commons",
}),
typedocRepo({
repoUrl: "https://github.com/Selenite-GEOS/graph-editor.git",
output: "graph-editor",
options: {
entryPoints: ["tmp/graph-editor/src/lib/graph-editor"],
},
}),
// testStarlightTypeDoc({
// entryPoints: ["tmp/test/src/lib"],
// tsconfig: "tmp/test/tsconfig.json",
// // watch: true,
// output: "developper/api/test",
// pagination: true,
// typeDoc: {
// entryPointStrategy: "expand",
// // entryFileName: "@selenite/commons",
// // navigation: {
// // excludeReferences: true,
// // },
// outputFileStrategy: "modules",
// categorizeByGroup: true,
// useCodeBlocks: true,
// },
// sidebar: {
// collapsed: true,
// label: "Test",
// },
// }),
],
// < link rel = "preconnect" href = "https://fonts.googleapis.com" >
// <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
Expand Down Expand Up @@ -89,13 +179,25 @@ export default defineConfig({
},
{
label: "Developper",
autogenerate: { directory: "developper" },
items: [
{
label: "Components",
link: "/developper/components",
},
{
label: "API",
autogenerate: {
directory: "developper/api",
},
collapsed: true,
},
],
collapsed: true,
translations: {
fr: "Développeur",
},
},
// Add the generated sidebar group to the sidebar.
typeDocSidebarGroup,
// {
// label: "Reference",
// autogenerate: { directory: "reference" },
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
},
"dependencies": {
"@astrojs/check": "0.9.3",
"@astrojs/starlight": "0.28.1",
"@astrojs/starlight": "0.27",
"astro": "4.15.8",
"lightningcss": "^1.26.0",
"sharp": "^0.32.5",
"starlight-typedoc": "^0.16.0",
"typedoc": "^0.26.7",
"typedoc-plugin-frontmatter": "^1.0.0",
"typedoc-plugin-markdown": "^4.2.7",
"typedoc-plugin-mdn-links": "^3.2.12",
"typescript": "^5.5.4"
},
"devDependencies": {
Expand Down
22 changes: 22 additions & 0 deletions src/plugins/frontmatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MarkdownPageEvent } from 'typedoc-plugin-markdown'

/** @param {import('typedoc-plugin-markdown').MarkdownApplication} app */
export function load(app) {
const re = RegExp(/([^\/]+?)(?:.svelte)?$/)
app.renderer.on(
MarkdownPageEvent.BEGIN,
/** @param {MarkdownPageEvent} page */
(page) => {
// Customize the frontmatter for a specific page.
const match = re.exec(page.model.name)
if (!match)
{
console.warn('unsupported name', page.model.name)
return;
}
page.model.name = match[1]
// console.log(page.model.name, page.model.url)
},

)
}

0 comments on commit 124b42a

Please sign in to comment.