Skip to content

Commit

Permalink
chore(build): update function type definitions
Browse files Browse the repository at this point in the history
This commit updates the way function type definitions are retrieved from TypeScript files. Instead of using the file path derived from the markdown file, we now use the path to the `index.ts` file within the function's package. This is to ensure consistency across all packages and to avoid issues with potential mismatches between file paths and actual exports.

Additionally, we updated the `indexes.json` file to reflect the latest `lastUpdated` timestamps for each package.
  • Loading branch information
Mr.Mao committed Jun 1, 2023
1 parent 3b67c93 commit d2960ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/.vitepress/plugins/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function MarkdownTransform(): Plugin {
}

export async function getFunctionMarkdown(mdPath: string, length: number) {
const types = await getTypeDefinition(mdPath.replace('.md', '.ts'))
const filepath = path.join(path.dirname(mdPath), 'src/index.ts')
const types = await getTypeDefinition(filepath)
let typingSection = ''

if (types) {
Expand Down
21 changes: 7 additions & 14 deletions packages/indexes.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,49 @@
{
"name": "Browser Utils",
"package": "@hairy/browser-utils",
"function": "index.ts",
"lastUpdated": 1685024011000,
"lastUpdated": 1685589170000,
"docs": "/web-browser/",
"description": "浏览器的一些工具函数,挺好用的,至少我认为是这样。"
},
{
"name": "Color Palette",
"package": "@hairy/palette",
"function": "index.ts",
"lastUpdated": 1685024011000,
"lastUpdated": 1685589170000,
"docs": "/util-color/",
"description": "颜色的处理、转换、计算"
},
{
"name": "Format Utils",
"package": "@hairy/format",
"function": "index.ts",
"lastUpdated": 1685024011000,
"lastUpdated": 1685589170000,
"docs": "/util-format/",
"description": "用来格式化一些字符串和数字的工具类,仅此而已。"
},
{
"name": "Hairy Utils",
"package": "@hairy/utils",
"function": "index.ts",
"lastUpdated": 1685024011000,
"lastUpdated": 1685589170000,
"docs": "/util-core/",
"description": "没什么特别的,除了为了让我变懒。"
},
{
"name": "Vue Use",
"package": "@hairy/vueuse",
"function": "index.ts",
"lastUpdated": 1685024011000,
"lastUpdated": 1685589170000,
"docs": "/vue-use/",
"description": "好的工具无需多言,也许我来兴趣了会编写文档?(别想了,我懒得写)"
},
{
"name": "Vue Utils",
"package": "@hairy/vue-utils",
"function": "index.ts",
"lastUpdated": 1685024011000,
"lastUpdated": 1685589170000,
"docs": "/vue-utils/",
"description": "Vue 的一些工具函数,其实没多少。"
},
{
"name": "Wechat Jssdk",
"package": "@hairy/wechat-jssdk",
"function": "index.ts",
"lastUpdated": 1685024011000,
"lastUpdated": 1685589170000,
"docs": "/web-wechat-jssdk/",
"description": "WechatJssdk 构造函数对 [wechat-jssdk](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html) 的 `api` 进行了 `promise` 处理,并且可直接调用,不需要执行 `wx.ready` 等待 `jssdk` 授权完毕。"
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { dirname, join } from 'node:path'
import { rollup } from 'rollup'
import rollupPluginDts from 'rollup-plugin-dts'
import md5 from 'md5'
Expand All @@ -7,7 +8,7 @@ import { dirSrc, formatTypescript, listFunctionMds } from './utils'
export async function updateFunctionTypes() {
const mdPaths = await listFunctionMds(dirSrc, { absolute: true })

const tsPaths = mdPaths.map(v => v.replace('.md', '.ts')).filter(v => fs.existsSync(v))
const tsPaths = mdPaths.map(v => join(dirname(v), 'src/index.ts')).filter(v => fs.existsSync(v))

await fs.ensureDir('node_modules/.cache/types')
for (const tsPath of tsPaths) {
Expand Down

0 comments on commit d2960ce

Please sign in to comment.