fix: 按模板包定位小程序构建产物

This commit is contained in:
que01 committed 2026-10-13 20:06:52 +08:00
1 parent 26f1157083
commit 8b4d27b0ee
1 file changed
+18 -7
@@ -12,6 +12,7 @@ import type { FastifyRequest } from "fastify";
import { existsSync } from "node:fs";
import { resolve } from "node:path";
import { Prisma } from "@prisma/client";
import { getTemplatePackageManifest, templatePackageRegistry } from "@personal-brand/config";
import { AdminAccessService } from "../../admin-access.service.js";
import { PrismaService } from "../../prisma.service.js";
import { AdminMiniAppReleaseService } from "./admin-miniapp-release.service.js";
@@ -25,6 +26,16 @@ import {
const MINIAPP_ARTIFACT_ROOT = process.env.MINIAPP_ARTIFACT_ROOT ?? "apps/taro/dist";
function miniAppTemplateKey(industryTemplateKey: string): string | null {
return (
getTemplatePackageManifest(industryTemplateKey)?.packageKey ??
templatePackageRegistry.find((item) =>
item.supportedIndustryTemplates.includes(industryTemplateKey),
)?.packageKey ??
null
);
}
interface MiniprogramCi {
Project: new (options: {
projectPath: string;
@@ -104,7 +115,7 @@ export class AdminMiniAppReleaseController {
...this.jsonObject(body.build),
} as Prisma.InputJsonObject,
...(credential ? { credential } : {}),
templateKey: current.templateKey ?? process.env.MINIAPP_TEMPLATE_KEY ?? "food",
templateKey: current.templateKey ?? null,
} satisfies Prisma.InputJsonObject;
await this.prisma.brandProfile.update({
where: { id: identity.brandId },
@@ -146,7 +157,7 @@ export class AdminMiniAppReleaseController {
throw new BadRequestException("当前小程序发布任务不能重复上传");
const brand = await this.prisma.brandProfile.findUniqueOrThrow({
where: { id: identity.brandId },
select: { miniAppSettings: true },
select: { miniAppSettings: true, templateKey: true },
});
const settings = this.jsonObject(brand.miniAppSettings);
const appid =
@@ -156,13 +167,13 @@ export class AdminMiniAppReleaseController {
const privateKey = settings.credential
? decryptMiniAppCredential(settings.credential)
: this.requiredEnv("WECHAT_UPLOAD_PRIVATE_KEY");
const templateKey =
typeof settings.templateKey === "string" && settings.templateKey
? settings.templateKey
: this.requiredEnv("MINIAPP_TEMPLATE_KEY");
const templateKey = miniAppTemplateKey(brand.templateKey);
if (!templateKey) throw new BadRequestException("当前品牌模板没有可上传的小程序包");
const projectPath = resolve(MINIAPP_ARTIFACT_ROOT, templateKey, "weapp");
if (!existsSync(projectPath) || !existsSync(resolve(projectPath, "app.json")))
throw new BadRequestException("小程序构建产物不存在");
throw new BadRequestException(
`小程序构建产物不存在:${projectPath},请先执行对应模板的微信小程序构建`,
);
const ci = (await import("miniprogram-ci")) as unknown as MiniprogramCi;
const project = new ci.Project({
projectPath,