npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@esydoc/plugin-codegen

v2.1.3

Published

> TODO: description

Downloads

96

Readme

@esydoc/plugin-codegen

A jsdoc plugin for schedule resolver to codeGen.

CodeGenScheduler

Hooks

学习 CodeGenScheduler Hooks 知识时,建议先了解下 tapable 的 hooks 有什么类型和作用。

import { AsyncParallelHook, SyncHook, SyncWaterfallHook } from 'tapable'

class CodeGenScheduler {
  hooks = {
    schedule: new SyncHook<ScheduledData>(['resolverData']), // 调度时触发
    resolve: new SyncWaterfallHook<ApiSource>(['apiSource']), // 解析 api 信息触发
    emit: new AsyncParallelHook<[SourceUpdateRsp[]]>(['results']), // emit 时触发
    collect: new SyncWaterfallHook<ConfigCollect>(['apiConfig']), // 收集配置时触发
  }
}

// 数据结构
export type ApiSource = {
  path: string,
  name: string,
  parent: string | null,
  filename: string
  configPath?: string
}

export type ApiInfo<T> = {
  apiConfig: T | null
  source: ApiSource
} 

export type SourceUpdateRsp = {
  key: string
  status: 'success' | 'fail'
  msg?: string
}

type ScheduledData<T = any> = {
  doclet: any
  ast: {
    args?: TransformedDataTreeNode
    ret?: TransformedDataTreeNode
  } | null
  config: ApiInfo<T>
}

type ConfigCollect = {
  update: boolean
  apiConfig: any
}

有上述提供的 hooks ,就可以开发相应的 resolver 和 scheduler plugin 啦~

resolver开发教程请戳这里, scheduler plugin 教程 请看下列例子:

开发

import { CodeGenScheduler, ApiSource } from '@esydoc/plugin-codegen'

const HyextLifeCircleSet = new Set([
  'onLoad',
  'onUnload',
  'onEnterForeground',
  'onLeaveForeground',
  'onAppear',
  'onDisappear',
])

class HyextCodeGenPlugin {
  apply(scheduler: CodeGenScheduler) {
    scheduler.hooks.resolve.tap(
      'HyextCodeGenPlugin',
      (apiSource: ApiSource) => {
        if (apiSource.parent === null) {
          if (HyextLifeCircleSet.has(apiSource.name)) {
            apiSource.parent = 'lifeCircle'
          } else {
            apiSource.parent = 'global'
          }
          apiSource.filename = `${apiSource.parent}.${apiSource.name}`
        }
        return apiSource
      }
    )
  }
}

export default HyextCodeGenPlugin

使用

const HYExtSchedulerPlugin = require('./plugins/HYExtSchedulerPlugin').default

const esydocConfig = {
  plugins: [
    new HYExtSchedulerPlugin()
  ]
}

这个插件的作用就是通过修改 apiSource,去改变接口的信息,改变其渲染的结果。

note: scheduler plugin 适合承担一些全局的操作,而 resolver 不合适,resolver的设计理念是彼此独立,不回去修改 元数据(apiSource...),这样子会影响其他resolver解析的结果。

Helper

scheduler.helper

  • helper.perttyCode(code: string): string - 格式化代码
  • helper.addFile(dist: string, content: string): Promise - 输出文件