fix: 完善工坊模板安装预览与详情样例

This commit is contained in:
que01 committed 2026-10-15 20:58:45 +08:00
1 parent 5313fd9d32
commit 50753db79d
16 files changed
+496 -26

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
import assert from "node:assert/strict";
import { PrismaService } from "../dist/prisma.service.js";
import { TemplateWorkspaceService } from "../dist/template-workspace.service.js";
// 显式创建独立品牌;不注册模板样例,不导入内容,也不发布。
const username = process.argv[2];
if (!username)
throw new Error("Usage: node --env-file=.env scripts/create-atelier-brand.mjs <admin-username>");
const prisma = new PrismaService();
try {
const admin = await prisma.adminUser.findUniqueOrThrow({ where: { username } });
assert.ok(admin.isEnabled && admin.role === "admin", "An enabled administrator is required");
const slug = "atelier-studio";
const existingBrands = await prisma.brandProfile.findMany({
where: { slug: { not: slug } },
orderBy: { id: "asc" },
});
const brand = await prisma.$transaction(async (tx) => {
let current = await tx.brandProfile.findUnique({ where: { slug } });
if (current) {
assert.equal(current.templateKey, "personal", "Existing brand has a different industry");
assert.equal(
current.config?.visualTemplateKey,
"atelier-solopreneur",
"Existing brand has a different visual template",
);
} else {
current = await tx.brandProfile.create({
data: {
slug,
name: "独立工坊 · 品牌小程序",
templateKey: "personal",
config: { visualTemplateKey: "atelier-solopreneur" },
},
});
}
await tx.brandMembership.upsert({
where: { adminUserId_brandId: { adminUserId: admin.id, brandId: current.id } },
create: { adminUserId: admin.id, brandId: current.id, role: "owner" },
update: {},
});
return current;
});
if (!(await prisma.brandTemplateInstallation.findFirst({ where: { brandId: brand.id } }))) {
await new TemplateWorkspaceService(prisma).install(brand.id, "personal");
}
assert.deepEqual(
await prisma.brandProfile.findMany({ where: { slug: { not: slug } }, orderBy: { id: "asc" } }),
existingBrands,
);
console.log(
JSON.stringify({
slug,
name: brand.name,
template: "atelier-solopreneur",
administrator: username,
sampleImported: false,
publishedByScript: false,
}),
);
} finally {
await prisma.$disconnect();
}