diff --git a/.codex-tasks/template-build-time-composition/EPIC.md b/.codex-tasks/template-build-time-composition/EPIC.md new file mode 100644 index 0000000..8ce8fc5 --- /dev/null +++ b/.codex-tasks/template-build-time-composition/EPIC.md @@ -0,0 +1,23 @@ +# 模板构建时叠加平台 + +## 目标 + +将 `template:dev` 收敛为运行时层、能力包、模板包三层叠加编译,产出可直接被微信开发者工具打开的完整小程序。运行时不携带任何行业或具体模板代码,新增行业模板只需新增模板包。 + +## 范围 + +- 运行时壳清理与品牌构建参数注入。 +- `template-contract` manifest 契约及 compiler 冲突校验。 +- `capability-booking` 小程序页面迁移。 +- 阿成、林境模板页面和资产包化。 +- 编译产物校验、第二行业 fixture、文档与门禁。 + +## 不在范围 + +- 后端 Booking capability 化。 +- 后台视觉模板切换、历史和回滚。 +- 微信第三方平台、`ext.json` 和订单通知。 + +## 验收 + +阿成和林境模板均可独立编译;产物页面、组件、`require`、tab 图标、品牌参数均通过自动校验;运行时目录不含模板专属代码;`pnpm check`、模板校验和 compiler 测试通过。 diff --git a/.codex-tasks/template-build-time-composition/PROGRESS.md b/.codex-tasks/template-build-time-composition/PROGRESS.md new file mode 100644 index 0000000..0faf1f8 --- /dev/null +++ b/.codex-tasks/template-build-time-composition/PROGRESS.md @@ -0,0 +1,26 @@ +# 执行记录 + +## 当前状态 + +本轮从既有未提交改动继续。叠加式 compiler 已可将 runtime、capability、template 编译成独立产物;`booking` 页面已迁入 capability 包;runtime 模板页面、模板组件和 tab 资产已移除。 + +## 已验证 + +- `acheng-campus-food` 编译成功。 +- `linjing-editorial` 编译成功。 +- compiler 已支持解析 `miniprogram_npm` 中的 TDesign 组件引用。 +- 顶层 `templates/` 镜像已删除,模板目录校验统一读取 `packages/template-*`。 +- `pnpm lint`、`pnpm typecheck`、模板 compiler 测试、模板契约测试和 miniapp fixture 均通过。 + +## 待办 + +- 更新 template catalog。 +- 修正并扩展 compiler 测试和 fixture。 +- 完成 runtime/template grep、typecheck、format、miniapp fixture 门禁。 +- 补齐 ADR、README 和新增模板说明。 +- `pnpm format:check` 全仓仍会报告已有 `.claude/settings.local.json`,该文件不属于本任务且未修改。 + +## 失败记录 + +- 初次编译因 `capability-booking/miniapp` 缺失而失败,已迁移页面解决。 +- 初次林境编译因 runtime tab 资产和模板资产冲突而失败,已将 tab 资产归属模板并清理 runtime。 diff --git a/.codex-tasks/template-build-time-composition/SUBTASKS.csv b/.codex-tasks/template-build-time-composition/SUBTASKS.csv new file mode 100644 index 0000000..c1cb501 --- /dev/null +++ b/.codex-tasks/template-build-time-composition/SUBTASKS.csv @@ -0,0 +1,6 @@ +id,title,status,depends_on,validation,notes +1,完成叠加式契约与编译器,DONE,,pnpm test:template-compiler,阿成和林境编译及错误场景测试通过 +2,清理运行时模板代码与资源,DONE,1,rg -n 'acheng|linjing|pageRenderer|templateKey ===' apps/miniapp,运行时生产目录无模板专属代码 +3,迁移 booking 能力包,DONE,1,node packages/template-compiler/src/cli.mjs --template acheng-campus-food, +4,完善两个模板包页面与资产,DONE,1;2,node packages/template-compiler/src/cli.mjs --template linjing-editorial,林境页面和 tab 资源已迁移并编译通过 +5,补齐测试、演练模板和文档,IN_PROGRESS,1;2;3;4,pnpm check,编译器测试、模板校验、fixture、lint、typecheck 通过;format 全仓受既有 settings 文件阻塞 diff --git a/README.md b/README.md index 894f40a..198deb3 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ packages/types # 共享类型 packages/api-client packages/validation packages/config +packages/template-compiler # 构建时叠加 runtime、capability、template +packages/template- # 独立行业 / 视觉模板包 +packages/capability- # 可选业务流程能力包 prisma/ docs/ prototype/ @@ -29,6 +32,17 @@ pnpm install pnpm check ``` +## 生成小程序模板 + +`apps/miniapp` 是运行时壳,不能直接作为完整小程序打开。使用模板编译器生成产物: + +```bash +pnpm template:dev acheng-campus-food --brand default-brand +pnpm template:dev linjing-editorial --brand linjing-doors +``` + +产物位于 `dist/miniapp//`,可直接用微信开发者工具打开。生产构建需额外提供 `--appid`、`--api https://...` 和 `--env prod`。 + ## 本地数据库 在有 Docker 的机器上执行: diff --git a/apps/api/src/modules/public/public-workspace.controller.ts b/apps/api/src/modules/public/public-workspace.controller.ts index baa2100..12c8e4b 100644 --- a/apps/api/src/modules/public/public-workspace.controller.ts +++ b/apps/api/src/modules/public/public-workspace.controller.ts @@ -279,10 +279,7 @@ export class PublicWorkspaceController { templatePackageManifest?.navigation.map((tab) => ({ key: tab.key, label: tab.label, - page: - templatePackageManifest.entrypoints[ - tab.page as keyof typeof templatePackageManifest.entrypoints - ] ?? tab.page, + page: templatePackageManifest.entrypoints[tab.page] ?? tab.page, })) ?? [], }, modules: runtimeModules, diff --git a/apps/miniapp/app.js b/apps/miniapp/app.js index 16e8823..ce7f59c 100644 --- a/apps/miniapp/app.js +++ b/apps/miniapp/app.js @@ -1,11 +1,16 @@ -const DEFAULT_API_BASE_URL = "http://localhost:3001"; -const DEFAULT_BRAND_SLUG = "default-brand"; +const runtimeConfig = require("./runtime-config"); + +// 仅开发构建允许用本地 storage 覆盖 API 地址和品牌,便于局域网真机调试。 +function devOverride(key) { + return runtimeConfig.env === "dev" ? wx.getStorageSync(key) : ""; +} App({ onLaunch() { this.globalData = { - apiBaseUrl: wx.getStorageSync("apiBaseUrl") || DEFAULT_API_BASE_URL, - brandSlug: wx.getStorageSync("brandSlug") || DEFAULT_BRAND_SLUG, + apiBaseUrl: devOverride("apiBaseUrl") || runtimeConfig.apiBaseUrl, + brandSlug: devOverride("brandSlug") || runtimeConfig.brandSlug, + templateKey: runtimeConfig.templateKey, brand: {}, }; }, diff --git a/apps/miniapp/app.json b/apps/miniapp/app.json index 4cfa839..ab47af0 100644 --- a/apps/miniapp/app.json +++ b/apps/miniapp/app.json @@ -1,10 +1,5 @@ { "pages": [ - "pages/index/index", - "pages/services/index", - "pages/stall-service/index", - "pages/booking/index", - "pages/bookings/index", "pages/offering/detail", "pages/inquiry/index", "pages/inquiry-success/index", diff --git a/apps/miniapp/assets/tab/briefcase-selected.png b/apps/miniapp/assets/tab/briefcase-selected.png deleted file mode 100644 index 0d23f4e..0000000 Binary files a/apps/miniapp/assets/tab/briefcase-selected.png and /dev/null differ diff --git a/apps/miniapp/assets/tab/briefcase.png b/apps/miniapp/assets/tab/briefcase.png deleted file mode 100644 index 2f55340..0000000 Binary files a/apps/miniapp/assets/tab/briefcase.png and /dev/null differ diff --git a/apps/miniapp/assets/tab/home-selected.png b/apps/miniapp/assets/tab/home-selected.png deleted file mode 100644 index e465c2d..0000000 Binary files a/apps/miniapp/assets/tab/home-selected.png and /dev/null differ diff --git a/apps/miniapp/assets/tab/home.png b/apps/miniapp/assets/tab/home.png deleted file mode 100644 index 5001009..0000000 Binary files a/apps/miniapp/assets/tab/home.png and /dev/null differ diff --git a/apps/miniapp/assets/tab/user-selected.png b/apps/miniapp/assets/tab/user-selected.png deleted file mode 100644 index a862cdc..0000000 Binary files a/apps/miniapp/assets/tab/user-selected.png and /dev/null differ diff --git a/apps/miniapp/assets/tab/user.png b/apps/miniapp/assets/tab/user.png deleted file mode 100644 index cd7368c..0000000 Binary files a/apps/miniapp/assets/tab/user.png and /dev/null differ diff --git a/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.js b/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.js deleted file mode 100644 index 3cd8c7d..0000000 --- a/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.js +++ /dev/null @@ -1,33 +0,0 @@ -Component({ - properties: { - active: { type: String, value: "home" }, - navigation: { type: Array, value: [] }, - }, - data: { - tabs: [], - }, - methods: { - navigate(e) { - const tab = e.currentTarget.dataset.tab; - if (!tab || tab.key === this.data.active) return; - wx.navigateTo({ url: tab.page }); - }, - }, - observers: { - navigation(navigation) { - this.setData({ - tabs: Array.isArray(navigation) - ? navigation.map((item) => ({ - ...item, - page: item.page && item.page.startsWith("/") ? item.page : `/${item.page || ""}`, - })) - : [], - }); - }, - }, - lifetimes: { - attached() { - this.setData({ tabs: this.data.navigation || [] }); - }, - }, -}); diff --git a/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.json b/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.json deleted file mode 100644 index 67f8e03..0000000 --- a/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.json +++ /dev/null @@ -1 +0,0 @@ -{ "component": true } diff --git a/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.wxml b/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.wxml deleted file mode 100644 index 7261c07..0000000 --- a/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.wxml +++ /dev/null @@ -1 +0,0 @@ -{{item.key === 'home' ? '⌂' : item.key === 'dishes' ? '♨' : item.key === 'service' ? '⌖' : item.key === 'owner' ? '♙' : item.key === 'booking' ? '✉' : '◈'}}{{item.label}} diff --git a/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.wxss b/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.wxss deleted file mode 100644 index 06805b6..0000000 --- a/apps/miniapp/components/runtime-tab-bar/runtime-tab-bar.wxss +++ /dev/null @@ -1,32 +0,0 @@ -.runtime-tab-bar { - position: fixed; - right: 0; - bottom: 0; - left: 0; - z-index: 20; - display: flex; - justify-content: space-around; - padding: 10rpx 6rpx calc(10rpx + env(safe-area-inset-bottom)); - border-top: 1rpx solid #eee5dc; - background: rgba(255, 255, 255, 0.97); - box-shadow: 0 -8rpx 24rpx rgba(48, 32, 20, 0.08); -} -.tab { - display: flex; - min-width: 0; - flex: 1; - flex-direction: column; - align-items: center; - gap: 4rpx; - color: #9a8d83; - font-size: 19rpx; -} -.icon { - height: 34rpx; - font-size: 31rpx; - line-height: 34rpx; -} -.tab.active { - color: #e87532; - font-weight: 700; -} diff --git a/apps/miniapp/components/templates/acheng-home/acheng-home.js b/apps/miniapp/components/templates/acheng-home/acheng-home.js deleted file mode 100644 index 1b3c019..0000000 --- a/apps/miniapp/components/templates/acheng-home/acheng-home.js +++ /dev/null @@ -1,19 +0,0 @@ -Component({ - properties: { - brand: { type: Object, value: {} }, - presentation: { type: Object, value: {} }, - trustContent: { type: Object, value: {} }, - offerings: { type: Array, value: [] }, - }, - methods: { - openOffering(e) { - this.triggerEvent("select", { id: e.currentTarget.dataset.id }); - }, - openInquiry() { - this.triggerEvent("inquiry"); - }, - openOfferings() { - this.triggerEvent("offerings"); - }, - }, -}); diff --git a/apps/miniapp/components/templates/acheng-home/acheng-home.json b/apps/miniapp/components/templates/acheng-home/acheng-home.json deleted file mode 100644 index 67f8e03..0000000 --- a/apps/miniapp/components/templates/acheng-home/acheng-home.json +++ /dev/null @@ -1 +0,0 @@ -{ "component": true } diff --git a/apps/miniapp/components/templates/acheng-home/acheng-home.wxml b/apps/miniapp/components/templates/acheng-home/acheng-home.wxml deleted file mode 100644 index d8e978a..0000000 --- a/apps/miniapp/components/templates/acheng-home/acheng-home.wxml +++ /dev/null @@ -1 +0,0 @@ -{{brand.founder}}{{brand.title}}“{{brand.slogan}}”{{presentation.stallTitle || '今日出摊点'}}{{brand.studioAddress || brand.address}}{{presentation.stallTime || '今日营业中'}}{{presentation.worksEyebrow || '本周学生票选招牌'}}{{presentation.worksTitle || '现做现吃,认真管饱'}}全部餐品 ›{{item.name}}{{item.desc}}{{item.priceRange}}{{presentation.manifestoEyebrow || '阿成的开档底线'}}{{presentation.manifestoTitle || '真材实料,当天现做'}}✓{{item.title}} diff --git a/apps/miniapp/components/templates/acheng-home/acheng-home.wxss b/apps/miniapp/components/templates/acheng-home/acheng-home.wxss deleted file mode 100644 index d90028b..0000000 --- a/apps/miniapp/components/templates/acheng-home/acheng-home.wxss +++ /dev/null @@ -1,177 +0,0 @@ -.page { - min-height: 100vh; - padding: 20rpx 28rpx 48rpx; - background: #fff8f0; - color: #29231f; -} -.brand-card { - padding: 28rpx; - border: 1rpx solid #f2d9c6; - border-radius: 28rpx; - background: #fff; - box-shadow: 0 12rpx 30rpx rgba(145, 75, 33, 0.08); -} -.identity { - display: flex; - gap: 20rpx; - align-items: center; -} -.identity image { - width: 96rpx; - height: 96rpx; - border: 4rpx solid #ffd9bb; - border-radius: 50%; - background: #fff1e5; -} -.name, -.title, -.slogan, -.notice-title, -.notice text, -.eyebrow, -.heading, -.more, -.dish-name, -.dish-sub, -.price, -.promise-title, -.promise-item text { - display: block; -} -.name { - font-size: 32rpx; - font-weight: 700; -} -.title { - margin-top: 6rpx; - color: #a2613b; - font-size: 21rpx; -} -.slogan { - margin-top: 10rpx; - color: #7a6a60; - font-size: 21rpx; -} -.notice { - position: relative; - margin-top: 24rpx; - padding: 20rpx; - border: 1rpx solid #f8d7b4; - border-radius: 20rpx; - background: #fff7df; - color: #6b4a35; - font-size: 22rpx; - line-height: 1.6; -} -.notice-title { - font-weight: 700; - color: #4f3020; -} -.notice-time { - position: absolute; - right: 18rpx; - top: 18rpx; - color: #c65c28; - font-size: 19rpx; -} -.actions { - display: flex; - gap: 14rpx; - margin-top: 20rpx; -} -.actions button { - flex: 1; - height: 76rpx; - border-radius: 20rpx; - background: #e87532; - color: #fff; - font-size: 24rpx; - line-height: 76rpx; -} -.actions .muted { - background: #fff0e5; - color: #b85e2c; -} -.section-head { - display: flex; - justify-content: space-between; - align-items: end; - margin: 34rpx 4rpx 18rpx; -} -.eyebrow { - color: #d2652b; - font-size: 19rpx; - letter-spacing: 2rpx; -} -.heading { - margin-top: 8rpx; - font-size: 34rpx; - font-weight: 700; -} -.more { - color: #d2652b; - font-size: 21rpx; -} -.dish-grid { - display: grid; - grid-template-columns: 1fr 1fr; - gap: 16rpx; -} -.dish { - overflow: hidden; - border: 1rpx solid #f2e2d6; - border-radius: 22rpx; - background: #fff; -} -.dish image { - display: block; - width: 100%; - height: 220rpx; - background: #f3e7de; -} -.dish-copy { - padding: 18rpx; -} -.dish-name { - font-size: 24rpx; - font-weight: 700; - line-height: 1.4; -} -.dish-sub { - margin-top: 6rpx; - color: #8c7b70; - font-size: 19rpx; - line-height: 1.4; -} -.price { - margin-top: 14rpx; - color: #dc6429; - font-size: 24rpx; - font-weight: 700; -} -.promise { - margin-top: 28rpx; - padding: 28rpx; - border-radius: 24rpx; - background: #3b2118; - color: #fff; -} -.light { - color: #ffc79f; -} -.promise-title { - margin-top: 8rpx; - font-size: 30rpx; - font-weight: 700; -} -.promise-item { - display: flex; - gap: 12rpx; - margin-top: 18rpx; - color: #ffe5d2; - font-size: 21rpx; -} -.promise-item text:first-child { - color: #ff9a5a; - font-weight: 700; -} diff --git a/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.js b/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.js deleted file mode 100644 index a5df8cf..0000000 --- a/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.js +++ /dev/null @@ -1,15 +0,0 @@ -Component({ - properties: { - brand: { type: Object, value: {} }, - presentation: { type: Object, value: {} }, - offerings: { type: Array, value: [] }, - }, - methods: { - open(e) { - this.triggerEvent("open", { id: e.currentTarget.dataset.id }); - }, - inquire() { - this.triggerEvent("inquire"); - }, - }, -}); diff --git a/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.json b/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.json deleted file mode 100644 index 67f8e03..0000000 --- a/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.json +++ /dev/null @@ -1 +0,0 @@ -{ "component": true } diff --git a/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.wxml b/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.wxml deleted file mode 100644 index ef77592..0000000 --- a/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.wxml +++ /dev/null @@ -1 +0,0 @@ -{{brand.name}}{{presentation.title || '今日菜单'}}{{presentation.subtitle || '现做现吃,支持提前预留和团体定制'}}米饭免费续,口味和忌口都可以在预约时备注{{item.name}}{{item.desc}}{{item.priceRange}}查看详情 › diff --git a/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.wxss b/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.wxss deleted file mode 100644 index 9518e4f..0000000 --- a/apps/miniapp/components/templates/acheng-offerings/acheng-offerings.wxss +++ /dev/null @@ -1,93 +0,0 @@ -.page { - min-height: 100vh; - padding: 28rpx; - background: #fff8f0; - color: #29231f; -} -.eyebrow { - display: block; - color: #d2652b; - font-size: 19rpx; - letter-spacing: 2rpx; -} -.title { - display: block; - margin-top: 8rpx; - font-size: 42rpx; - font-weight: 700; -} -.subtitle { - display: block; - margin-top: 8rpx; - color: #8c7b70; - font-size: 22rpx; -} -.tip { - margin-top: 22rpx; - padding: 18rpx 20rpx; - border: 1rpx solid #f8d7b4; - border-radius: 18rpx; - background: #fff7df; - color: #8c5c39; - font-size: 21rpx; -} -.list { - margin-top: 18rpx; -} -.dish { - display: flex; - gap: 18rpx; - margin-bottom: 16rpx; - padding: 14rpx; - border: 1rpx solid #f2e2d6; - border-radius: 22rpx; - background: #fff; -} -.dish image { - width: 196rpx; - height: 196rpx; - flex: none; - border-radius: 16rpx; - background: #f3e7de; -} -.copy { - display: flex; - min-width: 0; - flex: 1; - flex-direction: column; -} -.name { - font-size: 26rpx; - font-weight: 700; - line-height: 1.45; -} -.desc { - margin-top: 10rpx; - color: #8c7b70; - font-size: 20rpx; - line-height: 1.5; -} -.bottom { - display: flex; - align-items: end; - justify-content: space-between; - margin-top: auto; -} -.price { - color: #dc6429; - font-size: 25rpx; - font-weight: 700; -} -.action { - color: #d2652b; - font-size: 20rpx; -} -.cta { - margin: 22rpx 0 0; - height: 76rpx; - border-radius: 20rpx; - background: #e87532; - color: #fff; - font-size: 24rpx; - line-height: 76rpx; -} diff --git a/apps/miniapp/components/templates/acheng-profile/acheng-profile.js b/apps/miniapp/components/templates/acheng-profile/acheng-profile.js deleted file mode 100644 index 0baa99a..0000000 --- a/apps/miniapp/components/templates/acheng-profile/acheng-profile.js +++ /dev/null @@ -1,18 +0,0 @@ -Component({ - properties: { - brand: { type: Object, value: {} }, - presentation: { type: Object, value: {} }, - recordsCount: { type: Number, value: 0 }, - }, - methods: { - call() { - this.triggerEvent("call"); - }, - copy() { - this.triggerEvent("copy"); - }, - records() { - this.triggerEvent("records"); - }, - }, -}); diff --git a/apps/miniapp/components/templates/acheng-profile/acheng-profile.json b/apps/miniapp/components/templates/acheng-profile/acheng-profile.json deleted file mode 100644 index 67f8e03..0000000 --- a/apps/miniapp/components/templates/acheng-profile/acheng-profile.json +++ /dev/null @@ -1 +0,0 @@ -{ "component": true } diff --git a/apps/miniapp/components/templates/acheng-profile/acheng-profile.wxml b/apps/miniapp/components/templates/acheng-profile/acheng-profile.wxml deleted file mode 100644 index 15ba552..0000000 --- a/apps/miniapp/components/templates/acheng-profile/acheng-profile.wxml +++ /dev/null @@ -1 +0,0 @@ -{{brand.founder}}{{brand.title}}{{brand.slogan}}{{presentation.coverageTitle || '出摊与配送'}}{{brand.studioAddress || brand.address}}{{presentation.coverageContent || '支持校园摊位自取、宿舍配送和班级活动定制。'}}我的预约记录{{recordsCount}} 条记录 › diff --git a/apps/miniapp/components/templates/acheng-profile/acheng-profile.wxss b/apps/miniapp/components/templates/acheng-profile/acheng-profile.wxss deleted file mode 100644 index b879aea..0000000 --- a/apps/miniapp/components/templates/acheng-profile/acheng-profile.wxss +++ /dev/null @@ -1,72 +0,0 @@ -.page { - min-height: 100vh; - padding: 28rpx; - background: #fff8f0; - color: #29231f; -} -.profile-card { - padding: 36rpx 28rpx; - text-align: center; - border-radius: 28rpx; - background: #3b2118; - color: #fff; -} -.profile-card image { - width: 132rpx; - height: 132rpx; - border: 5rpx solid #ffbd8e; - border-radius: 50%; -} -.name, -.title, -.bio, -.card-title, -.card text { - display: block; -} -.name { - margin-top: 18rpx; - font-size: 36rpx; - font-weight: 700; -} -.title { - margin-top: 6rpx; - color: #ffc79f; - font-size: 22rpx; -} -.bio { - margin-top: 16rpx; - color: #ffe5d2; - font-size: 23rpx; - line-height: 1.6; -} -.contact { - display: flex; - gap: 14rpx; - margin-top: 24rpx; -} -.contact button { - flex: 1; - height: 70rpx; - border-radius: 18rpx; - background: #e87532; - color: #fff; - font-size: 22rpx; - line-height: 70rpx; -} -.card { - margin-top: 18rpx; - padding: 26rpx; - border: 1rpx solid #f2d9c6; - border-radius: 22rpx; - background: #fff; - color: #7a6a60; - font-size: 22rpx; - line-height: 1.7; -} -.card-title { - margin-bottom: 10rpx; - color: #4b2b1d; - font-size: 27rpx; - font-weight: 700; -} diff --git a/apps/miniapp/components/templates/linjing-home/linjing-home.js b/apps/miniapp/components/templates/linjing-home/linjing-home.js deleted file mode 100644 index 3f4fad2..0000000 --- a/apps/miniapp/components/templates/linjing-home/linjing-home.js +++ /dev/null @@ -1,17 +0,0 @@ -Component({ - properties: { - brand: { type: Object, value: {} }, - presentation: { type: Object, value: {} }, - hero: { type: Object, value: {} }, - trustContent: { type: Object, value: {} }, - offerings: { type: Array, value: [] }, - }, - methods: { - selectOffering(event) { - this.triggerEvent("select", { id: event.currentTarget.dataset.id }); - }, - goWorks() { - this.triggerEvent("works"); - }, - }, -}); diff --git a/apps/miniapp/components/templates/linjing-home/linjing-home.json b/apps/miniapp/components/templates/linjing-home/linjing-home.json deleted file mode 100644 index 67f8e03..0000000 --- a/apps/miniapp/components/templates/linjing-home/linjing-home.json +++ /dev/null @@ -1 +0,0 @@ -{ "component": true } diff --git a/apps/miniapp/components/templates/linjing-home/linjing-home.wxml b/apps/miniapp/components/templates/linjing-home/linjing-home.wxml deleted file mode 100644 index e77a0f5..0000000 --- a/apps/miniapp/components/templates/linjing-home/linjing-home.wxml +++ /dev/null @@ -1,8 +0,0 @@ - - {{brand.founder}}{{brand.title}}“{{brand.slogan}}”{{presentation.founderBadge}} - {{hero.eyebrow}}{{hero.title}}{{hero.slogan}}{{hero.cta}} - {{presentation.proofEyebrow}}{{presentation.proofTitle}}{{trustContent.bio}}{{item.value}}{{item.label}}{{item.sub}} - {{presentation.manifestoEyebrow}}{{presentation.manifestoTitle}}{{item.title}}{{item.desc}} - {{presentation.worksEyebrow}}{{presentation.worksTitle}}{{presentation.worksAction}}{{item.category}} · {{item.area}}{{item.name}}{{item.series}} · {{item.keywords[0]}} · {{item.keywords[1]}} - {{presentation.flowEyebrow}}{{presentation.flowTitle}}{{item.step}}{{item.name}}{{item.desc}} - diff --git a/apps/miniapp/components/templates/linjing-home/linjing-home.wxss b/apps/miniapp/components/templates/linjing-home/linjing-home.wxss deleted file mode 100644 index 1254b3b..0000000 --- a/apps/miniapp/components/templates/linjing-home/linjing-home.wxss +++ /dev/null @@ -1,261 +0,0 @@ -.page { - background: #f7f5f1; - color: #252525; - padding-bottom: 30rpx; -} -.founder-card { - position: relative; - display: flex; - gap: 20rpx; - align-items: flex-start; - margin: 32rpx 40rpx 20rpx; - padding: 28rpx; - border: 1rpx solid #e6ded5; - border-radius: 28rpx; - background: #fff; -} -.avatar { - width: 112rpx; - height: 112rpx; - flex: 0 0 112rpx; - border: 4rpx solid #d9c8b2; - border-radius: 50%; -} -.founder-copy { - min-width: 0; - padding-right: 78rpx; -} -.founder-name, -.founder-title, -.quote, -.eyebrow, -.hero-title, -.hero-slogan, -.section-title, -.body, -.stat-value, -.stat-label, -.stat-sub, -.pillar-title, -.pillar-desc, -.work-category, -.work-name, -.work-desc, -.flow-eyebrow, -.flow-title, -.flow-step, -.flow-name, -.flow-desc { - display: block; -} -.founder-name { - font: 30rpx serif; -} -.founder-title { - margin-top: 6rpx; - color: #77736b; - font-size: 20rpx; -} -.quote { - margin-top: 14rpx; - font: 21rpx serif; -} -.badge { - position: absolute; - top: 24rpx; - right: 20rpx; - padding: 8rpx 12rpx; - border-radius: 20rpx; - background: #f3ede6; - color: #8a6846; - font-size: 18rpx; -} -.hero { - position: relative; - height: 400rpx; - margin: 0 40rpx 42rpx; - overflow: hidden; - border-radius: 28rpx; -} -.hero-image { - width: 100%; - height: 100%; -} -.hero-shade { - position: absolute; - inset: 0; - background: linear-gradient(180deg, rgba(20, 22, 21, 0.1), rgba(20, 22, 21, 0.82)); -} -.hero-copy { - position: absolute; - right: 28rpx; - bottom: 28rpx; - left: 28rpx; - color: #fff; -} -.eyebrow { - margin-bottom: 14rpx; - color: #d9c8b2; - font-size: 18rpx; - letter-spacing: 3rpx; -} -.dark { - color: #8a6846; -} -.hero-title, -.section-title { - font: 34rpx serif; -} -.hero-slogan { - margin-top: 10rpx; - font-size: 21rpx; -} -.hero-button { - position: absolute; - right: 0; - bottom: 0; - padding: 12rpx 16rpx; - border: 1rpx solid rgba(255, 255, 255, 0.3); - color: #d9c8b2; - font-size: 19rpx; -} -.intro, -.section { - padding: 0 40rpx 48rpx; -} -.body { - color: #77736b; - font-size: 24rpx; - line-height: 1.8; -} -.stats { - display: grid; - grid-template-columns: 1fr 1fr; - gap: 16rpx; - margin-top: 22rpx; -} -.stats view { - padding: 22rpx; - border: 1rpx solid #e6ded5; - border-radius: 20rpx; - background: #fff; -} -.stat-value { - color: #8a6846; - font: 38rpx serif; -} -.stat-label { - margin-top: 4rpx; - font-size: 22rpx; - font-weight: 600; -} -.stat-sub { - margin-top: 6rpx; - color: #77736b; - font-size: 18rpx; - line-height: 1.5; -} -.trust { - padding: 42rpx 40rpx; - background: #202221; - color: #fff; -} -.light { - color: #fff; -} -.pillar { - margin-top: 24rpx; -} -.pillar-title { - color: #fff; - font: 28rpx serif; -} -.pillar-desc { - margin-top: 8rpx; - color: #c6c2ba; - font-size: 22rpx; - line-height: 1.65; -} -.section-head { - display: flex; - align-items: end; - justify-content: space-between; - margin-bottom: 22rpx; -} -.more { - color: #8a6846; - font-size: 21rpx; -} -.work-card { - margin-bottom: 24rpx; - overflow: hidden; - border: 1rpx solid #e6ded5; - border-radius: 28rpx; - background: #fff; -} -.work-card image { - width: 100%; - height: 300rpx; -} -.work-info { - padding: 24rpx; -} -.work-category { - color: #8a6846; - font-size: 19rpx; -} -.work-name { - margin: 10rpx 0; - font: 28rpx serif; -} -.work-desc { - color: #77736b; - font-size: 22rpx; - line-height: 1.6; -} -.flow { - margin: 0 40rpx 42rpx; - padding: 30rpx 24rpx; - border: 1rpx solid #e6ded5; - border-radius: 20rpx; - background: #efece6; - text-align: center; -} -.flow-eyebrow { - color: #8a6846; - font-size: 18rpx; - letter-spacing: 2rpx; -} -.flow-title { - margin-top: 6rpx; - font: 30rpx serif; -} -.flow-grid { - display: grid; - grid-template-columns: 1fr 1fr; - gap: 16rpx; - margin-top: 24rpx; - text-align: left; -} -.flow-item { - padding: 18rpx; - border: 1rpx solid #e6ded5; - border-radius: 14rpx; - background: #fff; -} -.flow-step { - color: #8a6846; - font-size: 18rpx; - font-weight: 700; -} -.flow-name { - margin-top: 5rpx; - font-size: 21rpx; - font-weight: 600; -} -.flow-desc { - margin-top: 6rpx; - color: #77736b; - font-size: 17rpx; - line-height: 1.5; -} diff --git a/apps/miniapp/components/templates/linjing-profile/linjing-profile.js b/apps/miniapp/components/templates/linjing-profile/linjing-profile.js deleted file mode 100644 index 0baa99a..0000000 --- a/apps/miniapp/components/templates/linjing-profile/linjing-profile.js +++ /dev/null @@ -1,18 +0,0 @@ -Component({ - properties: { - brand: { type: Object, value: {} }, - presentation: { type: Object, value: {} }, - recordsCount: { type: Number, value: 0 }, - }, - methods: { - call() { - this.triggerEvent("call"); - }, - copy() { - this.triggerEvent("copy"); - }, - records() { - this.triggerEvent("records"); - }, - }, -}); diff --git a/apps/miniapp/components/templates/linjing-profile/linjing-profile.json b/apps/miniapp/components/templates/linjing-profile/linjing-profile.json deleted file mode 100644 index 5aa1d8d..0000000 --- a/apps/miniapp/components/templates/linjing-profile/linjing-profile.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "component": true, - "usingComponents": { - "t-icon": "/miniprogram_npm/tdesign-miniprogram/icon/icon" - } -} diff --git a/apps/miniapp/components/templates/linjing-profile/linjing-profile.wxml b/apps/miniapp/components/templates/linjing-profile/linjing-profile.wxml deleted file mode 100644 index b80db86..0000000 --- a/apps/miniapp/components/templates/linjing-profile/linjing-profile.wxml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - {{brand.founder}}{{brand.title}} - - - {{presentation.phoneLabel}}{{brand.phone}} - {{presentation.wechatLabel}}{{brand.wechat}} - {{presentation.addressLabel}}{{brand.studioAddress}} - - - - - {{presentation.recordsTitle}}{{presentation.recordsSubtitle}} - {{recordsCount}} {{presentation.recordsCountUnit}} - - - {{presentation.coverageTitle}} - {{item.title}}{{item.content}} - - - {{presentation.warrantyTitle}} - •{{item}} - - diff --git a/apps/miniapp/components/templates/linjing-profile/linjing-profile.wxss b/apps/miniapp/components/templates/linjing-profile/linjing-profile.wxss deleted file mode 100644 index c483b30..0000000 --- a/apps/miniapp/components/templates/linjing-profile/linjing-profile.wxss +++ /dev/null @@ -1,194 +0,0 @@ -.profile { - min-height: 100vh; - padding: 28rpx 32rpx 56rpx; - background: #f7f5f1; - color: #252525; -} -.founder-card { - padding: 34rpx 30rpx; - border-radius: 20rpx; - background: #202221; - color: #fff; - box-shadow: 0 12rpx 34rpx rgba(32, 34, 33, 0.12); -} -.identity { - display: flex; - align-items: center; - gap: 22rpx; -} -.avatar { - width: 92rpx; - height: 92rpx; - border: 2rpx solid #8a6846; - border-radius: 50%; - background: #343736; -} -.founder, -.role, -.label, -.value, -.address-value, -.entry-copy text, -.entry-count text, -.note-title, -.note text, -.warranty text { - display: block; -} -.founder { - font: 34rpx serif; -} -.role { - margin-top: 8rpx; - color: #d9c8b2; - font-size: 22rpx; -} -.contact-lines { - margin-top: 24rpx; - border-top: 1rpx solid rgba(255, 255, 255, 0.12); -} -.contact-line { - display: flex; - align-items: center; - justify-content: space-between; - gap: 20rpx; - padding-top: 18rpx; - margin-top: 18rpx; - border-top: 1rpx solid rgba(255, 255, 255, 0.1); - font-size: 22rpx; -} -.contact-line:first-child { - border-top: 0; - margin-top: 0; -} -.label { - flex: 0 0 auto; - color: rgba(255, 255, 255, 0.52); -} -.contact-action { - display: flex; - min-width: 0; - align-items: center; - gap: 12rpx; -} -.value { - color: #fff; - font-family: monospace; - white-space: nowrap; -} -.accent { - color: #d9c8b2; -} -.contact-action button { - display: flex; - align-items: center; - justify-content: center; - gap: 5rpx; - min-width: 86rpx; - height: 46rpx; - margin: 0; - padding: 0 12rpx; - border-radius: 9rpx; - background: rgba(255, 255, 255, 0.1); - color: #d9c8b2; - font-size: 20rpx; - line-height: 46rpx; -} -.address { - align-items: flex-start; -} -.address-value { - max-width: 410rpx; - color: rgba(255, 255, 255, 0.82); - line-height: 1.55; - text-align: right; -} -.records-card, -.info-card { - margin-top: 20rpx; - border: 1rpx solid #e6ded5; - border-radius: 18rpx; - background: #fff; - box-shadow: 0 10rpx 30rpx -12rpx rgba(32, 34, 33, 0.08); -} -.records-card { - display: flex; - align-items: center; - gap: 18rpx; - padding: 26rpx; -} -.entry-icon { - display: flex; - align-items: center; - justify-content: center; - width: 66rpx; - height: 66rpx; - border-radius: 12rpx; - background: rgba(138, 104, 70, 0.1); - color: #8a6846; -} -.entry-copy { - flex: 1; - min-width: 0; -} -.entry-copy text:first-child { - color: #202221; - font-size: 25rpx; - font-weight: 600; -} -.entry-copy text:last-child { - margin-top: 7rpx; - color: #77736b; - font-size: 20rpx; - line-height: 1.4; -} -.entry-count { - display: flex; - align-items: center; - gap: 4rpx; - flex: 0 0 auto; - color: #8a6846; - font-size: 20rpx; -} -.info-card { - padding: 28rpx; -} -.card-title { - display: flex; - align-items: center; - gap: 12rpx; - color: #202221; - font-size: 26rpx; - font-weight: 700; -} -.card-title t-icon { - color: #8a6846; -} -.note { - margin-top: 18rpx; - padding: 20rpx; - border: 1rpx solid #e6ded5; - border-radius: 12rpx; - background: #f7f5f1; - color: #57534e; - font-size: 23rpx; - line-height: 1.7; -} -.note-title { - margin-bottom: 5rpx; - color: #202221; - font-size: 23rpx; - font-weight: 700; -} -.warranty { - display: flex; - gap: 10rpx; - margin-top: 16rpx; - color: #77736b; - font-size: 23rpx; - line-height: 1.65; -} -.dot { - flex: 0 0 auto; - color: #8a6846; -} diff --git a/apps/miniapp/pages/bookings/index.json b/apps/miniapp/pages/bookings/index.json deleted file mode 100644 index ae39f88..0000000 --- a/apps/miniapp/pages/bookings/index.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "navigationBarTitleText": "我的订单", - "navigationBarBackgroundColor": "#FBF7F1", - "navigationBarTextStyle": "black", - "usingComponents": { - "t-icon": "/miniprogram_npm/tdesign-miniprogram/icon/icon", - "profile-module": "/components/modules/profile/profile", - "linjing-profile": "/components/templates/linjing-profile/linjing-profile", - "acheng-profile": "/components/templates/acheng-profile/acheng-profile", - "runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar" - } -} diff --git a/apps/miniapp/pages/bookings/index.wxml b/apps/miniapp/pages/bookings/index.wxml deleted file mode 100644 index 3aa7e99..0000000 --- a/apps/miniapp/pages/bookings/index.wxml +++ /dev/null @@ -1 +0,0 @@ -{{error}} diff --git a/apps/miniapp/pages/bookings/index.wxss b/apps/miniapp/pages/bookings/index.wxss deleted file mode 100644 index c1c3570..0000000 --- a/apps/miniapp/pages/bookings/index.wxss +++ /dev/null @@ -1,166 +0,0 @@ -.page { - min-height: 100vh; - padding: 0; - background: #f7f5f1; - color: #252525; -} -.runtime-error { - margin: 48rpx 0; - padding: 28rpx; - border: 1rpx solid #e6ded5; - border-radius: 14rpx; - background: #fff; - color: #8a6846; - font-size: 25rpx; - line-height: 1.6; -} -.contact-card { - padding: 34rpx 30rpx; - background: #202221; - color: #fff; - border-radius: 18rpx; -} -.identity { - display: flex; - align-items: center; - gap: 20rpx; -} -.avatar { - width: 88rpx; - height: 88rpx; - border: 2rpx solid #8a6846; - border-radius: 50%; - display: flex; - align-items: center; - justify-content: center; - color: #d9c8b2; - font: 42rpx serif; -} -.founder { - display: block; - font: 34rpx serif; -} -.role { - display: block; - margin-top: 8rpx; - color: #d9c8b2; - font-size: 22rpx; -} -.contact-line { - display: flex; - justify-content: space-between; - align-items: center; - margin-top: 22rpx; - padding-top: 18rpx; - border-top: 1rpx solid rgba(255, 255, 255, 0.12); - color: #aaa; - font-size: 23rpx; -} -.contact-line > view { - display: flex; - align-items: center; - gap: 10rpx; - color: #fff; -} -.contact-line button { - margin: 0; - padding: 0 14rpx; - background: rgba(255, 255, 255, 0.1); - color: #d9c8b2; - font-size: 21rpx; -} -.records-entry, -.info-card { - margin-top: 20rpx; - padding: 28rpx; - background: #fff; - border: 1rpx solid #e6ded5; - border-radius: 16rpx; -} -.records-entry { - display: flex; - justify-content: space-between; - font-size: 26rpx; -} -.records-entry text:last-child { - color: #8a6846; -} -.card-title { - display: block; - font-weight: 700; - font-size: 27rpx; -} -.note, -.bullet { - display: block; - margin-top: 16rpx; - color: #77736b; - font-size: 24rpx; - line-height: 1.75; -} -.entry-icon { - width: 64rpx; - height: 64rpx; - border-radius: 12rpx; - background: rgba(138, 104, 70, 0.1); - color: #8a6846; - display: flex; - align-items: center; - justify-content: center; -} -.records-entry { - align-items: center; - gap: 18rpx; -} -.entry-copy { - flex: 1; -} -.entry-copy text { - display: block; -} -.entry-copy text:last-child { - margin-top: 8rpx; - color: #77736b; - font-size: 21rpx; -} -.count { - color: #8a6846; - font-size: 22rpx; -} -.card-title { - display: flex; - align-items: center; - gap: 12rpx; - color: #202221; -} -.note { - padding: 20rpx; - background: #f7f5f1; - border: 1rpx solid #e6ded5; - border-radius: 12rpx; -} -.note-title { - display: block; - margin-bottom: 6rpx; - color: #202221; - font-weight: 700; -} -.bullet { - padding-left: 8rpx; -} -.contact-line button { - display: flex; - align-items: center; - justify-content: center; - gap: 6rpx; - height: 44rpx; - line-height: 44rpx; - white-space: nowrap; -} -.contact-line button t-icon { - display: inline-flex; - vertical-align: middle; -} -.page { - padding-bottom: 150rpx; -} diff --git a/apps/miniapp/pages/index/index.js b/apps/miniapp/pages/index/index.js deleted file mode 100644 index 8f1e853..0000000 --- a/apps/miniapp/pages/index/index.js +++ /dev/null @@ -1,87 +0,0 @@ -const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); -const config = require("../../utils/config"); -Page({ - data: { - brand: {}, - trustContent: [], - offerings: [], - modules: [], - moduleVariants: {}, - pageRenderer: "", - layout: [], - theme: {}, - hero: { image: "", eyebrow: "", title: "", slogan: "", cta: "" }, - loading: false, - loadedBrandSlug: "", - templateKey: "", - navigation: [], - }, - onLoad() { - this.loadWorkspace(); - }, - onShow() { - if (this.data.loadedBrandSlug && this.data.loadedBrandSlug !== config.brandSlug) { - this.loadWorkspace(); - } - }, - loadWorkspace() { - this.setData({ loading: true }); - loadWorkspaceWithFallback() - .then((workspace) => { - const activeBrand = workspace.brand || {}; - const activeOfferings = workspace.offerings || []; - const layout = workspace.layout?.home || [ - "founder-card", - "brand-hero", - "trust-proof", - "trust-manifesto", - "offering-list", - ]; - const firstOffering = activeOfferings[0] || {}; - const configuredHero = - activeBrand.homeHero && typeof activeBrand.homeHero === "object" - ? activeBrand.homeHero - : {}; - this.setData({ - brand: activeBrand, - trustContent: workspace.trustPresentation || {}, - offerings: activeOfferings, - modules: workspace.modules || [], - moduleVariants: workspace.moduleVariants || {}, - pageRenderer: workspace.pageRenderers?.home || "", - layout, - theme: workspace.theme || {}, - hero: { - ...this.data.hero, - image: activeBrand.heroImage || this.data.hero.image, - eyebrow: activeBrand.tagline || activeBrand.name, - title: firstOffering.name || activeBrand.name, - slogan: activeBrand.description || "", - ...configuredHero, - }, - loading: false, - loadedBrandSlug: config.brandSlug, - templateKey: workspace.visualTemplate?.key || "", - navigation: workspace.navigation || [], - }); - wx.setNavigationBarTitle({ title: activeBrand.name || "个人品牌" }); - }) - .catch((error) => this.setData({ error: error.message, loading: false })); - }, - showModule(e) { - return this.data.layout.includes(e); - }, - selectOffering(e) { - const id = e.detail ? e.detail.id : e.currentTarget.dataset.id; - wx.navigateTo({ url: "/pages/offering/detail?id=" + id }); - }, - goWorks() { - wx.switchTab({ url: "/pages/services/index" }); - }, - goInquiry() { - wx.navigateTo({ url: "/pages/inquiry/index" }); - }, - goProfile() { - wx.navigateTo({ url: "/pages/bookings/index" }); - }, -}); diff --git a/apps/miniapp/pages/index/index.json b/apps/miniapp/pages/index/index.json deleted file mode 100644 index e363cdf..0000000 --- a/apps/miniapp/pages/index/index.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "navigationBarTitleText": "品牌首页", - "usingComponents": { - "linjing-home": "/components/templates/linjing-home/linjing-home", - "acheng-home": "/components/templates/acheng-home/acheng-home", - "founder-card": "/components/modules/founder-card/founder-card", - "brand-hero": "/components/modules/brand-hero/brand-hero", - "trust-proof": "/components/modules/trust-proof/trust-proof", - "trust-manifesto": "/components/modules/trust-manifesto/trust-manifesto", - "offering-list": "/components/modules/offering-list/offering-list", - "runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar" - } -} diff --git a/apps/miniapp/pages/index/index.wxml b/apps/miniapp/pages/index/index.wxml deleted file mode 100644 index 60a9108..0000000 --- a/apps/miniapp/pages/index/index.wxml +++ /dev/null @@ -1,17 +0,0 @@ - - {{error}} - - - - - - - - - - - - - - - diff --git a/apps/miniapp/pages/index/index.wxss b/apps/miniapp/pages/index/index.wxss deleted file mode 100644 index 0e70a2c..0000000 --- a/apps/miniapp/pages/index/index.wxss +++ /dev/null @@ -1,221 +0,0 @@ -.page { - background: #f7f5f1; - color: #252525; - min-height: 100vh; - padding-bottom: 30rpx; -} -.runtime-error { - margin: 48rpx 32rpx; - padding: 28rpx; - border: 1rpx solid #e6ded5; - border-radius: 14rpx; - background: #fff; - color: #8a6846; - font-size: 25rpx; - line-height: 1.6; -} -.founder { - margin: 32rpx 40rpx 20rpx; - padding: 28rpx; - background: #fff; - border: 1px solid #e6ded5; - border-radius: 28rpx; - display: flex; - gap: 20rpx; - align-items: flex-start; - position: relative; -} -.avatar { - width: 112rpx; - height: 112rpx; - border-radius: 50%; - border: 4rpx solid #d9c8b2; -} -.founder-name { - display: block; - font-family: serif; - font-size: 30rpx; -} -.founder-title { - display: block; - color: #77736b; - font-size: 20rpx; - margin-top: 6rpx; -} -.quote { - display: block; - font-family: serif; - font-size: 21rpx; - margin-top: 14rpx; -} -.badge { - position: absolute; - right: 20rpx; - top: 24rpx; - color: #8a6846; - background: #f3ede6; - padding: 8rpx 12rpx; - border-radius: 20rpx; - font-size: 18rpx; -} -.hero { - margin: 0 40rpx 42rpx; - height: 400rpx; - position: relative; - border-radius: 28rpx; - overflow: hidden; -} -.hero-image { - width: 100%; - height: 100%; -} -.hero-shade { - position: absolute; - inset: 0; - background: linear-gradient(180deg, rgba(20, 22, 21, 0.1), rgba(20, 22, 21, 0.82)); -} -.hero-copy { - position: absolute; - left: 28rpx; - right: 28rpx; - bottom: 28rpx; - color: #fff; -} -.eyebrow { - display: block; - font-size: 18rpx; - letter-spacing: 3rpx; - color: #d9c8b2; - margin-bottom: 14rpx; -} -.eyebrow.dark { - color: #8a6846; -} -.hero-title { - display: block; - font-size: 34rpx; - font-family: serif; -} -.hero-slogan { - display: block; - font-size: 21rpx; - margin-top: 10rpx; -} -.hero-button { - position: absolute; - right: 0; - bottom: 0; - background: rgba(255, 255, 255, 0.12); - color: #d9c8b2; - border: 1px solid rgba(255, 255, 255, 0.3); - font-size: 19rpx; - height: 54rpx; - line-height: 54rpx; - margin: 0; -} -.intro, -.section { - padding: 0 40rpx 48rpx; -} -.section-title { - display: block; - font-size: 34rpx; - font-family: serif; - margin-bottom: 16rpx; -} -.body { - display: block; - color: #77736b; - line-height: 1.8; - font-size: 24rpx; -} -.stats { - display: grid; - grid-template-columns: 1fr 1fr; - gap: 16rpx; - margin-top: 22rpx; -} -.stats view { - background: #fff; - border: 1px solid #e6ded5; - border-radius: 20rpx; - padding: 22rpx; -} -.stat-value { - display: block; - font-size: 38rpx; - color: #8a6846; - font-family: serif; -} -.stat-label { - display: block; - font-size: 22rpx; - font-weight: 600; - margin-top: 4rpx; -} -.section-head { - display: flex; - justify-content: space-between; - align-items: end; - margin-bottom: 22rpx; -} -.more { - font-size: 21rpx; - color: #8a6846; -} -.work-card { - background: #fff; - border: 1px solid #e6ded5; - border-radius: 28rpx; - overflow: hidden; - margin-bottom: 24rpx; -} -.work-card image { - width: 100%; - height: 300rpx; - display: block; -} -.work-info { - padding: 24rpx; -} -.work-category { - font-size: 19rpx; - color: #8a6846; -} -.work-name { - display: block; - font-family: serif; - font-size: 28rpx; - margin: 10rpx 0; -} -.work-desc { - font-size: 22rpx; - color: #77736b; - line-height: 1.6; -} -.trust { - margin-top: 10rpx; - background: #202221; - color: #fff; - padding: 42rpx 40rpx; -} -.light { - color: #fff; -} -.light-body { - color: #c6c2ba; - margin-bottom: 26rpx; -} -.outline-button { - margin: 0; - background: transparent; - border: 1px solid #d9c8b2; - color: #d9c8b2; - border-radius: 0; - font-size: 24rpx; - height: 72rpx; - line-height: 72rpx; -} -.page { - padding-bottom: 150rpx; -} diff --git a/apps/miniapp/pages/inquiry/index.js b/apps/miniapp/pages/inquiry/index.js index 184f9b0..f32eb3d 100644 --- a/apps/miniapp/pages/inquiry/index.js +++ b/apps/miniapp/pages/inquiry/index.js @@ -13,8 +13,6 @@ Page({ fields: [], formId: "", error: "", - templateKey: "", - navigation: [], }, onLoad(options) { loadWorkspaceWithFallback() @@ -39,8 +37,6 @@ Page({ subtitle: presentation.subtitle || "提交信息后由主理人与你联系", submitLabel: isQuote ? "提交报价需求" : presentation.submitLabel || "提交需求", presentation, - templateKey: workspace.visualTemplate?.key || "", - navigation: workspace.navigation || [], }); }) .catch((error) => this.setData({ error: error.message })); diff --git a/apps/miniapp/pages/inquiry/index.json b/apps/miniapp/pages/inquiry/index.json index 082eb3a..8537ceb 100644 --- a/apps/miniapp/pages/inquiry/index.json +++ b/apps/miniapp/pages/inquiry/index.json @@ -7,7 +7,6 @@ "brand-field": "/components/ui/brand-field/brand-field", "brand-loading": "/components/ui/brand-loading/brand-loading", "brand-empty": "/components/ui/brand-empty/brand-empty", - "inquiry-form": "/components/modules/inquiry-form/inquiry-form", - "runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar" + "inquiry-form": "/components/modules/inquiry-form/inquiry-form" } } diff --git a/apps/miniapp/pages/services/index.js b/apps/miniapp/pages/services/index.js deleted file mode 100644 index 3939a70..0000000 --- a/apps/miniapp/pages/services/index.js +++ /dev/null @@ -1,71 +0,0 @@ -const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); -const config = require("../../utils/config"); -Page({ - data: { - loading: false, - error: "", - offerings: [], - filtered: [], - modules: [], - theme: {}, - brand: {}, - presentation: {}, - category: "all", - categories: [], - pageRenderer: "", - loadedBrandSlug: "", - templateKey: "", - navigation: [], - }, - onLoad() { - this.loadWorkspace(); - }, - onShow() { - if (this.data.loadedBrandSlug && this.data.loadedBrandSlug !== config.brandSlug) { - this.loadWorkspace(); - } - }, - loadWorkspace() { - loadWorkspaceWithFallback() - .then((workspace) => { - const items = workspace.offerings || []; - this.setData({ - offerings: items, - filtered: items, - categories: [ - { key: "all", label: "全部" }, - ...Array.from(new Set(items.map((item) => item.category).filter(Boolean))).map( - (key) => ({ - key, - label: key, - }), - ), - ], - modules: workspace.modules || [], - theme: workspace.theme || {}, - brand: workspace.brand || {}, - presentation: workspace.brand?.visualPresentation?.offerings || {}, - brand: workspace.brand || {}, - pageRenderer: workspace.pageRenderers?.offerings || "", - loadedBrandSlug: config.brandSlug, - templateKey: workspace.visualTemplate?.key || "", - navigation: workspace.navigation || [], - }); - }) - .catch((error) => this.setData({ error: error.message })); - }, - switchCategory(e) { - const category = e.currentTarget.dataset.category; - const items = this.data.offerings || []; - this.setData({ - category, - filtered: category === "all" ? items : items.filter((item) => item.category === category), - }); - }, - open(e) { - wx.navigateTo({ url: "/pages/offering/detail?id=" + e.currentTarget.dataset.id }); - }, - inquire() { - wx.navigateTo({ url: "/pages/inquiry/index" }); - }, -}); diff --git a/apps/miniapp/pages/services/index.json b/apps/miniapp/pages/services/index.json deleted file mode 100644 index 7df6e9b..0000000 --- a/apps/miniapp/pages/services/index.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "navigationBarTitleText": "服务列表", - "navigationBarBackgroundColor": "#FBF7F1", - "navigationBarTextStyle": "black", - "usingComponents": { - "acheng-offerings": "/components/templates/acheng-offerings/acheng-offerings", - "linjing-offerings": "/components/templates/linjing-offerings/linjing-offerings", - "brand-loading": "/components/ui/brand-loading/brand-loading", - "brand-empty": "/components/ui/brand-empty/brand-empty", - "runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar" - } -} diff --git a/apps/miniapp/pages/services/index.wxml b/apps/miniapp/pages/services/index.wxml deleted file mode 100644 index 8d2a47f..0000000 --- a/apps/miniapp/pages/services/index.wxml +++ /dev/null @@ -1 +0,0 @@ -{{error}}{{brand.name}}{{presentation.title}}{{presentation.subtitle}}{{item.label}}{{item.category}}{{item.tag}}{{item.area}}{{item.spaceType}}{{item.name}}{{item.series}}{{presentation.materialLabel}}{{item.woodMaterial}}{{presentation.hardwareLabel}}{{item.hardware}} diff --git a/apps/miniapp/pages/services/index.wxss b/apps/miniapp/pages/services/index.wxss deleted file mode 100644 index 8f3af06..0000000 --- a/apps/miniapp/pages/services/index.wxss +++ /dev/null @@ -1,202 +0,0 @@ -.page { - background: #f7f5f1; - min-height: 100vh; - color: #252525; -} -.runtime-error { - margin: 48rpx 32rpx; - padding: 28rpx; - border: 1rpx solid #e6ded5; - border-radius: 14rpx; - background: #fff; - color: #8a6846; - font-size: 25rpx; - line-height: 1.6; -} -.head { - background: #252827; - color: #fff; - padding: 70rpx 40rpx 55rpx; -} -.eyebrow { - font-size: 20rpx; - letter-spacing: 3rpx; - color: #d9c8b2; - display: block; - margin-bottom: 18rpx; -} -.title { - font-size: 52rpx; - font-family: serif; - display: block; -} -.sub { - font-size: 26rpx; - color: #c6c2ba; - display: block; - margin-top: 16rpx; -} -.tabs { - white-space: nowrap; - padding: 28rpx 32rpx; - background: #f7f5f1; -} -.tab { - display: inline-block; - font-size: 25rpx; - color: #77736b; - margin: 0 14rpx; - padding-bottom: 12rpx; -} -.tab.active { - color: #8a6846; - border-bottom: 2px solid #8a6846; -} -.list { - padding: 0 32rpx 40rpx; -} -.card { - background: #fff; - margin-bottom: 30rpx; - overflow: hidden; - border: 1rpx solid #e6ded5; - border-radius: 18rpx; - box-shadow: 0 10rpx 30rpx -12rpx rgba(32, 34, 33, 0.08); -} -.media { - position: relative; - height: 380rpx; - background: #202221; -} -.card image { - width: 100%; - height: 100%; - display: block; -} -.media-category, -.media-tag, -.media-meta { - position: absolute; - color: #fff; - font-size: 20rpx; -} -.media-category { - top: 20rpx; - left: 20rpx; - padding: 8rpx 14rpx; - border: 1rpx solid rgba(255, 255, 255, 0.15); - border-radius: 8rpx; - background: rgba(32, 34, 33, 0.76); - color: #d9c8b2; -} -.media-tag { - top: 20rpx; - right: 20rpx; - padding: 8rpx 14rpx; - border-radius: 6rpx; - background: #8a6846; -} -.media-meta { - right: 20rpx; - bottom: 20rpx; - left: 20rpx; - display: flex; - justify-content: space-between; - gap: 20rpx; - padding: 10rpx 14rpx; - border: 1rpx solid rgba(255, 255, 255, 0.12); - border-radius: 10rpx; - background: rgba(0, 0, 0, 0.4); - color: rgba(255, 255, 255, 0.9); - font-size: 19rpx; -} -.media-meta text:last-child { - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; - color: #d9c8b2; -} -.card-body { - padding: 28rpx; -} -.category { - font-size: 20rpx; - color: #8a6846; - display: block; -} -.name { - display: block; - font-size: 34rpx; - line-height: 1.45; - margin: 12rpx 0 6rpx; -} -.series { - display: block; - color: #77736b; - font-size: 24rpx; -} -.desc { - display: block; - color: #77736b; - font-size: 25rpx; - line-height: 1.7; - margin-top: 18rpx; -} -.specs { - margin-top: 20rpx; - padding: 18rpx; - border: 1rpx solid #e6ded5; - border-radius: 12rpx; - background: #f7f5f1; - color: #252525; - font-size: 20rpx; - line-height: 1.55; -} -.specs view { - display: flex; - gap: 8rpx; -} -.specs view + view { - margin-top: 10rpx; -} -.specs text:first-child { - flex: 0 0 auto; - color: #77736b; -} -.actions { - display: flex; - gap: 14rpx; - margin-top: 22rpx; -} -.actions button { - flex: 1; - height: 70rpx; - margin: 0; - border-radius: 12rpx; - font-size: 21rpx; - line-height: 70rpx; -} -.detail { - border: 1rpx solid #202221; - background: #fff; - color: #202221; -} -.inquire { - background: #8a6846; - color: #fff; -} -.foot { - display: flex; - justify-content: space-between; - border-top: 1px solid #eee7de; - margin-top: 24rpx; - padding-top: 20rpx; - color: #999; - font-size: 22rpx; -} -.arrow { - color: #8a6846; -} -.page { - padding-bottom: 150rpx; -} diff --git a/apps/miniapp/pages/stall-service/index.js b/apps/miniapp/pages/stall-service/index.js deleted file mode 100644 index 4edc0de..0000000 --- a/apps/miniapp/pages/stall-service/index.js +++ /dev/null @@ -1,17 +0,0 @@ -const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); -Page({ - data: { brand: {}, templateKey: "", presentation: {}, navigation: [], loading: true }, - onLoad() { - loadWorkspaceWithFallback() - .then((workspace) => - this.setData({ - brand: workspace.brand || {}, - templateKey: workspace.visualTemplate?.key || "", - presentation: workspace.brand?.visualPresentation?.home || {}, - navigation: workspace.navigation || [], - loading: false, - }), - ) - .catch(() => this.setData({ loading: false })); - }, -}); diff --git a/apps/miniapp/pages/stall-service/index.json b/apps/miniapp/pages/stall-service/index.json deleted file mode 100644 index 4208aee..0000000 --- a/apps/miniapp/pages/stall-service/index.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "navigationBarTitleText": "出摊服务", - "usingComponents": { "runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar" } -} diff --git a/apps/miniapp/pages/stall-service/index.wxml b/apps/miniapp/pages/stall-service/index.wxml deleted file mode 100644 index 3188259..0000000 --- a/apps/miniapp/pages/stall-service/index.wxml +++ /dev/null @@ -1 +0,0 @@ -出摊与服务今天在哪里,怎么取餐{{brand.hours || '营业时间以当天通知为准'}}固定出摊与取餐{{brand.studioAddress || brand.address || '校园生活区附近'}}支持摊位自取、校内配送,以及班级和社团活动定制。定制餐品流程1. 提交人数、时间和口味需求2. 主理人确认菜单与取餐方式3. 当天现做并按约定时间交付 diff --git a/apps/miniapp/pages/stall-service/index.wxss b/apps/miniapp/pages/stall-service/index.wxss deleted file mode 100644 index 8f52ff9..0000000 --- a/apps/miniapp/pages/stall-service/index.wxss +++ /dev/null @@ -1,42 +0,0 @@ -.page { - min-height: 100vh; - padding: 28rpx 32rpx 150rpx; - background: #fff8f0; - color: #29231f; -} -.head { - padding: 38rpx 4rpx 28rpx; -} -.eyebrow { - display: block; - color: #c65c28; - font-size: 22rpx; -} -.title { - display: block; - margin-top: 12rpx; - font-size: 42rpx; - font-weight: 800; -} -.sub { - display: block; - margin-top: 12rpx; - color: #7a6a60; - font-size: 24rpx; -} -.card { - display: flex; - flex-direction: column; - gap: 14rpx; - margin-bottom: 22rpx; - padding: 28rpx; - border: 1rpx solid #f2d9c6; - border-radius: 24rpx; - background: #fff; - line-height: 1.7; -} -.card-title { - color: #4f3020; - font-size: 29rpx; - font-weight: 700; -} diff --git a/apps/miniapp/runtime-config.js b/apps/miniapp/runtime-config.js new file mode 100644 index 0000000..86e8d07 --- /dev/null +++ b/apps/miniapp/runtime-config.js @@ -0,0 +1,9 @@ +// 开发默认配置。template:dev 编译时会用品牌构建参数覆盖此文件。 +module.exports = { + env: "dev", + apiBaseUrl: "http://localhost:3001", + brandSlug: "default-brand", + templateKey: "", + templateVersion: "", + runtimeContract: "1.0", +}; diff --git a/apps/miniapp/test/validate-fixture.cjs b/apps/miniapp/test/validate-fixture.cjs index ef95c91..58b6ec4 100644 --- a/apps/miniapp/test/validate-fixture.cjs +++ b/apps/miniapp/test/validate-fixture.cjs @@ -1,5 +1,7 @@ const fs = require("node:fs"); const path = require("node:path"); +const os = require("node:os"); +const { execFileSync } = require("node:child_process"); const root = path.resolve(__dirname, ".."); const requestSource = fs.readFileSync(path.join(root, "utils/request.js"), "utf8"); const configSource = fs.readFileSync(path.join(root, "utils/config.js"), "utf8"); @@ -13,7 +15,7 @@ if ( console.error("miniapp: public requests must carry the configured brand slug"); process.exit(1); } -if (!moduleRegistrySource.includes("Object.values(manifest?.pages || {})")) { +if (!moduleRegistrySource.includes("manifest.pages")) { console.error("miniapp: visual page renderers must resolve from the manifest"); process.exit(1); } @@ -24,10 +26,11 @@ if ( console.error("miniapp: customer sessions must be brand-scoped"); process.exit(1); } -const productionRoots = ["components/modules", "components/templates", "pages"]; +const productionRoots = ["components/modules", "pages"]; const productionSources = []; function collectSources(directory) { const current = path.join(root, directory); + if (!fs.existsSync(current)) return; for (const item of fs.readdirSync(current, { withFileTypes: true })) { const itemPath = path.join(current, item.name); if (item.isDirectory()) collectSources(path.relative(root, itemPath)); @@ -83,8 +86,23 @@ for (const fixture of fixtures) { records: "pages/records/index", profile: "pages/bookings/index", }; + const templateKey = fixture.templateKey.startsWith("acheng") + ? "acheng-campus-food" + : "linjing-editorial"; + const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-fixture-")); + execFileSync( + process.execPath, + [ + path.resolve(root, "../../packages/template-compiler/src/cli.mjs"), + "--template", + templateKey, + "--out", + output, + ], + { stdio: "ignore" }, + ); const missingPages = fixture.pages.filter( - (key) => !fs.existsSync(path.join(root, `${pageMap[key]}.json`)), + (key) => !fs.existsSync(path.join(output, `${pageMap[key]}.json`)), ); if (missingPages.length) { console.error(`${fixture.templateKey}: missing page manifests: ${missingPages.join(", ")}`); diff --git a/apps/miniapp/utils/config.js b/apps/miniapp/utils/config.js index f323f8a..7cc2df9 100644 --- a/apps/miniapp/utils/config.js +++ b/apps/miniapp/utils/config.js @@ -1,13 +1,15 @@ +const runtimeConfig = require("../runtime-config"); + const app = getApp(); module.exports = { get apiBaseUrl() { - return app.globalData.apiBaseUrl; + return app.globalData.apiBaseUrl || runtimeConfig.apiBaseUrl; }, get brand() { return app.globalData.brand || {}; }, get brandSlug() { - return wx.getStorageSync("brandSlug") || app.globalData.brandSlug || "default-brand"; + return app.globalData.brandSlug || runtimeConfig.brandSlug; }, }; diff --git a/apps/miniapp/utils/module-registry.js b/apps/miniapp/utils/module-registry.js index b6cc0fd..2c942ce 100644 --- a/apps/miniapp/utils/module-registry.js +++ b/apps/miniapp/utils/module-registry.js @@ -90,10 +90,6 @@ function resolveRuntime(workspace) { : resolved.map((item) => item.type); const moduleVariants = {}; for (const item of manifestHome || []) moduleVariants[item.type] = item.variant; - const pageRenderers = {}; - for (const page of Object.values(manifest?.pages || {})) { - if (page.renderer) pageRenderers[page.key] = page.renderer; - } const navigation = Array.isArray(manifest?.navigation) ? manifest.navigation.map((item) => ({ ...item, @@ -110,7 +106,6 @@ function resolveRuntime(workspace) { modules: resolved, layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) }, moduleVariants, - pageRenderers, navigation, visualManifest: manifest, capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [], diff --git a/docs/adr/0015-template-build-time-composition.md b/docs/adr/0015-template-build-time-composition.md new file mode 100644 index 0000000..ed19b5e --- /dev/null +++ b/docs/adr/0015-template-build-time-composition.md @@ -0,0 +1,31 @@ +# ADR 0015:模板采用构建时叠加编译 + +## 背景 + +平台需要支持大量行业和视觉风格不同的小程序模板。把所有模板代码放在 `apps/miniapp`,再通过运行时分支选择,会让壳持续膨胀、模板之间互相污染,也无法可靠验证某个品牌最终打开的页面。 + +## 决策 + +`template:dev` 采用三层构建时叠加: + +1. `apps/miniapp` 只提供品牌无关的运行时、通用 UI、公共页面和 TDesign 依赖。 +2. `packages/capability-*` 提供独立业务流程页面,由模板 manifest 的 `requiredCapabilities` 声明引入。 +3. `packages/template-*` 提供完整视觉模板页面、组件、资源和 `app.json` 窗口配置。 + +编译器按运行时 → 能力包 → 模板包的顺序复制,并对同路径文件执行显式冲突校验。模板只能通过 `overrides` 声明替换下层页面或组件目录。最终生成 `app.json`、`project.config.json`、`runtime-config.js` 和 `template.runtime.json`,产物可直接由微信开发者工具打开。 + +品牌 slug、API 地址和 AppID 是构建参数;开发构建允许通过 storage 覆盖 API 和品牌,生产构建必须显式提供并使用 HTTPS API。模板切换不在小程序运行时完成,而是在构建时选择模板包。 + +## 替代方案 + +- 运行时携带全部模板并按 `templateKey` 分支:代码和资源随模板数量线性膨胀,容易混用,放弃。 +- 运行时下载 WXML/JS 模板:微信小程序安全和编译模型不支持,放弃。 +- 每个模板独立复制完整小程序:公共能力重复、修复无法统一,放弃。 + +## 后果 + +新增模板只需新增 package 和 manifest,不需要改 compiler 或 runtime。模板包需要自行提供 manifest 声明的页面四件套和 tab 资源,编译测试会阻止缺页、缺图标、组件引用或 `require` 路径错误。后台视觉模板切换不会直接改变已构建小程序,后台切换历史和回滚属于后续治理任务。 + +## 迁移计划 + +先完成阿成、林境两个模板和 `booking` capability 的迁移,再增加第二行业演练模板。每个新增模板必须通过 compiler 产物校验、模板契约校验和小程序 fixture 检查后才能进入目录 registry。 diff --git a/docs/template-runtime-progress.md b/docs/template-runtime-progress.md index bc8437f..7e814dc 100644 --- a/docs/template-runtime-progress.md +++ b/docs/template-runtime-progress.md @@ -6,6 +6,14 @@ `feat/template-runtime-platform` +### 构建时模板叠加基线 + +- [x] Runtime、Capability、Template 三层编译结构已落地,详见 `docs/adr/0015-template-build-time-composition.md`。 +- [x] 阿成、林境页面与 tab 资源已迁入独立模板包,Runtime 不再携带行业页面和模板组件。 +- [x] `booking` 下单页面已迁入 `packages/capability-booking`。 +- [x] 编译产物校验覆盖页面文件、组件引用、`require`、tab 图标、品牌参数和能力依赖错误。 +- [ ] 增加第二行业最小演练模板并接入视觉截图回归。 + ## 阶段状态 ### Phase 0:冻结林境门作基线 diff --git a/eslint.config.mjs b/eslint.config.mjs index 892f7c2..0b2f5b4 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,6 +15,7 @@ export default tseslint.config( "apps/miniapp/pages/**/*.js", "apps/miniapp/app.js", "apps/admin/vite.config.ts", + "packages/config/src/generated-template-packages.js", ], }, eslint.configs.recommended, diff --git a/packages/capability-booking/README.md b/packages/capability-booking/README.md new file mode 100644 index 0000000..712d34b --- /dev/null +++ b/packages/capability-booking/README.md @@ -0,0 +1,9 @@ +# booking 能力包 + +为需要"选择数量 + 自取/配送"下单流程的模板提供小程序页面。模板在 `template.json` 的 +`requiredCapabilities` 中声明 `booking` 后,`template:dev` 会把 `miniapp/` 叠加进产物。 + +- `miniapp/pages/booking`:下单页,提交到 `POST /customer/bookings`。 +- `miniapp/utils/booking-templates.js`:下单页文案。 + +当前后端仍使用核心 `Booking` 模型;把它迁移为独立 capability 是后续任务。 diff --git a/packages/capability-booking/capability.json b/packages/capability-booking/capability.json new file mode 100644 index 0000000..34a8a62 --- /dev/null +++ b/packages/capability-booking/capability.json @@ -0,0 +1,7 @@ +{ + "key": "booking", + "version": "1.0.0", + "runtimeContract": "1.0", + "description": "带数量、自取/配送的下单能力,提交到 /customer/bookings。", + "pages": ["pages/booking/index"] +} diff --git a/apps/miniapp/pages/booking/index.js b/packages/capability-booking/miniapp/pages/booking/index.js similarity index 98% rename from apps/miniapp/pages/booking/index.js rename to packages/capability-booking/miniapp/pages/booking/index.js index a7da68f..2f6192c 100644 --- a/apps/miniapp/pages/booking/index.js +++ b/packages/capability-booking/miniapp/pages/booking/index.js @@ -1,5 +1,5 @@ const { request, customerRequest, customerTokenKey } = require("../../utils/request"); -const { getTemplate } = require("../../utils/templates"); +const { getTemplate } = require("../../utils/booking-templates"); Page({ data: { service: {}, diff --git a/apps/miniapp/pages/booking/index.json b/packages/capability-booking/miniapp/pages/booking/index.json similarity index 100% rename from apps/miniapp/pages/booking/index.json rename to packages/capability-booking/miniapp/pages/booking/index.json diff --git a/apps/miniapp/pages/booking/index.wxml b/packages/capability-booking/miniapp/pages/booking/index.wxml similarity index 100% rename from apps/miniapp/pages/booking/index.wxml rename to packages/capability-booking/miniapp/pages/booking/index.wxml diff --git a/apps/miniapp/pages/booking/index.wxss b/packages/capability-booking/miniapp/pages/booking/index.wxss similarity index 100% rename from apps/miniapp/pages/booking/index.wxss rename to packages/capability-booking/miniapp/pages/booking/index.wxss diff --git a/apps/miniapp/utils/templates.js b/packages/capability-booking/miniapp/utils/booking-templates.js similarity index 100% rename from apps/miniapp/utils/templates.js rename to packages/capability-booking/miniapp/utils/booking-templates.js diff --git a/packages/capability-booking/package.json b/packages/capability-booking/package.json new file mode 100644 index 0000000..5333256 --- /dev/null +++ b/packages/capability-booking/package.json @@ -0,0 +1,6 @@ +{ + "name": "@personal-brand/capability-booking", + "version": "1.0.0", + "private": true, + "description": "下单能力的小程序页面,由声明 booking 能力的模板在编译时引入。" +} diff --git a/packages/config/src/generated-template-packages.js b/packages/config/src/generated-template-packages.js index 07845c6..84d56e6 100644 --- a/packages/config/src/generated-template-packages.js +++ b/packages/config/src/generated-template-packages.js @@ -341,28 +341,16 @@ export const generatedTemplatePackageRegistry = [ "capabilityKey": "booking" } }, - "renderers": { - "home": "acheng-home", - "offerings": "acheng-offerings", - "profile": "acheng-profile" - }, - "runtimeOwnedPages": [ - "detail", - "inquiry", - "success", - "records" + "pages": [ + "pages/index/index", + "pages/services/index", + "pages/stall-service/index", + "pages/bookings/index" ], - "ownedPaths": [ - "components/templates/acheng-home", - "components/templates/acheng-offerings", - "components/templates/acheng-profile", - "pages/index", - "pages/services", - "pages/bookings", + "overrides": [ "pages/inquiry", - "pages/stall-service", - "pages/offering", "pages/inquiry-success", + "pages/offering", "pages/records" ], "visualTemplateKey": "acheng-campus-food" @@ -866,24 +854,13 @@ export const generatedTemplatePackageRegistry = [ "capabilityKey": "inquiry" } }, - "renderers": { - "home": "linjing-home", - "offerings": "linjing-offerings", - "profile": "linjing-profile" - }, - "runtimeOwnedPages": [ - "detail", - "inquiry", - "success", - "records" - ], - "ownedPaths": [ - "components/templates/linjing-home", - "components/templates/linjing-offerings", - "components/templates/linjing-profile" + "pages": [ + "pages/index/index", + "pages/services/index", + "pages/bookings/index" ], "visualTemplateKey": "linjing-editorial" } ]; export const generatedTemplatePackageRegistryHash = - "6d56212ec96d9b7b99a9e12aa278ca0927dc5e4472ec6ece3098a7d99842897b"; + "254f31edcf4073091691fc5f88fced2b5857c60aec3d1175a5f1e44b9e45acd0"; diff --git a/packages/template-acheng-campus-food/template.json b/packages/template-acheng-campus-food/template.json index 5a6a152..f3f386e 100644 --- a/packages/template-acheng-campus-food/template.json +++ b/packages/template-acheng-campus-food/template.json @@ -310,23 +310,11 @@ "capabilityKey": "booking" } }, - "renderers": { - "home": "acheng-home", - "offerings": "acheng-offerings", - "profile": "acheng-profile" - }, - "runtimeOwnedPages": ["detail", "inquiry", "success", "records"], - "ownedPaths": [ - "components/templates/acheng-home", - "components/templates/acheng-offerings", - "components/templates/acheng-profile", - "pages/index", - "pages/services", - "pages/bookings", - "pages/inquiry", - "pages/stall-service", - "pages/offering", - "pages/inquiry-success", - "pages/records" - ] + "pages": [ + "pages/index/index", + "pages/services/index", + "pages/stall-service/index", + "pages/bookings/index" + ], + "overrides": ["pages/inquiry", "pages/inquiry-success", "pages/offering", "pages/records"] } diff --git a/packages/template-compiler/src/cli.mjs b/packages/template-compiler/src/cli.mjs index 374e7f0..3cb9e2f 100644 --- a/packages/template-compiler/src/cli.mjs +++ b/packages/template-compiler/src/cli.mjs @@ -1,306 +1,257 @@ #!/usr/bin/env node +// 叠加式模板编译器:运行时(apps/miniapp)→ 能力包 → 模板包,再注入品牌构建参数。 +// 编译器只负责拼装和校验,不改写任何页面源码。 import fs from "node:fs"; import path from "node:path"; -import { fileURLToPath } from "node:url"; +import { fileURLToPath, pathToFileURL } from "node:url"; +import { + CORE_CAPABILITIES, + validateCapabilityPackageManifest, + validateTemplatePackageManifest, +} from "../../template-contract/src/index.ts"; -const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../.."); -const packagesRoot = path.join(root, "packages"); -const generatedRoot = path.join(root, "apps/miniapp-generated"); +export const workspaceRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../.."); +const packagesRoot = path.join(workspaceRoot, "packages"); +const runtimeRoot = path.join(workspaceRoot, "apps/miniapp"); -function usage() { - console.log("Usage: template-compiler --template [--out ]"); +const DEV_API_BASE_URL = "http://localhost:3001"; +const DEV_BRAND_SLUG = "default-brand"; +// 运行时目录中不属于小程序产物的内容,以及由编译器生成的文件。 +const RUNTIME_EXCLUDES = new Set([ + "node_modules", + "test", + "src", + "dist", + ".turbo", + "package.json", + "tsconfig.json", + "project.private.config.json", + "app.json", + "project.config.json", + "runtime-config.js", + "assets", + "pages/booking", + "utils/templates.js", + "components/templates", + "components/runtime-tab-bar", + "pages/index", + "pages/services", + "pages/bookings", + "pages/stall-service", +]); +const LAYER_EXCLUDES = new Set(["node_modules", ".turbo", "dist", ".gitkeep", "app.json"]); +const PAGE_EXTENSIONS = [".js", ".json", ".wxml"]; + +class CompileError extends Error {} + +function fail(message) { + throw new CompileError(message); } -function validateManifest(manifest) { - const requiredPages = ["home", "offerings", "detail", "inquiry", "success", "records", "profile"]; - if (!manifest.packageKey || !manifest.version || !manifest.displayName) - throw new Error("template.json requires packageKey, version and displayName"); - if (manifest.runtimeContract !== "1.0") throw new Error("Only runtimeContract 1.0 is supported"); - for (const page of requiredPages) { - if (typeof manifest.entrypoints?.[page] !== "string") - throw new Error(`template.json missing entrypoint: ${page}`); - } - if (!Array.isArray(manifest.navigation) || !manifest.navigation.length) - throw new Error("template.json navigation must not be empty"); - if (!Array.isArray(manifest.dataSlots) || !manifest.dataSlots.length) - throw new Error("template.json dataSlots must not be empty"); - if (!Array.isArray(manifest.assetSlots)) - throw new Error("template.json assetSlots must be an array"); - if (!manifest.admin || !Array.isArray(manifest.admin.sections) || !manifest.admin.sections.length) - throw new Error("template.json admin.sections must not be empty"); - for (const section of manifest.admin.sections) { - if (!section.key || !section.title || !section.description || !Array.isArray(section.fields)) - throw new Error("template.json admin sections require key, title, description and fields"); - for (const field of section.fields) { - if (!field.key || !field.binding || !field.label || !field.input) - throw new Error("template.json admin fields require key, binding, label and input"); - } - } - if ( - manifest.renderers !== undefined && - (typeof manifest.renderers !== "object" || Array.isArray(manifest.renderers)) - ) - throw new Error("template.json renderers must be an object"); - for (const page of ["home", "offerings", "profile"]) { - if (typeof manifest.renderers?.[page] !== "string" || !manifest.renderers[page]) { - throw new Error(`template.json requires a dedicated renderer for visual page: ${page}`); - } - } - if ( - manifest.runtimeOwnedPages !== undefined && - (!Array.isArray(manifest.runtimeOwnedPages) || - manifest.runtimeOwnedPages.some( - (page) => !["detail", "inquiry", "success", "records"].includes(page), - )) - ) - throw new Error("template.json runtimeOwnedPages contains an unsupported page"); - for (const item of manifest.navigation) { - if (!item || typeof item.key !== "string" || typeof item.label !== "string") - throw new Error("template.json navigation items require key and label"); - if (typeof item.page !== "string" || typeof manifest.entrypoints?.[item.page] !== "string") - throw new Error(`template.json navigation page is not a declared entrypoint: ${item.key}`); - } +function readJson(filePath) { + return JSON.parse(fs.readFileSync(filePath, "utf8")); } -function validateEntrypoints(output, manifest) { - for (const [key, relativePath] of Object.entries(manifest.entrypoints || {})) { - const pagePath = path.join(output, relativePath); - for (const extension of [".js", ".json", ".wxml", ".wxss"]) { - if (!fs.existsSync(`${pagePath}${extension}`)) { - throw new Error(`Template entrypoint ${key} is missing ${relativePath}${extension}`); - } - } - } +function toPosix(relativePath) { + return relativePath.split(path.sep).join("/"); } -function validateGeneratedIsolation(output) { - const forbidden = [ - "components/templates", - "runtime-tab-bar", - "acheng-", - "linjing-", - "templateKey ===", +function listFiles(directory, exclude, base = directory) { + const files = []; + for (const entry of fs.readdirSync(directory, { withFileTypes: true })) { + const entryPath = toPosix(path.relative(base, path.join(directory, entry.name))); + if ( + exclude.has(entry.name) || + [...exclude].some((value) => entryPath === value || entryPath.startsWith(value + "/")) + ) + continue; + if (entry.name === ".gitkeep") continue; + const filePath = path.join(directory, entry.name); + if (entry.isDirectory()) files.push(...listFiles(filePath, exclude, base)); + else files.push(toPosix(path.relative(base, filePath))); + } + return files; +} + +function underPrefix(relativePath, prefix) { + return relativePath === prefix || relativePath.startsWith(prefix + "/"); +} + +function resolveTemplateDirectory(options) { + if (options.templateDir) return path.resolve(options.templateDir); + const candidates = [ + path.join(packagesRoot, `template-${options.template}`), + path.join(packagesRoot, options.template), ]; - const visit = (directory) => { - for (const entry of fs.readdirSync(directory, { withFileTypes: true })) { - const filePath = path.join(directory, entry.name); - if (entry.isDirectory()) visit(filePath); - else if (/\.(wxml|json|js|wxss)$/.test(entry.name)) { - const source = fs.readFileSync(filePath, "utf8"); - for (const token of forbidden) { - if (source.includes(token)) - throw new Error(`Generated output contains forbidden token ${token}: ${filePath}`); - } - } - } - }; - visit(path.join(output, "pages")); + const found = candidates.find((candidate) => + fs.existsSync(path.join(candidate, "template.json")), + ); + if (!found) fail(`Template package not found: ${options.template}`); + return found; } -function copyDirectory(source, target) { - fs.mkdirSync(target, { recursive: true }); - for (const entry of fs.readdirSync(source, { withFileTypes: true })) { - if (["node_modules", ".turbo", "dist"].includes(entry.name)) continue; - const from = path.join(source, entry.name); - const to = path.join(target, entry.name); - if (entry.isDirectory()) copyDirectory(from, to); - else fs.copyFileSync(from, to); +function loadTemplate(options) { + const directory = resolveTemplateDirectory(options); + const manifest = readJson(path.join(directory, "template.json")); + if (options.template && manifest.packageKey !== options.template) + fail(`template.json packageKey ${manifest.packageKey} does not match ${options.template}`); + const errors = validateTemplatePackageManifest(manifest); + if (errors.length) fail(`Invalid template ${manifest.packageKey}:\n ${errors.join("\n ")}`); + if (!fs.existsSync(path.join(directory, "miniapp"))) + fail(`Template package has no miniapp directory: ${manifest.packageKey}`); + return { directory, manifest }; +} + +function loadCapabilities(manifest, capabilitiesRoot) { + const capabilities = []; + for (const key of manifest.requiredCapabilities) { + if (CORE_CAPABILITIES.includes(key)) continue; + const directory = path.join(capabilitiesRoot, `capability-${key}`); + const manifestPath = path.join(directory, "capability.json"); + if (!fs.existsSync(manifestPath)) + fail(`Template ${manifest.packageKey} requires unknown capability: ${key}`); + const capability = readJson(manifestPath); + const errors = validateCapabilityPackageManifest(capability); + if (capability.key !== key) errors.push(`capability.json key must be ${key}`); + if (errors.length) fail(`Invalid capability ${key}:\n ${errors.join("\n ")}`); + capabilities.push({ key, directory, manifest: capability }); } + return capabilities; } -function removeOwnedPaths(rootDirectory, ownedPaths = []) { - for (const relativePath of ownedPaths) { - fs.rmSync(path.join(rootDirectory, relativePath), { recursive: true, force: true }); +function resolveParams(options, manifest) { + const env = options.env || "dev"; + if (!["dev", "prod"].includes(env)) fail(`--env must be dev or prod, got ${env}`); + if (env === "prod") { + const missing = ["brand", "appid", "api"].filter((key) => !options[key]); + if (missing.length) + fail(`Production build requires ${missing.map((key) => "--" + key).join(", ")}`); + if (!options.api.startsWith("https://")) fail("Production --api must use https://"); } -} - -function removeRuntimeTabBar(output) { - const pagesDirectory = path.join(output, "pages"); - if (!fs.existsSync(pagesDirectory)) return; - const visit = (directory) => { - for (const entry of fs.readdirSync(directory, { withFileTypes: true })) { - const filePath = path.join(directory, entry.name); - if (entry.isDirectory()) visit(filePath); - else if (entry.name.endsWith(".wxml")) { - const source = fs.readFileSync(filePath, "utf8"); - const cleaned = source.replace(/]*\/\s*>/g, ""); - if (cleaned !== source) fs.writeFileSync(filePath, cleaned); - } else if (entry.name.endsWith(".json")) { - const json = JSON.parse(fs.readFileSync(filePath, "utf8")); - if (json.usingComponents?.["runtime-tab-bar"]) { - delete json.usingComponents["runtime-tab-bar"]; - fs.writeFileSync(filePath, JSON.stringify(json, null, 2) + "\n"); - } - } - } + const runtimeProject = readJson(path.join(runtimeRoot, "project.config.json")); + return { + env, + brandSlug: options.brand || manifest.defaultBrandSlug || DEV_BRAND_SLUG, + appid: options.appid || runtimeProject.appid, + apiBaseUrl: options.api || DEV_API_BASE_URL, }; - visit(pagesDirectory); - fs.rmSync(path.join(output, "components/runtime-tab-bar"), { recursive: true, force: true }); } -function pruneUndeclaredPages(output, manifest) { - const appJsonPath = path.join(output, "app.json"); - const appJson = JSON.parse(fs.readFileSync(appJsonPath, "utf8")); - const allowed = new Set([ - ...manifest.navigation.map((item) => manifest.entrypoints[item.page]), - ...(manifest.runtimeOwnedPages || []).map((page) => manifest.entrypoints[page]), +function prepareOutput(output) { + const resolved = path.resolve(output); + if ( + resolved === path.parse(resolved).root || + resolved === workspaceRoot || + workspaceRoot.startsWith(resolved + path.sep) + ) + fail(`Refusing to use output directory: ${resolved}`); + if (fs.existsSync(resolved)) { + const entries = fs.readdirSync(resolved); + if (entries.length && !entries.includes("template.runtime.json")) + fail(`Output directory is not empty and was not generated by the compiler: ${resolved}`); + fs.rmSync(resolved, { recursive: true, force: true }); + } + fs.mkdirSync(resolved, { recursive: true }); + return resolved; +} + +/** 按层复制文件;除模板显式 override 的目录外,任何同名文件都视为冲突。 */ +function createLayerWriter(output) { + const owners = new Map(); + return { + owners, + copy(sourceDirectory, layer, exclude) { + for (const relativePath of listFiles(sourceDirectory, exclude)) { + if (owners.has(relativePath)) + fail( + `${layer} conflicts with ${owners.get(relativePath)} at ${relativePath}; declare it in overrides`, + ); + const target = path.join(output, relativePath); + fs.mkdirSync(path.dirname(target), { recursive: true }); + fs.copyFileSync(path.join(sourceDirectory, relativePath), target); + owners.set(relativePath, layer); + } + }, + release(prefix, layer) { + const released = [...owners.keys()].filter((relativePath) => + underPrefix(relativePath, prefix), + ); + if (!released.length) fail(`${layer} overrides ${prefix}, but no lower layer provides it`); + for (const relativePath of released) { + fs.rmSync(path.join(output, relativePath), { force: true }); + owners.delete(relativePath); + } + }, + }; +} + +function unique(values) { + return [...new Set(values)]; +} + +function buildAppJson(manifest, templateDirectory, capabilities) { + const runtimeApp = readJson(path.join(runtimeRoot, "app.json")); + const templateAppPath = path.join(templateDirectory, "miniapp/app.json"); + const templateApp = fs.existsSync(templateAppPath) ? readJson(templateAppPath) : {}; + const pages = unique([ + manifest.entrypoints.home, + ...manifest.pages, + ...(runtimeApp.pages || []), + ...capabilities.flatMap((capability) => capability.manifest.pages), ]); - for (const page of appJson.pages || []) { - if (allowed.has(page)) continue; - fs.rmSync(path.join(output, path.dirname(page)), { recursive: true, force: true }); - } - appJson.pages = (appJson.pages || []).filter((page) => allowed.has(page)); - fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 2) + "\n"); - const appJsPath = path.join(output, "app.js"); - if (fs.existsSync(appJsPath) && manifest.defaultBrandSlug) { - const appJs = fs - .readFileSync(appJsPath, "utf8") - .replace( - /const DEFAULT_BRAND_SLUG = "[^"]*";/, - `const DEFAULT_BRAND_SLUG = ${JSON.stringify(manifest.defaultBrandSlug)};`, - ); - fs.writeFileSync(appJsPath, appJs); + for (const [key, page] of Object.entries(manifest.entrypoints)) { + if (!pages.includes(page)) fail(`entrypoints.${key} (${page}) is not provided by any layer`); } + const tabBarStyle = templateApp.tabBar || {}; + return { + ...runtimeApp, + pages, + window: { + ...runtimeApp.window, + navigationBarTitleText: manifest.displayName, + ...(templateApp.window || {}), + }, + tabBar: { + color: tabBarStyle.color || "#8b8178", + selectedColor: tabBarStyle.selectedColor || "#3b2118", + backgroundColor: tabBarStyle.backgroundColor || "#ffffff", + borderStyle: tabBarStyle.borderStyle || "white", + list: manifest.navigation.map((item) => ({ + pagePath: manifest.entrypoints[item.page], + text: item.label, + ...(item.iconPath ? { iconPath: item.iconPath } : {}), + ...(item.selectedIconPath ? { selectedIconPath: item.selectedIconPath } : {}), + })), + }, + }; } -function materializeRendererAliases(output, packageDirectory, manifest) { - const rendererRoot = path.join(packageDirectory, "miniapp/components/templates"); - const pagePaths = { - home: "pages/index/index", - offerings: "pages/services/index", - profile: "pages/bookings/index", - }; - for (const page of Object.keys(pagePaths)) { - const renderer = manifest.renderers?.[page]; - const source = path.join(rendererRoot, renderer); - if (!fs.existsSync(source)) { - throw new Error(`Template renderer source is missing: ${renderer}`); - } - const aliasDirectory = path.join(output, "components/template-pages", page); - fs.mkdirSync(aliasDirectory, { recursive: true }); - for (const entry of fs.readdirSync(source, { withFileTypes: true })) { - if (!entry.isFile()) continue; - fs.copyFileSync( - path.join(source, entry.name), - path.join(aliasDirectory, `${page}${path.extname(entry.name)}`), - ); - } - const pageDirectory = path.join(output, pagePaths[page]); - const jsonPath = `${pageDirectory}.json`; - const wxmlPath = `${pageDirectory}.wxml`; - const pageJson = JSON.parse(fs.readFileSync(jsonPath, "utf8")); - pageJson.usingComponents = pageJson.usingComponents || {}; - for (const key of Object.keys(pageJson.usingComponents)) { - if (/-home$|-offerings$|-profile$/.test(key)) delete pageJson.usingComponents[key]; - } - pageJson.usingComponents[`template-${page}`] = `/components/template-pages/${page}/${page}`; - fs.writeFileSync(jsonPath, JSON.stringify(pageJson, null, 2) + "\n"); - const rendererPattern = new RegExp(`<([a-z0-9-]+)-${page}\\b`, "g"); - const originalWxml = fs.readFileSync(wxmlPath, "utf8"); - const wxml = - page === "offerings" - ? `` - : originalWxml.replace(rendererPattern, ` `wx:${branch}="{{${renderer === selected}}}"`, - ); - const selectedAlias = - page === "offerings" - ? frozen.replace( - '= 0 ? args[outputIndex + 1] : generatedRoot); - const packageDirectory = fs.existsSync(path.join(packagesRoot, packageKey)) - ? path.join(packagesRoot, packageKey) - : path.join(packagesRoot, `template-${packageKey}`); - const manifestPath = path.join(packageDirectory, "template.json"); - if (!fs.existsSync(manifestPath)) throw new Error(`Template package not found: ${packageKey}`); - const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); - if (manifest.packageKey !== packageKey) - throw new Error("template.json packageKey does not match requested template"); - validateManifest(manifest); - fs.rmSync(output, { recursive: true, force: true }); - const shell = path.join(root, "apps/miniapp"); - if (!fs.existsSync(shell)) throw new Error("Mini Program shell is missing: apps/miniapp"); - copyDirectory(shell, output); - // 迁移期间保留 shell 的模板目录,直到模板包提供对应页面的完整覆盖。 - // ownedPaths 只记录最终所有权,不在不完整迁移时删除可用 renderer。 - const source = path.join(packageDirectory, "miniapp"); - if (!fs.existsSync(source)) - throw new Error(`Template package has no miniapp directory: ${packageKey}`); - for (const entry of fs.readdirSync(source, { withFileTypes: true })) { - if (entry.name === "app.json") continue; - const from = path.join(source, entry.name); - const to = path.join(output, entry.name); - if (entry.isDirectory()) copyDirectory(from, to); - else fs.copyFileSync(from, to); - } - materializeRendererAliases(output, packageDirectory, manifest); - freezeRendererConditions(output, manifest); - removeRuntimeTabBar(output); - pruneUndeclaredPages(output, manifest); - validateEntrypoints(output, manifest); - for (const relativePath of manifest.ownedPaths || []) { - if (!fs.existsSync(path.join(output, relativePath))) - throw new Error(`Template package did not provide owned path: ${relativePath}`); - } - for (const renderer of Object.values(manifest.renderers || {})) { - const rendererPath = path.join(output, "components/templates", renderer, `${renderer}.wxml`); - if (!fs.existsSync(rendererPath)) throw new Error(`Template renderer is missing: ${renderer}`); - } - fs.rmSync(path.join(output, "components/templates"), { recursive: true, force: true }); - validateGeneratedIsolation(output); - const appJsonPath = path.join(output, "app.json"); - const appJson = JSON.parse(fs.readFileSync(appJsonPath, "utf8")); - appJson.window = { - ...appJson.window, - navigationBarTitleText: manifest.displayName, - }; - appJson.tabBar = { - color: "#8b8178", - selectedColor: "#3b2118", - backgroundColor: "#ffffff", - borderStyle: "white", - list: manifest.navigation.map((item) => ({ - pagePath: manifest.entrypoints[item.page], - text: item.label, - ...(item.iconPath ? { iconPath: item.iconPath } : {}), - ...(item.selectedIconPath ? { selectedIconPath: item.selectedIconPath } : {}), - })), - }; - fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 2) + "\n"); +function writeGeneratedFiles(output, manifest, params, appJson, capabilities) { + fs.writeFileSync(path.join(output, "app.json"), JSON.stringify(appJson, null, 2) + "\n"); + const project = readJson(path.join(runtimeRoot, "project.config.json")); fs.writeFileSync( - path.join(output, "template.manifest.json"), - JSON.stringify(manifest, null, 2) + "\n", + path.join(output, "project.config.json"), + JSON.stringify( + { + ...project, + appid: params.appid, + projectname: `${params.brandSlug}-${manifest.packageKey}`, + }, + null, + 2, + ) + "\n", + ); + const runtimeConfig = { + env: params.env, + apiBaseUrl: params.apiBaseUrl, + brandSlug: params.brandSlug, + templateKey: manifest.packageKey, + templateVersion: manifest.version, + runtimeContract: manifest.runtimeContract, + }; + fs.writeFileSync( + path.join(output, "runtime-config.js"), + `// 由 template-compiler 生成,请勿手动修改。\nmodule.exports = ${JSON.stringify(runtimeConfig, null, 2)};\n`, ); fs.writeFileSync( path.join(output, "template.runtime.json"), @@ -309,18 +260,191 @@ function main() { packageKey: manifest.packageKey, version: manifest.version, runtimeContract: manifest.runtimeContract, + brandSlug: params.brandSlug, + env: params.env, + capabilities: capabilities.map((capability) => ({ + key: capability.key, + version: capability.manifest.version, + })), + pages: appJson.pages, entrypoints: manifest.entrypoints, navigation: manifest.navigation, - requiredCapabilities: manifest.requiredCapabilities, - renderers: manifest.renderers || {}, - runtimeOwnedPages: manifest.runtimeOwnedPages || [], - ownedPaths: manifest.ownedPaths || [], }, null, 2, ) + "\n", ); - console.log(`Generated ${packageKey}@${manifest.version} -> ${path.relative(root, output)}`); } -main(); +function otherTemplateComponentNames(currentDirectory) { + const names = new Set(); + for (const entry of fs.readdirSync(packagesRoot, { withFileTypes: true })) { + if (!entry.isDirectory() || !entry.name.startsWith("template-")) continue; + const directory = path.join(packagesRoot, entry.name); + if (path.resolve(directory) === path.resolve(currentDirectory)) continue; + const componentRoot = path.join(directory, "miniapp/components/templates"); + if (!fs.existsSync(componentRoot)) continue; + for (const component of fs.readdirSync(componentRoot)) names.add(component); + } + return names; +} + +function resolveComponent(output, fromFile, reference) { + const base = reference.startsWith("/") + ? path.join(output, reference) + : reference.startsWith(".") + ? path.resolve(path.dirname(path.join(output, fromFile)), reference) + : path.join(output, "miniprogram_npm", reference); + return [".json", ".js", ".wxml"].every((extension) => fs.existsSync(base + extension)); +} + +function resolveRequire(output, fromFile, reference) { + const base = path.resolve(path.dirname(path.join(output, fromFile)), reference); + return [base, base + ".js", path.join(base, "index.js")].some( + (candidate) => fs.existsSync(candidate) && fs.statSync(candidate).isFile(), + ); +} + +/** 校验产物可以被微信开发者工具直接打开:页面、组件、require、图标和模板隔离。 */ +function validateOutput(output, appJson, templateDirectory) { + const errors = []; + const warnings = []; + for (const page of appJson.pages) { + for (const extension of PAGE_EXTENSIONS) { + if (!fs.existsSync(path.join(output, page + extension))) + errors.push(`page ${page} is missing ${extension}`); + } + } + for (const item of appJson.tabBar.list) { + for (const icon of [item.iconPath, item.selectedIconPath]) { + if (icon && !fs.existsSync(path.join(output, icon))) + errors.push(`tabBar icon is missing: ${icon}`); + } + } + const hasNpm = fs.existsSync(path.join(output, "miniprogram_npm")); + const forbiddenComponents = otherTemplateComponentNames(templateDirectory); + const sourceFiles = listFiles(output, new Set(["miniprogram_npm"])).filter((file) => + /\.(js|json|wxml)$/.test(file), + ); + for (const file of sourceFiles) { + const source = fs.readFileSync(path.join(output, file), "utf8"); + if (file.endsWith(".json") && (file.startsWith("pages/") || file.startsWith("components/"))) { + const usingComponents = JSON.parse(source).usingComponents || {}; + for (const [name, reference] of Object.entries(usingComponents)) { + if (reference.startsWith("/miniprogram_npm/") && !hasNpm) { + warnings.push(`${file}: ${name} needs miniprogram_npm (build npm in apps/miniapp first)`); + continue; + } + if (reference.startsWith("plugin://")) continue; + if (!resolveComponent(output, file, reference)) + errors.push(`${file}: component ${name} cannot be resolved (${reference})`); + } + } + if (file.endsWith(".js")) { + for (const match of source.matchAll(/require\(\s*["'](\.{1,2}\/[^"']+)["']\s*\)/g)) { + if (!resolveRequire(output, file, match[1])) + errors.push(`${file}: require("${match[1]}") cannot be resolved`); + } + } + if (file.startsWith("pages/") || file.startsWith("components/")) { + for (const token of ["pageRenderer", "templateKey ==="]) { + if (source.includes(token)) errors.push(`${file}: contains template branch token ${token}`); + } + for (const component of forbiddenComponents) { + if (source.includes(component)) + errors.push(`${file}: references another template's ${component}`); + } + } + } + return { errors, warnings }; +} + +/** + * 编译一个模板为完整的小程序目录。 + * @param {{ template?: string, templateDir?: string, brand?: string, appid?: string, api?: string, + * env?: "dev" | "prod", out?: string, capabilitiesRoot?: string }} options + */ +export function compileTemplate(options) { + const { directory: templateDirectory, manifest } = loadTemplate(options); + const capabilities = loadCapabilities(manifest, options.capabilitiesRoot || packagesRoot); + const params = resolveParams(options, manifest); + const output = prepareOutput( + options.out || path.join(workspaceRoot, "dist/miniapp", params.brandSlug), + ); + const writer = createLayerWriter(output); + writer.copy(runtimeRoot, "runtime", RUNTIME_EXCLUDES); + for (const capability of capabilities) { + writer.copy( + path.join(capability.directory, "miniapp"), + `capability:${capability.key}`, + LAYER_EXCLUDES, + ); + for (const page of capability.manifest.pages) { + if (!fs.existsSync(path.join(output, page + ".js"))) + fail(`capability ${capability.key} declares ${page} but does not provide it`); + } + } + for (const prefix of manifest.overrides || []) + writer.release(prefix, `template:${manifest.packageKey}`); + writer.copy( + path.join(templateDirectory, "miniapp"), + `template:${manifest.packageKey}`, + LAYER_EXCLUDES, + ); + const appJson = buildAppJson(manifest, templateDirectory, capabilities); + writeGeneratedFiles(output, manifest, params, appJson, capabilities); + const { errors, warnings } = validateOutput(output, appJson, templateDirectory); + if (errors.length) fail(`Generated mini program is invalid:\n ${errors.join("\n ")}`); + return { output, manifest, params, warnings }; +} + +function parseArgs(argv) { + const options = {}; + const names = { + "--template": "template", + "--template-dir": "templateDir", + "--brand": "brand", + "--appid": "appid", + "--api": "api", + "--env": "env", + "--out": "out", + }; + for (let index = 0; index < argv.length; index += 1) { + const argument = argv[index]; + if (!names[argument]) { + if (!options.template && !argument.startsWith("--")) options.template = argument; + else fail(`Unknown argument: ${argument}`); + continue; + } + const value = argv[index + 1]; + if (!value || value.startsWith("--")) fail(`${argument} requires a value`); + options[names[argument]] = value; + index += 1; + } + return options; +} + +function main() { + const usage = + "Usage: template:dev