create-miniprogram-scaffold 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +26 -0
- package/package.json +1 -1
- package/templates/meta/CLAUDE.md +74 -0
package/bin/cli.js
CHANGED
|
@@ -39289,6 +39289,13 @@ var SERVERS = {
|
|
|
39289
39289
|
};
|
|
39290
39290
|
|
|
39291
39291
|
// src/scaffolder.js
|
|
39292
|
+
function renderTemplate(templatePath, vars) {
|
|
39293
|
+
let content = import_fs_extra.default.readFileSync(templatePath, "utf-8");
|
|
39294
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
39295
|
+
content = content.replaceAll(`{{${key}}}`, value);
|
|
39296
|
+
}
|
|
39297
|
+
return content;
|
|
39298
|
+
}
|
|
39292
39299
|
function generateAppConfig(pages, tabbar) {
|
|
39293
39300
|
const pagesStr = pages.map((p) => ` '${p}'`).join(",\n");
|
|
39294
39301
|
let tabbarStr = "";
|
|
@@ -39335,6 +39342,10 @@ async function scaffold(projectName, config) {
|
|
|
39335
39342
|
const mDir = import_path.default.join(dir, "miniprogram");
|
|
39336
39343
|
const layoutCfg = LAYOUTS[layout];
|
|
39337
39344
|
const serverCfg = SERVERS[server];
|
|
39345
|
+
const serverLabel = serverCfg.label;
|
|
39346
|
+
const serverExt = server === "python" ? "py" : "go";
|
|
39347
|
+
const startCmd = server === "python" ? "pip install -r requirements.txt && python main.py" : "go mod tidy && go run main.go";
|
|
39348
|
+
const startCmdFull = server === "python" ? "cd server && pip install -r requirements.txt && python main.py" : "cd server && go mod tidy && go run main.go";
|
|
39338
39349
|
await import_fs_extra.default.ensureDir(mDir);
|
|
39339
39350
|
await import_fs_extra.default.ensureDir(import_path.default.join(dir, "server"));
|
|
39340
39351
|
await import_fs_extra.default.copy(import_path.default.join(tDir, "miniprogram"), mDir, {
|
|
@@ -39370,6 +39381,21 @@ async function scaffold(projectName, config) {
|
|
|
39370
39381
|
await import_fs_extra.default.writeFile(envPath, env);
|
|
39371
39382
|
await import_fs_extra.default.writeFile(envExamplePath, env);
|
|
39372
39383
|
}
|
|
39384
|
+
const repoRoot = import_path.default.join(tDir, "..", "..");
|
|
39385
|
+
await import_fs_extra.default.copy(import_path.default.join(repoRoot, "reusable"), import_path.default.join(dir, "reusable"));
|
|
39386
|
+
await import_fs_extra.default.copy(import_path.default.join(repoRoot, "docs"), import_path.default.join(dir, "docs"));
|
|
39387
|
+
const metaDir = import_path.default.join(tDir, "meta");
|
|
39388
|
+
const tplVars = {
|
|
39389
|
+
PROJECT_NAME: projectName,
|
|
39390
|
+
SERVER_LABEL: serverLabel,
|
|
39391
|
+
SERVER_EXT: serverExt,
|
|
39392
|
+
LAYOUT: layout,
|
|
39393
|
+
START_CMD: startCmd,
|
|
39394
|
+
START_CMD_FULL: startCmdFull
|
|
39395
|
+
};
|
|
39396
|
+
const claudeContent = renderTemplate(import_path.default.join(metaDir, "CLAUDE.md"), tplVars);
|
|
39397
|
+
await import_fs_extra.default.writeFile(import_path.default.join(dir, "CLAUDE.md"), claudeContent);
|
|
39398
|
+
await import_fs_extra.default.writeFile(import_path.default.join(dir, "AGENT.md"), claudeContent);
|
|
39373
39399
|
await import_fs_extra.default.writeFile(import_path.default.join(dir, "README.md"), generateReadme(projectName, layout, server));
|
|
39374
39400
|
}
|
|
39375
39401
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# {{PROJECT_NAME}}
|
|
2
|
+
|
|
3
|
+
## 技术栈
|
|
4
|
+
|
|
5
|
+
- 前端:Taro 3 + React + TypeScript + Sass
|
|
6
|
+
- 后端:{{SERVER_LABEL}}
|
|
7
|
+
- 布局:{{LAYOUT}}
|
|
8
|
+
|
|
9
|
+
## 常用命令
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
cd miniprogram && pnpm install && pnpm dev:weapp # 前端开发
|
|
13
|
+
cd server && {{START_CMD}} # 后端开发
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 项目规范
|
|
17
|
+
|
|
18
|
+
- CSS 字号用变量 `var(--fs-xxl)`,禁止写死 px
|
|
19
|
+
- 类名 BEM:`.block__element--modifier`
|
|
20
|
+
- API 返回 `{ code: 0, message, data, pagination? }`
|
|
21
|
+
- 纯展示组件用 `memo()` 包裹
|
|
22
|
+
- PNG only,不用 SVG
|
|
23
|
+
- `<Image>` 容器必须有显式 width/height
|
|
24
|
+
|
|
25
|
+
## 项目结构
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
├── miniprogram/ # Taro 前端
|
|
29
|
+
│ ├── src/layouts/ # 布局组件
|
|
30
|
+
│ ├── src/pages/ # 页面
|
|
31
|
+
│ └── config/ # 构建配置
|
|
32
|
+
├── server/ # {{SERVER_LABEL}} 后端
|
|
33
|
+
├── reusable/ # 可复用组件和工具
|
|
34
|
+
├── docs/ # 项目文档
|
|
35
|
+
├── CLAUDE.md # AI 协作规范
|
|
36
|
+
└── AGENT.md # Agent 使用指南
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 可复用资产
|
|
40
|
+
|
|
41
|
+
`reusable/` 包含可直接复用的组件、工具和踩坑文档:
|
|
42
|
+
|
|
43
|
+
### 组件(reusable/components/)
|
|
44
|
+
|
|
45
|
+
| 组件 | 说明 |
|
|
46
|
+
|------|------|
|
|
47
|
+
| CachedImage | 远程图本地缓存 |
|
|
48
|
+
| AppNoticeModal | 公告弹窗 |
|
|
49
|
+
| AnnouncementModal | 系统公告 |
|
|
50
|
+
| PageHeader | 页面标题区 |
|
|
51
|
+
| Page | 页面容器壳 |
|
|
52
|
+
| GlobalFab | 全局浮动按钮 |
|
|
53
|
+
| Confetti | 撒花特效 |
|
|
54
|
+
| SearchBar | 搜索输入条 |
|
|
55
|
+
| DetailCard | 详情卡片壳 |
|
|
56
|
+
|
|
57
|
+
### 工具(reusable/utils/)
|
|
58
|
+
|
|
59
|
+
- `subscribeMessage.ts` — 微信订阅消息统一封装
|
|
60
|
+
- `obfuscate.ts` — Base64 + JSON 混淆
|
|
61
|
+
|
|
62
|
+
### 踩坑文档(reusable/patterns/)
|
|
63
|
+
|
|
64
|
+
- bundle-size-optimization / ios-date-parse / wxss-compatibility
|
|
65
|
+
- taro-build-gotchas / local-image-imports / page-scroll-and-tabbar
|
|
66
|
+
- css-variables-and-bem / cached-image-container-size
|
|
67
|
+
- api-response-format / subscribe-message-flow
|
|
68
|
+
- blue-green-deployment / smoke-test
|
|
69
|
+
|
|
70
|
+
## 注意事项
|
|
71
|
+
|
|
72
|
+
- 部署前确认用户意图,不要主动 deploy
|
|
73
|
+
- 不要手动 push 到 main
|
|
74
|
+
- 只跑 build 验证编译,不要起服务
|