ci: 增加发布产物打包脚本
This commit is contained in:
1 parent
9c15a822e9
commit
f57c0ca0ea
3 files changed
+59
No files matched your search
@@ -68,6 +68,14 @@ pnpm --filter @personal-brand/api db:migrate:deploy
|
||||
|
||||
部署产物中的模板预览入口是 `apps/admin/dist/template-preview/index.html`,资源位于同级 `assets`、`css`、`js` 目录,线上必须保留 `/template-preview/` 前缀。
|
||||
|
||||
也可以把生产产物整理成统一发布目录:
|
||||
|
||||
```bash
|
||||
pnpm deploy:package
|
||||
```
|
||||
|
||||
脚本会先执行数据库迁移,再生成 `dist/release`,其中 `admin/` 是静态站点,`api/` 是编译后的 API 产物,`manifest.json` 记录关键入口的大小和 SHA-256。发布进程需要保留 API 的 `node_modules` 或在目标机器重新执行 `pnpm install --prod --frozen-lockfile`。
|
||||
|
||||
首次部署可以执行一次 `pnpm db:seed` 创建管理员与演示品牌。已有生产环境禁止重复执行种子命令;模板示例内容只能由管理员在后台对指定品牌显式导入,不能把示例数据扩展到全局种子。
|
||||
|
||||
### 3. 发布前门禁
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
"preview:linjing": "TEMPLATE_KEY=linjing-editorial PREVIEW_PORT=3003 pnpm --filter @personal-brand/taro dev:h5",
|
||||
"preview:templates": "pnpm --filter @personal-brand/taro dev:preview",
|
||||
"deploy:verify": "node scripts/deploy/verify-release.mjs",
|
||||
"deploy:package": "node scripts/deploy/package-release.mjs",
|
||||
"test:deploy-verify": "node --test scripts/deploy/verify-release.test.mjs",
|
||||
"build:admin:preview": "PREVIEW_ALL_TEMPLATES=true API_BASE_URL=/api PREVIEW_PUBLIC_PATH=/template-preview/ pnpm --filter @personal-brand/taro build:preview && node scripts/package-template-preview.cjs && VITE_APP_BASE_PATH=/admin/ VITE_API_BASE_URL=/api pnpm --filter @personal-brand/admin build",
|
||||
"build:taro:food": "pnpm --filter @personal-brand/taro build:h5 && pnpm --filter @personal-brand/taro build:weapp",
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
const root = path.resolve(import.meta.dirname, "../..");
|
||||
const source = path.join(root, "apps/admin/dist");
|
||||
const output = path.join(root, "dist/release");
|
||||
|
||||
function run(command, args, environment = {}) {
|
||||
const result = spawnSync(command, args, {
|
||||
cwd: root,
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, ...environment },
|
||||
});
|
||||
if (result.status !== 0) process.exit(result.status ?? 1);
|
||||
}
|
||||
|
||||
const requiredFiles = ["index.html", "template-preview/index.html"];
|
||||
const manifest = { createdAt: new Date().toISOString(), files: [] };
|
||||
|
||||
for (const file of requiredFiles) {
|
||||
await readFile(path.join(source, file));
|
||||
}
|
||||
|
||||
run("pnpm", ["--filter", "@personal-brand/api", "db:migrate:deploy"]);
|
||||
|
||||
await rm(output, { recursive: true, force: true });
|
||||
await mkdir(path.join(output, "api"), { recursive: true });
|
||||
await cp(source, path.join(output, "admin"), { recursive: true });
|
||||
await cp(path.join(root, "apps/api/dist"), path.join(output, "api"), { recursive: true });
|
||||
|
||||
for (const relativePath of [
|
||||
"api/main.js",
|
||||
"admin/index.html",
|
||||
"admin/template-preview/index.html",
|
||||
]) {
|
||||
const file = path.join(output, relativePath);
|
||||
const content = await readFile(file);
|
||||
manifest.files.push({
|
||||
path: relativePath,
|
||||
bytes: content.byteLength,
|
||||
sha256: createHash("sha256").update(content).digest("hex"),
|
||||
});
|
||||
}
|
||||
|
||||
await writeFile(path.join(output, "manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`);
|
||||
console.log(
|
||||
`release package: ${path.relative(root, output)} (${manifest.files.length} checked files)`,
|
||||
);
|
||||
Reference in new issue
Block a user