fix prod
This commit is contained in:
parent
c7091db7c9
commit
8f7f06156c
|
|
@ -6,13 +6,17 @@ import { validate } from "uuid";
|
||||||
import { dir } from "dir";
|
import { dir } from "dir";
|
||||||
import { existsAsync, readAsync, exists } from "fs-jetpack";
|
import { existsAsync, readAsync, exists } from "fs-jetpack";
|
||||||
import { code } from "../ws/sync/code/code";
|
import { code } from "../ws/sync/code/code";
|
||||||
|
import { encode } from "msgpackr";
|
||||||
|
import { binaryExtensions } from "../util/binary-ext";
|
||||||
export const _ = {
|
export const _ = {
|
||||||
url: "/prod-zip/:site_id",
|
url: "/prod-zip/:site_id",
|
||||||
async api(site_id: string) {
|
async api(site_id: string) {
|
||||||
const { req, res } = apiContext(this);
|
const { req, res } = apiContext(this);
|
||||||
|
|
||||||
|
let is_msgpack = req.query_parameters["msgpack"];
|
||||||
|
|
||||||
if (validate(site_id)) {
|
if (validate(site_id)) {
|
||||||
|
const mode = is_msgpack ? "binary" : "string";
|
||||||
const result = {
|
const result = {
|
||||||
layouts: await _db.page.findMany({
|
layouts: await _db.page.findMany({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -53,6 +57,7 @@ export const _ = {
|
||||||
select: { id: true, content_tree: true },
|
select: { id: true, content_tree: true },
|
||||||
}),
|
}),
|
||||||
public: readDirectoryRecursively(
|
public: readDirectoryRecursively(
|
||||||
|
mode,
|
||||||
code.path(site_id, "site", "src", "public")
|
code.path(site_id, "site", "src", "public")
|
||||||
),
|
),
|
||||||
site: await _db.site.findFirst({
|
site: await _db.site.findFirst({
|
||||||
|
|
@ -67,24 +72,29 @@ export const _ = {
|
||||||
}),
|
}),
|
||||||
code: {
|
code: {
|
||||||
server: readDirectoryRecursively(
|
server: readDirectoryRecursively(
|
||||||
|
mode,
|
||||||
code.path(site_id, "server", "build")
|
code.path(site_id, "server", "build")
|
||||||
),
|
),
|
||||||
site: readDirectoryRecursively(code.path(site_id, "site", "build")),
|
site: readDirectoryRecursively(
|
||||||
core: readDirectoryRecursively(dir.path(`/app/srv/core`)),
|
mode,
|
||||||
|
code.path(site_id, "site", "build")
|
||||||
|
),
|
||||||
|
core: readDirectoryRecursively(mode, dir.path(`/app/srv/core`)),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return await gzipAsync(JSON.stringify(result));
|
return await gzipAsync(encode(result));
|
||||||
}
|
}
|
||||||
return new Response("NOT FOUND", { status: 403 });
|
return new Response("NOT FOUND", { status: 403 });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export function readDirectoryRecursively(
|
export function readDirectoryRecursively(
|
||||||
|
mode: "string" | "binary",
|
||||||
dirPath: string,
|
dirPath: string,
|
||||||
baseDir?: string[]
|
baseDir?: string[]
|
||||||
): Record<string, string> {
|
): Record<string, string | Uint8Array> {
|
||||||
const result: Record<string, string> = {};
|
const result: Record<string, string | Uint8Array> = {};
|
||||||
|
|
||||||
if (!exists(dirPath)) return result;
|
if (!exists(dirPath)) return result;
|
||||||
const contents = fs.readdirSync(dirPath);
|
const contents = fs.readdirSync(dirPath);
|
||||||
|
|
@ -94,11 +104,19 @@ export function readDirectoryRecursively(
|
||||||
const stats = fs.statSync(itemPath);
|
const stats = fs.statSync(itemPath);
|
||||||
|
|
||||||
if (stats.isFile()) {
|
if (stats.isFile()) {
|
||||||
const content = fs.readFileSync(itemPath, "utf-8");
|
let content: any = "";
|
||||||
|
if (mode === "string") content = fs.readFileSync(itemPath, "utf-8");
|
||||||
|
else {
|
||||||
|
if (binaryExtensions.includes(itemPath.split(".").pop() || "")) {
|
||||||
|
content = new Uint8Array(fs.readFileSync(itemPath));
|
||||||
|
} else {
|
||||||
|
content = fs.readFileSync(itemPath, "utf-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
result[[...(baseDir || []), item].join("/")] = content;
|
result[[...(baseDir || []), item].join("/")] = content;
|
||||||
} else if (stats.isDirectory()) {
|
} else if (stats.isDirectory()) {
|
||||||
if (item !== "node_modules") {
|
if (item !== "node_modules") {
|
||||||
const subdirResult = readDirectoryRecursively(itemPath, [
|
const subdirResult = readDirectoryRecursively(mode, itemPath, [
|
||||||
...(baseDir || []),
|
...(baseDir || []),
|
||||||
item,
|
item,
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,263 @@
|
||||||
|
export const binaryExtensions = [
|
||||||
|
"3dm",
|
||||||
|
"3ds",
|
||||||
|
"3g2",
|
||||||
|
"3gp",
|
||||||
|
"7z",
|
||||||
|
"a",
|
||||||
|
"aac",
|
||||||
|
"adp",
|
||||||
|
"afdesign",
|
||||||
|
"afphoto",
|
||||||
|
"afpub",
|
||||||
|
"ai",
|
||||||
|
"aif",
|
||||||
|
"aiff",
|
||||||
|
"alz",
|
||||||
|
"ape",
|
||||||
|
"apk",
|
||||||
|
"appimage",
|
||||||
|
"ar",
|
||||||
|
"arj",
|
||||||
|
"asf",
|
||||||
|
"au",
|
||||||
|
"avi",
|
||||||
|
"bak",
|
||||||
|
"baml",
|
||||||
|
"bh",
|
||||||
|
"bin",
|
||||||
|
"bk",
|
||||||
|
"bmp",
|
||||||
|
"btif",
|
||||||
|
"bz2",
|
||||||
|
"bzip2",
|
||||||
|
"cab",
|
||||||
|
"caf",
|
||||||
|
"cgm",
|
||||||
|
"class",
|
||||||
|
"cmx",
|
||||||
|
"cpio",
|
||||||
|
"cr2",
|
||||||
|
"cur",
|
||||||
|
"dat",
|
||||||
|
"dcm",
|
||||||
|
"deb",
|
||||||
|
"dex",
|
||||||
|
"djvu",
|
||||||
|
"dll",
|
||||||
|
"dmg",
|
||||||
|
"dng",
|
||||||
|
"doc",
|
||||||
|
"docm",
|
||||||
|
"docx",
|
||||||
|
"dot",
|
||||||
|
"dotm",
|
||||||
|
"dra",
|
||||||
|
"DS_Store",
|
||||||
|
"dsk",
|
||||||
|
"dts",
|
||||||
|
"dtshd",
|
||||||
|
"dvb",
|
||||||
|
"dwg",
|
||||||
|
"dxf",
|
||||||
|
"ecelp4800",
|
||||||
|
"ecelp7470",
|
||||||
|
"ecelp9600",
|
||||||
|
"egg",
|
||||||
|
"eol",
|
||||||
|
"eot",
|
||||||
|
"epub",
|
||||||
|
"exe",
|
||||||
|
"f4v",
|
||||||
|
"fbs",
|
||||||
|
"fh",
|
||||||
|
"fla",
|
||||||
|
"flac",
|
||||||
|
"flatpak",
|
||||||
|
"fli",
|
||||||
|
"flv",
|
||||||
|
"fpx",
|
||||||
|
"fst",
|
||||||
|
"fvt",
|
||||||
|
"g3",
|
||||||
|
"gh",
|
||||||
|
"gif",
|
||||||
|
"graffle",
|
||||||
|
"gz",
|
||||||
|
"gzip",
|
||||||
|
"h261",
|
||||||
|
"h263",
|
||||||
|
"h264",
|
||||||
|
"icns",
|
||||||
|
"ico",
|
||||||
|
"ief",
|
||||||
|
"img",
|
||||||
|
"ipa",
|
||||||
|
"iso",
|
||||||
|
"jar",
|
||||||
|
"jpeg",
|
||||||
|
"jpg",
|
||||||
|
"jpgv",
|
||||||
|
"jpm",
|
||||||
|
"jxr",
|
||||||
|
"key",
|
||||||
|
"ktx",
|
||||||
|
"lha",
|
||||||
|
"lib",
|
||||||
|
"lvp",
|
||||||
|
"lz",
|
||||||
|
"lzh",
|
||||||
|
"lzma",
|
||||||
|
"lzo",
|
||||||
|
"m3u",
|
||||||
|
"m4a",
|
||||||
|
"m4v",
|
||||||
|
"mar",
|
||||||
|
"mdi",
|
||||||
|
"mht",
|
||||||
|
"mid",
|
||||||
|
"midi",
|
||||||
|
"mj2",
|
||||||
|
"mka",
|
||||||
|
"mkv",
|
||||||
|
"mmr",
|
||||||
|
"mng",
|
||||||
|
"mobi",
|
||||||
|
"mov",
|
||||||
|
"movie",
|
||||||
|
"mp3",
|
||||||
|
"mp4",
|
||||||
|
"mp4a",
|
||||||
|
"mpeg",
|
||||||
|
"mpg",
|
||||||
|
"mpga",
|
||||||
|
"mxu",
|
||||||
|
"nef",
|
||||||
|
"npx",
|
||||||
|
"numbers",
|
||||||
|
"nupkg",
|
||||||
|
"o",
|
||||||
|
"odp",
|
||||||
|
"ods",
|
||||||
|
"odt",
|
||||||
|
"oga",
|
||||||
|
"ogg",
|
||||||
|
"ogv",
|
||||||
|
"otf",
|
||||||
|
"ott",
|
||||||
|
"pages",
|
||||||
|
"pbm",
|
||||||
|
"pcx",
|
||||||
|
"pdb",
|
||||||
|
"pdf",
|
||||||
|
"pea",
|
||||||
|
"pgm",
|
||||||
|
"pic",
|
||||||
|
"png",
|
||||||
|
"pnm",
|
||||||
|
"pot",
|
||||||
|
"potm",
|
||||||
|
"potx",
|
||||||
|
"ppa",
|
||||||
|
"ppam",
|
||||||
|
"ppm",
|
||||||
|
"pps",
|
||||||
|
"ppsm",
|
||||||
|
"ppsx",
|
||||||
|
"ppt",
|
||||||
|
"pptm",
|
||||||
|
"pptx",
|
||||||
|
"psd",
|
||||||
|
"pya",
|
||||||
|
"pyc",
|
||||||
|
"pyo",
|
||||||
|
"pyv",
|
||||||
|
"qt",
|
||||||
|
"rar",
|
||||||
|
"ras",
|
||||||
|
"raw",
|
||||||
|
"resources",
|
||||||
|
"rgb",
|
||||||
|
"rip",
|
||||||
|
"rlc",
|
||||||
|
"rmf",
|
||||||
|
"rmvb",
|
||||||
|
"rpm",
|
||||||
|
"rtf",
|
||||||
|
"rz",
|
||||||
|
"s3m",
|
||||||
|
"s7z",
|
||||||
|
"scpt",
|
||||||
|
"sgi",
|
||||||
|
"shar",
|
||||||
|
"snap",
|
||||||
|
"sil",
|
||||||
|
"sketch",
|
||||||
|
"slk",
|
||||||
|
"smv",
|
||||||
|
"snk",
|
||||||
|
"so",
|
||||||
|
"stl",
|
||||||
|
"suo",
|
||||||
|
"sub",
|
||||||
|
"swf",
|
||||||
|
"tar",
|
||||||
|
"tbz",
|
||||||
|
"tbz2",
|
||||||
|
"tga",
|
||||||
|
"tgz",
|
||||||
|
"thmx",
|
||||||
|
"tif",
|
||||||
|
"tiff",
|
||||||
|
"tlz",
|
||||||
|
"ttc",
|
||||||
|
"ttf",
|
||||||
|
"txz",
|
||||||
|
"udf",
|
||||||
|
"uvh",
|
||||||
|
"uvi",
|
||||||
|
"uvm",
|
||||||
|
"uvp",
|
||||||
|
"uvs",
|
||||||
|
"uvu",
|
||||||
|
"viv",
|
||||||
|
"vob",
|
||||||
|
"war",
|
||||||
|
"wav",
|
||||||
|
"wax",
|
||||||
|
"wbmp",
|
||||||
|
"wdp",
|
||||||
|
"weba",
|
||||||
|
"webm",
|
||||||
|
"webp",
|
||||||
|
"whl",
|
||||||
|
"wim",
|
||||||
|
"wm",
|
||||||
|
"wma",
|
||||||
|
"wmv",
|
||||||
|
"wmx",
|
||||||
|
"woff",
|
||||||
|
"woff2",
|
||||||
|
"wrm",
|
||||||
|
"wvx",
|
||||||
|
"xbm",
|
||||||
|
"xif",
|
||||||
|
"xla",
|
||||||
|
"xlam",
|
||||||
|
"xls",
|
||||||
|
"xlsb",
|
||||||
|
"xlsm",
|
||||||
|
"xlsx",
|
||||||
|
"xlt",
|
||||||
|
"xltm",
|
||||||
|
"xltx",
|
||||||
|
"xm",
|
||||||
|
"xmind",
|
||||||
|
"xpi",
|
||||||
|
"xpm",
|
||||||
|
"xwd",
|
||||||
|
"xz",
|
||||||
|
"z",
|
||||||
|
"zip",
|
||||||
|
"zipx",
|
||||||
|
];
|
||||||
|
|
@ -5,7 +5,7 @@ import { removeAsync } from "fs-jetpack";
|
||||||
import { polyfillNode } from "esbuild-plugin-polyfill-node";
|
import { polyfillNode } from "esbuild-plugin-polyfill-node";
|
||||||
|
|
||||||
await removeAsync(dir.path("/app/srv/core"));
|
await removeAsync(dir.path("/app/srv/core"));
|
||||||
await $`bun tailwindcss -i src/nova/prod/tailwind.css -m -o ../srv/core/index.css`
|
await $`bun tailwindcss -i src/nova/prod/tailwind.css -o ../srv/core/index.css`
|
||||||
.cwd(dir.path(`/app/web`))
|
.cwd(dir.path(`/app/web`))
|
||||||
.quiet();
|
.quiet();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue