@lark-apaas/coding-templates
v0.1.3
Published
OpenClaw project templates for mclaw CLI
Readme
@lark-apaas/coding-templates
OpenClaw 项目模板包,供 mclaw CLI 使用。
模板列表
| 模板 | 目录 | 说明 |
|---|---|---|
| html | template-html/ | 纯 HTML,零依赖,原型验证 |
| nextjs-static | template-nextjs-static/ | Next.js Pages Router,静态导出,纯前端 |
| nextjs-fullstack | template-nextjs-fullstack/ | Next.js App Router + Drizzle + PostgreSQL,全栈 |
包结构
template/
├── package.json # npm 包定义(@lark-apaas/coding-templates)
├── meta.json # 模板元数据(业务侧生成,名称/描述/特性标签)
├── template-html/
│ ├── _gitignore
│ ├── package.json # mclaw.type: "html"
│ └── index.html
├── template-nextjs-static/
│ ├── _gitignore # CLI 复制时重命名为 .gitignore
│ ├── package.json # mclaw.type: "nextjs-static",name 为 {{projectName}}
│ ├── tailwind.config.ts
│ ├── eslint.config.js
│ ├── postcss.config.js
│ ├── components.json
│ └── src/
│ ├── pages/ # Pages Router 路由
│ ├── components/ui/ # shadcn/ui 58 个组件
│ ├── hooks/
│ ├── lib/
│ └── styles/globals.css
└── template-nextjs-fullstack/
├── _gitignore
├── _env.local.example # CLI 复制时重命名为 .env.local.example
├── package.json # mclaw.type: "nextjs-fullstack",name 为 {{projectName}}
├── drizzle.config.ts
├── tailwind.config.ts
├── eslint.config.js
├── postcss.config.js
├── components.json
└── src/
├── app/ # App Router 路由 + Server Actions
├── components/ui/ # shadcn/ui 58 个组件
├── db/ # Drizzle ORM schema + 连接
├── hooks/
└── lib/特殊文件命名
npm publish 会忽略 .gitignore 和 .env*,因此模板中使用 _ 前缀:
| 模板中的文件名 | CLI 复制后的文件名 |
|---|---|
| _gitignore | .gitignore |
| _env.local.example | .env.local.example |
模板类型标识
每个模板的 package.json 包含 mclaw.type 字段,标识模板类型:
{
"mclaw": {
"type": "nextjs-static"
}
}meta.json 由业务侧生成和维护。若 meta.json 丢失,CLI 可扫描各模板目录的 package.json 中的 mclaw.type 恢复。
mclaw CLI 集成方式
const path = require('path');
const fs = require('fs-extra');
// 1. 读取模板元数据
const meta = require('@lark-apaas/coding-templates/meta.json');
// 2. 定位模板目录
const templateDir = path.dirname(require.resolve('@lark-apaas/coding-templates/meta.json'));
const srcDir = path.join(templateDir, selectedTemplate.dir);
// 3. 复制到目标目录
await fs.copy(srcDir, targetDir);
// 4. 重命名特殊文件
const renames = { '_gitignore': '.gitignore', '_env.local.example': '.env.local.example' };
for (const [from, to] of Object.entries(renames)) {
const filePath = path.join(targetDir, from);
if (fs.existsSync(filePath)) {
await fs.rename(filePath, path.join(targetDir, to));
}
}
// 5. 替换 package.json 中的占位符
const pkgPath = path.join(targetDir, 'package.json');
if (fs.existsSync(pkgPath)) {
let content = await fs.readFile(pkgPath, 'utf-8');
content = content.replace('{{projectName}}', projectName);
await fs.writeFile(pkgPath, content);
}技术栈
两个 Next.js 模板共享相同的技术选型:
- Next.js 16 + React 19 + TypeScript 5
- Tailwind CSS 4(
@tailwindcss/postcss,CSS-first 配置) - shadcn/ui(base-nova 风格,lucide 图标,58 个组件预装)
- ESLint 9 flat config(
@eslint/js+typescript-eslint,无eslint-config-next) - next-themes(暗色模式)
fullstack 模板额外包含:Drizzle ORM + PostgreSQL + Zod
发版
cd template
npm version patch
npm publish