Skip to content

Commit

Permalink
chore: add template to build doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Oct 29, 2024
1 parent 19ee58b commit 49caea4
Show file tree
Hide file tree
Showing 38 changed files with 337 additions and 87 deletions.
3 changes: 3 additions & 0 deletions docs/.templates/code-highlight/code-highlight.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```ts
<%- code %>
```
11 changes: 11 additions & 0 deletions docs/.templates/code-highlight/code-highlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {stripsComments} from "@tsed/ts-doc/src/utils/strips.js";

export default {
name: "codeHighlight",
trim: false,
method(overview, symbolName, deprecated) {
return {code: stripsComments(overview
.replace(/( )+#private;\n/gi, ""))
.replace(/\n( )+\n/gi, '\n'), deprecated};
}
};
30 changes: 30 additions & 0 deletions docs/.templates/page/page.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
meta:
- name: keywords
description: api typescript node.js documentation <%- symbol.symbolName %> <%- symbol.symbolType %>
---
# <%- symbol.symbolLabel %> <%- symbol.symbolName %>

<%- components.symbolSummary(symbol) %>
<% if(symbol.overview) { %>
## Overview
<%- components.codeHighlight(symbol.overview, symbol.symbolName) %>
<% }
if (hasParams) { %>
<%- components.symbolParams(params, symbol.overview) %>
<% }
if (description) { %>
<!-- Description -->
## Description
<%- description %>
<% }
if (symbol.members.length) { %>
<!-- Members -->
<%- components.symbolMembers(symbol) %>
<% } %>
21 changes: 21 additions & 0 deletions docs/.templates/page/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
name: "page",
trim: false,
method(symbol) {
let params = [],
hasParams = false;
let description = symbol.description || "";

if (symbol.symbolType === "function" || symbol.symbolType === "decorator") {
params = symbol.getParams();
hasParams = params.length && symbol.overview.match(/\((.*)\):/);
}

return {
params,
hasParams,
symbol,
description
};
}
};
25 changes: 25 additions & 0 deletions docs/.templates/page/page.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%- components.symbolHeader(symbol) %>
<!-- summary -->
<%- components.symbolSummary(symbol) %>
<!-- overview -->
<% if(symbol.overview) { %>

### Overview

<%- components.codeHighlight(symbol.overview, symbol.symbolName) %>
<% } %>
<!-- Parameters -->
<% if (hasParams) { %>
<%- components.symbolParams(params, symbol.overview) %>
<% } %>
<!-- Description -->
<% if (description) { %>

### Description

<%- description %>
<% } %>
<!-- Members -->
<% if (symbol.members.length) { %>
<%- components.symbolMembers(symbol) %>
<% } %>
1 change: 1 addition & 0 deletions docs/.templates/symbol-header/symbol-header.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Badge text="<%- symbol.symbolLabel %>" type="<%- symbol.symbolType %>"/> <%- labels.map((label) => components.symbolLabel(label)).join(' ') %>
28 changes: 28 additions & 0 deletions docs/.templates/symbol-header/symbol-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default {
name: "symbolHeader",
trim: true,
method(symbol) {
const ignoreLabels = ["type", "returns", "decorator", "param", "constructor"];
const id = symbol.symbolName.replace(/ /gi, "").toLowerCase();
let isPrivateAdded;

const labels = (symbol.labels || [])
.filter((label) => ignoreLabels.indexOf(label.key) === -1)
.filter((label) => {
if (label.key === "private" && !isPrivateAdded) {
isPrivateAdded = true;
return true;
}
if (label.key === "private") {
return !isPrivateAdded;
}
return true;
});

return {
id,
symbol,
labels
};
}
};
1 change: 1 addition & 0 deletions docs/.templates/symbol-label/symbol-label.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Badge text="<%- label.key %>" title="<%- label.value %>" type="<%- label.key %>"/>
7 changes: 7 additions & 0 deletions docs/.templates/symbol-label/symbol-label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
name: "symbolLabel",
trim: true,
method(label) {
return {label};
}
};
9 changes: 9 additions & 0 deletions docs/.templates/symbol-member/symbol-member.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## <%- title %>

<%- components.codeHighlight(member.overview.trim(), undefined) %>
<% if (hasParams) { %>
<%- components.symbolParams(member.params, member.overview) %>
<% } %>
<% if (member.description) { %>
<%- member.description %>
<% } %>
25 changes: 25 additions & 0 deletions docs/.templates/symbol-member/symbol-member.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default {
name: "symbolMember",
method(member) {
let deprecated = false;
const hasParams = member.params.length && member.overview.match(/\((.*)\):/);

if (member.labels) {
if (member.labels.find((k) => k.key === "deprecated")) {
deprecated = true;
}
}

const title = member.overview.match(/(.*)(\(|\?|=|:)+/)

return {
title: title ? title[1]
.split("(")[0]
.split("<")[0]
.trim() : "",
member,
deprecated,
hasParams
};
}
};
19 changes: 19 additions & 0 deletions docs/.templates/symbol-members/symbol-members.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%# Constructor %>
<% if (hasConstructor) { %>
## Constructor
<% if (hasConstructorOverview) { %>
<%- components.codeHighlight(construct.overview) %>
<% } %>
<% if (construct.description) { %>
<%- construct.description %>
<% } %>
<% } %>
<% if (members.length) { %>
<% members.forEach((member, index, map) => { %>
<%- components.symbolMember(member) %>
<% }) %>
<% } %>
20 changes: 20 additions & 0 deletions docs/.templates/symbol-members/symbol-members.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
name: "symbolMembers",
trim: false,
method(symbol) {
const flattenMembers = symbol.getMembers();
const construct = flattenMembers.filter((member) => member.overview.match("constructor"))[0];
const hasConstructor = construct && (construct.description || !construct.overview.match("constructor()"));
let hasConstructorOverview = hasConstructor && construct.overview.match("constructor()");
const members = flattenMembers
.filter((member) => !member.overview.includes("#private"))
.filter((member) => !member.overview.match("constructor"));

return {
hasConstructor,
hasConstructorOverview,
members,
construct
};
}
};
6 changes: 6 additions & 0 deletions docs/.templates/symbol-params/symbol-params.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<% params.forEach(param => { %>
- **<%- param.paramKey %>** (<%- param.type %>): <%- param.description %>
<% }) %>
39 changes: 39 additions & 0 deletions docs/.templates/symbol-params/symbol-params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

export default {
name: "symbolParams",
trim: false,
method(params, overview) {
const signatureMatch = overview.match(/\((.*)\):/);
const signature = signatureMatch[1] + ",";

params = params.map((param) => {
const matched = signature.match(new RegExp(`${param.paramKey}(\\?)?:?(.[^,]+),`));
const type = (param.type || matched[2] ? matched[2].trim() : "")
.split("|")
.map((type) => {
// type = bindSymbols(type.trim(), "");

// if (type.startsWith("<") && type.endsWith(">")) {
// return type;
// }

return `\`${type.trim()}\``.trim();
})
.join(" | ");

const description = (matched[1] ? "Optional. " : "") + param.description.replace(/Optional\.?/gi, "").trim();

return {
param,
signature,
paramKey: param.paramKey,
type: type,
description
};
});

return {
params
};
}
};
7 changes: 7 additions & 0 deletions docs/.templates/symbol-summary/symbol-summary.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Usage

```typescript
import { <%- symbol.symbolName %> } from "<%- symbol.importFrom %>";
```

> See [<%- symbol.relativePath %>](<%- symbol.githubUrl %>).
9 changes: 9 additions & 0 deletions docs/.templates/symbol-summary/symbol-summary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
name: "symbolSummary",
trim: false,
method(symbol) {
return {
symbol
};
}
};
17 changes: 10 additions & 7 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ export default defineConfig({
// ['link', { rel: 'icon', type: 'image/svg+xml', href: '/tsed.svg' }],
["link", {rel: "icon", type: "image/png", href: "/tsed-og.png"}],
["link", {rel: "shortcut icon", href: "/favicon.ico", type: "image/x-icon"}],
["link", {rel: "icon", href: "/favicon.ico", type: "apple-touch-icon"}],
["link", {rel: "icon", href: "/apple-touch-icon.png", type: "image/x-icon", sizes: "180x180"}],
["link", {rel: "icon", href: "/favicon-32x32.png", type: "image/png", sizes: "32x32"}],
["link", {rel: "icon", href: "/favicon-16x16.png", type: "image/png", sizes: "16x16"}],
["link", {rel: "icon", href: "/icon512_maskable.png", type: "apple-touch-icon"}],
["link", {rel: "icon", href: "/icon512_maskable.png", type: "image/x-icon", sizes: "512x512"}],
["meta", {name: "theme-color", content: "#5f67ee"}],
["meta", {property: "og:type", content: "website"}],
["meta", {property: "og:locale", content: "en"}],
Expand All @@ -31,8 +29,8 @@ export default defineConfig({
themeConfig: {
logo: "/tsed.svg",
siteTitle: false,
apiUrl: "https://tsed.io/api.json",
apiRedirectUrl: "https://api-docs.tsed.io",
apiUrl: "http://localhost:5173/api.json",
apiRedirectUrl: "",
repo: "tsedio/tsed",
githubProxyUrl: "https://api.tsed.io/rest/github/tsedio/tsed",
editLink: {
Expand Down Expand Up @@ -163,7 +161,8 @@ export default defineConfig({
link: `/docs/testing`
},
{text: "Upload files", link: "/docs/upload-files"},
{text: "Customize 404", link: "/docs/not-found-page"}
{text: "Customize 404", link: "/docs/not-found-page"},
{text: "Api references", link: "/api"},
]
},
{
Expand Down Expand Up @@ -433,6 +432,10 @@ export default defineConfig({
{
text: "Customize 404",
link: "/docs/not-found-page"
},
{
text: "Api references",
link: "/api"
}
]
}
Expand Down
21 changes: 21 additions & 0 deletions docs/api.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {defineLoader} from "vitepress";
import * as fs from "node:fs/promises";
import {mapApiReferences} from "@tsed/vitepress-theme/composables/api/mappers/mapApiReferences";
import type {ApiResponse} from "@tsed/vitepress-theme/composables/api/interfaces/Api";

export interface Data extends ApiResponse {
// data type
}

declare const data: Data;
export {data};

export default defineLoader({
watch: ["./public/api.json"],
async load(watchedFiles) {
// fetch remote data
const response = JSON.parse(await fs.readFile(watchedFiles[0], {encoding: "utf-8"}));

return mapApiReferences(response);
}
});
14 changes: 14 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: page
meta:
- name: description
content: Api Reference of Ts.ED. Use decorator to build your model and map data.
- name: keywords
content: api reference model decorators ts.ed express typescript node.js javascript jsonschema json mapper serialization deserialization
---

<script setup>
import {data} from './api.data';
</script>

<Api :modules="data.modules" :symbol-types="data.symbolTypes" />
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"docs:preview": "vitepress preview ."
},
"dependencies": {
"@tsed/vitepress-theme": "1.0.8",
"@tsed/vitepress-theme": "1.2.2",
"@vueuse/core": "10.11.0",
"axios": "1.7.7",
"lodash": "4.17.21",
Expand Down
Binary file removed docs/public/apple-touch-icon.png
Binary file not shown.
Binary file added docs/public/icon512_maskable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/tsed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@tsed/docs-new@workspace:."
dependencies:
"@tsed/vitepress-theme": "npm:1.0.8"
"@tsed/vitepress-theme": "npm:1.2.0"
"@vueuse/core": "npm:10.11.0"
autoprefixer: "npm:^10.4.19"
axios: "npm:1.7.7"
Expand All @@ -746,14 +746,14 @@ __metadata:
languageName: unknown
linkType: soft

"@tsed/vitepress-theme@npm:1.0.8":
version: 1.0.8
resolution: "@tsed/vitepress-theme@npm:1.0.8"
"@tsed/vitepress-theme@npm:1.2.0":
version: 1.2.0
resolution: "@tsed/vitepress-theme@npm:1.2.0"
dependencies:
"@vueuse/core": "npm:10.11.0"
axios: "npm:1.7.7"
lucide-vue-next: "npm:^0.436.0"
checksum: 10/b20cba3e438419347298dc76ad8460eec78e04a3021f466943b04fc70b032fbdc139a82b4a46c313411ab32b2800a839436ac822f14e79466e3ed1d9d7ecf376
checksum: 10/acac9f8f7f0ef8a17311e6fd0991cb6f3c5fdb45bd17d065b78836eaedec674f2d68c6accca756baab01f5c413d92992eff19cb0fa64a26005fa1aa84fbe95c3
languageName: node
linkType: hard

Expand Down
Loading

0 comments on commit 49caea4

Please sign in to comment.