Skip to content

Commit

Permalink
docs: 📚 aPI文档部分完成
Browse files Browse the repository at this point in the history
  • Loading branch information
Plumbiu committed Aug 12, 2023
1 parent ee73e9c commit d81ac7e
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default defineConfig({
],

socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
{ icon: 'github', link: 'https://github.com/truthRestorer/truth-cli' },
],
},
})
21 changes: 0 additions & 21 deletions docs/about/optimize.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,3 @@
```

不只是 `relation`,如果你深入了解 `truth-cli` 生成的文件,`truth-cli` 都对其体积进行了优化

## 生成依赖文件的格式

在项目根目录下运行 `truth-cli analyze --json` 会产生 `pkgs.json` 文件,格式如下:

```json
{
"name": "_root_",
"version": "1.0.0",
"type": 1,
"packages": {
"@antfu/eslint-config": {
"version": "^0.39.8",
"type": 0,
"packages": {
// ...
}
}
}
}
```
134 changes: 133 additions & 1 deletion docs/guide/api.md
Original file line number Diff line number Diff line change
@@ -1 +1,133 @@
# @truth-cli/core
# API 指南

::: tip 首先说明
`truth-cli` 只是一个命令行工具,提供 api 的依赖是 `@truth-cli/core`
:::

## 安装

::: code-group
```bash [npm]
npm install @truth-cli/core
```
```bash [yarn]
yarn add @truth-cli/core
```
```bash [pnpm]
pnpm add @truth-cli/core
```
:::

## genRelations

::: tip API 介绍
`genRelations` 用于生成 `relations` 数据;**后续 API 都需要先调用 `genRelations` 函数**
:::

```ts
function genRelations(): Partial<IRelations>

interface IRelationRepository {
type: string
url: string
[key: string]: string
}

interface IRelations {
name: string
description: string
version: string
dependencies: { [key: string]: string }
devDependencies: { [key: string]: string }
repository: IRelationRepository[]
author: string
homepage: string
[key: string]: any
}
```

> 你可以将 `relations` 数据看作是所有依赖的 `package.json` 的合集
## genGraph

::: tip 功能介绍
`genGraph` 用于生成 `echarts``graph` 图所需要的数据
:::

```ts
declare function genGraph(): {
nodes: INodes[]
links: ILinks[]
}

interface INodes {
name: string
category: number
value: string
symbolSize?: number
}

interface ILinks {
source: string
target: string
v: string
}
```

## genTree

::: tip 功能介绍
`genTree` API 用于生成 `echarts``tree` 图所需要的数据
:::

```ts
declare function genTree(maxDep: number): ITree
interface ITree {
name: string
value: string
children?: ITree[]
}
```

## genVersions

::: tip 功能介绍
`genVersions` 用于生成同一个依赖的多个版本数据
:::

```ts
declare function genVersions(): IVersions
interface IVersions {
[key: string]: {
[key: string]: string[]
}
}
```

## genPkgs

::: tip 功能介绍
`genPkgs` API 用于生成 `pkgs.json` 文件数据
:::

```ts
declare function genPkgs(depth: number): IPkgs

interface IPkgs {
name: string
version: string
type: EDep
packages: IPkgs
[key: string]: any
}
```

## genPkgTree

::: tip 功能介绍
`genPkgTree` API 用于生成树形结构的文本数据,在根目录中生成 `treePkgs.txt`
:::

```ts
declare function genPkgTree(maxDep: number): string
```
12 changes: 6 additions & 6 deletions docs/guide/full.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## analyze 命令

### --dep/-d
### --dep/-d 参数

::: tip 功能介绍
`--dep` 或者 `-d` 参数用于指定依赖引用关系的深度。
`--dep` `-d` 参数用于指定依赖引用关系的深度。
:::

::: code-group
Expand All @@ -17,10 +17,10 @@ truth-cli analyze -d 4
```
:::

### --json/-j
### --json/-j 参数

::: tip 功能介绍
`--json` 或者 `-j` 表示只会生成文件,参数值为生成文件的路径。
`--json` `-j` 表示只会生成文件,参数值为生成文件的路径。
:::


Expand Down Expand Up @@ -61,10 +61,10 @@ truth-cli analyze -j --dep 3
```
:::

### --both/-b
### --both/-b 参数

::: tip 功能介绍
`--both` 或者 `-b` 参数表示生成文件并打开页面。
`--both` `-b` 参数表示生成文件并打开页面。
:::

::: code-group
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ hero:
actions:
- theme: brand
text: 快速开始
link: /markdown-examples
link: /guide/index.md
- theme: alt
text: 查看源码
link: https://github.com/truthRestorer/truth-cli
Expand Down

0 comments on commit d81ac7e

Please sign in to comment.