@hotbunny/hackhub-content-sdk 0.4.0 → 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/index.d.ts +14 -12
- 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/index.d.ts
CHANGED
|
@@ -937,17 +937,17 @@ export declare abstract class Quest {
|
|
|
937
937
|
* }
|
|
938
938
|
* ```
|
|
939
939
|
*
|
|
940
|
-
* In your HTML,
|
|
940
|
+
* In your HTML, exported functions are available as globals:
|
|
941
941
|
* ```html
|
|
942
942
|
* <script>
|
|
943
|
-
* const formatted =
|
|
943
|
+
* const formatted = formatPost("hello");
|
|
944
944
|
* </script>
|
|
945
945
|
* ```
|
|
946
946
|
*
|
|
947
|
-
* SDK APIs are available via `
|
|
947
|
+
* SDK APIs are available via the `HackhubSDK` global:
|
|
948
948
|
* ```html
|
|
949
949
|
* <script>
|
|
950
|
-
*
|
|
950
|
+
* HackhubSDK.Mail.send({ to: "user@mail.com", subject: "Hi" });
|
|
951
951
|
* </script>
|
|
952
952
|
* ```
|
|
953
953
|
*/
|
|
@@ -958,8 +958,9 @@ export declare abstract class Website {
|
|
|
958
958
|
abstract Pages: WebsitePageDefinition[];
|
|
959
959
|
Popular?: boolean;
|
|
960
960
|
/**
|
|
961
|
-
* Functions/values exposed to all pages' HTML
|
|
962
|
-
*
|
|
961
|
+
* Functions/values exposed to all pages' HTML as globals.
|
|
962
|
+
* Each key becomes directly callable in your HTML scripts (e.g. `formatPost("hello")`).
|
|
963
|
+
* Also accessible via the `ModExports` namespace.
|
|
963
964
|
*/
|
|
964
965
|
Exports?: Record<string, any>;
|
|
965
966
|
}
|
|
@@ -1030,18 +1031,18 @@ export declare abstract class Command {
|
|
|
1030
1031
|
* }
|
|
1031
1032
|
* ```
|
|
1032
1033
|
*
|
|
1033
|
-
* In your HTML,
|
|
1034
|
+
* In your HTML, exported functions are available as globals:
|
|
1034
1035
|
* ```html
|
|
1035
1036
|
* <script>
|
|
1036
|
-
* const pw =
|
|
1037
|
+
* const pw = generate(16);
|
|
1037
1038
|
* document.getElementById("result").textContent = pw;
|
|
1038
1039
|
* </script>
|
|
1039
1040
|
* ```
|
|
1040
1041
|
*
|
|
1041
|
-
* SDK APIs are available via `
|
|
1042
|
+
* SDK APIs are available via the `HackhubSDK` global:
|
|
1042
1043
|
* ```html
|
|
1043
1044
|
* <script>
|
|
1044
|
-
*
|
|
1045
|
+
* HackhubSDK.Events.emit("PasswordGenerated");
|
|
1045
1046
|
* </script>
|
|
1046
1047
|
* ```
|
|
1047
1048
|
*/
|
|
@@ -1061,8 +1062,9 @@ export declare abstract class App {
|
|
|
1061
1062
|
/** If true, the app is unlocked in the AppStore by default (no quest required). */
|
|
1062
1063
|
Unlocked?: boolean;
|
|
1063
1064
|
/**
|
|
1064
|
-
* Functions/values exposed to the app's HTML
|
|
1065
|
-
*
|
|
1065
|
+
* Functions/values exposed to the app's HTML as globals.
|
|
1066
|
+
* Each key becomes directly callable in your HTML scripts (e.g. `generate(16)`).
|
|
1067
|
+
* Also accessible via the `ModExports` namespace.
|
|
1066
1068
|
*/
|
|
1067
1069
|
Exports?: Record<string, any>;
|
|
1068
1070
|
}
|
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",
|