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

sfe-mock-tool

v1.1.1

Published

Sunlands FE Mock Server Tool

Downloads

7

Readme

SFE Mock Tool

Sunlands 前端 Mock 服务器工具,用于快速生成和提供接口 Mock 数据。

功能特性

  • 🚀 自动从数据库获取接口定义
  • 📁 生成符合 Mock.js 规范的测试数据
  • 🌐 提供本地 Mock 服务器
  • ⚡ 支持并行生成多个模块
  • 🔧 可配置化运行参数

安装

npm install sfe-mock-tool 
# 或
yarn add sfe-mock-tool

初始化项目

sfe-mock init

此命令会自动在项目的 package.json 中添加以下 scripts:

{
  "scripts": {
    "mock:generate": "sfe-mock generate",
    "mock:start": "sfe-mock start"
  }
}

使用方法

1. 生成 Mock 数据

sfe-mock generate [moduleUrls...] [options]

# 示例
sfe-mock generate "project/123/module/456" -p 3

参数说明:

  • moduleUrls: 模块URL数组,格式为 project/{projectId}/module/{moduleId}
  • --config-c: 配置文件路径 (默认: ./mock/config/mock.config.json)
  • --parallel-p: 并行处理数量 (默认: 5)

2. 启动 Mock 服务器

sfe-mock start [options]

# 示例
sfe-mock start -p 3001 -h 0.0.0.0

参数说明:

  • --port-p: 服务器端口 (默认: 3000)
  • --host-h: 服务器主机 (默认: localhost)
  • --env-e: 运行环境 (默认: development)

3. 使用 npm scripts

# 生成 Mock 数据
npm run mock:generate  project/123/module/456

# 启动 Mock 服务器
npm run mock:start -p 3001

配置文件

工具会在 ./mock/config/mock.config.json 维护以下配置:

{
  "mockRootPrefixPath": "testdata", // 默认在mock/testdata文件夹下创建文件
  "existingModules": [],  // 已生成的模块
  "toGenerateModules": [], // 待生成的模块
}

数据库配置

通过环境变量配置数据库连接:

export DB_HOST=your_db_host
export DB_USER=your_db_user
export DB_PASSWORD=your_db_password
export DB_NAME=your_db_name

或直接修改 lib/core/dbClient.js 中的默认值。

Mock 数据类型支持

支持以下 mockType 的数据生成:

| 类型 | 说明 | 示例 | |------|------|------| | 1 | 浮点数 | 23.45 | | 2 | 整数 | 42 | | 3 | 百分比 | "45%" | | 4 | 中文标题 | "这是一个标题" | | 5 | 中文姓名 | "张三" | | 6 | 中文句子 | "这是一个测试句子" | | 7 | URL | "http://example.com" | | 8 | 图片URL | "http://dummyimage.com/200x200" | | 15 | 布尔值 | true | | 16 | 数组对象 | [{...}, {...}] | | 19 | 随机字符串 | "aBcDeF" |

项目结构

sfe-mock-tool/
├── bin/                # 命令行入口
├── lib/                # 核心代码
│   ├── commands/       # 命令实现
│   ├── core/           # 核心功能
│   ├── server/         # 服务器代码
│   └── utils/          # 工具类
├── mock/               # 生成的 mock 数据
└── test/               # 测试代码