zois-core 2.0.0 → 2.0.1

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.
@@ -0,0 +1,17 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg"
2
+ width="86" height="86"
3
+ viewBox="0 0 86 86"
4
+ fill="none">
5
+ <g transform="translate(0.000000,86.000000) scale(0.100000,-0.100000)"
6
+ fill="currentColor" stroke="none">
7
+ <path d="M120 507 l0 -305 151 -81 c83 -45 160 -81 170 -81 18 0 19 12 19 281
8
+ 0 163 -4 288 -10 299 -11 20 -44 40 -212 129 l-118 62 0 -304z"/>
9
+ <path d="M260 787 c31 -19 52 -23 180 -27 l145 -5 3 -72 3 -73 29 0 30 0 0 81
10
+ c0 126 14 119 -223 119 l-202 0 35 -23z"/>
11
+ <path d="M690 590 c0 -19 -7 -20 -90 -20 l-90 0 0 -60 0 -60 90 0 c83 0 90 -1
12
+ 90 -20 0 -11 3 -20 7 -20 14 0 93 84 93 99 0 16 -78 101 -92 101 -4 0 -8 -9
13
+ -8 -20z"/>
14
+ <path d="M590 336 l0 -76 -40 0 c-38 0 -40 -2 -40 -30 0 -29 1 -30 50 -30 77 0
15
+ 92 20 88 123 -3 81 -3 82 -30 85 l-28 3 0 -75z"/>
16
+ </g>
17
+ </svg>
@@ -1,37 +1,8 @@
1
1
  import { MOD_DATA } from ".";
2
2
  import { logger } from "./logging";
3
- import { toastsManager } from "./toasts";
4
- const avatarsCache = /* @__PURE__ */ new Map();
5
- class GitHubAPI {
6
- static baseUrl = "https://api.github.com";
7
- static getHeaders() {
8
- const headers = {
9
- "Accept": "application/vnd.github.v3+json",
10
- "User-Agent": "GitHubAPI-Client"
11
- };
12
- return headers;
13
- }
14
- static async getCommit(sha) {
15
- const effectiveOwner = MOD_DATA.changelog?.owner;
16
- const effectiveRepo = MOD_DATA.changelog?.repo;
17
- const url = `${GitHubAPI.baseUrl}/repos/${effectiveOwner}/${effectiveRepo}/commits/${sha}`;
18
- const response = await fetch(url, {
19
- method: "GET",
20
- headers: this.getHeaders()
21
- });
22
- if (!response.ok) {
23
- const error = await response.json().catch(() => ({}));
24
- logger.error(`GitHub API error: ${response.status} ${error.message || response.statusText}`);
25
- return null;
26
- }
27
- return await response.json();
28
- }
29
- }
30
- async function showChangelogModal() {
3
+ import { addDynamicClass } from "./ui";
4
+ function showChangelogModal() {
31
5
  const changelog = MOD_DATA.changelog;
32
- const id = toastsManager.spinner({
33
- message: "Preparing changelog..."
34
- });
35
6
  const { data } = changelog;
36
7
  const overlay = document.createElement("div");
37
8
  overlay.style.cssText = `
@@ -93,8 +64,8 @@ async function showChangelogModal() {
93
64
  commitsList.style.display = "flex";
94
65
  commitsList.style.flexDirection = "column";
95
66
  commitsList.style.gap = "16px";
96
- for (const commitData of data) {
97
- const commitElement = await createCommitElement(commitData);
67
+ for (const commitData of data.changes) {
68
+ const commitElement = createCommitElement(commitData);
98
69
  if (commitElement) commitsList.appendChild(commitElement);
99
70
  }
100
71
  content.appendChild(commitsList);
@@ -112,14 +83,9 @@ async function showChangelogModal() {
112
83
  document.removeEventListener("keydown", handler);
113
84
  }
114
85
  });
115
- toastsManager.removeSpinner(id);
116
86
  }
117
- async function createCommitElement(changelogCommit) {
87
+ function createCommitElement(changelogCommit) {
118
88
  try {
119
- if (!avatarsCache.has(changelogCommit.author)) {
120
- const githubCommit = await GitHubAPI.getCommit(changelogCommit.hash);
121
- avatarsCache.set(changelogCommit.author, githubCommit?.author?.avatar_url || githubCommit?.committer?.avatar_url || "https://github.com/identicons/default.png");
122
- }
123
89
  const commitDiv = document.createElement("div");
124
90
  commitDiv.style.cssText = `
125
91
  display: flex;
@@ -133,7 +99,7 @@ async function createCommitElement(changelogCommit) {
133
99
  commitDiv.onmouseover = () => commitDiv.style.borderColor = "#3b82f6";
134
100
  commitDiv.onmouseout = () => commitDiv.style.borderColor = "#e5e7eb";
135
101
  const avatar = document.createElement("img");
136
- avatar.src = avatarsCache.get(changelogCommit.author);
102
+ avatar.src = changelogCommit.author.avatar_url;
137
103
  avatar.style.cssText = `
138
104
  width: 48px;
139
105
  height: 48px;
@@ -142,23 +108,43 @@ async function createCommitElement(changelogCommit) {
142
108
  `;
143
109
  const info = document.createElement("div");
144
110
  info.style.flex = "1";
111
+ info.style.position = "relative";
145
112
  const author = document.createElement("div");
146
- author.textContent = changelogCommit.author;
113
+ author.textContent = changelogCommit.author.name;
147
114
  author.style.fontWeight = "600";
148
115
  author.style.marginBottom = "4px";
149
116
  const message = document.createElement("div");
150
117
  message.textContent = changelogCommit.message;
151
118
  message.style.cssText = "color: #374151; line-height: 1.4;";
152
- info.append(author, message);
119
+ const tags = document.createElement("div");
120
+ tags.style.cssText = "display: flex; gap: 4px; position: absolute; right: 2px; top: 2px;";
121
+ for (const tag of changelogCommit.tags) {
122
+ const tagEl = document.createElement("p");
123
+ tagEl.textContent = tag;
124
+ addDynamicClass(tagEl, {
125
+ base: {
126
+ fontSize: "0.85em",
127
+ padding: "2px 6px",
128
+ borderRadius: "6px",
129
+ background: tag === "fix" ? "#f9b4b4" : tag === "feature" ? "#cbffcbc7" : "#a1e0f4",
130
+ color: tag === "fix" ? "#771515" : tag === "feature" ? "#147914" : "#09093e",
131
+ borderWidth: "1",
132
+ borderStyle: "solid",
133
+ borderColor: tag === "fix" ? "#ca6565" : tag === "feature" ? "#4eea4e" : "#66adec"
134
+ }
135
+ });
136
+ tags.append(tagEl);
137
+ }
138
+ info.append(author, message, tags);
153
139
  commitDiv.style.cursor = "pointer";
154
140
  commitDiv.onclick = () => {
155
- window.open(`https://github.com/${MOD_DATA.changelog.owner}/${MOD_DATA.changelog.repo}/commit/${changelogCommit.hash}`, "_blank");
141
+ window.open(changelogCommit.commit_url, "_blank");
156
142
  };
157
143
  commitDiv.appendChild(avatar);
158
144
  commitDiv.appendChild(info);
159
145
  return commitDiv;
160
146
  } catch (err) {
161
- logger.error(`Failed to load commit ${changelogCommit.hash}:`, err);
147
+ logger.error(`Failed to load commit ${changelogCommit.sha}:`, err);
162
148
  return null;
163
149
  }
164
150
  }
package/dist/core.js CHANGED
@@ -39,6 +39,9 @@ function registerSubscreen() {
39
39
  }
40
40
  let loginScreenElements = [];
41
41
  async function registerCore() {
42
+ const style = document.createElement("style");
43
+ style.innerHTML = styles;
44
+ document.head.append(style);
42
45
  if (localStorage.getItem("autoConnectToDevServer") === "true") {
43
46
  hookFunction("CommonGetServer", HookPriority.OVERRIDE_BEHAVIOR, (args, next) => {
44
47
  return "https://bondage-club-server-test.herokuapp.com/";
@@ -84,9 +87,6 @@ async function registerCore() {
84
87
  coreSettings = JSON.parse(LZString.decompressFromBase64(Player.ExtensionSettings.ZOIS_CORE) ?? "{}");
85
88
  }
86
89
  if (coreSettings.devMode) registerSubscreen();
87
- const style = document.createElement("style");
88
- style.innerHTML = styles;
89
- document.head.append(style);
90
90
  window.ZOIS_CORE = Object.freeze({
91
91
  version,
92
92
  enableDevMode: () => {
package/dist/dialogs.js CHANGED
@@ -4,7 +4,7 @@ function createDialog(dialog) {
4
4
  const clear = () => {
5
5
  _dialog.remove();
6
6
  background.remove();
7
- document.removeEventListener("keydown", handleKeyDown);
7
+ document.removeEventListener("keydown", handleKeyDown, { capture: true });
8
8
  };
9
9
  const submit = () => {
10
10
  clear();
@@ -30,7 +30,7 @@ function createDialog(dialog) {
30
30
  if (e.key === "Enter") submit();
31
31
  if (e.key === "Escape") cancel();
32
32
  };
33
- document.addEventListener("keydown", handleKeyDown);
33
+ document.addEventListener("keydown", handleKeyDown, { capture: true });
34
34
  const background = document.createElement("div");
35
35
  background.style.cssText = "position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; opacity: 0.5; background: black;";
36
36
  const _dialog = document.createElement("div");
package/dist/index.js CHANGED
@@ -45,6 +45,9 @@ function bootstrap(modData) {
45
45
  }
46
46
  }
47
47
  );
48
+ ServerIsLoggedInAsync().then(() => {
49
+ if (modData.onReady) setTimeout(modData.onReady, getRandomNumber(3e3, 6e3));
50
+ });
48
51
  }
49
52
  function formatString(text) {
50
53
  if (!text || typeof text !== "string") {
@@ -165,9 +168,6 @@ function injectStyles(stylesToInject) {
165
168
  style.innerHTML = stylesToInject;
166
169
  document.head.append(style);
167
170
  }
168
- function waitForStart(callback) {
169
- waitFor(() => typeof window.Player?.MemberNumber === "number").then(() => setTimeout(callback, getRandomNumber(3e3, 6e3)));
170
- }
171
171
  function normalizeObject(obj) {
172
172
  if (!CommonIsObject(obj)) return obj;
173
173
  if (Array.isArray(obj)) {
@@ -197,6 +197,5 @@ export {
197
197
  normalizeObject,
198
198
  sleep,
199
199
  version,
200
- waitFor,
201
- waitForStart
200
+ waitFor
202
201
  };
@@ -1,3 +1,4 @@
1
+ import { createElement, ExternalLink } from "lucide";
1
2
  import { MOD_DATA } from "../index";
2
3
  import { addDynamicClass, autosetFontSize, setFontFamily, setFontSize } from "../ui";
3
4
  import { Shard } from "./shard";
@@ -36,33 +37,52 @@ class ButtonShard extends Shard {
36
37
  ":hover .tooltip": {
37
38
  visibility: "visible"
38
39
  },
39
- "[data-zc-style=green]": {
40
- background: "rgb(124, 255, 124)",
41
- borderColor: "rgb(82, 204, 82)",
42
- color: "black"
43
- },
44
- "[data-zc-style=green]:hover": {
45
- background: "rgb(94, 197, 94)",
46
- color: "black"
47
- },
48
- "[data-zc-style=inverted]": {
40
+ "[data-zc-variant=filled]": {
49
41
  background: "var(--tmd-accent, #111)",
50
42
  border: "2px solid var(--tmd-accent, #111)",
51
43
  color: "var(--tmd-text, white)"
52
44
  },
53
- "[data-zc-style=inverted]:hover": {
45
+ "[data-zc-variant=filled]:hover": {
54
46
  background: "var(--tmd-accent-hover, none)",
55
47
  color: "var(--tmd-text, black)"
48
+ },
49
+ "> .external-link-icon": {
50
+ display: "flex",
51
+ columnGap: "0.25em",
52
+ position: "absolute",
53
+ right: "-0.25em",
54
+ top: "-0.25em",
55
+ width: "0.75em",
56
+ height: "0.75em",
57
+ background: "var(--tmd-accent, #5b5bff)",
58
+ color: "var(--tmd-text, white)",
59
+ padding: "0.1em",
60
+ borderRadius: "50%"
61
+ },
62
+ ":hover > .external-link-icon": {
63
+ minWidth: "fit-content",
64
+ padding: "0.1em 0.25em",
65
+ borderRadius: "0.5em",
66
+ bottom: "calc(100% + 0.25em)",
67
+ top: "unset"
68
+ },
69
+ "> .external-link-icon > span": {
70
+ display: "none",
71
+ fontSize: "0.5em",
72
+ whiteSpace: "nowrap"
73
+ },
74
+ ":hover > .external-link-icon > span": {
75
+ display: "inline"
56
76
  }
57
77
  };
58
78
  }
59
79
  generateBody() {
60
- const { text, fontSize, width, height, padding, style, icon, iconAbsolutePosition = true, tooltip, onClick, isDisabled } = this.context;
80
+ const { text, variant, icon, iconAbsolutePosition = true, tooltip, href, onClick, isDisabled } = this.context;
61
81
  let iconElement;
62
82
  let textElement;
63
83
  const btn = document.createElement("button");
64
84
  addDynamicClass(btn, this.dynamicClassButton);
65
- btn.setAttribute("data-zc-style", style);
85
+ btn.setAttribute("data-zc-variant", variant);
66
86
  btn.style.display = "flex";
67
87
  btn.style.alignItems = "center";
68
88
  btn.style.justifyContent = "center";
@@ -96,10 +116,22 @@ class ButtonShard extends Shard {
96
116
  tooltipEl.textContent = tooltip.text;
97
117
  btn.append(tooltipEl);
98
118
  }
119
+ if (href) {
120
+ const externalLinkContainer = document.createElement("div");
121
+ externalLinkContainer.classList.add("external-link-icon");
122
+ const externalLinkIcon = createElement(ExternalLink);
123
+ externalLinkIcon.style.width = "auto";
124
+ externalLinkIcon.style.height = "100%";
125
+ const externalLinkLabel = document.createElement("span");
126
+ externalLinkLabel.textContent = href;
127
+ externalLinkContainer.append(externalLinkIcon, externalLinkLabel);
128
+ btn.append(externalLinkContainer);
129
+ }
99
130
  if (typeof isDisabled === "function" && isDisabled()) btn.classList.add("zcDisabled");
100
131
  btn.addEventListener("click", () => {
101
132
  if (typeof isDisabled === "function" && isDisabled()) return btn.classList.add("zcDisabled");
102
133
  if (typeof onClick === "function") onClick();
134
+ if (href) window.open(href, "_blank", "noopener,noreferrer");
103
135
  });
104
136
  return {
105
137
  text: textElement,
@@ -1,4 +1,4 @@
1
- import { setSize } from "../ui";
1
+ import { recolorSVG, setSize } from "../ui";
2
2
  import { Shard } from "./shard";
3
3
  class SvgShard extends Shard {
4
4
  generateBody() {
@@ -10,24 +10,6 @@ class SvgShard extends Shard {
10
10
  div.innerHTML = svgString;
11
11
  return div.firstElementChild;
12
12
  }
13
- function recolorSVG(svgElement, { fill: fill2, stroke: stroke2 }) {
14
- const elements = svgElement.querySelectorAll("*");
15
- elements.forEach((element) => {
16
- if (element.getAttribute("fill") !== "none") {
17
- element.setAttribute("fill", fill2);
18
- }
19
- if (element.getAttribute("stroke") !== "none") {
20
- element.setAttribute("stroke", stroke2);
21
- }
22
- });
23
- if (svgElement.getAttribute("fill") !== "none") {
24
- svgElement.setAttribute("fill", fill2);
25
- }
26
- if (svgElement.getAttribute("stroke") !== "none") {
27
- svgElement.setAttribute("stroke", stroke2);
28
- }
29
- return svgElement;
30
- }
31
13
  const svg = dataURLToSVGElement(dataurl);
32
14
  if (svg) {
33
15
  recolorSVG(svg, { fill, stroke });
package/dist/toasts.js CHANGED
@@ -105,9 +105,10 @@ function createToast({ title, message, type, duration, theme, id }) {
105
105
  _message.textContent = message;
106
106
  textContainer.append(_message);
107
107
  toast.append(getToastIcon(type, theme), textContainer);
108
- update();
109
108
  window.addEventListener("resize", update);
110
109
  toastContainer.append(toast);
110
+ update();
111
+ void toast.offsetHeight;
111
112
  setTimeout(() => {
112
113
  toast.style.animation = `${pos.includes("left") ? "zcSlideOutToLeft" : "zcSlideOutToRight"} 0.3s ease-out forwards`;
113
114
  }, duration);
@@ -1 +1 @@
1
- export declare function showChangelogModal(): Promise<void>;
1
+ export declare function showChangelogModal(): void;
@@ -0,0 +1,6 @@
1
+ interface Window {
2
+ ZOIS_CORE: {
3
+ enableDevMode: () => void
4
+ getSettings: () => import("../core").CoreSettings
5
+ }
6
+ }
@@ -26,14 +26,21 @@ export interface ModData {
26
26
  };
27
27
  changelog?: {
28
28
  data: {
29
- hash: string;
30
- author: string;
31
- message: string;
32
- date: string;
33
- }[];
34
- repo: string;
35
- owner: string;
29
+ generated_at: string;
30
+ changes: {
31
+ message: string;
32
+ sha: string;
33
+ author: {
34
+ name: string;
35
+ avatar_url: string;
36
+ };
37
+ date: string;
38
+ tags: ("feature" | "chore" | "fix")[];
39
+ commit_url: string;
40
+ }[];
41
+ };
36
42
  };
43
+ onReady?: () => void;
37
44
  }
38
45
  interface ThemedColorsModule {
39
46
  base: {
@@ -103,6 +110,5 @@ export declare function getPlayer(value: string | number): Character | null;
103
110
  export declare function getNickname(target: Character): string;
104
111
  export declare function getThemedColorsModule(): ThemedColorsModule | null;
105
112
  export declare function injectStyles(stylesToInject: string): void;
106
- export declare function waitForStart(callback: () => void): void;
107
113
  export declare function normalizeObject<T>(obj: T[]): T[];
108
114
  export declare function normalizeObject<T extends object>(obj: T): T;
@@ -3,13 +3,14 @@ import { Shard, ShardContext } from "./shard";
3
3
  export interface ButtonShardContext extends ShardContext<"icon" | "text"> {
4
4
  text?: string;
5
5
  fontSize?: number | "auto";
6
- style?: "default" | "green" | "inverted";
6
+ variant?: "outlined" | "filled";
7
7
  icon?: string | SVGElement;
8
8
  iconAbsolutePosition?: boolean;
9
9
  tooltip?: {
10
10
  text: string;
11
11
  position: "left" | "right";
12
12
  };
13
+ href?: string;
13
14
  onClick?: () => void;
14
15
  isDisabled?: () => boolean;
15
16
  }
@@ -22,7 +22,14 @@ export interface DynamicClassStyles {
22
22
  [key: string]: Partial<CSSStyleDeclaration> | undefined;
23
23
  }
24
24
  export declare function hexToRgb(hex: string): string;
25
- export declare function dataUrlSvgWithColor(dataUrl: string, newColor: string): string;
25
+ export declare function recolorSVG(svgElement: SVGElement, { fill, stroke }: {
26
+ fill: string;
27
+ stroke: string;
28
+ }): SVGElement;
29
+ export declare function dataUrlSvgWithColor(dataUrl: string, newColor: {
30
+ fill?: string;
31
+ stroke?: string;
32
+ }): string;
26
33
  export declare function dataUrlSvgReplaceVars(dataUrl: string, vars: Record<string, string>): string;
27
34
  export declare function cssVar(name: string, fallback: string): string;
28
35
  export declare function getRelativeHeight(height: number): number;
package/dist/ui.js CHANGED
@@ -3,6 +3,7 @@ import { StyleModule } from "./shard-modules";
3
3
  import { MOD_DATA } from "./index";
4
4
  import { ButtonShard, TextShard, InputShard, CheckboxShard, InputListShard, ImageShard, SvgShard, BackNextButtonShard, TabsShard, CardShard, SelectShard, ContainerShard } from "./shards";
5
5
  import { logger } from "./logging";
6
+ import exitIcon from "./assets/icons/exit.svg";
6
7
  function hexToRgb(hex) {
7
8
  hex = hex.replace("#", "");
8
9
  const r = parseInt(hex.substring(0, 2), 16);
@@ -10,8 +11,30 @@ function hexToRgb(hex) {
10
11
  const b = parseInt(hex.substring(4, 6), 16);
11
12
  return `rgb(${r}, ${g}, ${b})`;
12
13
  }
14
+ function recolorSVG(svgElement, { fill, stroke }) {
15
+ const elements = svgElement.querySelectorAll("*");
16
+ elements.forEach((element) => {
17
+ if (element.getAttribute("fill") !== "none") {
18
+ element.setAttribute("fill", fill);
19
+ }
20
+ if (element.getAttribute("stroke") !== "none") {
21
+ element.setAttribute("stroke", stroke);
22
+ }
23
+ });
24
+ if (svgElement.getAttribute("fill") !== "none") {
25
+ svgElement.setAttribute("fill", fill);
26
+ }
27
+ if (svgElement.getAttribute("stroke") !== "none") {
28
+ svgElement.setAttribute("stroke", stroke);
29
+ }
30
+ return svgElement;
31
+ }
13
32
  function dataUrlSvgWithColor(dataUrl, newColor) {
14
- return dataUrl.replace(/fill="[^"]*"/g, `fill="${newColor}"`).replace(/stroke="[^"]*"/g, `stroke="${newColor}"`);
33
+ if (newColor.fill?.startsWith("#")) newColor.fill = hexToRgb(newColor.fill);
34
+ if (newColor.stroke?.startsWith("#")) newColor.stroke = hexToRgb(newColor.stroke);
35
+ if (newColor.fill) dataUrl = dataUrl.replace(/fill="[^"]*"/g, `fill="${newColor.fill}"`);
36
+ if (newColor.stroke) dataUrl = dataUrl.replace(/stroke="[^"]*"/g, `stroke="${newColor.stroke}"`);
37
+ return dataUrl;
15
38
  }
16
39
  function dataUrlSvgReplaceVars(dataUrl, vars) {
17
40
  for (let [name, value] of Object.entries(vars)) {
@@ -156,7 +179,7 @@ function setSubscreen(subscreen) {
156
179
  try {
157
180
  previousSubscreen.unload();
158
181
  } catch (e) {
159
- logger.error("Failed to unload subscreen", previousSubscreen);
182
+ logger.error("Failed to unload subscreen", previousSubscreen, e);
160
183
  }
161
184
  window.dispatchEvent(new SubscreenUnloadedEvent({ subscreen: previousSubscreen }));
162
185
  }
@@ -164,7 +187,7 @@ function setSubscreen(subscreen) {
164
187
  try {
165
188
  subscreen.load();
166
189
  } catch (e) {
167
- logger.error("Failed to load subscreen", subscreen);
190
+ logger.error("Failed to load subscreen", subscreen, e);
168
191
  }
169
192
  window.dispatchEvent(new SubscreenLoadedEvent({ subscreen }));
170
193
  }
@@ -191,7 +214,7 @@ class BaseSubscreen {
191
214
  y: 75,
192
215
  width: 90,
193
216
  height: 90,
194
- icon: "Icons/Exit.png",
217
+ icon: dataUrlSvgWithColor(exitIcon, { fill: cssVar("--tmd-text", "black") }),
195
218
  tooltip: {
196
219
  position: "left",
197
220
  text: "Back"
@@ -341,6 +364,7 @@ export {
341
364
  getRelativeY,
342
365
  hexToRgb,
343
366
  hookSubscreen,
367
+ recolorSVG,
344
368
  setFontFamily,
345
369
  setFontSize,
346
370
  setPadding,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "zois-core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "The core for the my mods, which contains a shared code reused in all my mods",
5
5
  "bin": {
6
- "generate-changelog": "scripts/generateChangelog.mjs"
6
+ "zois-core": "scripts/zois-core.mjs"
7
7
  },
8
8
  "author": "Zoi",
9
9
  "license": "MIT",
@@ -69,7 +69,9 @@
69
69
  }
70
70
  },
71
71
  "dependencies": {
72
+ "@octokit/rest": "^22.0.1",
72
73
  "bondage-club-mod-sdk": "^1.2.0",
74
+ "chalk": "^5.6.2",
73
75
  "class-transformer": "^0.5.1",
74
76
  "class-validator": "^0.14.4",
75
77
  "lucide": "^1.24.0",
@@ -78,8 +80,9 @@
78
80
  "devDependencies": {
79
81
  "bc-stubs": "130.0.0-Beta.1",
80
82
  "esbuild": "^0.28.1",
83
+ "esbuild-plugin-copy": "^2.1.1",
84
+ "glob": "^13.0.6",
81
85
  "nodemon": "^3.1.14",
82
- "simple-git": "^3.36.0",
83
86
  "typescript": "^5.9.3"
84
87
  },
85
88
  "scripts": {
@@ -0,0 +1,126 @@
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+ import chalk from 'chalk';
4
+ import { Octokit } from "@octokit/rest";
5
+
6
+ const octokit = new Octokit();
7
+ const args = process.argv.slice(2);
8
+ const command = args[0];
9
+
10
+ function getArg(name) {
11
+ const arg = args.find((a) => a.startsWith("--" + name));
12
+ if (arg) return arg.slice(name.length + 3);
13
+ return null;
14
+ }
15
+
16
+ switch (command) {
17
+ case "generate-changelog": {
18
+ generateChangelog().catch((err) => {
19
+ console.log(chalk.red("Script failed:"), err.message);
20
+ process.exit(1);
21
+ });
22
+ break;
23
+ }
24
+ default: {
25
+ console.log(chalk.red("Unknown command"), `"${chalk.cyan(command)}"`);
26
+ console.log("Available commands:")
27
+ console.log(`• ${chalk.cyan("generate-changelog")} — Generate changelog bundle`)
28
+ }
29
+ }
30
+
31
+ async function getCommitsSince(owner, repo, sinceSha, perPage = 50) {
32
+ const commits = [];
33
+ let page = 1;
34
+ let hasMore = true;
35
+
36
+ try {
37
+ while (hasMore) {
38
+ const { data } = await octokit.rest.repos.listCommits({
39
+ owner,
40
+ repo,
41
+ sha: "HEAD",
42
+ per_page: perPage,
43
+ page: page,
44
+ });
45
+
46
+ if (data.length === 0) break;
47
+
48
+ const startIndex = data.findIndex((commit) => commit.sha === sinceSha);
49
+
50
+ if (startIndex !== -1) {
51
+ commits.push(...data.slice(0, startIndex + 1));
52
+ break;
53
+ } else {
54
+ commits.push(...data);
55
+ }
56
+
57
+ page++;
58
+ hasMore = data.length === perPage;
59
+ }
60
+
61
+ return commits.map((commit) => ({
62
+ sha: commit.sha,
63
+ message: commit.commit.message,
64
+ date: commit.commit.author.date,
65
+ author: {
66
+ name: commit.author?.login || commit.commit.author.name,
67
+ avatar_url: commit.author?.avatar_url,
68
+ html_url: commit.author?.html_url,
69
+ },
70
+ committer: {
71
+ name: commit.committer?.login || commit.commit.committer.name,
72
+ avatar_url: commit.committer?.avatar_url,
73
+ }
74
+ }));
75
+
76
+ } catch (error) {
77
+ console.log(chalk.red("Error getting commits:"), error.message);
78
+ throw error;
79
+ }
80
+ }
81
+
82
+ async function generateChangelog() {
83
+ const owner = getArg("owner");
84
+ if (!owner) {
85
+ console.log(chalk.red("--owner argument not specified"));
86
+ process.exit(1);
87
+ }
88
+ const repo = getArg("repo");
89
+ if (!repo) {
90
+ console.log(chalk.red("--repo argument not specified"));
91
+ process.exit(1);
92
+ }
93
+ const fromCommit = getArg("from");
94
+ if (!fromCommit) {
95
+ console.log(chalk.red("--from argument not specified"));
96
+ process.exit(1);
97
+ }
98
+ console.log(`Generating changelog from commit ${chalk.cyan(fromCommit)}...`);
99
+
100
+ const commits = await getCommitsSince(owner, repo, fromCommit);
101
+
102
+ const resultToWrite = {
103
+ generated_at: (new Date()).toISOString(),
104
+ changes: commits.map((c) => ({
105
+ message: c.message,
106
+ sha: c.sha,
107
+ author: {
108
+ name: c.author.name,
109
+ avatar_url: c.author.avatar_url ?? "https://avatars.githubusercontent.com/" + c.author.name,
110
+ },
111
+ date: c.date,
112
+ tags: [],
113
+ commit_url: `https://github.com/${owner}/${repo}/commit/${c.sha}`
114
+ }))
115
+ };
116
+
117
+ const outputPath = path.join(process.cwd(), "changelog.json");
118
+
119
+ await fs.writeFile(
120
+ outputPath,
121
+ JSON.stringify(resultToWrite, null, 2),
122
+ "utf-8"
123
+ );
124
+
125
+ console.log(`Generated changelog.json. (${commits.length} commits)`);
126
+ }
@@ -1,80 +0,0 @@
1
- import simpleGit from "simple-git";
2
- import fs from "fs/promises";
3
- import path from "path";
4
-
5
- const git = simpleGit({ baseDir: process.cwd() });
6
-
7
- async function getUnpushedCommits() {
8
- try {
9
- const branchSummary = await git.branch();
10
- const currentBranch = branchSummary.current;
11
-
12
- const remoteBranch = `origin/${currentBranch}`;
13
-
14
- try {
15
- const log = await git.log([`${remoteBranch}..HEAD`]);
16
- return log.all;
17
- } catch (err) {
18
- console.warn("No remote tracking branch found, returning all commits.");
19
- const log = await git.log();
20
- return log.all;
21
- }
22
- } catch (error) {
23
- console.error("Error getting unpushed commits:", error.message);
24
- return [];
25
- }
26
- }
27
-
28
- async function getCommitsFromHash(hash) {
29
- try {
30
- const log = await git.log({
31
- from: hash,
32
- to: "HEAD"
33
- });
34
- return log.all;
35
- } catch (error) {
36
- console.error(`Error getting commits from hash ${hash}:`, error.message);
37
- return [];
38
- }
39
- }
40
-
41
- async function generateChangelog() {
42
- const args = process.argv.slice(2);
43
- let commits = [];
44
-
45
- if (args.length > 0 && args[0].startsWith("--from=")) {
46
- const hash = args[0].split("=")[1];
47
- if (hash) {
48
- console.log(`Generating changelog from commit ${hash}...`);
49
- commits = await getCommitsFromHash(hash);
50
- } else {
51
- console.error("Invalid --from= hash provided.");
52
- process.exit(1);
53
- }
54
- } else {
55
- console.log("Generating changelog for unpushed commits...");
56
- commits = await getUnpushedCommits();
57
- }
58
-
59
- const changelog = commits.map((commit) => ({
60
- hash: commit.hash,
61
- author: commit.author_name || commit.author || "Unknown",
62
- message: commit.message || commit.body || "",
63
- date: commit.date
64
- }));
65
-
66
- const outputPath = path.join(process.cwd(), "changelog.json");
67
-
68
- await fs.writeFile(
69
- outputPath,
70
- JSON.stringify(changelog, null, 2),
71
- "utf-8"
72
- );
73
-
74
- console.log(`Generated changelog.json. (${changelog.length} commits)`);
75
- }
76
-
77
- generateChangelog().catch((err) => {
78
- console.error("❌ Script failed:", err.message);
79
- process.exit(1);
80
- });