@mdframe/forge-create
v0.1.1
Published
Interactive Forge project generator CLI.
Readme
Forge Create CLI
用于交互式生成 Forge 客户工程,并可选择初始化 MySQL 数据库。
本地使用
node src/cli.mjs ./md-psi-system \
--template-source /Users/yaomindong/Desktop/project/mdframe/forge-project全局安装
发布到 npm 后,可以像安装 @openai/codex 一样全局安装:
npm install -g @mdframe/forge-create
forge-create --help也可以直接使用另一个命令别名:
create-forge --help@mdframe/forge-create 中的 @mdframe 是 npm scope。发布前需要确认当前 npm 账号拥有这个 scope;如果要使用公司或个人 scope,请先修改 package.json 里的 name。
交互模式支持方向键操作:
- 单选:
↑/↓移动,Enter确认。 - 多选:
↑/↓移动,Space勾选或取消,Enter确认。 - 返回上一步:在单选/多选页面按
b或Esc;在文本输入页面输入:back。
非交互生成
node src/cli.mjs ./md-psi-system \
--template-source /Users/yaomindong/Desktop/project/mdframe/forge-project \
--subsystem minimal-admin \
--include business-core \
--project-name md-psi-system \
--display-name 内蒙古商品进销存管理系统 \
--base-package con.mdframe \
--group-id con.mdframe \
--database-name psi_admin \
--strip-module-prefix md \
--force \
--yes子系统
CLI 现在按业务子系统选择初始化模块。--subsystem 优先级高于 --preset,--preset 可传子系统 ID;未与子系统同名的模板原始 preset 也继续支持。
| 子系统 ID | 说明 |
| --- | --- |
| minimal-admin | 最小后台:系统管理、代码生成、定时任务模块、消息管理、多租户。 |
| ai-data-platform | 企业级 AI 数据分析平台:系统管理、AI 代码生成、定时任务、消息管理、多租户、数据模块、report 模块、AI 模块、forge-plugin-external。 |
| ai-lowcode-platform | 企业级 AI 低代码平台:系统管理、AI 代码生成、定时任务、消息管理、多租户、AI 模块。 |
| full | 全量系统:保留模板支持的全部后端子模块和前端工程。 |
初始化数据库
生成完成后可以追加 --init-db,CLI 会调用生成工程中的统一脚本:
<project>/<artifact-prefix>-server/scripts/db/init-db.sh示例:
node src/cli.mjs ./md-psi-system \
--template-source /Users/yaomindong/Desktop/project/mdframe/forge-project \
--subsystem minimal-admin \
--project-name md-psi-system \
--display-name 内蒙古商品进销存管理系统 \
--base-package con.mdframe \
--group-id con.mdframe \
--database-name psi_admin \
--strip-module-prefix md \
--init-db \
--db-host 127.0.0.1 \
--db-port 3306 \
--db-user root \
--db-password your_password如需执行按模块收集的 SQL,增加 --with-module。
NPX 形态
方式一:直接从 Git 仓库运行
把本仓库推到 Git 后,其他人不需要先 clone,可以直接用 npx --package 从 Git 安装并执行 forge-create。
公共仓库示例:
npx --yes \
--package git+https://github.com/<org>/forge-create-cli.git \
forge-create --help指定分支或 tag:
npx --yes \
--package "git+https://github.com/<org>/forge-create-cli.git#v0.1.0" \
forge-create --help私有仓库可以用 SSH 地址,前提是用户本机已经配置好 Git SSH Key:
npx --yes \
--package git+ssh://[email protected]/<org>/forge-create-cli.git \
forge-create --help从 Git 生成项目
CLI 仓库只负责交互和调度,真正的 Forge 模板源需要通过 --template-git 或 --template-source 指定。推荐把 forge-project 模板仓库也推到 Git,然后这样使用:
npx --yes \
--package git+https://github.com/<org>/forge-create-cli.git \
forge-create ./md-psi-system \
--template-git https://github.com/<org>/forge-project.git \
--template-ref main \
--subsystem minimal-admin \
--include business-core \
--project-name md-psi-system \
--display-name 内蒙古商品进销存管理系统 \
--base-package con.mdframe \
--group-id con.mdframe \
--database-name psi_admin \
--strip-module-prefix md如果使用私有模板仓库:
npx --yes \
--package git+ssh://[email protected]/<org>/forge-create-cli.git \
forge-create ./md-psi-system \
--template-git [email protected]:<org>/forge-project.git \
--template-ref main方式二:发布到 npm 后运行
不想全局安装时,可以用 npx 临时运行:
npx @mdframe/forge-create ./md-psi-system带模板 Git 源:
npx @mdframe/forge-create ./md-psi-system \
--template-git https://github.com/<org>/forge-project.git \
--template-ref v1.0.0发布前检查
npm run check
npm run pack:dry-run发布到 npm
首次发布 scoped public 包:
npm login --registry=https://registry.npmjs.org/
npm publish --access public --registry=https://registry.npmjs.org/后续版本发布:
npm version patch
npm publish发布后验证:
npm install -g @mdframe/forge-create
forge-create --help最常用的完整生成命令:
forge-create ./md-psi-system \
--template-git https://github.com/<org>/forge-project.git \
--template-ref main \
--subsystem minimal-admin \
--project-name md-psi-system \
--display-name 商品进销存管理系统 \
--base-package con.mdframe \
--group-id con.mdframe \
--database-name psi_admin \
--strip-module-prefix md \
--force \
--yes
如果模板在本地:
forge-create ./md-psi-system \
--template-source /Users/yaomindong/Desktop/project/mdframe/forge-project \
--subsystem minimal-admin \
--project-name md-psi-system \
--display-name 商品进销存管理系统 \
--base-package con.mdframe \
--group-id con.mdframe \
--database-name psi_admin \
--strip-module-prefix md \
--force \
--yes
可选子系统:
--subsystem minimal-admin
--subsystem ai-data-platform
--subsystem ai-lowcode-platform
--subsystem full
带数据库初始化:
forge-create ./md-psi-system \
--template-git https://github.com/<org>/forge-project.git \
--template-ref main \
--subsystem minimal-admin \
--project-name md-psi-system \
--display-name 商品进销存管理系统 \
--base-package con.mdframe \
--group-id con.mdframe \
--database-name psi_admin \
--strip-module-prefix md \
--force \
--yes \
--init-db \
--db-host 127.0.0.1 \
--db-port 3306 \
--db-user root \
--db-password your_password如果 npx 报 ~/.npm 权限问题,可以临时指定 cache:
npm_config_cache=/tmp/forge-create-npm-cache npx --yes \
--package git+https://github.com/<org>/forge-create-cli.git \
forge-create --help