refactor: Taro 模板发现与校验收敛为目录驱动
This commit is contained in:
1 parent
89fdfd7d83
commit
076c6124c8
5 files changed
+20
-10
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
Vendored
+1
-1
@@ -18,5 +18,5 @@ interface ImportMeta {
|
||||
glob<T = unknown>(pattern: string, options?: { eager?: boolean }): Record<string, T>;
|
||||
}
|
||||
declare module "@template" {
|
||||
export { TemplatePage } from "../../../packages/template-acheng-campus-food/taro";
|
||||
export { TemplatePage } from "./runtime/template-preview-entry";
|
||||
}
|
||||
@@ -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`)),
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user