Spaces:
Running
Running
Update generate_html.cjs
Browse files- generate_html.cjs +21 -8
generate_html.cjs
CHANGED
|
@@ -2,6 +2,7 @@ const Packager = require("@turbowarp/packager");
|
|
| 2 |
const fetch = require("cross-fetch").default;
|
| 3 |
const fs = require("fs");
|
| 4 |
|
|
|
|
| 5 |
async function fetchProjectData(projectId) {
|
| 6 |
const metaRes = await fetch(`https://api.scratch.mit.edu/projects/${encodeURIComponent(projectId)}`);
|
| 7 |
if (!metaRes.ok) throw new Error(`project metadata fetch failed: ${metaRes.status}`);
|
|
@@ -16,6 +17,7 @@ async function fetchProjectData(projectId) {
|
|
| 16 |
return Buffer.from(await projectRes.arrayBuffer());
|
| 17 |
}
|
| 18 |
|
|
|
|
| 19 |
async function imageFromUrl(url) {
|
| 20 |
if (!url) return undefined;
|
| 21 |
const res = await fetch(url);
|
|
@@ -25,6 +27,7 @@ async function imageFromUrl(url) {
|
|
| 25 |
return new Packager.Image(contentType, buffer);
|
| 26 |
}
|
| 27 |
|
|
|
|
| 28 |
function bool(v, fallback = false) {
|
| 29 |
if (v === undefined || v === null || v === "") return fallback;
|
| 30 |
if (typeof v === "boolean") return v;
|
|
@@ -66,17 +69,24 @@ async function main() {
|
|
| 66 |
if (options.appearance.accent) packager.options.appearance.accent = options.appearance.accent;
|
| 67 |
}
|
| 68 |
|
| 69 |
-
//
|
| 70 |
if (options.loadingScreen) {
|
| 71 |
-
packager.options.
|
| 72 |
-
if (options.loadingScreen.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
const loadingImage = await imageFromUrl(options.loadingScreen.image);
|
| 74 |
-
if (loadingImage) packager.options.
|
| 75 |
}
|
| 76 |
|
| 77 |
// app
|
| 78 |
if (options.app) {
|
| 79 |
-
if (
|
|
|
|
|
|
|
| 80 |
const icon = await imageFromUrl(options.app.icon);
|
| 81 |
if (icon) packager.options.app.icon = icon;
|
| 82 |
}
|
|
@@ -93,7 +103,7 @@ async function main() {
|
|
| 93 |
packager.options.chunks.pointerlock = bool(options.chunks.pointerlock);
|
| 94 |
}
|
| 95 |
|
| 96 |
-
//
|
| 97 |
if (options.cloudVariables) {
|
| 98 |
packager.options.cloudVariables.mode = options.cloudVariables.mode || packager.options.cloudVariables.mode;
|
| 99 |
packager.options.cloudVariables.cloudHost = options.cloudVariables.cloudHost || packager.options.cloudVariables.cloudHost;
|
|
@@ -101,11 +111,14 @@ async function main() {
|
|
| 101 |
packager.options.cloudVariables.unsafeCloudBehaviors = bool(options.cloudVariables.unsafeCloudBehaviors);
|
| 102 |
}
|
| 103 |
|
| 104 |
-
//
|
| 105 |
if ("bakeExtensions" in options) packager.options.bakeExtensions = bool(options.bakeExtensions);
|
| 106 |
|
|
|
|
| 107 |
const result = await packager.package();
|
| 108 |
-
|
|
|
|
|
|
|
| 109 |
}
|
| 110 |
|
| 111 |
main().catch((err) => {
|
|
|
|
| 2 |
const fetch = require("cross-fetch").default;
|
| 3 |
const fs = require("fs");
|
| 4 |
|
| 5 |
+
// Scratch γγγΈγ§γ―γγγΌγΏγεεΎ
|
| 6 |
async function fetchProjectData(projectId) {
|
| 7 |
const metaRes = await fetch(`https://api.scratch.mit.edu/projects/${encodeURIComponent(projectId)}`);
|
| 8 |
if (!metaRes.ok) throw new Error(`project metadata fetch failed: ${metaRes.status}`);
|
|
|
|
| 17 |
return Buffer.from(await projectRes.arrayBuffer());
|
| 18 |
}
|
| 19 |
|
| 20 |
+
// URL γγη»εγ Packager.Image γ«ε€ζ
|
| 21 |
async function imageFromUrl(url) {
|
| 22 |
if (!url) return undefined;
|
| 23 |
const res = await fetch(url);
|
|
|
|
| 27 |
return new Packager.Image(contentType, buffer);
|
| 28 |
}
|
| 29 |
|
| 30 |
+
// ηε½ε€ε€ζγ¦γΌγγ£γͺγγ£
|
| 31 |
function bool(v, fallback = false) {
|
| 32 |
if (v === undefined || v === null || v === "") return fallback;
|
| 33 |
if (typeof v === "boolean") return v;
|
|
|
|
| 69 |
if (options.appearance.accent) packager.options.appearance.accent = options.appearance.accent;
|
| 70 |
}
|
| 71 |
|
| 72 |
+
// loadingScreen
|
| 73 |
if (options.loadingScreen) {
|
| 74 |
+
packager.options.loadingScreen.progressBar = bool(options.loadingScreen.progressBar, true);
|
| 75 |
+
if (typeof options.loadingScreen.text === "string") {
|
| 76 |
+
packager.options.loadingScreen.text = options.loadingScreen.text;
|
| 77 |
+
}
|
| 78 |
+
if (typeof options.loadingScreen.imageMode === "string") {
|
| 79 |
+
packager.options.loadingScreen.imageMode = options.loadingScreen.imageMode;
|
| 80 |
+
}
|
| 81 |
const loadingImage = await imageFromUrl(options.loadingScreen.image);
|
| 82 |
+
if (loadingImage) packager.options.loadingScreen.image = loadingImage;
|
| 83 |
}
|
| 84 |
|
| 85 |
// app
|
| 86 |
if (options.app) {
|
| 87 |
+
if (typeof options.app.windowTitle === "string" && options.app.windowTitle.trim() !== "") {
|
| 88 |
+
packager.options.app.windowTitle = options.app.windowTitle;
|
| 89 |
+
}
|
| 90 |
const icon = await imageFromUrl(options.app.icon);
|
| 91 |
if (icon) packager.options.app.icon = icon;
|
| 92 |
}
|
|
|
|
| 103 |
packager.options.chunks.pointerlock = bool(options.chunks.pointerlock);
|
| 104 |
}
|
| 105 |
|
| 106 |
+
// cloudVariables
|
| 107 |
if (options.cloudVariables) {
|
| 108 |
packager.options.cloudVariables.mode = options.cloudVariables.mode || packager.options.cloudVariables.mode;
|
| 109 |
packager.options.cloudVariables.cloudHost = options.cloudVariables.cloudHost || packager.options.cloudVariables.cloudHost;
|
|
|
|
| 111 |
packager.options.cloudVariables.unsafeCloudBehaviors = bool(options.cloudVariables.unsafeCloudBehaviors);
|
| 112 |
}
|
| 113 |
|
| 114 |
+
// bakeExtensions
|
| 115 |
if ("bakeExtensions" in options) packager.options.bakeExtensions = bool(options.bakeExtensions);
|
| 116 |
|
| 117 |
+
// γγγ±γΌγΈδ½ζ
|
| 118 |
const result = await packager.package();
|
| 119 |
+
|
| 120 |
+
// γγ€γγͺγγΌγΏγ¨γγ¦εΊε
|
| 121 |
+
process.stdout.write(Buffer.from(result.data));
|
| 122 |
}
|
| 123 |
|
| 124 |
main().catch((err) => {
|