fix: 按模板包定位小程序构建产物
This commit is contained in:
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 { existsSync } from "node:fs";
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
|
import { getTemplatePackageManifest, templatePackageRegistry } from "@personal-brand/config";
|
||||||
import { AdminAccessService } from "../../admin-access.service.js";
|
import { AdminAccessService } from "../../admin-access.service.js";
|
||||||
import { PrismaService } from "../../prisma.service.js";
|
import { PrismaService } from "../../prisma.service.js";
|
||||||
import { AdminMiniAppReleaseService } from "./admin-miniapp-release.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";
|
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 {
|
interface MiniprogramCi {
|
||||||
Project: new (options: {
|
Project: new (options: {
|
||||||
projectPath: string;
|
projectPath: string;
|
||||||
@@ -104,7 +115,7 @@ export class AdminMiniAppReleaseController {
|
|||||||
...this.jsonObject(body.build),
|
...this.jsonObject(body.build),
|
||||||
} as Prisma.InputJsonObject,
|
} as Prisma.InputJsonObject,
|
||||||
...(credential ? { credential } : {}),
|
...(credential ? { credential } : {}),
|
||||||
templateKey: current.templateKey ?? process.env.MINIAPP_TEMPLATE_KEY ?? "food",
|
templateKey: current.templateKey ?? null,
|
||||||
} satisfies Prisma.InputJsonObject;
|
} satisfies Prisma.InputJsonObject;
|
||||||
await this.prisma.brandProfile.update({
|
await this.prisma.brandProfile.update({
|
||||||
where: { id: identity.brandId },
|
where: { id: identity.brandId },
|
||||||
@@ -146,7 +157,7 @@ export class AdminMiniAppReleaseController {
|
|||||||
throw new BadRequestException("当前小程序发布任务不能重复上传");
|
throw new BadRequestException("当前小程序发布任务不能重复上传");
|
||||||
const brand = await this.prisma.brandProfile.findUniqueOrThrow({
|
const brand = await this.prisma.brandProfile.findUniqueOrThrow({
|
||||||
where: { id: identity.brandId },
|
where: { id: identity.brandId },
|
||||||
select: { miniAppSettings: true },
|
select: { miniAppSettings: true, templateKey: true },
|
||||||
});
|
});
|
||||||
const settings = this.jsonObject(brand.miniAppSettings);
|
const settings = this.jsonObject(brand.miniAppSettings);
|
||||||
const appid =
|
const appid =
|
||||||
@@ -156,13 +167,13 @@ export class AdminMiniAppReleaseController {
|
|||||||
const privateKey = settings.credential
|
const privateKey = settings.credential
|
||||||
? decryptMiniAppCredential(settings.credential)
|
? decryptMiniAppCredential(settings.credential)
|
||||||
: this.requiredEnv("WECHAT_UPLOAD_PRIVATE_KEY");
|
: this.requiredEnv("WECHAT_UPLOAD_PRIVATE_KEY");
|
||||||
const templateKey =
|
const templateKey = miniAppTemplateKey(brand.templateKey);
|
||||||
typeof settings.templateKey === "string" && settings.templateKey
|
if (!templateKey) throw new BadRequestException("当前品牌模板没有可上传的小程序包");
|
||||||
? settings.templateKey
|
|
||||||
: this.requiredEnv("MINIAPP_TEMPLATE_KEY");
|
|
||||||
const projectPath = resolve(MINIAPP_ARTIFACT_ROOT, templateKey, "weapp");
|
const projectPath = resolve(MINIAPP_ARTIFACT_ROOT, templateKey, "weapp");
|
||||||
if (!existsSync(projectPath) || !existsSync(resolve(projectPath, "app.json")))
|
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 ci = (await import("miniprogram-ci")) as unknown as MiniprogramCi;
|
||||||
const project = new ci.Project({
|
const project = new ci.Project({
|
||||||
projectPath,
|
projectPath,
|
||||||
|
|||||||
Reference in new issue
Block a user