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

@chaobinchen/mes-cli

v1.0.1

Published

MES 数据库查询 CLI — 快速查询工单进度等业务数据

Readme

mes-cli

MES 数据库查询 CLI — 连接 SQL Server,快速查询 MES 业务数据。

安装

npm install -g @chaobinchen/mes-cli
# 或本地开发
git clone ...
cd mes-cli
npm install
node bin/mes-dynamic.js --help

快速开始

1. 初始化连接配置

mes init           # 当前目录(项目级)
mes init --global  # HOME 目录(全局)

向导会创建 .mes.json,并自动将其加入 .gitignore

{
  "server": "172.29.x.x",
  "port": 1433,
  "user": "sa",
  "password": "YOUR_PASSWORD",
  "database": "mes_master"
}

2. 也可用环境变量连接

MES_DB_SERVER=172.29.x.x MES_DB_USER=sa MES_DB_PASSWORD=xxx mes progress MO6303A035

Windows PowerShell:

$env:MES_DB_SERVER='172.29.x.x'; $env:MES_DB_USER='sa'; $env:MES_DB_PASSWORD='xxx'
mes progress MO6303A035

优先级:CLI 参数 > 环境变量 > .mes.json


全局连接参数

所有命令均支持以下参数(可覆盖配置文件 / 环境变量):

-S, --server    <server>    数据库服务器地址
-P, --port      <port>      端口(默认 1433)
-u, --user      <user>      用户名
-p, --password  <password>  密码
-d, --database  <database>  数据库名

命令列表

工单类

| 命令 | 别名 | 说明 | |------|------|------| | mes progress <orderNum> | pg | 工单进度(称量 + 生产状态) | | mes risk-orders | ro | 延期风险工单清单 | | mes order-info <orderNum> | oi | 工单基础信息 | | mes active-orders | ao | 生产中工单清单(需指定日期) | | mes pending-discharge | pdc | 待出锅工单清单 | | mes daily-plan | dp | 某天计划生产工单(需指定日期) | | mes qc-result <orderNum> | qcr | 工单质检结果 | | mes exec-overview <orderNum> | eo | 半成品生产执行概览 |

称量类

| 命令 | 别名 | 说明 | |------|------|------| | mes weighing-overview <orderNum> | wov | 称量工单执行概览 | | mes weighing-tasks <orderNum> | wt | 称量任务清单 | | mes pending-weighing <orderNum> | pw | 未完成称量项 | | mes weighing-detail <orderNum> | wdt | 称量执行明细 | | mes operator-records <operator> | orec | 操作员称量记录 | | mes review-status <orderNum> | rvs | 称量复核状态 | | mes accounting-status <orderNum> | acs | 称量账务状态 | | mes weighing-exceptions <orderNum> | wex | 称量异常 / 作废记录 | | mes weighing-duration <orderNum> | wdur | 称量耗时分析 |

物料类

| 命令 | 别名 | 说明 | |------|------|------| | mes stock-records <materialCode> | sr | 物料出入库记录 | | mes stock-inventory <materialCode> | si | 物料库存查询 | | mes trace-forward | tf | 半成品批次追溯原料 | | mes trace-backward | tb | 原料批次反向追踪半成品 | | mes material-usage <materialCode> | mu | 近期原料使用明细 | | mes stock-coverage <materialCode> | sc | 库存与用量对比(预计可用天数) |

报告类

| 命令 | 别名 | 说明 | |------|------|------| | mes weighing-report <orderNum> | wr | 称量批记录报告(表头 + 明细) | | mes bulk-report <orderNum> | br | 半成品生产报告(表头 + 明细) |


常用示例

# 工单进度
mes progress MO6303A035
mes pg MO6303A035

# 延期风险工单(可选车间 / 日期过滤)
mes risk-orders
mes ro --workshop 车间A
mes ro -d 2026-04-10

# 生产中工单(必填日期)
mes active-orders --date 2026-04-14
mes ao -d 2026-04-14 --workshop 车间A

# 今日计划工单
mes daily-plan --date 2026-04-14
mes dp -d 2026-04-14

# 称量任务 / 未完成项
mes weighing-tasks MO6303A035
mes pending-weighing MO6303A035

# 称量明细(可追加物料编码过滤)
mes weighing-detail MO6303A035 --material C160
mes wdt MO6303A035 -m C160

# 操作员记录(必填起止日期)
mes operator-records 陈金波 --start 2026-04-01 --end 2026-04-14

# 物料追溯
mes trace-forward --code 215B654 --batch 2026033101
mes trace-backward --code C160 --batch P122632

# 库存与用量(默认 180 天)
mes stock-coverage C160
mes sc C160 --days 30

# 生产报告
mes weighing-report MO6318A001
mes bulk-report MO6205A045

参数说明(常用选项)

| 命令 | 必填选项 | 可选选项 | |------|---------|---------| | risk-orders | — | -w/--workshop, -d/--date | | active-orders | -d/--date <YYYY-MM-DD> | -w/--workshop | | daily-plan | -d/--date <YYYY-MM-DD> | — | | weighing-detail | <orderNum> | -m/--material <code> | | operator-records | <operator>, --start, --end | — | | trace-forward | --code <半成品编码>, -b/--batch <批次> | — | | trace-backward | --code <原料编码>, -b/--batch <批次> | — | | stock-records | <materialCode> | -b/--batch | | stock-inventory | <materialCode> | -b/--batch | | material-usage | <materialCode> | -n/--days(默认 180), -b/--batch | | stock-coverage | <materialCode> | -n/--days(默认 180), -b/--batch |


动态命令配置

标准查询命令已经改成由 commands/commands.json 驱动,CLI 启动时会自动读取并注册。

配置结构示例:

{
  "risk-orders": {
    "alias": "ro",
    "description": "延期风险工单清单",
    "arguments": [],
    "output": "table",
    "options": [
      { "flag": "-w, --workshop <name>", "desc": "车间名称" },
      { "flag": "-d, --date <date>", "desc": "日期" }
    ],
    "sql": "SELECT ... WHERE (@workshop_name IS NULL OR workshop_name = @workshop_name)",
    "params": [
      { "name": "workshop_name", "type": "NVarChar", "from": "option.workshop", "nullable": true },
      { "name": "check_date", "type": "DateTime2", "from": "option.date", "default": "today" }
    ]
  }
}

字段说明:

  • arguments: 位置参数定义,syntax 会直接注册到 commander。
  • options: 命令选项定义,支持 requireddefaultValue
  • output: 目前支持 tabledetail
  • params: SQL 参数映射,from 支持 arg.xxxoption.xxxliteral.xxx
  • type: 映射到 mssql 类型,例如 NVarCharIntDateDateTime2

新增一个标准命令的工作流:

  1. commands/commands.json 增加一条定义。
  2. 运行 npm test 验证命令能正常注册。
  3. 发布新版本:npm version patch && npm publish

说明:

  • initprogresstrace-forwardtrace-backwardweighing-reportbulk-report 这类复杂命令目前仍保留在代码里。
  • 它们通常涉及更复杂的逻辑、临时表、结果清洗或多结果集,暂时不强行配置化。
  • 已经迁移到 commands.json 的旧实现文件已删除,避免同时维护两套逻辑。

项目结构

mes-cli/
├── bin/
│   └── mes-dynamic.js            # 新入口:动态注册命令
├── commands/
│   └── commands.json             # 标准命令定义(主要维护入口)
├── src/
│   ├── engine.js                 # 动态命令执行引擎
│   ├── config.js                 # 连接配置解析
│   ├── db.js                     # mssql 查询封装
│   ├── display.js                # cli-table3 表格输出
│   ├── encoding.js               # Windows 编码处理
│   └── commands/
│       ├── init.js               # init 命令
│       ├── progress.js           # progress 命令
│       ├── trace.js              # 正反向追溯命令
│       └── reports.js            # 报告类(2 个命令)
├── skills/
│   └── mes-cli/
│       ├── SKILL.md              # Codex 技能说明
│       ├── agents/
│       │   └── openai.yaml       # OpenAI agent 配置
│       └── scripts/
│           └── mes-query.ps1     # PowerShell 查询封装脚本
├── package.json
└── README.md

当前状态:

  • 大多数标准查询命令只维护在 commands/commands.json
  • src/commands/ 目录只保留无法轻量配置化的命令实现。

依赖


License

ISC