From 076c6124c83eadd95e46e88128c35c6270005278 Mon Sep 17 00:00:00 2001 From: que01 Date: Mon, 12 Oct 2026 10:06:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20Taro=20=E6=A8=A1=E6=9D=BF=E5=8F=91?= =?UTF-8?q?=E7=8E=B0=E4=B8=8E=E6=A0=A1=E9=AA=8C=E6=94=B6=E6=95=9B=E4=B8=BA?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/taro/config/index.ts | 6 ++++-- apps/taro/package.json | 2 +- apps/taro/src/env.d.ts | 2 +- apps/taro/test/build-contract.test.mjs | 9 ++++++++- scripts/check-local-media.mjs | 11 ++++++----- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/taro/config/index.ts b/apps/taro/config/index.ts index 6bed523..65f474e 100644 --- a/apps/taro/config/index.ts +++ b/apps/taro/config/index.ts @@ -3,7 +3,6 @@ import path from "node:path"; import fs from "node:fs"; const root = path.resolve(__dirname, "../../.."); -const key = process.env.TEMPLATE_KEY || "acheng-campus-food"; const previewAllTemplates = process.env.PREVIEW_ALL_TEMPLATES === "true"; const templates = fs .readdirSync(path.join(root, "packages")) @@ -13,7 +12,10 @@ const templates = fs fs.existsSync(path.join(root, "packages", directory, "taro/index.tsx")) && fs.existsSync(path.join(root, "packages", directory, "template.json")), ) - .map((directory) => directory.slice("template-".length)); + .map((directory) => directory.slice("template-".length)) + .sort(); +const key = process.env.TEMPLATE_KEY || templates[0]; +if (!key) throw new Error("No Taro template package found"); if (!templates.includes(key)) throw new Error(`Unsupported Taro template: ${key}`); const template = path.join(root, "packages", `template-${key}`); const manifest = JSON.parse(fs.readFileSync(path.join(template, "template.json"), "utf8")) as { diff --git a/apps/taro/package.json b/apps/taro/package.json index 0818539..4ac1f1f 100644 --- a/apps/taro/package.json +++ b/apps/taro/package.json @@ -8,7 +8,7 @@ "build:preview": "PREVIEW_ALL_TEMPLATES=true taro build --type h5", "build:weapp": "taro build --type weapp", "typecheck": "tsc --noEmit", - "lint": "pnpm --workspace-root exec eslint apps/taro/src apps/taro/config packages/template-acheng-campus-food/taro packages/template-linjing-editorial/taro", + "lint": "pnpm --workspace-root exec eslint apps/taro/src apps/taro/config \"packages/template-*/taro/**/*.{ts,tsx}\"", "test": "node --experimental-strip-types --test test/*.test.mjs", "test:browser": "playwright test" }, diff --git a/apps/taro/src/env.d.ts b/apps/taro/src/env.d.ts index 98c27f3..71f4495 100644 --- a/apps/taro/src/env.d.ts +++ b/apps/taro/src/env.d.ts @@ -18,5 +18,5 @@ interface ImportMeta { glob(pattern: string, options?: { eager?: boolean }): Record; } declare module "@template" { - export { TemplatePage } from "../../../packages/template-acheng-campus-food/taro"; + export { TemplatePage } from "./runtime/template-preview-entry"; } diff --git a/apps/taro/test/build-contract.test.mjs b/apps/taro/test/build-contract.test.mjs index a83ff2f..6d783d6 100644 --- a/apps/taro/test/build-contract.test.mjs +++ b/apps/taro/test/build-contract.test.mjs @@ -3,7 +3,14 @@ import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; const root = path.resolve(import.meta.dirname, "../../.."); -for (const key of ["acheng-campus-food", "linjing-editorial"]) +const templateKeys = fs + .readdirSync(path.join(root, "packages")) + .filter((directory) => directory.startsWith("template-")) + .filter((directory) => fs.existsSync(path.join(root, "packages", directory, "template.json"))) + .map((directory) => directory.slice("template-".length)) + .sort(); + +for (const key of templateKeys) test(`${key} 两端产物有真实入口及模板导航`, () => { const manifest = JSON.parse( fs.readFileSync(path.join(root, `packages/template-${key}/template.json`)), diff --git a/scripts/check-local-media.mjs b/scripts/check-local-media.mjs index 271e6a7..9390387 100644 --- a/scripts/check-local-media.mjs +++ b/scripts/check-local-media.mjs @@ -1,10 +1,11 @@ import { readdir, readFile } from "node:fs/promises"; +import { existsSync } from "node:fs"; -const files = [ - "packages/template-acheng-campus-food/template.json", - "packages/template-linjing-editorial/template.json", - "apps/api/prisma/seed.ts", -]; +const packageDirectory = "packages"; +const templateManifests = (await readdir(packageDirectory)) + .filter((directory) => directory.startsWith("template-")) + .map((directory) => `${packageDirectory}/${directory}/template.json`); +const files = [...templateManifests, "apps/api/prisma/seed.ts"].filter((file) => existsSync(file)); const remoteImagePattern = /https?:\/\/[^\s"']+/gi;