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

emp-proptypes-docgen-plugin

v0.0.35

Published

A webpack plugin to inject react typescript docgen information in cweb.

Downloads

55

Readme

Install

npm install --save-dev emp-proptypes-docgen-plugin
# or
yarn add -D emp-proptypes-docgen-plugin

使用

const ts = require("typescript");
const EmpPropTypesDocgenPlugin = require("emp-proptypes-docgen-plugin").default;
const {node_modulesPropFilter} = require("emp-proptypes-docgen-plugin");

module.exports = {
  plugins: [
    // Will default to loading your root tsconfig.json
    new EmpPropTypesDocgenPlugin(),
    // or with a specific tsconfig
    new EmpPropTypesDocgenPlugin({ tsconfigPath: "./tsconfig.dev.json" }),
    // or with compiler options
    new EmpPropTypesDocgenPlugin({
      compilerOptions: { jsx: ts.JsxEmit.Preserve }
    })
    // 新版默认关闭组件内联挂载,需要手动开启
    new EmpPropTypesDocgenPlugin({
      inlineWithComponent: true
    })
    new EmpPropTypesDocgenPlugin({
      include: [path.resolve(__dirname, './src/**/*.tsx')],
      // 忽略node_modules的ts生成,用于缩减产物大小
      propFilter: node_modulesPropFilter(prop)
    })
  ]
};

支持直接推导的类型

| Props 类型 | 表单控件 | | ------------------- | --------------------- | | string | Input | | number | InputNumber | | boolean | Switch | | React.CSSProperties | StyleEdit(样式编辑器) | | enum , 'a' \| 'b' | Select |

常用 JSDoc 规范

| 常用注释类型 | 作用 | | -------------------- | -------------------------------------- | | @default | 指定默认值 | | @desc / @description | 指定参数描述 | | @type | 默认从类型值直接推断,指定@type 时优先 |

例子

分离到 emp.docgen.json

组件内联生成例子

生成组件名称和描述

empPropTypes.defined.description

/**
 * @label 礼物图标
 * @desc 营收礼物图标
 * @visibleName PropsIcon
 */
export const PropsIcon = (props: PropsIconType) => {}

      ↓ ↓ ↓ ↓ ↓ ↓

PropsIcon.empPropTypes = {
  "defined": {
    "description": "营收礼物图标"
  },
  "name": "PropsIcon",
  "props": {...}
}

生成组件参数

empPropTypes.props

// 通过类型获取`description`和`type`
export type PropsIconType = {
  /**
   *  @type {EmpPropTypes.Upload}
   *  @default https://www.baidu.com/icon.png
   *  @desc 图标地址
   */
  iconUrl: string;
}
      ↓ ↓ ↓ ↓ ↓ ↓
PropsIcon.empPropTypes = {
  "defined": {
    "description": "营收礼物图标"
  },
  "name": "PropsIcon",
  "props": {
    "iconUrl": {
      "defaultValue": "https://www.baidu.com",
      "description": "图标地址",
      "label": "iconUrl",
      "required": true,
      "type": "Upload"
    }
  }
}

枚举类型

生成 antd - Select 组件需要的options

enum Nums = {
  /** 1个 */
  One = 1,
  /** 两个 */
  Two = 2
}
// 通过类型获取`description`和`type`
export type PropsIconType = {
  nums: Nums
}
      ↓ ↓ ↓ ↓ ↓ ↓
PropsIcon.empPropTypes = {
  "defined": {
    "description": "营收礼物图标"
  },
  "name": "PropsIcon",
  "props": {
    "nums": {
      "options": {
        "options": [{
          label: "1个",
          value: 1
        },{
          label: "两个",
          value: 2
        }]
      }
      "type": "Select"
    }
  }
}

注意事项

  1. 需要指定@visibleName(推荐指定),表示挂载配置对象的变量名。
  2. 若不指定,默认取文件名或者所在文件夹名称(一般与组件名一致)。

About

支持react-docgen-typescript 的所有参数透传。其他可用的配置项可以参考react-docgen-typescript-plugin