Skip to content

Commit

Permalink
docs: migrate website on new template
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Nov 30, 2024
1 parent 607a470 commit 83aafa5
Show file tree
Hide file tree
Showing 114 changed files with 12,613 additions and 19,875 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ jobs:
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.test_number }}
parallel: true
flag-name: "@tsed/logger"
path-to-lcov: './packages/logger/coverage/lcov.info'

coveralls:
needs: test
Expand Down
17 changes: 15 additions & 2 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
api
.vuepress/public/api.json
dist
.vitepress/public/api.json
.vitepress/cache
.vitepress/dist
public/api.json

# Yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/cache
!.yarn/sdks
!.yarn/versions

Empty file removed docs/.nojekyll
Empty file.
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};
}
};
41 changes: 41 additions & 0 deletions docs/.templates/page/page.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
meta:
- name: keywords
description: api typescript node.js documentation <%- symbol.symbolName %> <%- symbol.symbolType %>
---

<script setup>
import ApiIcon from "@tsed/vitepress-theme/atoms/api-icon/ApiIcon.vue";
</script>

<div class="flex space-x-3">
<ApiIcon type="<%- symbol.symbolType %>" class="mt-3" />
<div>
<h1><%- symbol.symbolName %></h1>
<div class="module-name"><%- symbol.module.moduleName %></div>
</div>
</div>

<%- 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 %>
<% } %>
26 changes: 26 additions & 0 deletions docs/.templates/symbol-member/symbol-member.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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()
.replace("?", "") : "",
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 && 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 && 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
};
}
};
7 changes: 7 additions & 0 deletions docs/.vitepress/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"singleQuote": false,
"bracketSpacing": false,
"trailingComma": "none",
"arrowParens": "always"
}
42 changes: 42 additions & 0 deletions docs/.vitepress/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {mapApiReferences} from "@tsed/vitepress-theme/composables/api/mappers/mapApiReferences.js";
import api from "../public/api.json";

const IS_CORES = /@tsed\/logger$/;

export function getSidebar() {
const coreModules = [];
const thirdParties = [];

Object.entries(mapApiReferences(api).modules)
.forEach(([module, {symbols}]) => {
const item = {
text: module,
collapsed: true,
items: symbols.map((symbol) => {
return {
text: symbol.symbolName,
link: symbol.path
};
})
};


if (IS_CORES.test(module)) {
coreModules.push(item);
} else {
thirdParties.push(item);
}
});

return [
{
text: "Core",
items: coreModules.sort((a, b) => a.text.localeCompare(b.text))
},
{
text: "Third parties",
items: thirdParties.sort((a, b) => a.text.localeCompare(b.text))
}
];
}

Loading

0 comments on commit 83aafa5

Please sign in to comment.