@overmvp/kumi 0.1.0 → 0.4.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/README.md +59 -6
- package/animation/index.ts +4 -0
- package/animation/motion-policy.ts +20 -0
- package/animation/slide.ts +61 -0
- package/animation/spring.ts +75 -0
- package/animation/staggered-reveal.ts +34 -0
- package/builder/css-gradients.mjs +74 -0
- package/builder/css-mask-assets.mjs +52 -0
- package/builder/css-mask-assets.test.mjs +31 -0
- package/builder/css-v1.mjs +127 -23
- package/builder/css-v1.test.mjs +82 -2
- package/builder/link-addon-package.mjs +47 -6
- package/builder/module-declarations.test.mjs +9 -18
- package/builder/native-kernels.mjs +1 -1
- package/builder/src/compiler.rs +205 -8
- package/builder/src/lua_upvalues.rs +641 -0
- package/builder/src/main.rs +20 -5
- package/builder/src/native_ir.rs +1 -1
- package/builder/src/native_signal.rs +46 -10
- package/builder/src/numbers.lua +14 -0
- package/builder/src/project-front.mjs +385 -34
- package/builder/src/routes.rs +11 -14
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -1
- package/builder/src/ts-lower.mjs +2 -2
- package/builder/src/wow-reads.lua +22 -0
- package/builder/style-modules.mjs +111 -0
- package/builder/style-modules.test.mjs +24 -0
- package/builder/style-states.mjs +6 -4
- package/config.ts +56 -14
- package/eslint.mjs +74 -0
- package/form/index.ts +15 -11
- package/package.json +11 -7
- package/router/index.ts +10 -2
- package/router/link.tsx +32 -0
- package/router/navigation.ts +22 -0
- package/router/router-view.ts +134 -0
- package/scripts/addon-build.mjs +377 -0
- package/scripts/addon-project.mjs +89 -0
- package/scripts/kumi-cli.mjs +52 -17
- package/scripts/link-addons.mjs +12 -2
- package/src/bindings.ts +12 -6
- package/src/context.ts +31 -7
- package/src/css-tokens.ts +27 -13
- package/src/css-v1.ts +13 -0
- package/src/elements.ts +35 -0
- package/src/flex-layout.ts +26 -5
- package/src/frame-scheduler.ts +6 -2
- package/src/index.ts +2 -1
- package/src/jsx-runtime.ts +8 -1
- package/src/keyed-list.ts +17 -11
- package/src/module-ui.ts +163 -0
- package/src/module.ts +51 -8
- package/src/owned-collections.ts +8 -0
- package/src/providers.ts +7 -1
- package/src/reactive-scope.ts +3 -3
- package/src/reactivity.ts +42 -8
- package/src/result.ts +6 -0
- package/src/signal-kernel.ts +35 -2
- package/src/style-classes.ts +22 -1
- package/src/style-states.ts +13 -6
- package/state/index.ts +6 -0
- package/state/setup-store-persistence.ts +206 -0
- package/state/setup-store-view.ts +10 -0
- package/state/setup-store.ts +342 -0
- package/state/store.ts +2 -0
- package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/AGENTS.md +34 -0
- package/templates/addon/Assets/Art/Corner10.tga +0 -0
- package/templates/addon/Assets/Art/Corner11.tga +0 -0
- package/templates/addon/Assets/Art/Corner12.tga +0 -0
- package/templates/addon/Assets/Art/Corner13.tga +0 -0
- package/templates/addon/Assets/Art/Corner14.tga +0 -0
- package/templates/addon/Assets/Art/Corner15.tga +0 -0
- package/templates/addon/Assets/Art/Corner16.tga +0 -0
- package/templates/addon/Assets/Art/Corner2.tga +0 -0
- package/templates/addon/Assets/Art/Corner3.tga +0 -0
- package/templates/addon/Assets/Art/Corner4.tga +0 -0
- package/templates/addon/Assets/Art/Corner5.tga +0 -0
- package/templates/addon/Assets/Art/Corner6.tga +0 -0
- package/templates/addon/Assets/Art/Corner7.tga +0 -0
- package/templates/addon/Assets/Art/Corner8.tga +0 -0
- package/templates/addon/Assets/Art/Corner9.tga +0 -0
- package/templates/addon/Assets/Art/Dot.tga +0 -0
- package/templates/addon/Assets/Art/Gear.tga +0 -0
- package/templates/addon/Assets/Art/Grip.tga +0 -0
- package/templates/addon/Assets/Art/Outline10.tga +0 -0
- package/templates/addon/Assets/Art/Outline12.tga +0 -0
- package/templates/addon/Assets/Art/Outline13.tga +0 -0
- package/templates/addon/Assets/Art/Outline14.tga +0 -0
- package/templates/addon/Assets/Art/Outline15.tga +0 -0
- package/templates/addon/Assets/Art/Outline2.tga +0 -0
- package/templates/addon/Assets/Art/Outline3.tga +0 -0
- package/templates/addon/Assets/Art/Outline5.tga +0 -0
- package/templates/addon/Assets/Art/Outline7.tga +0 -0
- package/templates/addon/Assets/Art/Outline9.tga +0 -0
- package/templates/addon/Assets/Art/Round11.tga +0 -0
- package/templates/addon/Assets/Art/Round11Border.tga +0 -0
- package/templates/addon/Assets/Art/Round4.tga +0 -0
- package/templates/addon/Assets/Art/Round4Border.tga +0 -0
- package/templates/addon/Assets/Art/Round6.tga +0 -0
- package/templates/addon/Assets/Art/Round6Border.tga +0 -0
- package/templates/addon/Assets/Art/Round8.tga +0 -0
- package/templates/addon/Assets/Art/Round8Border.tga +0 -0
- package/templates/addon/Assets/Art/Search.tga +0 -0
- package/templates/addon/CLAUDE.md +1 -0
- package/templates/addon/README.md +42 -7
- package/templates/addon/eslint.config.mjs +3 -9
- package/templates/addon/gitignore +1 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +4 -5
- package/templates/addon/src/app/app.module.ts +18 -0
- package/templates/addon/src/app/commands.store.ts +11 -0
- package/templates/addon/src/app/layout/AppWindow.module.css +90 -0
- package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
- package/templates/addon/src/app/main.ts +5 -0
- package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
- package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
- package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
- package/templates/addon/src/app/theme.ts +6 -0
- package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
- package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
- package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
- package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
- package/templates/addon/src/modules/greeting/ui/Greeting.module.css +103 -0
- package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
- package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
- package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
- package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
- package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
- package/templates/addon/src/modules/playtime/ui/Playtime.module.css +23 -0
- package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
- package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
- package/templates/addon/src/shared/api/native-art.ts +28 -0
- package/templates/addon/src/shared/assets/close.png +0 -0
- package/templates/addon/src/shared/lib/format.ts +20 -0
- package/templates/addon/src/shared/styles/tokens.css +13 -0
- package/templates/addon/src/shared/ui/Button.tsx +29 -0
- package/templates/addon/src/shared/ui/Choice.tsx +34 -0
- package/templates/addon/src/shared/ui/Controls.module.css +91 -0
- package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
- package/templates/addon/src/shared/ui/Slider.tsx +25 -0
- package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
- package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
- package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
- package/templates/addon/tsconfig.json +49 -10
- package/wow/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +244 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +38 -0
- package/wow/animation.ts +3 -14
- package/wow/app-ui.ts +230 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-background-image.ts +75 -0
- package/wow/css-box.ts +46 -10
- package/wow/css-image-mask.ts +32 -0
- package/wow/css-surfaces.ts +295 -43
- package/wow/cursor.ts +45 -0
- package/wow/element-events.ts +33 -13
- package/wow/frame-access.ts +23 -1
- package/wow/frame-timing.ts +13 -0
- package/wow/heal-prediction.ts +2 -4
- package/wow/hooks.ts +133 -0
- package/wow/index.ts +19 -4
- package/wow/layout-view.ts +44 -23
- package/wow/locale-font.ts +15 -0
- package/wow/module-replacements.ts +103 -0
- package/wow/native.ts +18 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/pointer-click.ts +35 -0
- package/wow/protect.ts +27 -3
- package/wow/protected-view.ts +139 -0
- package/wow/range-art.ts +7 -0
- package/wow/readable-api.ts +120 -0
- package/wow/rounded-texture.ts +38 -6
- package/wow/saved-variables.ts +67 -18
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +31 -8
- package/wow/state-paint.ts +5 -14
- package/wow/texture-fill.ts +10 -0
- package/wow/unit-cast.ts +6 -4
- package/wow/view.ts +458 -228
- package/templates/addon/__ADDON_NAME__.toc +0 -4
- package/templates/addon/scripts/build.mjs +0 -25
- package/templates/addon/src/app/main.tsx +0 -13
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { createContext } from "../src/context";
|
|
2
|
+
import { createElement, type UIElement } from "../src/elements";
|
|
3
|
+
import { jsxMap } from "../src/keyed-list";
|
|
4
|
+
import type { ModulePage } from "../src/module-ui";
|
|
5
|
+
import { ownedArray, type OwnedArray, type OwnedReadonlyArray } from "../src/owned-collections";
|
|
6
|
+
import { computed, currentScope, withReactiveScope } from "../src/reactive-scope";
|
|
7
|
+
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
8
|
+
import { fail, formatFailure, ok, type Protect, type Result } from "../src/result";
|
|
9
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
10
|
+
import type { ClassNames } from "../src/style-classes";
|
|
11
|
+
import { withNavigation, type Navigation } from "./navigation";
|
|
12
|
+
|
|
13
|
+
/** A page the window can show: a file route or a page a module added. */
|
|
14
|
+
export interface RoutePage {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
readonly title: string;
|
|
17
|
+
readonly order: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** What `<RouterView>` needs from its window. */
|
|
21
|
+
export interface RouterHost {
|
|
22
|
+
readonly navigation: Navigation<string>;
|
|
23
|
+
/** Render a file route, or return undefined when the path is not a file route. */
|
|
24
|
+
render(this: void, path: string): UIElement | undefined;
|
|
25
|
+
readonly modulePages: ReadonlyRef<readonly ModulePage[]>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Activation = (this: void, scope: RuntimeScope) => void;
|
|
29
|
+
|
|
30
|
+
interface PageSetup {
|
|
31
|
+
readonly activations: OwnedArray<Activation>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const hostContext = createContext<RouterHost>();
|
|
35
|
+
const pageContext = createContext<PageSetup>();
|
|
36
|
+
|
|
37
|
+
/** @internal Render the window layout with its router. */
|
|
38
|
+
export function withRouterHost<View>(this: void, host: RouterHost, render: (this: void) => View, protect: Protect) {
|
|
39
|
+
return withNavigation(host.navigation, () => {
|
|
40
|
+
const result = hostContext.run(host, render, protect);
|
|
41
|
+
if (!result.ok) throw new Error(formatFailure(result));
|
|
42
|
+
return result.value;
|
|
43
|
+
}, protect);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Run code each time the page becomes the active page. The scope closes when the user leaves the page,
|
|
48
|
+
* so subscriptions and timers made inside stop on their own. Call it during the page's setup.
|
|
49
|
+
*/
|
|
50
|
+
export function onActivated(this: void, run: Activation): void {
|
|
51
|
+
const page = pageContext.use();
|
|
52
|
+
if (page === undefined) throw new Error("onActivated works only during the setup of a page shown by <RouterView>");
|
|
53
|
+
page.activations.push(run);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Run code when the user leaves the page. Call it during the page's setup. */
|
|
57
|
+
export function onDeactivated(this: void, run: (this: void) => void): void {
|
|
58
|
+
onActivated(scope => { scope.onDispose(run); });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface Visit {
|
|
62
|
+
readonly path: string;
|
|
63
|
+
readonly scope: RuntimeScope;
|
|
64
|
+
readonly activations: OwnedArray<Activation>;
|
|
65
|
+
readonly content?: UIElement;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Show the window's active page. Visited pages stay mounted and hidden, so their state and controls
|
|
70
|
+
* survive switching pages. Pass `className` to style the box around each page.
|
|
71
|
+
*/
|
|
72
|
+
export function RouterView(this: void, props: { readonly className?: ClassNames }): UIElement {
|
|
73
|
+
const host = hostContext.use();
|
|
74
|
+
const owner = currentScope();
|
|
75
|
+
if (host === undefined || owner === undefined) throw new Error("<RouterView> works inside the addon window's layout");
|
|
76
|
+
const visits = ref<readonly Visit[]>([]);
|
|
77
|
+
let activity: RuntimeScope | undefined;
|
|
78
|
+
let active: Visit | undefined;
|
|
79
|
+
|
|
80
|
+
function renderPage(path: string): Result<UIElement> {
|
|
81
|
+
const page = host!.render(path);
|
|
82
|
+
if (page !== undefined) return ok(page);
|
|
83
|
+
for (const added of host!.modulePages.value as OwnedReadonlyArray<ModulePage>) {
|
|
84
|
+
if (added.path === path) return ok(createElement(added.component, {}));
|
|
85
|
+
}
|
|
86
|
+
return fail("No page at " + path);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function visit(path: string): Visit | undefined {
|
|
90
|
+
for (const existing of visits.value as OwnedReadonlyArray<Visit>) if (existing.path === path) return existing;
|
|
91
|
+
const scope = owner!.fork();
|
|
92
|
+
const activations = ownedArray<Activation>();
|
|
93
|
+
const rendered = withNavigation(host!.navigation, () => withReactiveScope(scope, () => {
|
|
94
|
+
const result = pageContext.run({ activations }, () => renderPage(path), scope.protect);
|
|
95
|
+
return result.ok ? result.value : result;
|
|
96
|
+
}), scope.protect);
|
|
97
|
+
const flat = rendered.ok ? rendered.value : rendered;
|
|
98
|
+
const content = flat.ok ? flat.value : flat;
|
|
99
|
+
if (!content.ok) {
|
|
100
|
+
scope.dispose();
|
|
101
|
+
throw new Error(content.reason);
|
|
102
|
+
}
|
|
103
|
+
const created: Visit = { path, scope, activations, content: content.value };
|
|
104
|
+
const next = ownedArray<Visit>();
|
|
105
|
+
for (const existing of visits.value as OwnedReadonlyArray<Visit>) next.push(existing);
|
|
106
|
+
next.push(created);
|
|
107
|
+
visits.value = next;
|
|
108
|
+
return created;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function activate(path: string | undefined) {
|
|
112
|
+
if (active?.path === path) return;
|
|
113
|
+
const previous = activity;
|
|
114
|
+
activity = undefined;
|
|
115
|
+
active = undefined;
|
|
116
|
+
previous?.dispose();
|
|
117
|
+
if (path === undefined) return;
|
|
118
|
+
const next = visit(path);
|
|
119
|
+
if (next === undefined) return;
|
|
120
|
+
active = next;
|
|
121
|
+
const scope = next.scope.fork();
|
|
122
|
+
activity = scope;
|
|
123
|
+
for (const run of next.activations) run(scope);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const watched = owner.watch(() => host.navigation.path.value, path => { activate(path); }, true);
|
|
127
|
+
if (!watched.ok) throw new Error(watched.reason);
|
|
128
|
+
owner.onDispose(() => { activity?.dispose(); });
|
|
129
|
+
|
|
130
|
+
return jsxMap(() => visits.value, entry => entry.path, entry => createElement("div", {
|
|
131
|
+
className: props.className,
|
|
132
|
+
shown: computed(() => host.navigation.path.value === entry.path),
|
|
133
|
+
}, entry.content));
|
|
134
|
+
}
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
// Build a Kumi addon and its plugins from kumi.config.ts.
|
|
2
|
+
import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { linkAddonPackage } from "../builder/link-addon-package.mjs";
|
|
7
|
+
import { writeGeneratedText } from "../builder/generated-output.mjs";
|
|
8
|
+
|
|
9
|
+
const sdkPackage = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).name;
|
|
10
|
+
const ADDON_NAME = /^[A-Za-z][A-Za-z0-9_-]{0,62}$/u;
|
|
11
|
+
const PLUGIN_ID = /^[a-z][a-z0-9-]{0,30}$/u;
|
|
12
|
+
const GLOBAL_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
13
|
+
const DEFAULT_INTERFACE = { retail: 120105, forever: 16001 };
|
|
14
|
+
const MANIFEST = "KumiAddon.lua";
|
|
15
|
+
const SHARED = "KumiShared.lua";
|
|
16
|
+
const LINK_STAMP = "kumi-cli-link";
|
|
17
|
+
const quote = JSON.stringify;
|
|
18
|
+
const luaString = text => '"' + text.replace(/["\\\x00-\x1f\x7f]/gu, char =>
|
|
19
|
+
char === '"' || char === "\\" ? "\\" + char : "\\" + String(char.charCodeAt(0)).padStart(3, "0")) + '"';
|
|
20
|
+
|
|
21
|
+
function inside(base, path) {
|
|
22
|
+
const child = relative(base, path);
|
|
23
|
+
return child !== "" && !isAbsolute(child) && child !== ".." && !child.startsWith("../") && !child.startsWith("..\\");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function problem(message) {
|
|
27
|
+
return new Error("kumi.config.ts: " + message);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function text(value, field, required = false) {
|
|
31
|
+
if (value === undefined && !required) return undefined;
|
|
32
|
+
if (typeof value !== "string" || value.trim() === "" || /[\r\n]/u.test(value)) throw problem(field + " must be one line of text");
|
|
33
|
+
return value.trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function interfaces(value, field) {
|
|
37
|
+
const list = Array.isArray(value) ? value : [value];
|
|
38
|
+
if (!list.length || !list.every(number => Number.isSafeInteger(number) && number > 0)) {
|
|
39
|
+
throw problem(field + " must be a positive interface number or a list of them");
|
|
40
|
+
}
|
|
41
|
+
return list.join(", ");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Find the exported @Module classes of a plugin file without running it.
|
|
45
|
+
function moduleExports(workspace, file) {
|
|
46
|
+
const ts = createRequire(join(workspace, "package.json"))("typescript");
|
|
47
|
+
const source = ts.createSourceFile(file, readFileSync(file, "utf8"), ts.ScriptTarget.ES2020, true);
|
|
48
|
+
const names = [];
|
|
49
|
+
for (const statement of source.statements) {
|
|
50
|
+
if (!ts.isClassDeclaration(statement) || !statement.name) continue;
|
|
51
|
+
const exported = ts.getModifiers(statement)?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
52
|
+
const decorated = ts.getDecorators(statement)?.some(decorator => {
|
|
53
|
+
const call = decorator.expression;
|
|
54
|
+
return ts.isCallExpression(call) && ts.isIdentifier(call.expression) && call.expression.text === "Module";
|
|
55
|
+
});
|
|
56
|
+
if (exported && decorated) names.push(statement.name.text);
|
|
57
|
+
}
|
|
58
|
+
return names;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Read and validate kumi.config.ts. */
|
|
62
|
+
export async function readProject(workspace) {
|
|
63
|
+
const path = join(workspace, "kumi.config.ts");
|
|
64
|
+
if (!existsSync(path)) throw new Error("Add kumi.config.ts to the project root. Run kumi init to see an example.");
|
|
65
|
+
const { default: config } = await import(pathToFileURL(path).href + "?t=" + Date.now());
|
|
66
|
+
if (config === null || typeof config !== "object") throw problem("export the config object as default");
|
|
67
|
+
const addon = config.addon;
|
|
68
|
+
if (addon === null || typeof addon !== "object") throw problem("add an addon section");
|
|
69
|
+
const name = text(addon.name, "addon.name", true);
|
|
70
|
+
if (!ADDON_NAME.test(name)) throw problem("addon.name must start with a letter and use letters, digits, _ or -");
|
|
71
|
+
for (const field of ["savedVariables", "savedVariablesPerCharacter"]) {
|
|
72
|
+
if (addon[field] !== undefined && (typeof addon[field] !== "string" || !GLOBAL_NAME.test(addon[field]))) {
|
|
73
|
+
throw problem("addon." + field + " must be a Lua global name such as " + name.replace(/[^A-Za-z0-9_]/gu, "") + "DB");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (addon.optionalDependencies !== undefined && (!Array.isArray(addon.optionalDependencies)
|
|
77
|
+
|| !addon.optionalDependencies.every(item => typeof item === "string" && ADDON_NAME.test(item)))) {
|
|
78
|
+
throw problem("addon.optionalDependencies must list addon folder names");
|
|
79
|
+
}
|
|
80
|
+
const icon = text(addon.icon, "addon.icon");
|
|
81
|
+
if (icon !== undefined && (!existsSync(join(workspace, icon)) || icon.includes(".."))) {
|
|
82
|
+
throw problem("addon.icon must name a texture inside the project, such as Assets/Art/Icon.tga");
|
|
83
|
+
}
|
|
84
|
+
const pluginState = config.pluginState ?? "account";
|
|
85
|
+
if (pluginState !== "account" && pluginState !== "character") throw problem('pluginState must be "account" or "character"');
|
|
86
|
+
|
|
87
|
+
const entries = config.plugins ?? {};
|
|
88
|
+
if (entries === null || typeof entries !== "object" || Array.isArray(entries)) throw problem("plugins must map plugin IDs to plugins");
|
|
89
|
+
const src = realpathSync(join(workspace, "src"));
|
|
90
|
+
const plugins = Object.keys(entries).sort().map(id => {
|
|
91
|
+
const field = "plugins." + id;
|
|
92
|
+
if (!PLUGIN_ID.test(id)) throw problem(field + ": use lowercase letters, digits and dashes for a plugin ID");
|
|
93
|
+
const entry = entries[id];
|
|
94
|
+
if (entry === null || typeof entry !== "object") throw problem(field + " must be an object");
|
|
95
|
+
if (typeof entry.module !== "string") throw problem(field + ".module must name the plugin's module file");
|
|
96
|
+
const requested = resolve(workspace, entry.module);
|
|
97
|
+
if (!/\.(ts|tsx)$/u.test(requested) || requested.endsWith(".d.ts") || !existsSync(requested)) {
|
|
98
|
+
throw problem(field + ".module must be an existing TypeScript file: " + entry.module);
|
|
99
|
+
}
|
|
100
|
+
const file = realpathSync(requested);
|
|
101
|
+
if (!inside(src, file) || !lstatSync(file).isFile()) throw problem(field + ".module must be inside src");
|
|
102
|
+
const exported = moduleExports(workspace, file);
|
|
103
|
+
let symbol = entry.export;
|
|
104
|
+
if (symbol !== undefined) {
|
|
105
|
+
if (!exported.includes(symbol)) throw problem(field + ".export: " + entry.module + " has no exported @Module class " + symbol);
|
|
106
|
+
} else if (exported.length === 1) {
|
|
107
|
+
symbol = exported[0];
|
|
108
|
+
} else {
|
|
109
|
+
throw problem(field + ".module: " + entry.module + (exported.length
|
|
110
|
+
? " exports several @Module classes. Name one with export: " + exported.join(" or ")
|
|
111
|
+
: " must export a class decorated with @Module"));
|
|
112
|
+
}
|
|
113
|
+
const load = entry.load ?? "startup";
|
|
114
|
+
if (load !== "startup" && load !== "demand") throw problem(field + '.load must be "startup" or "demand"');
|
|
115
|
+
if (entry.enabled !== undefined && typeof entry.enabled !== "boolean") throw problem(field + ".enabled must be true or false");
|
|
116
|
+
const moduleKey = "addon/" + relative(workspace, file).replaceAll("\\", "/");
|
|
117
|
+
return {
|
|
118
|
+
id, file, export: symbol, load, enabled: entry.enabled !== false,
|
|
119
|
+
title: text(entry.title, field + ".title", true), notes: text(entry.notes, field + ".notes"),
|
|
120
|
+
addon: name + "_" + id, moduleKey, folderKey: moduleKey.slice(0, moduleKey.lastIndexOf("/") + 1),
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
for (const plugin of plugins) {
|
|
124
|
+
for (const other of plugins) {
|
|
125
|
+
if (other !== plugin && plugin.folderKey.startsWith(other.folderKey)) {
|
|
126
|
+
throw problem("plugins." + plugin.id + " sits inside the folder of plugin " + other.id + ". Give each plugin its own folder.");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
name, pluginState, plugins, icon,
|
|
132
|
+
addon: {
|
|
133
|
+
title: text(addon.title, "addon.title", true), notes: text(addon.notes, "addon.notes"),
|
|
134
|
+
author: text(addon.author, "addon.author"), version: text(addon.version, "addon.version"),
|
|
135
|
+
interface: addon.interface ?? {}, savedVariables: addon.savedVariables,
|
|
136
|
+
savedVariablesPerCharacter: addon.savedVariablesPerCharacter, optionalDependencies: addon.optionalDependencies ?? [],
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function interfaceFor(project, target, toc) {
|
|
142
|
+
if (toc !== undefined) return toc;
|
|
143
|
+
const configured = project.addon.interface[target];
|
|
144
|
+
return configured === undefined ? String(DEFAULT_INTERFACE[target]) : interfaces(configured, "addon.interface." + target);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function iconPath(project) {
|
|
148
|
+
return project.icon === undefined ? undefined
|
|
149
|
+
: "Interface\\AddOns\\" + project.name + "\\" + project.icon.replace(/\.(tga|blp|png)$/iu, "").replaceAll("/", "\\");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The main addon's TOC. */
|
|
153
|
+
export function mainToc(project, interfaceVersion, files) {
|
|
154
|
+
const { addon } = project;
|
|
155
|
+
const lines = ["## Interface: " + interfaceVersion, "## Title: " + addon.title];
|
|
156
|
+
if (addon.notes) lines.push("## Notes: " + addon.notes);
|
|
157
|
+
if (addon.author) lines.push("## Author: " + addon.author);
|
|
158
|
+
if (addon.version) lines.push("## Version: " + addon.version);
|
|
159
|
+
const icon = iconPath(project);
|
|
160
|
+
if (icon) lines.push("## IconTexture: " + icon);
|
|
161
|
+
if (addon.savedVariables) lines.push("## SavedVariables: " + addon.savedVariables);
|
|
162
|
+
if (addon.savedVariablesPerCharacter) lines.push("## SavedVariablesPerCharacter: " + addon.savedVariablesPerCharacter);
|
|
163
|
+
if (addon.optionalDependencies.length) lines.push("## OptionalDeps: " + addon.optionalDependencies.join(", "));
|
|
164
|
+
return [...lines, "", ...files, ""].join("\n");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** A plugin's TOC: a dependency of the main addon, grouped under it in the addon list. */
|
|
168
|
+
export function pluginToc(project, plugin, interfaceVersion) {
|
|
169
|
+
const { addon } = project;
|
|
170
|
+
const lines = ["## Interface: " + interfaceVersion, "## Title: " + addon.title + ": " + plugin.title];
|
|
171
|
+
if (plugin.notes) lines.push("## Notes: " + plugin.notes);
|
|
172
|
+
if (addon.author) lines.push("## Author: " + addon.author);
|
|
173
|
+
if (addon.version) lines.push("## Version: " + addon.version);
|
|
174
|
+
const icon = iconPath(project);
|
|
175
|
+
if (icon) lines.push("## IconTexture: " + icon);
|
|
176
|
+
lines.push("## Dependencies: " + project.name, "## Group: " + project.name, "## X-Kumi-Plugin: " + plugin.id);
|
|
177
|
+
if (plugin.load === "demand") lines.push("## LoadOnDemand: 1");
|
|
178
|
+
if (!plugin.enabled) lines.push("## DefaultState: disabled");
|
|
179
|
+
return [...lines, "", plugin.addon + ".lua", ""].join("\n");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Lua that publishes the addon's settings and plugin list to its own runtime. */
|
|
183
|
+
export function manifestLua(project) {
|
|
184
|
+
const plugins = project.plugins.map(plugin => " { id = " + quote(plugin.id) + ", addon = " + quote(plugin.addon)
|
|
185
|
+
+ ", title = " + quote(plugin.title) + ", notes = " + quote(plugin.notes ?? "") + ", load = " + quote(plugin.load) + " },");
|
|
186
|
+
const optional = (field, value) => value === undefined ? [] : [" " + field + " = " + quote(value) + ","];
|
|
187
|
+
const variables = project.styleVariables?.size ? [
|
|
188
|
+
" styleVariables = {",
|
|
189
|
+
...Array.from(project.styleVariables, ([name, value]) => ` [${luaString(name)}] = ${luaString(value)},`),
|
|
190
|
+
" },",
|
|
191
|
+
] : [];
|
|
192
|
+
return [
|
|
193
|
+
"-- Generated by kumi build.",
|
|
194
|
+
"local name, owner = ...",
|
|
195
|
+
"if name ~= " + quote(project.name) + " or type(owner) ~= 'table' then error('Load " + project.name + " as its own addon', 0) end",
|
|
196
|
+
"if rawget(owner, 'KumiAddon') ~= nil then error('Duplicate Kumi manifest for ' .. name, 0) end",
|
|
197
|
+
"local plugins = {",
|
|
198
|
+
...plugins,
|
|
199
|
+
"}",
|
|
200
|
+
"local manifest = {",
|
|
201
|
+
" name = name,",
|
|
202
|
+
...optional("savedVariables", project.addon.savedVariables),
|
|
203
|
+
...optional("savedVariablesPerCharacter", project.addon.savedVariablesPerCharacter),
|
|
204
|
+
...variables,
|
|
205
|
+
" pluginState = " + quote(project.pluginState) + ",",
|
|
206
|
+
" plugins = plugins,",
|
|
207
|
+
" registered = {},",
|
|
208
|
+
" failures = {},",
|
|
209
|
+
" started = false,",
|
|
210
|
+
"}",
|
|
211
|
+
"rawset(owner, 'KumiAddon', manifest)",
|
|
212
|
+
...(project.plugins.length === 0 ? [] : [
|
|
213
|
+
"local hosts = rawget(_G, 'KumiAddonHosts')",
|
|
214
|
+
"if hosts == nil then hosts = {}; rawset(_G, 'KumiAddonHosts', hosts) end",
|
|
215
|
+
"if type(hosts) ~= 'table' or hosts[name] ~= nil then error('Kumi addon collision for ' .. name, 0) end",
|
|
216
|
+
"local declared = {}",
|
|
217
|
+
"for _, plugin in ipairs(plugins) do declared[plugin.addon] = plugin end",
|
|
218
|
+
"-- A plugin receives the addon table only while WoW loads it: at startup, or inside load() for a demand plugin.",
|
|
219
|
+
"hosts[name] = function(addon)",
|
|
220
|
+
" local plugin = declared[addon]",
|
|
221
|
+
" if plugin == nil then return nil end",
|
|
222
|
+
" if plugin.load == 'demand' then",
|
|
223
|
+
" if manifest.loading ~= addon then return nil end",
|
|
224
|
+
" elseif manifest.started then",
|
|
225
|
+
" return nil",
|
|
226
|
+
" end",
|
|
227
|
+
" return owner",
|
|
228
|
+
"end",
|
|
229
|
+
]),
|
|
230
|
+
"",
|
|
231
|
+
].join("\n");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function wrapPlugin(project, plugin, body) {
|
|
235
|
+
const owner = quote(project.name);
|
|
236
|
+
return [
|
|
237
|
+
"-- Generated by kumi build. Plugin " + plugin.id + " of " + project.name + ".",
|
|
238
|
+
"local name = ...",
|
|
239
|
+
"local hosts = rawget(_G, 'KumiAddonHosts')",
|
|
240
|
+
"local host = type(hosts) == 'table' and hosts[" + owner + "] or nil",
|
|
241
|
+
"local owner = type(host) == 'function' and host(name) or nil",
|
|
242
|
+
"if name ~= " + quote(plugin.addon) + " or type(owner) ~= 'table' then",
|
|
243
|
+
" error(" + quote(plugin.addon + " is a plugin of " + project.name + ". Enable " + project.name + " and reload the UI.") + ", 0)",
|
|
244
|
+
"end",
|
|
245
|
+
"local manifest = rawget(owner, 'KumiAddon')",
|
|
246
|
+
"local function initialize(...)",
|
|
247
|
+
body,
|
|
248
|
+
"end",
|
|
249
|
+
"local ok, failure = pcall(initialize, " + owner + ", owner)",
|
|
250
|
+
"if not ok then",
|
|
251
|
+
" manifest.failures[" + quote(plugin.id) + "] = tostring(failure)",
|
|
252
|
+
" error(failure, 0)",
|
|
253
|
+
"end",
|
|
254
|
+
"",
|
|
255
|
+
].join("\n");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function inventoryFile(workspace) {
|
|
259
|
+
return join(workspace, "build", "kumi", "outputs.json");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function previousOutputs(workspace, name) {
|
|
263
|
+
const path = inventoryFile(workspace);
|
|
264
|
+
if (!existsSync(path)) return [];
|
|
265
|
+
const outputs = JSON.parse(readFileSync(path, "utf8"));
|
|
266
|
+
if (!Array.isArray(outputs) || outputs.some(folder => typeof folder !== "string" || !(folder === name || folder.startsWith(name + "_")))) {
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
return outputs;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Generate the typed plugin map and the TypeScript entry of each plugin. */
|
|
273
|
+
export async function writePluginSources(workspace, project) {
|
|
274
|
+
const generated = join(workspace, "build", "kumi");
|
|
275
|
+
const entries = join(generated, "plugins");
|
|
276
|
+
mkdirSync(entries, { recursive: true });
|
|
277
|
+
const keep = new Set();
|
|
278
|
+
for (const plugin of project.plugins) {
|
|
279
|
+
const entry = join(entries, plugin.id + ".ts");
|
|
280
|
+
let specifier = relative(entries, plugin.file).replaceAll("\\", "/").replace(/\.(ts|tsx)$/u, "");
|
|
281
|
+
if (!specifier.startsWith(".")) specifier = "./" + specifier;
|
|
282
|
+
await writeGeneratedText(entry, [
|
|
283
|
+
"// Generated by kumi build.",
|
|
284
|
+
"import { " + plugin.export + " as Module } from " + quote(specifier) + ";",
|
|
285
|
+
"import { registerPlugin } from " + quote(sdkPackage + "/wow/plugins") + ";",
|
|
286
|
+
"registerPlugin(" + quote(plugin.id) + ", Module);",
|
|
287
|
+
"",
|
|
288
|
+
].join("\n"));
|
|
289
|
+
keep.add(plugin.id + ".ts");
|
|
290
|
+
}
|
|
291
|
+
for (const file of readdirSync(entries)) if (!keep.has(file)) rmSync(join(entries, file), { force: true });
|
|
292
|
+
const imports = project.plugins.map(plugin => {
|
|
293
|
+
let specifier = relative(generated, plugin.file).replaceAll("\\", "/").replace(/\.(ts|tsx)$/u, "");
|
|
294
|
+
if (!specifier.startsWith(".")) specifier = "./" + specifier;
|
|
295
|
+
return " " + quote(plugin.id) + ": typeof import(" + quote(specifier) + ")." + plugin.export + ";";
|
|
296
|
+
});
|
|
297
|
+
await writeGeneratedText(join(generated, "plugins.d.ts"), [
|
|
298
|
+
"// Generated by kumi check and kumi build: the plugins declared in kumi.config.ts.",
|
|
299
|
+
"import type {} from \"@kumi/wow\";",
|
|
300
|
+
"declare module \"@kumi/wow\" {",
|
|
301
|
+
" interface KumiPlugins {",
|
|
302
|
+
...imports,
|
|
303
|
+
" }",
|
|
304
|
+
"}",
|
|
305
|
+
"",
|
|
306
|
+
].join("\n"));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Build every addon folder in a staging area, then swap them into build/addons. */
|
|
310
|
+
export async function buildProject(workspace, project, interfaceVersion, pack) {
|
|
311
|
+
const output = join(workspace, "build", "addons");
|
|
312
|
+
const generated = join(workspace, "build", "kumi");
|
|
313
|
+
mkdirSync(output, { recursive: true });
|
|
314
|
+
mkdirSync(generated, { recursive: true });
|
|
315
|
+
await writePluginSources(workspace, project);
|
|
316
|
+
const stage = mkdtempSync(join(generated, "stage-"));
|
|
317
|
+
try {
|
|
318
|
+
const main = join(stage, project.name);
|
|
319
|
+
mkdirSync(main);
|
|
320
|
+
const mainLua = project.name + ".lua";
|
|
321
|
+
await writeGeneratedText(join(main, MANIFEST), manifestLua(project));
|
|
322
|
+
const assetsDir = relative(workspace, main);
|
|
323
|
+
if (project.plugins.length === 0) {
|
|
324
|
+
pack(["compile", "src/app/main.ts", "--tsconfig", "tsconfig.json", "--addon-entry",
|
|
325
|
+
"--addon-assets-dir", assetsDir, "--compile-output", relative(workspace, join(main, mainLua))]);
|
|
326
|
+
await writeGeneratedText(join(main, project.name + ".toc"), mainToc(project, interfaceVersion, [MANIFEST, mainLua]));
|
|
327
|
+
} else {
|
|
328
|
+
const common = ["--tsconfig", "tsconfig.json", "--addon-entry", "--addon-link", LINK_STAMP,
|
|
329
|
+
"--addon-fragments", "--addon-assets-dir", assetsDir];
|
|
330
|
+
const chunks = [];
|
|
331
|
+
const compile = (entry, chunk, lua, plugin) => {
|
|
332
|
+
const fragment = join(stage, chunk + ".fragment");
|
|
333
|
+
pack(["compile", entry, ...common, "--compile-output", relative(workspace, fragment)]);
|
|
334
|
+
chunks.push({ fragment, lua, name: chunk, lazyModule: plugin?.moduleKey, ownedFolder: plugin?.folderKey, pluginId: plugin?.id });
|
|
335
|
+
};
|
|
336
|
+
compile("src/app/main.ts", project.name, join(main, mainLua));
|
|
337
|
+
for (const plugin of project.plugins) {
|
|
338
|
+
const folder = join(stage, plugin.addon);
|
|
339
|
+
mkdirSync(folder);
|
|
340
|
+
compile(relative(workspace, join(generated, "plugins", plugin.id + ".ts")), plugin.addon,
|
|
341
|
+
join(folder, plugin.addon + ".lua"), plugin);
|
|
342
|
+
await writeGeneratedText(join(folder, plugin.addon + ".toc"), pluginToc(project, plugin, interfaceVersion));
|
|
343
|
+
}
|
|
344
|
+
await linkAddonPackage(chunks, join(main, SHARED), false, LINK_STAMP);
|
|
345
|
+
for (const plugin of project.plugins) {
|
|
346
|
+
const lua = join(stage, plugin.addon, plugin.addon + ".lua");
|
|
347
|
+
await writeGeneratedText(lua, wrapPlugin(project, plugin, readFileSync(lua, "utf8")));
|
|
348
|
+
}
|
|
349
|
+
for (const chunk of chunks) rmSync(chunk.fragment, { force: true });
|
|
350
|
+
await writeGeneratedText(join(main, project.name + ".toc"), mainToc(project, interfaceVersion, [SHARED, MANIFEST, mainLua]));
|
|
351
|
+
}
|
|
352
|
+
const assets = join(workspace, "Assets");
|
|
353
|
+
if (existsSync(assets)) cpSync(assets, join(main, "Assets"), { recursive: true });
|
|
354
|
+
for (const [path, data] of project.styleMaskAssets ?? []) {
|
|
355
|
+
const destination = join(main, path);
|
|
356
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
357
|
+
writeFileSync(destination, data);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Replace whole folders so files from an older build cannot linger, then drop folders of removed plugins.
|
|
361
|
+
const folders = [project.name, ...project.plugins.map(plugin => plugin.addon)];
|
|
362
|
+
const previous = previousOutputs(workspace, project.name);
|
|
363
|
+
for (const folder of folders) {
|
|
364
|
+
rmSync(join(output, folder), { recursive: true, force: true });
|
|
365
|
+
renameSync(join(stage, folder), join(output, folder));
|
|
366
|
+
}
|
|
367
|
+
for (const folder of previous) {
|
|
368
|
+
if (!folders.includes(folder)) rmSync(join(output, folder), { recursive: true, force: true });
|
|
369
|
+
}
|
|
370
|
+
await writeGeneratedText(inventoryFile(workspace), JSON.stringify(folders) + "\n");
|
|
371
|
+
for (const folder of folders) console.log("Addon available at " + join("build", "addons", folder));
|
|
372
|
+
return folders;
|
|
373
|
+
} finally {
|
|
374
|
+
rmSync(stage, { recursive: true, force: true });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, join, relative } from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import postcss from "postcss";
|
|
6
|
+
import { compile } from "sass";
|
|
7
|
+
import { prepareCssMaskImages } from "../builder/css-mask-assets.mjs";
|
|
8
|
+
import { compileLocalStyleModule, readStyleBreakpoints, readStyleTokens } from "../builder/style-modules.mjs";
|
|
9
|
+
import { buildProject, interfaceFor, readProject, writePluginSources } from "./addon-build.mjs";
|
|
10
|
+
|
|
11
|
+
function readCss(file) {
|
|
12
|
+
const css = file.endsWith(".scss") ? compile(file).css : readFileSync(file, "utf8");
|
|
13
|
+
return postcss.parse(css, { from: file });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function writeGenerated(file, text) {
|
|
17
|
+
if (existsSync(file) && readFileSync(file, "utf8") === text) return;
|
|
18
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
19
|
+
writeFileSync(file, text);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function prepareStyles(workspace, addonName) {
|
|
23
|
+
const source = join(workspace, "src");
|
|
24
|
+
const styles = join(workspace, "build", "styles");
|
|
25
|
+
const tokensSource = join(source, "shared", "styles", "tokens.css");
|
|
26
|
+
const tokens = existsSync(tokensSource) ? readStyleTokens(readCss(tokensSource)) : new Map();
|
|
27
|
+
const breakpointsSource = join(source, "shared", "styles", "breakpoints.tokens.scss");
|
|
28
|
+
const breakpoints = existsSync(breakpointsSource)
|
|
29
|
+
? readStyleBreakpoints(readCss(breakpointsSource))
|
|
30
|
+
: new Map([[0, "base"]]);
|
|
31
|
+
const breakpointValues = Object.fromEntries([...breakpoints].map(([width, name]) => [name, width]));
|
|
32
|
+
writeGenerated(join(styles, "shared", "styles", "breakpoints.ts"),
|
|
33
|
+
"export default " + JSON.stringify(breakpointValues) + " as const;\n");
|
|
34
|
+
|
|
35
|
+
const styleOutputs = new Map();
|
|
36
|
+
const styleMaskAssets = new Map();
|
|
37
|
+
for (const entry of readdirSync(source, { recursive: true, withFileTypes: true })) {
|
|
38
|
+
if (!entry.isFile() || !/\.module\.(css|scss)$/u.test(entry.name)) continue;
|
|
39
|
+
const path = join(entry.parentPath, entry.name);
|
|
40
|
+
const output = relative(source, path).replace(/\.module\.(css|scss)$/u, ".ts");
|
|
41
|
+
if (styleOutputs.has(output)) throw new Error(`Style modules ${styleOutputs.get(output)} and ${path} have the same import name`);
|
|
42
|
+
styleOutputs.set(output, path);
|
|
43
|
+
const classes = compileLocalStyleModule(readCss(path), breakpoints, tokens);
|
|
44
|
+
prepareCssMaskImages(classes, addonName, styleMaskAssets);
|
|
45
|
+
writeGenerated(join(styles, output),
|
|
46
|
+
'import type { StyleClass } from "@kumi/core";\n' +
|
|
47
|
+
"export default " + JSON.stringify(classes, null, 2) + " satisfies Record<string, StyleClass>;\n");
|
|
48
|
+
}
|
|
49
|
+
return { styleVariables: tokens, styleMaskAssets };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function prepareProject(workspace, project, pack) {
|
|
53
|
+
const styles = prepareStyles(workspace, project.name);
|
|
54
|
+
if (!existsSync(join(workspace, "build", "types", "wow-api.d.ts"))) pack(["wow-api"]);
|
|
55
|
+
if (existsSync(join(workspace, "src", "app", "routes"))) pack(["routes"]);
|
|
56
|
+
return styles;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function projectTool(workspace, packageName, command) {
|
|
60
|
+
const require = createRequire(join(workspace, "package.json"));
|
|
61
|
+
const file = require.resolve(packageName + "/package.json");
|
|
62
|
+
const manifest = JSON.parse(readFileSync(file, "utf8"));
|
|
63
|
+
const entry = typeof manifest.bin === "string" ? manifest.bin : manifest.bin?.[command];
|
|
64
|
+
if (typeof entry !== "string") throw new Error(`The project needs the ${packageName} package`);
|
|
65
|
+
return join(dirname(file), entry);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function checkAddon(workspace, args, pack, run) {
|
|
69
|
+
const { values } = parseArgs({ args, options: { "types-only": { type: "boolean" } } });
|
|
70
|
+
const project = await readProject(workspace);
|
|
71
|
+
prepareProject(workspace, project, pack);
|
|
72
|
+
await writePluginSources(workspace, project);
|
|
73
|
+
run(process.execPath, ["--v8-pool-size=1", projectTool(workspace, "typescript", "tsc"), "-p", "tsconfig.json"]);
|
|
74
|
+
if (!values["types-only"]) {
|
|
75
|
+
run(process.execPath, ["--v8-pool-size=1", projectTool(workspace, "eslint", "eslint"), "src"]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function buildAddon(workspace, args, pack) {
|
|
80
|
+
const { values } = parseArgs({ args, options: { target: { type: "string" }, toc: { type: "string" } } });
|
|
81
|
+
const target = values.target ?? "retail";
|
|
82
|
+
if (target !== "retail" && target !== "forever") throw new Error("Expected --target retail or --target forever");
|
|
83
|
+
if (values.toc !== undefined && (!/^[1-9][0-9]*$/u.test(values.toc) || !Number.isSafeInteger(Number(values.toc)))) {
|
|
84
|
+
throw new Error("Expected a positive interface number after --toc");
|
|
85
|
+
}
|
|
86
|
+
const project = await readProject(workspace);
|
|
87
|
+
const styles = prepareProject(workspace, project, pack);
|
|
88
|
+
await buildProject(workspace, { ...project, ...styles }, interfaceFor(project, target, values.toc), pack);
|
|
89
|
+
}
|