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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fairys/mocker-cli

v0.0.8

Published

Fairys Mocker CLI for mock data generation

Readme

mocker-cli

功能强大的 Mock 数据生成和代理转发工具

安装

npm install @fairys/mocker-cli -D # pnpm install @fairys/mocker-cli -D # yarn add @fairys/mocker-cli -D

参数

Usage:
  $ fairys-mocker

Options:
  --root            设置根目录路径(默认取环境变量中的`FAIRYS_MOCKER_ROOT_DIR`)
  --dir             设置目录名(默认取环境变量中的`FAIRYS_MOCKER_DIR`)
  --file            设置文件名(默认取环境变量中的`FAIRYS_MOCKER_FILE`)
  --file2           设置文件名2(默认取环境变量中的`FAIRYS_MOCKER_PROXY_FILE`)
  --static          设置静态文件目录
  --static-prefix   设置静态文件路径前缀
  --is-mock-file    是否生成mock数据文件,默认:true.
  --is-proxy-file   是否生成proxy数据文件,默认:true.
  --is-connect      是否是connect服务.默认:false,默认使用`express`服务.

Example:

  fairys-mocker --dir mocker --file index.mock --file2 proxy --is-connect true

参数说明

  • FAIRYS_MOCKER_ROOT_DIRroot:未设置时,取当前执行命令目录
  • FAIRYS_MOCKER_DIR或者dir:未设置时,取当前执行命令目录的mock文件夹
  • FAIRYS_MOCKER_FILE或者file:未设置时,取当前执行命令目录的mock文件夹下的index.mock.cache.json文件
  • FAIRYS_MOCKER_PROXY_FILE或者file2:未设置时,取当前执行命令目录的mock文件夹下的proxy.cache.json文件

:::tip

filefile2值为移除.cache.json的文件名,不是完整的文件名,

例如file=index.mock, file2=proxy 内部会进行转换为 index.mock.cache.jsonindex.mock.tsproxy.cache.jsonproxy.ts 这4个文件名称

:::

在使用的过程中会生成4个文件

  1. index.mock.cache.json: 生成mock数据的原始配置(页面渲染取值)
{
  "mockList": [
    {
      "url": "/api/test",
      "method": "POST",
      "status": "200",
      "delay": 0,
      "body": {
        "code": 200,
        "data": {
          "id": "@id",
          "name": "@name",
          "email": "@email"
        },
        "message": "success"
      },
      "listCount": 20
    },
  ],
  "rootDir": "...",
  "dir": "mock",
  "fileName": "index.mock",
  "cache": "index.mock.cache.json"
}
  1. index.mock.ts: 生成的mock数据
// Mock 配置文件
export interface MockerItem {
  /**该接口允许的 请求方法,默认同时支持 GET 和 POST*/
  method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
  /**状态码*/
  status: string;
  //配置响应延迟时间, 如果传入的是一个数组,则代表延迟时间的范围
  delay: number | [number, number];
  /**响应体(可以自定义返回格式)*/
  body: any;
  /**接口地址*/
  url: string;
  /**列表数据条数(仅 list 格式有效)*/
  listCount?: number;
}
/**mock配置 列表*/
export type DefineMockList = MockerItem[];
export const mockList: DefineMockList = [
  {
    "url": "/api/test",
    "method": "POST",
    "status": "200",
    "delay": 0,
    "body": {
      "code": 200,
      "message": "success",
      "data": {
        "id": "450000200805311843",
        "name": "Sarah Lee",
        "email": "[email protected]"
      }
    },
    "listCount": 20
  },
];
export default mockList;
  1. proxy.cache.json: 生成代理数据原始配置(页面渲染取值)
{
  "proxyList": [
    {
      "path": "^/docks",
      "target": "http://localhost:9009"
    }
  ],
  "rootDir": "...",
  "dir": "mock",
  "fileName": "proxy",
  "cache": "proxy.cache.json"
}
  1. proxy.ts: 生成的代理服务数据
// 代理配置文件
/**
 * 代理配置参数
 */
export type ProxyItem = Record<string,{
  /**转发地址*/
  target: string,
  /**路径重写*/
  pathRewrite?: Record<string, string>,
  /**是否开启ws*/
  ws?: boolean
}> 

export const proxyConfig: ProxyItem = {
  "^/tsx": {
    "target": "http://localhost:9009"
  },
  "^/wsdse": {
    "target": "http://localhost:8982",
    "pathRewrite": {
      "^/wsdse": ""
    },
    "ws": true
  },
  "^/docks": {
    "target": "http://localhost:9009"
  }
};
export default proxyConfig;