Skip to content

Commit

Permalink
feat: 功能调整
Browse files Browse the repository at this point in the history
  • Loading branch information
kongjing committed Apr 14, 2023
1 parent 67d6c91 commit c8797c3
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 78 deletions.
81 changes: 78 additions & 3 deletions antm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,96 @@ export default defineConfig({
docs: {
title: 'antmjs',
src: join(CWD, './packages'),
logo: 'https://fastly.jsdelivr.net/npm/@vant/assets/logo.png',
route: {
level: 2,
exclude: [join(CWD, './packages/doc/**/*.md')],
},
headerLinks: [
{
title: 'https://b.yzcdn.cn/vant/logo/github.svg',
url: 'https://github.com/AntmJS/antm/',
type: 'img',
},
],
menu: getMenus(),
},
})

function getMenus(): IDocMenuNavs {
return [
{
name: '使用指南',
name: '编译相关',
items: [
{
path: 'babel-preset',
title: 'babel-preset 转译js',
},
{
path: 'eslint',
title: 'eslint 代码规范',
},
{
path: 'stylelint',
title: 'stylelint 样式规范',
},
{
path: 'plugin-icestark',
title: 'plugin-icestark 微应用&Taro',
},
{
path: 'plugin-vantui',
title: 'plugin-vantui 适配组件库',
},
{
path: 'plugin-mini-fix',
title: 'plugin-mini-fix 异常处理&Taro',
},
{
path: 'plugin-global-fix',
title: 'plugin-global-fix 支付宝polyfill',
},
],
},
{
name: '运行时相关',
items: [
{
path: 'introduce',
title: '介绍',
path: 'cache',
title: 'cache 缓存',
},
{
path: 'unite',
title: 'unite 简化hooks&Taro',
},
{
path: 'utils',
title: 'utils 通用工具',
},
{
path: 'trace',
title: 'trace 埋点&异常',
},
{
path: 'api',
title: 'api 接口&数据',
},
],
},
{
name: 'cli工具',
items: [
{
path: 'iconfont',
title: 'iconfont 图标样式',
},
{
path: 'warning',
title: 'warning 文件监控',
},
{
path: 'upload-tencent',
title: 'upload-tencent 腾讯云上传',
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"release:beta": "lerna publish --force-publish=* --exact --skip-temp-tag --preid=beta --npm-tag=beta",
"test": "npx lerna run test",
"prepare": "husky install",
"docs:start": "npx ts-node ./packages/doc/scripts/run",
"docs:start": "npx antm-doc-start",
"docs:build": "npx ts-node ./packages/doc/scripts/build",
"release": "npx gh-pages -d doc_build -e ./main"
},
Expand Down
28 changes: 8 additions & 20 deletions packages/doc/config/utils/create-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ function unitWork(mp) {
const moduleFilePath = join(ANTM_TEMP_DIR, `${routeName}.js`)
extraEntrys[routeName] = moduleFilePath
const res = markdownCardWrapper(Markdown.render(mdstr))
const docs = '`' + `${res.html}` + '`'
const docs =
'`' + `${res.html.replace(/\`/g, '::::').replace(/\$\{/g, '::_::')}` + '`'
writeFileSync(
moduleFilePath,
`export default {
Expand Down Expand Up @@ -176,26 +177,15 @@ async function injectGlobalStyles(globalStyles?: string[]) {
*/
function getRoutePath(ps: string): string {
const paths = ps.replace('.md', '')
const arr = paths
.split('/')
.reverse()
.filter((item) => item !== 'README')
const arr = paths.split('/').reverse()
const res: string[] = []
for (let i = 0; i < _level; i++) {
const it = arr[i]
if (it) {
if (it && it !== 'README') {
res.push(it)
}
}

console.info(
paths,
'>>>>>>>>>>',
arr,
'**********************',
res.reverse().join('__'),
)

return res.reverse().join('__')
}
/**
Expand Down Expand Up @@ -258,15 +248,13 @@ function markdownCardWrapper(htmlCode) {

h3Ids.push(h3Title)

const h3Id = encodeURIComponent(h3Title)

const newFragment = fragment.replace(
'<h3>',
`<h3 id="${encodeURIComponent(
h3Title,
)}"><svg viewBox="0 0 1024 1024" width="14" height="14"><path d="M491.054545 779.636364l-125.672727 125.672727c-32.581818 32.581818-76.8 51.2-123.345454 51.2s-90.763636-18.618182-123.345455-51.2c-67.490909-67.490909-67.490909-179.2 0-246.690909l223.418182-223.418182c32.581818-32.581818 76.8-51.2 123.345454-51.2s90.763636 18.618182 123.345455 51.2c13.963636 13.963636 34.909091 13.963636 46.545455 0 13.963636-13.963636 13.963636-34.909091 0-46.545455-93.090909-93.090909-246.690909-93.090909-342.109091 0L69.818182 612.072727c-46.545455 46.545455-69.818182 107.054545-69.818182 169.890909C0 847.127273 25.6 907.636364 69.818182 954.181818c46.545455 46.545455 109.381818 69.818182 169.890909 69.818182 62.836364 0 123.345455-23.272727 169.890909-69.818182l125.672727-125.672727c13.963636-13.963636 13.963636-34.909091 0-46.545455-9.309091-16.290909-30.254545-16.290909-44.218182-2.327272z" p-id="2808"></path><path d="M954.181818 69.818182c-93.090909-93.090909-246.690909-93.090909-342.109091 0l-125.672727 125.672727c-13.963636 13.963636-13.963636 34.909091 0 46.545455 13.963636 13.963636 34.909091 13.963636 46.545455 0L658.618182 116.363636c32.581818-32.581818 76.8-51.2 123.345454-51.2s90.763636 18.618182 123.345455 51.2c67.490909 67.490909 67.490909 179.2 0 246.690909l-223.418182 223.418182c-32.581818 32.581818-76.8 51.2-123.345454 51.2s-90.763636-18.618182-123.345455-51.2c-13.963636-13.963636-34.909091-13.963636-46.545455 0-13.963636 13.963636-13.963636 34.909091 0 46.545455 46.545455 46.545455 109.381818 69.818182 169.89091 69.818182 62.836364 0 123.345455-23.272727 169.890909-69.818182l223.418181-223.418182c46.545455-46.545455 69.818182-107.054545 69.818182-169.890909C1024 176.872727 998.4 116.363636 954.181818 69.818182z" p-id="2809"></path></svg>`,
`<h3 id="${h3Id}"><svg viewBox="0 0 1024 1024" width="14" height="14"><path d="M491.054545 779.636364l-125.672727 125.672727c-32.581818 32.581818-76.8 51.2-123.345454 51.2s-90.763636-18.618182-123.345455-51.2c-67.490909-67.490909-67.490909-179.2 0-246.690909l223.418182-223.418182c32.581818-32.581818 76.8-51.2 123.345454-51.2s90.763636 18.618182 123.345455 51.2c13.963636 13.963636 34.909091 13.963636 46.545455 0 13.963636-13.963636 13.963636-34.909091 0-46.545455-93.090909-93.090909-246.690909-93.090909-342.109091 0L69.818182 612.072727c-46.545455 46.545455-69.818182 107.054545-69.818182 169.890909C0 847.127273 25.6 907.636364 69.818182 954.181818c46.545455 46.545455 109.381818 69.818182 169.890909 69.818182 62.836364 0 123.345455-23.272727 169.890909-69.818182l125.672727-125.672727c13.963636-13.963636 13.963636-34.909091 0-46.545455-9.309091-16.290909-30.254545-16.290909-44.218182-2.327272z" p-id="2808"></path><path d="M954.181818 69.818182c-93.090909-93.090909-246.690909-93.090909-342.109091 0l-125.672727 125.672727c-13.963636 13.963636-13.963636 34.909091 0 46.545455 13.963636 13.963636 34.909091 13.963636 46.545455 0L658.618182 116.363636c32.581818-32.581818 76.8-51.2 123.345454-51.2s90.763636 18.618182 123.345455 51.2c67.490909 67.490909 67.490909 179.2 0 246.690909l-223.418182 223.418182c-32.581818 32.581818-76.8 51.2-123.345454 51.2s-90.763636-18.618182-123.345455-51.2c-13.963636-13.963636-34.909091-13.963636-46.545455 0-13.963636 13.963636-13.963636 34.909091 0 46.545455 46.545455 46.545455 109.381818 69.818182 169.89091 69.818182 62.836364 0 123.345455-23.272727 169.890909-69.818182l223.418181-223.418182c46.545455-46.545455 69.818182-107.054545 69.818182-169.890909C1024 176.872727 998.4 116.363636 954.181818 69.818182z" p-id="2809"></path></svg>`,
)
return `<div class="card">
${newFragment}
</div>`
return `<div class="card">${newFragment}</div>`
}

return fragment
Expand Down
1 change: 1 addition & 0 deletions packages/doc/src/components/pageLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function PageLayout() {
// @ts-ignore
import('../../.temp/antm-doc/markdown-main.js').then((res) => {
setMarkdownMain(res.default)
console.info('DOC_ROUTERS', res.default)
})
}, [])

Expand Down
2 changes: 1 addition & 1 deletion packages/doc/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const Docs = function Docs({
const result = res.default
document.title = result.tile
historyMd = result.docs
setMd(result.docs)
setMd(result.docs.replaceAll('::::', '`').replaceAll('::_::', '${'))
setRightNavs(result.h3Ids.split(':::'))
})
} else if (firstPage) {
Expand Down
106 changes: 53 additions & 53 deletions packages/rapper/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Rapper 是什么?
# Rapper 是什么?

> 注:可以使用@antmjs/api 代替
Expand All @@ -7,15 +7,15 @@ Rapper 是 TypeScript 的最佳拍档,它可以帮你生成具有类型定义
- 无需自行书写请求代码,把 HTTP 接口当做函数调用
- 请求参数/返回数据类型化,静态校验、自动补全快到飞起

## @antmjs/rapper 是什么?
### @antmjs/rapper 是什么?

基于 Rapper 开发,使配置更灵活,同时增加本地类型同步远程文档重要功能

- ++++
- 本地接口类型上传到 rapper 远程文档,本地编码驱动远程文档
- 自定义请求函数模板,满足不同编程规范

## 快速开始
### 快速开始

1. package.json scripts 中 添加
{ "rap" : "npx rapper"}
Expand All @@ -41,7 +41,7 @@ Rapper 是 TypeScript 的最佳拍档,它可以帮你生成具有类型定义

3. 开始写你的 ts 接口类型, 然后执行 npm run rap

## rapper 名称对应 接口 ts 类型介绍
### rapper 名称对应 接口 ts 类型介绍

> ts 接口类型需要配合 rapper 使用
Expand Down Expand Up @@ -98,8 +98,6 @@ export type IUserInfo = {
> 注意 jsDoc 关键字的值中【@】符号由于转义问题需要替换成【#】或者【\\@】或者【/@】
## 文档
### 命令函入参会和 config 合并(命令行优先级更高)
- --u 上传
Expand All @@ -108,65 +106,67 @@ export type IUserInfo = {
### rapper 配置 config 有三种方案
- 方案一(推荐)
通过 antm.config.js 配置 config
```js
<!-- antm.config.js文件 -->
const antmRapper = require('@antmjs/rapper')
<!-- 使用antm 提供 defineConfig 会有类型提示 -->
export.default = antmRapper.defineConfig({
upload: { xx: xx }, // 本地上传 配置
})
```

- 方案二
通过 命令行参数执行 config 路径

```bash
$ npx rapper --config ./config/index.js
```

```js
<!-- ./config/index.js文件 -->
const antmRapper = require('@antmjs/rapper')
<!-- antmRapper 提供 defineConfig 会有类型提示 -->
export.default = antmRapper.defineConfig({
upload: { xx: xx }, // 本地上传 配置
download: { xx: xx } // 远程下载 配置
})
```

- 方案三
通过 package.json 配置 antm.rapper

```js
<!--package.json 文件 -->
{
'antm': {
'rapper': {
'upload': { xx: xx }, // 本地上传 配置
}
}
##### 方案一(推荐)
通过 antm.config.js 配置 config
```js
// <!-- antm.config.js文件 -->
const antmRapper = require('@antmjs/rapper')
// <!-- 使用antm 提供 defineConfig 会有类型提示 -->
export.default = antmRapper.defineConfig({
upload: { xx: xx }, // 本地上传 配置
})
```

##### 方案二

通过 命令行参数执行 config 路径

```bash
$ npx rapper --config ./config/index.js
```

```js
// <!-- ./config/index.js文件 -->
const antmRapper = require('@antmjs/rapper')
// <!-- antmRapper 提供 defineConfig 会有类型提示 -->
export.default = antmRapper.defineConfig({
upload: { xx: xx }, // 本地上传 配置
download: { xx: xx } // 远程下载 配置
})
```

##### 方案三

通过 package.json 配置 antm.rapper

```js
<!--package.json 文件 -->
{
'antm': {
'rapper': {
'upload': { xx: xx }, // 本地上传 配置
}
```
}
}
```

## 本地代码类型同步到远程 raper 文档
### 本地代码类型同步到远程 raper 文档

- 解析本地文件
- fetch 方法追加注释 (接口 id 接口模块 id)
- 格式化 类型
- 调用 rapper 接口

## 增量更新实现
### 增量更新实现

- 每次更新会给文件头部 加一个 MD5 值
- 初始化会检查合法的文件(符合 formatFunc 结构的文件) MD5 值 对不住
- 去解析当前文件以及 依赖当前文件的文件
- 提交变更的模块接口(文件级检查),做不到方法级检查

## config 接口类型
### config 接口类型

```ts
interface IConfig {
Expand Down Expand Up @@ -267,9 +267,9 @@ interface IConfig {
export type IOptions = Partial<IConfig>
```
## defaultConfig 会和传进来的 config 合并补全
### defaultConfig 会和传进来的 config 合并补全
````js
````typescript
const defaultOptions = {
download: {
//请求 function 模板
Expand Down
4 changes: 4 additions & 0 deletions packages/upload-tencent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ module.exports = {

##### 注:会自动生成随机串作为目录以防资源被覆盖

```bash
antm-upload-tencent upload --help

antm-upload-tencent upload --file-path ./a.png [--exclude-regexp "(.+?).map"]

antm-upload-tencent upload --dir ./ [--exclude-regexp "(.+?).map"]
```

### Bundle 上传

##### 注:通过--target-dir 作为目录以防资源被覆盖

```bash
antm-upload-tencent bundle --help

antm-upload-tencent bundle --target-dir \`static/${process.env.API_ENV}/${pkg.name}/${process.env.DEPOLY_VERSION}\` --dir \`./build\` [--exclude-regexp "(.+?).map"]
```

0 comments on commit c8797c3

Please # to comment.