@hotbunny/hackhub-content-sdk 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.mjs +96 -0
- package/package.json +12 -3
package/build.mjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
function copyDirSync(src, dest) {
|
|
5
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
6
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
7
|
+
const srcPath = path.join(src, entry.name);
|
|
8
|
+
const destPath = path.join(dest, entry.name);
|
|
9
|
+
if (entry.isDirectory()) {
|
|
10
|
+
copyDirSync(srcPath, destPath);
|
|
11
|
+
} else {
|
|
12
|
+
fs.copyFileSync(srcPath, destPath);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function prepareDist() {
|
|
18
|
+
fs.mkdirSync("dist", { recursive: true });
|
|
19
|
+
if (fs.existsSync("manifest.json")) {
|
|
20
|
+
fs.copyFileSync("manifest.json", path.join("dist", "manifest.json"));
|
|
21
|
+
}
|
|
22
|
+
if (fs.existsSync("public")) {
|
|
23
|
+
copyDirSync("public", "dist");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* esbuild plugin: scans HTML files for local asset references
|
|
29
|
+
* (script src, link href, img src) and copies them into dist/.
|
|
30
|
+
*/
|
|
31
|
+
export function htmlAssetsPlugin() {
|
|
32
|
+
const assetPattern = /(?:src|href)\s*=\s*["'](\.[^"']+)["']/g;
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
name: "html-assets",
|
|
36
|
+
setup(build) {
|
|
37
|
+
build.onLoad({ filter: /\.html$/ }, (args) => {
|
|
38
|
+
const html = fs.readFileSync(args.path, "utf-8");
|
|
39
|
+
const htmlDir = path.dirname(args.path);
|
|
40
|
+
let match;
|
|
41
|
+
|
|
42
|
+
while ((match = assetPattern.exec(html)) !== null) {
|
|
43
|
+
const ref = match[1];
|
|
44
|
+
if (ref.startsWith("./") || !ref.startsWith("/")) {
|
|
45
|
+
const absPath = path.resolve(htmlDir, ref);
|
|
46
|
+
if (fs.existsSync(absPath)) {
|
|
47
|
+
const rel = ref.startsWith("./") ? ref.slice(2) : ref;
|
|
48
|
+
const dest = path.join("dist", rel);
|
|
49
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
50
|
+
fs.copyFileSync(absPath, dest);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { contents: html, loader: "text" };
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Builds a HackHub mod project.
|
|
63
|
+
* Call this from your esbuild.config.ts — all build logic is handled here.
|
|
64
|
+
*
|
|
65
|
+
* @param {object} [options]
|
|
66
|
+
* @param {string} [options.entryPoint] - Entry file (default: "src/index.ts")
|
|
67
|
+
* @param {string} [options.outfile] - Output file (default: "dist/mod.js")
|
|
68
|
+
* @param {import("esbuild").Plugin[]} [options.plugins] - Extra esbuild plugins
|
|
69
|
+
*/
|
|
70
|
+
export async function buildMod(options = {}) {
|
|
71
|
+
const esbuild = await import("esbuild");
|
|
72
|
+
const isWatch = process.argv.includes("--watch");
|
|
73
|
+
|
|
74
|
+
prepareDist();
|
|
75
|
+
|
|
76
|
+
const config = {
|
|
77
|
+
entryPoints: [options.entryPoint || "src/index.ts"],
|
|
78
|
+
bundle: true,
|
|
79
|
+
outfile: options.outfile || "dist/mod.js",
|
|
80
|
+
format: "cjs",
|
|
81
|
+
platform: "neutral",
|
|
82
|
+
target: "es2020",
|
|
83
|
+
external: ["@hotbunny/hackhub-content-sdk"],
|
|
84
|
+
loader: { ".html": "text" },
|
|
85
|
+
plugins: [htmlAssetsPlugin(), ...(options.plugins || [])],
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
if (isWatch) {
|
|
89
|
+
const ctx = await esbuild.context(config);
|
|
90
|
+
await ctx.watch();
|
|
91
|
+
console.log("Watching for changes...");
|
|
92
|
+
} else {
|
|
93
|
+
await esbuild.build(config);
|
|
94
|
+
console.log("Build complete: " + config.outfile);
|
|
95
|
+
}
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hotbunny/hackhub-content-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Type definitions and
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Type definitions and build tools for HackHub mod development",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./index.d.ts"
|
|
9
|
+
},
|
|
10
|
+
"./build": {
|
|
11
|
+
"import": "./build.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
6
14
|
"files": [
|
|
7
|
-
"index.d.ts"
|
|
15
|
+
"index.d.ts",
|
|
16
|
+
"build.mjs"
|
|
8
17
|
],
|
|
9
18
|
"keywords": [
|
|
10
19
|
"hackhub",
|