chore: 固化一键生产部署流程
This commit is contained in:
1 parent
c78deafee3
commit
47a24e0d53
6 files changed
+189
-40
No files matched your search
@@ -21,21 +21,24 @@ const contentTypes = new Map([
|
||||
]);
|
||||
|
||||
async function checkResource(url, expectedType, label) {
|
||||
const response = await fetch(url);
|
||||
const response = await fetch(url, { signal: AbortSignal.timeout(10000) });
|
||||
const contentType = response.headers.get("content-type") ?? "";
|
||||
assert.equal(response.status, 200, label + " returned " + response.status);
|
||||
assert.ok(contentType.includes(expectedType), label + " has content type " + contentType);
|
||||
await response.body?.cancel();
|
||||
}
|
||||
|
||||
async function checkHtmlAssets(relativeEntry, localPath, publicPath) {
|
||||
const html = await readFile(localPath, "utf8");
|
||||
const checks = [];
|
||||
for (const match of html.matchAll(/(?:src|href)=["']([^"']+)["']/g)) {
|
||||
const asset = match[1];
|
||||
if (!/\.(?:js|css)(?:[?#]|$)/.test(asset)) continue;
|
||||
const url = new URL(asset, baseUrl + publicPath);
|
||||
const expectedType = /\.css(?:[?#]|$)/.test(url.pathname) ? "text/css" : "javascript";
|
||||
await checkResource(url, expectedType, relativeEntry + " -> " + asset);
|
||||
checks.push(checkResource(url, expectedType, relativeEntry + " -> " + asset));
|
||||
}
|
||||
await Promise.all(checks);
|
||||
}
|
||||
|
||||
async function listFiles(directory, prefix = "") {
|
||||
@@ -49,7 +52,9 @@ async function listFiles(directory, prefix = "") {
|
||||
return files;
|
||||
}
|
||||
|
||||
const apiHealthResponse = await fetch(baseUrl + "/api/health");
|
||||
const apiHealthResponse = await fetch(baseUrl + "/api/health", {
|
||||
signal: AbortSignal.timeout(10000),
|
||||
});
|
||||
assert.equal(apiHealthResponse.status, 200, "public API health check failed");
|
||||
assert.match(apiHealthResponse.headers.get("content-type") ?? "", /application\/json/);
|
||||
assert.equal((await apiHealthResponse.json()).status, "ok");
|
||||
@@ -67,23 +72,27 @@ for (const [entry, localFile, publicPath] of [
|
||||
}
|
||||
|
||||
const assetRoot = path.join(root, "apps/admin/dist/assets");
|
||||
for (const asset of await listFiles(assetRoot)) {
|
||||
const extension = path.extname(asset).toLowerCase();
|
||||
const expectedType = contentTypes.get(extension);
|
||||
if (!expectedType) continue;
|
||||
await checkResource(
|
||||
baseUrl + "/assets/" + asset.split("/").map(encodeURIComponent).join("/"),
|
||||
expectedType,
|
||||
"static asset " + asset,
|
||||
);
|
||||
}
|
||||
await Promise.all(
|
||||
(await listFiles(assetRoot)).map(async (asset) => {
|
||||
const extension = path.extname(asset).toLowerCase();
|
||||
const expectedType = contentTypes.get(extension);
|
||||
if (!expectedType) return;
|
||||
await checkResource(
|
||||
baseUrl + "/assets/" + asset.split("/").map(encodeURIComponent).join("/"),
|
||||
expectedType,
|
||||
"static asset " + asset,
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
for (const entry of await readdir(path.join(root, "seed-media"))) {
|
||||
await checkResource(
|
||||
baseUrl + "/media/seed/" + encodeURIComponent(entry),
|
||||
"image/jpeg",
|
||||
"seed media " + entry,
|
||||
);
|
||||
}
|
||||
await Promise.all(
|
||||
(await readdir(path.join(root, "seed-media"))).map((entry) =>
|
||||
checkResource(
|
||||
baseUrl + "/media/seed/" + encodeURIComponent(entry),
|
||||
"image/jpeg",
|
||||
"seed media " + entry,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
console.log("public release verified: admin, preview, assets, and seed media");
|
||||
Reference in new issue
Block a user