@rubenlangeweg/mero-ui 0.9.0 → 0.10.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/CHANGELOG.md +27 -0
- package/README.md +28 -10
- package/agent-docs/components/accordion.md +1 -1
- package/agent-docs/components/action-bar.md +1 -1
- package/agent-docs/components/action-button.md +1 -1
- package/agent-docs/components/agenda.md +1 -1
- package/agent-docs/components/alert-dialog.md +1 -1
- package/agent-docs/components/alert.md +1 -1
- package/agent-docs/components/app-layout.md +1 -1
- package/agent-docs/components/area-chart.md +1 -1
- package/agent-docs/components/aura.md +1 -1
- package/agent-docs/components/autocomplete.md +1 -1
- package/agent-docs/components/avatar-group.md +1 -1
- package/agent-docs/components/avatar.md +1 -1
- package/agent-docs/components/badge.md +1 -1
- package/agent-docs/components/bar-chart.md +1 -1
- package/agent-docs/components/breadcrumbs.md +1 -1
- package/agent-docs/components/browser-mockup.md +1 -1
- package/agent-docs/components/button-group.md +1 -1
- package/agent-docs/components/button.md +1 -1
- package/agent-docs/components/calendar.md +3 -3
- package/agent-docs/components/card.md +1 -1
- package/agent-docs/components/carousel.md +1 -1
- package/agent-docs/components/cell-color-picker.md +1 -1
- package/agent-docs/components/cell-select.md +1 -1
- package/agent-docs/components/cell-slider.md +1 -1
- package/agent-docs/components/cell-switch.md +1 -1
- package/agent-docs/components/chain-of-thought.md +1 -1
- package/agent-docs/components/chart-tooltip.md +1 -1
- package/agent-docs/components/chat-attachment.md +1 -1
- package/agent-docs/components/chat-conversation.md +1 -1
- package/agent-docs/components/chat-list-view.md +1 -1
- package/agent-docs/components/chat-loader.md +1 -1
- package/agent-docs/components/chat-message-actions.md +1 -1
- package/agent-docs/components/chat-message.md +1 -1
- package/agent-docs/components/chat-source.md +1 -1
- package/agent-docs/components/chat-tool.md +1 -1
- package/agent-docs/components/checkbox-button-group.md +1 -1
- package/agent-docs/components/checkbox-group.md +1 -1
- package/agent-docs/components/checkbox.md +1 -1
- package/agent-docs/components/chip.md +1 -1
- package/agent-docs/components/close-button.md +1 -1
- package/agent-docs/components/code-block.md +1 -1
- package/agent-docs/components/code-mockup.md +1 -1
- package/agent-docs/components/color-area.md +1 -1
- package/agent-docs/components/color-field.md +1 -1
- package/agent-docs/components/color-picker.md +1 -1
- package/agent-docs/components/color-slider.md +1 -1
- package/agent-docs/components/color-swatch.md +1 -1
- package/agent-docs/components/combo-box.md +41 -1
- package/agent-docs/components/command-menu.md +1 -1
- package/agent-docs/components/command.md +1 -1
- package/agent-docs/components/composed-chart.md +1 -1
- package/agent-docs/components/context-menu.md +1 -1
- package/agent-docs/components/countdown.md +1 -1
- package/agent-docs/components/data-grid.md +1 -1
- package/agent-docs/components/date-field.md +1 -1
- package/agent-docs/components/date-picker.md +1 -1
- package/agent-docs/components/date-range-picker.md +1 -1
- package/agent-docs/components/description-list.md +1 -1
- package/agent-docs/components/description.md +1 -1
- package/agent-docs/components/diff.md +1 -1
- package/agent-docs/components/disclosure-group.md +1 -1
- package/agent-docs/components/disclosure.md +1 -1
- package/agent-docs/components/dock.md +1 -1
- package/agent-docs/components/drawer.md +1 -1
- package/agent-docs/components/drop-zone.md +1 -1
- package/agent-docs/components/dropdown.md +1 -1
- package/agent-docs/components/emoji-picker.md +1 -1
- package/agent-docs/components/emoji-reaction-button.md +1 -1
- package/agent-docs/components/empty-state.md +1 -1
- package/agent-docs/components/error-message.md +1 -1
- package/agent-docs/components/fab.md +1 -1
- package/agent-docs/components/field-error.md +1 -1
- package/agent-docs/components/fieldset.md +1 -1
- package/agent-docs/components/file-input.md +1 -1
- package/agent-docs/components/file-tree.md +1 -1
- package/agent-docs/components/filter-chips.md +1 -1
- package/agent-docs/components/floating-toc.md +1 -1
- package/agent-docs/components/footer.md +1 -1
- package/agent-docs/components/form.md +1 -1
- package/agent-docs/components/hero.md +1 -1
- package/agent-docs/components/holo-card.md +1 -1
- package/agent-docs/components/hover-card.md +1 -1
- package/agent-docs/components/hover-gallery.md +1 -1
- package/agent-docs/components/indicator.md +1 -1
- package/agent-docs/components/inline-select.md +1 -1
- package/agent-docs/components/input-group.md +1 -1
- package/agent-docs/components/input-otp.md +1 -1
- package/agent-docs/components/input.md +1 -1
- package/agent-docs/components/item-card-group.md +1 -1
- package/agent-docs/components/item-card.md +1 -1
- package/agent-docs/components/join.md +1 -1
- package/agent-docs/components/joined-filter.md +1 -1
- package/agent-docs/components/kanban.md +1 -1
- package/agent-docs/components/kbd.md +1 -1
- package/agent-docs/components/kpi-group.md +1 -1
- package/agent-docs/components/kpi.md +1 -1
- package/agent-docs/components/label.md +1 -1
- package/agent-docs/components/line-chart.md +1 -1
- package/agent-docs/components/link.md +1 -1
- package/agent-docs/components/list-box.md +1 -1
- package/agent-docs/components/list-view.md +1 -1
- package/agent-docs/components/live-progress.md +1 -1
- package/agent-docs/components/map.md +1 -1
- package/agent-docs/components/markdown.md +1 -1
- package/agent-docs/components/mask.md +1 -1
- package/agent-docs/components/megamenu.md +1 -1
- package/agent-docs/components/menu-button.md +1 -1
- package/agent-docs/components/menu.md +1 -1
- package/agent-docs/components/meter.md +1 -1
- package/agent-docs/components/modal.md +1 -1
- package/agent-docs/components/native-select.md +1 -1
- package/agent-docs/components/navbar.md +1 -1
- package/agent-docs/components/number-field.md +1 -1
- package/agent-docs/components/number-stepper.md +1 -1
- package/agent-docs/components/number-value.md +1 -1
- package/agent-docs/components/page-header.md +1 -1
- package/agent-docs/components/pagination.md +1 -1
- package/agent-docs/components/phone-mockup.md +1 -1
- package/agent-docs/components/pie-chart.md +1 -1
- package/agent-docs/components/popover.md +1 -1
- package/agent-docs/components/pressable-feedback.md +1 -1
- package/agent-docs/components/progress-bar.md +1 -1
- package/agent-docs/components/progress-circle.md +1 -1
- package/agent-docs/components/prompt-input.md +1 -1
- package/agent-docs/components/prompt-suggestion.md +1 -1
- package/agent-docs/components/radar-chart.md +1 -1
- package/agent-docs/components/radial-chart.md +1 -1
- package/agent-docs/components/radio-button-group.md +1 -1
- package/agent-docs/components/radio-group.md +1 -1
- package/agent-docs/components/range-calendar.md +1 -1
- package/agent-docs/components/rating.md +1 -1
- package/agent-docs/components/resizable.md +1 -1
- package/agent-docs/components/rich-text-editor.md +1 -1
- package/agent-docs/components/scroll-shadow.md +1 -1
- package/agent-docs/components/search-field.md +1 -1
- package/agent-docs/components/segment.md +1 -1
- package/agent-docs/components/select.md +1 -1
- package/agent-docs/components/separator.md +1 -1
- package/agent-docs/components/sheet.md +1 -1
- package/agent-docs/components/sidebar.md +1 -1
- package/agent-docs/components/skeleton.md +1 -1
- package/agent-docs/components/slider.md +1 -1
- package/agent-docs/components/sortable-table.md +1 -1
- package/agent-docs/components/spinner.md +1 -1
- package/agent-docs/components/stack.md +1 -1
- package/agent-docs/components/status.md +1 -1
- package/agent-docs/components/stepper.md +1 -1
- package/agent-docs/components/surface.md +1 -1
- package/agent-docs/components/swap.md +1 -1
- package/agent-docs/components/switch.md +1 -1
- package/agent-docs/components/table.md +1 -1
- package/agent-docs/components/tabs.md +1 -1
- package/agent-docs/components/tag-group.md +1 -1
- package/agent-docs/components/text-area.md +1 -1
- package/agent-docs/components/text-field.md +1 -1
- package/agent-docs/components/text-rotate.md +1 -1
- package/agent-docs/components/text-shimmer.md +1 -1
- package/agent-docs/components/theme-controller.md +1 -1
- package/agent-docs/components/time-field.md +1 -1
- package/agent-docs/components/timeline.md +1 -1
- package/agent-docs/components/toast.md +1 -1
- package/agent-docs/components/toggle-button-group.md +1 -1
- package/agent-docs/components/toggle-button.md +1 -1
- package/agent-docs/components/toolbar.md +1 -1
- package/agent-docs/components/tooltip.md +1 -1
- package/agent-docs/components/trend-chip.md +1 -1
- package/agent-docs/components/typed-confirmation.md +1 -1
- package/agent-docs/components/typography.md +1 -1
- package/agent-docs/components/validator.md +23 -2
- package/agent-docs/components/visually-hidden.md +1 -1
- package/agent-docs/components/widget.md +1 -1
- package/agent-docs/components/window-mockup.md +1 -1
- package/agent-docs/llms-components.txt +237 -176
- package/agent-docs/llms-full.txt +309 -198
- package/agent-docs/llms-patterns.txt +73 -23
- package/agent-docs/llms.txt +1 -1
- package/bin/mero-ui.mjs +505 -0
- package/dist/manifest.json +230 -0
- package/dist/ui/mero-collections.min.css +3 -0
- package/dist/ui/mero-collections.min.js +2 -0
- package/dist/ui/mero-composition.min.css +3 -0
- package/dist/ui/mero-composition.min.js +2 -0
- package/dist/ui/mero-forms.min.js +2 -0
- package/dist/ui/mero-gallery.min.css +3 -0
- package/dist/ui/mero-gallery.min.js +2 -0
- package/dist/ui/mero-insights.min.css +3 -0
- package/dist/ui/mero-insights.min.js +2 -0
- package/dist/ui/mero-layouts.min.css +3 -0
- package/dist/ui/mero-live.min.js +2 -0
- package/dist/ui/mero-themes.min.css +3 -0
- package/dist/ui/mero-workspace.min.css +3 -0
- package/dist/ui/mero-workspace.min.js +4 -0
- package/dist/ui/mero.min.css +3 -0
- package/dist/ui/mero.min.js +2 -0
- package/package.json +24 -5
- package/ui/insight-charts.d.ts +20 -0
- package/ui/insight-charts.mjs +1 -1
- package/ui/insight-markdown.d.ts +2 -0
- package/ui/insight-markdown.mjs +2 -2
- package/ui/mero-collections.css +3 -1
- package/ui/mero-collections.js +1 -1
- package/ui/mero-composition.css +3 -1
- package/ui/mero-composition.js +2 -2
- package/ui/mero-forms.js +383 -71
- package/ui/mero-gallery.css +4 -16
- package/ui/mero-gallery.js +1 -1
- package/ui/mero-insights.css +3 -1
- package/ui/mero-insights.js +2 -2
- package/ui/mero-layouts.css +3 -1
- package/ui/mero-live.js +68 -10
- package/ui/mero-themes.css +186 -0
- package/ui/mero-workspace.css +3 -1
- package/ui/mero-workspace.js +1 -1
- package/ui/mero.css +104 -16
- package/ui/mero.d.ts +162 -0
- package/ui/mero.js +433 -56
- package/ui/mero-inventory.css +0 -182
- package/ui/mero-inventory.js +0 -56
- package/ui/studio-lamp.webp +0 -0
package/bin/mero-ui.mjs
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { copyFile, lstat, mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
5
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
const pkgRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
9
|
+
|
|
10
|
+
export const FAMILIES = {
|
|
11
|
+
core: ["mero.css", "mero.js", "mero-forms.js", "mero-live.js"],
|
|
12
|
+
themes: ["mero-themes.css"],
|
|
13
|
+
gallery: ["mero-gallery.css", "mero-gallery.js"],
|
|
14
|
+
layouts: ["mero-layouts.css"],
|
|
15
|
+
collections: ["mero-collections.css", "mero-collections.js"],
|
|
16
|
+
workspace: ["mero-workspace.css", "mero-workspace.js"],
|
|
17
|
+
insights: ["mero-insights.css", "mero-insights.js"],
|
|
18
|
+
composition: ["mero-composition.css", "mero-composition.js"],
|
|
19
|
+
charts: ["insight-charts.mjs"],
|
|
20
|
+
markdown: ["insight-markdown.mjs"],
|
|
21
|
+
types: ["mero.d.ts", "insight-charts.d.ts", "insight-markdown.d.ts"],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const BROWSER_OPTIONAL = ["themes", "gallery", "layouts", "collections", "workspace", "insights", "composition"];
|
|
25
|
+
|
|
26
|
+
const USAGE = `Usage:
|
|
27
|
+
mero-ui init <dir> [--with <families>] [--minified] [--base-url <path>]
|
|
28
|
+
mero-ui verify <dir> [--strict-version]
|
|
29
|
+
mero-ui upgrade <dir> [--with <families>] [--minified | --unminified] [--base-url <path>]
|
|
30
|
+
|
|
31
|
+
Commands:
|
|
32
|
+
init Copy Core 4 (plus optional --with families) and LICENSE.txt, and write MERO.json.
|
|
33
|
+
verify Check that every file in <dir>/MERO.json exists, matches its SHA-256 checksum,
|
|
34
|
+
and (when versions match) is byte-identical to the installed package.
|
|
35
|
+
upgrade Re-copy managed assets from the installed package, update MERO.json, and print
|
|
36
|
+
any Breaking or Deprecated changelog entries since the previous version.
|
|
37
|
+
|
|
38
|
+
Optional families (--with, comma-separated or repeated):
|
|
39
|
+
${Object.keys(FAMILIES).filter(name => name !== "core").join(", ")}, all
|
|
40
|
+
|
|
41
|
+
Options:
|
|
42
|
+
--with <list> Include optional families alongside core.
|
|
43
|
+
--minified Copy minified dist/ui/*.min.{css,js} files (requires built dist/).
|
|
44
|
+
--unminified Switch back to readable ui/*.{css,js} files during upgrade.
|
|
45
|
+
--base-url <path> Prefix used in the printed HTML snippet (default: /mero).
|
|
46
|
+
--strict-version Fail verify if MERO.json version differs from installed package.
|
|
47
|
+
-v, --version Print package name and version.
|
|
48
|
+
-h, --help Show this help text.
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
function sha256Hex(buffer) {
|
|
52
|
+
return createHash("sha256").update(buffer).digest("hex");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function sha384Sri(buffer) {
|
|
56
|
+
return "sha384-" + createHash("sha384").update(buffer).digest("base64");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseSemver(version) {
|
|
60
|
+
const match = String(version || "").trim().match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/);
|
|
61
|
+
if (!match) return null;
|
|
62
|
+
return { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), pre: match[4] || "" };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function comparePrerelease(a, b) {
|
|
66
|
+
const pa = a.split(".");
|
|
67
|
+
const pb = b.split(".");
|
|
68
|
+
const len = Math.max(pa.length, pb.length);
|
|
69
|
+
for (let i = 0; i < len; i++) {
|
|
70
|
+
if (i >= pa.length) return -1;
|
|
71
|
+
if (i >= pb.length) return 1;
|
|
72
|
+
if (pa[i] === pb[i]) continue;
|
|
73
|
+
const numA = /^\d+$/.test(pa[i]);
|
|
74
|
+
const numB = /^\d+$/.test(pb[i]);
|
|
75
|
+
if (numA && numB) return Number(pa[i]) > Number(pb[i]) ? 1 : -1;
|
|
76
|
+
if (numA) return -1;
|
|
77
|
+
if (numB) return 1;
|
|
78
|
+
return pa[i] > pb[i] ? 1 : -1;
|
|
79
|
+
}
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function compareSemver(a, b) {
|
|
84
|
+
const pa = parseSemver(a);
|
|
85
|
+
const pb = parseSemver(b);
|
|
86
|
+
if (!pa || !pb) return 0;
|
|
87
|
+
for (const key of ["major", "minor", "patch"]) {
|
|
88
|
+
if (pa[key] !== pb[key]) return pa[key] > pb[key] ? 1 : -1;
|
|
89
|
+
}
|
|
90
|
+
if (pa.pre === pb.pre) return 0;
|
|
91
|
+
if (!pa.pre) return 1;
|
|
92
|
+
if (!pb.pre) return -1;
|
|
93
|
+
return comparePrerelease(pa.pre, pb.pre);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function extractChangelogNotices(changelogText, previousVersion, currentVersion) {
|
|
97
|
+
const sections = [];
|
|
98
|
+
let current = null;
|
|
99
|
+
for (const rawLine of changelogText.split(/\r?\n/)) {
|
|
100
|
+
const heading = rawLine.match(/^##\s+(.+?)\s*$/);
|
|
101
|
+
if (heading) {
|
|
102
|
+
const label = heading[1].trim();
|
|
103
|
+
const versionMatch = label.match(/^(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)\b/);
|
|
104
|
+
const isUnreleased = /^unreleased\b/i.test(label);
|
|
105
|
+
const version = versionMatch ? versionMatch[1] : null;
|
|
106
|
+
const include = isUnreleased
|
|
107
|
+
? true
|
|
108
|
+
: version !== null && compareSemver(version, previousVersion) > 0 &&
|
|
109
|
+
(!currentVersion || compareSemver(version, currentVersion) <= 0);
|
|
110
|
+
current = include ? { heading: label, notices: [] } : null;
|
|
111
|
+
if (current) sections.push(current);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!current) continue;
|
|
115
|
+
const trimmed = rawLine.trim();
|
|
116
|
+
if (/^-\s+\*\*(?:Breaking|Deprecated):\*\*/i.test(trimmed)) {
|
|
117
|
+
current.notices.push(trimmed);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return sections.filter(section => section.notices.length > 0);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function isSafeFilename(name) {
|
|
124
|
+
return typeof name === "string" && name.length > 0 && basename(name) === name &&
|
|
125
|
+
!name.includes("..") && !name.includes("/") && !name.includes("\\");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function safeTargetPath(targetDir, name) {
|
|
129
|
+
if (!isSafeFilename(name)) return null;
|
|
130
|
+
const full = resolve(targetDir, name);
|
|
131
|
+
return relative(targetDir, full) === name ? full : null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function parseArgs(argv) {
|
|
135
|
+
const positionals = [];
|
|
136
|
+
const withFamilies = [];
|
|
137
|
+
let minified;
|
|
138
|
+
let baseUrl = "/mero";
|
|
139
|
+
let strictVersion = false;
|
|
140
|
+
let help = false;
|
|
141
|
+
let version = false;
|
|
142
|
+
|
|
143
|
+
for (let i = 0; i < argv.length; i++) {
|
|
144
|
+
const arg = argv[i];
|
|
145
|
+
if (arg === "-h" || arg === "--help") {
|
|
146
|
+
help = true;
|
|
147
|
+
} else if (arg === "-v" || arg === "--version") {
|
|
148
|
+
version = true;
|
|
149
|
+
} else if (arg === "--minified") {
|
|
150
|
+
minified = true;
|
|
151
|
+
} else if (arg === "--unminified") {
|
|
152
|
+
minified = false;
|
|
153
|
+
} else if (arg === "--strict-version") {
|
|
154
|
+
strictVersion = true;
|
|
155
|
+
} else if (arg === "--with" || arg.startsWith("--with=")) {
|
|
156
|
+
const value = arg === "--with" ? argv[++i] : arg.slice("--with=".length);
|
|
157
|
+
if (!value || value.startsWith("-")) throw new Error("Option --with requires a comma-separated family list.");
|
|
158
|
+
for (const item of value.split(",")) {
|
|
159
|
+
const name = item.trim().toLowerCase();
|
|
160
|
+
if (name) withFamilies.push(name);
|
|
161
|
+
}
|
|
162
|
+
} else if (arg === "--base-url" || arg.startsWith("--base-url=")) {
|
|
163
|
+
const value = arg === "--base-url" ? argv[++i] : arg.slice("--base-url=".length);
|
|
164
|
+
if (!value) throw new Error("Option --base-url requires a URL prefix.");
|
|
165
|
+
baseUrl = value;
|
|
166
|
+
} else if (arg.startsWith("-")) {
|
|
167
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
168
|
+
} else {
|
|
169
|
+
positionals.push(arg);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { positionals, withFamilies, minified, baseUrl, strictVersion, help, version };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function resolveFamilies(requested) {
|
|
176
|
+
const ordered = ["core"];
|
|
177
|
+
for (const name of requested) {
|
|
178
|
+
if (name === "core") continue;
|
|
179
|
+
if (name === "all") {
|
|
180
|
+
for (const opt of BROWSER_OPTIONAL) {
|
|
181
|
+
if (!ordered.includes(opt)) ordered.push(opt);
|
|
182
|
+
}
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (!Object.hasOwn(FAMILIES, name)) {
|
|
186
|
+
throw new Error(`Unknown family "${name}". Available: ${Object.keys(FAMILIES).join(", ")}, all.`);
|
|
187
|
+
}
|
|
188
|
+
if (!ordered.includes(name)) ordered.push(name);
|
|
189
|
+
}
|
|
190
|
+
return ordered;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function assetDescriptor(file, minified) {
|
|
194
|
+
if (minified && /\.(?:css|js)$/.test(file)) {
|
|
195
|
+
const minName = file.replace(/\.(css|js)$/, ".min.$1");
|
|
196
|
+
return { destName: minName, sourceRel: "dist/ui/" + minName };
|
|
197
|
+
}
|
|
198
|
+
return { destName: file, sourceRel: "ui/" + file };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function expectedBundlePlan(families, minified) {
|
|
202
|
+
const plan = [];
|
|
203
|
+
const seen = new Set();
|
|
204
|
+
for (const family of families) {
|
|
205
|
+
for (const file of FAMILIES[family]) {
|
|
206
|
+
const desc = assetDescriptor(file, minified);
|
|
207
|
+
if (seen.has(desc.destName)) continue;
|
|
208
|
+
seen.add(desc.destName);
|
|
209
|
+
plan.push({ ...desc, srcAbs: join(pkgRoot, desc.sourceRel) });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
plan.push({ destName: "LICENSE.txt", sourceRel: "LICENSE", srcAbs: join(pkgRoot, "LICENSE") });
|
|
213
|
+
return plan;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function fileExists(path) {
|
|
217
|
+
try {
|
|
218
|
+
await stat(path);
|
|
219
|
+
return true;
|
|
220
|
+
} catch {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function readPkg() {
|
|
226
|
+
return JSON.parse(await readFile(join(pkgRoot, "package.json"), "utf8"));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function rejectSymlink(path, label) {
|
|
230
|
+
try {
|
|
231
|
+
const info = await lstat(path);
|
|
232
|
+
if (info.isSymbolicLink()) throw new Error(`Refusing to write through symlink destination: ${label}`);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (error?.code !== "ENOENT") throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function writeBundle(targetDir, pkg, families, minified) {
|
|
239
|
+
const plan = expectedBundlePlan(families, minified);
|
|
240
|
+
for (const item of plan) {
|
|
241
|
+
if (!await fileExists(item.srcAbs)) {
|
|
242
|
+
throw new Error(
|
|
243
|
+
minified
|
|
244
|
+
? `Minified asset ${item.sourceRel} is not present in the installed package. Run "npm run build:ui" or omit --minified.`
|
|
245
|
+
: `Package asset ${item.sourceRel} was not found.`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
await mkdir(targetDir, { recursive: true });
|
|
251
|
+
const manifestPath = join(targetDir, "MERO.json");
|
|
252
|
+
await rejectSymlink(manifestPath, "MERO.json");
|
|
253
|
+
const filesManifest = {};
|
|
254
|
+
for (const item of plan) {
|
|
255
|
+
const destAbs = safeTargetPath(targetDir, item.destName);
|
|
256
|
+
if (!destAbs) throw new Error(`Refusing to write unsafe destination filename: ${item.destName}`);
|
|
257
|
+
await rejectSymlink(destAbs, item.destName);
|
|
258
|
+
await copyFile(item.srcAbs, destAbs);
|
|
259
|
+
const bytes = await readFile(destAbs);
|
|
260
|
+
filesManifest[item.destName] = {
|
|
261
|
+
source: item.sourceRel,
|
|
262
|
+
bytes: bytes.byteLength,
|
|
263
|
+
sha256: sha256Hex(bytes),
|
|
264
|
+
integrity: sha384Sri(bytes),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const sortedFiles = Object.fromEntries(Object.entries(filesManifest).sort(([a], [b]) => a.localeCompare(b)));
|
|
269
|
+
const manifest = {
|
|
270
|
+
package: pkg.name,
|
|
271
|
+
version: pkg.version,
|
|
272
|
+
minified,
|
|
273
|
+
families,
|
|
274
|
+
files: sortedFiles,
|
|
275
|
+
};
|
|
276
|
+
await writeFile(manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
|
|
277
|
+
return { manifest, orderedAssets: plan.map(item => item.destName).filter(name => name !== "LICENSE.txt") };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function renderHtmlSnippet(orderedAssets, baseUrl) {
|
|
281
|
+
const prefix = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
282
|
+
const css = orderedAssets.filter(name => name.endsWith(".css"));
|
|
283
|
+
const js = orderedAssets.filter(name => name.endsWith(".js"));
|
|
284
|
+
const lines = [
|
|
285
|
+
...css.map(name => `<link rel="stylesheet" href="${prefix}/${name}">`),
|
|
286
|
+
`<script defer src="/vendor/htmx.min.js"></script>`,
|
|
287
|
+
...js.map(name => `<script defer src="${prefix}/${name}"></script>`),
|
|
288
|
+
];
|
|
289
|
+
return lines.join("\n");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async function cmdInit(targetArg, options, io) {
|
|
293
|
+
if (!targetArg) throw new Error("Missing target directory. Usage: mero-ui init <dir> [--with ...] [--minified]");
|
|
294
|
+
const targetDir = resolve(targetArg);
|
|
295
|
+
const pkg = await readPkg();
|
|
296
|
+
const families = resolveFamilies(options.withFamilies);
|
|
297
|
+
const minified = Boolean(options.minified);
|
|
298
|
+
const { manifest, orderedAssets } = await writeBundle(targetDir, pkg, families, minified);
|
|
299
|
+
io.stdout(`Copied ${Object.keys(manifest.files).length} files (${pkg.name} ${pkg.version}) to ${targetDir}\n`);
|
|
300
|
+
io.stdout(`Wrote ${join(targetDir, "MERO.json")}\n\n`);
|
|
301
|
+
io.stdout(`Add to your HTML <head>:\n${renderHtmlSnippet(orderedAssets, options.baseUrl)}\n`);
|
|
302
|
+
return 0;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async function cmdVerify(targetArg, options, io) {
|
|
306
|
+
if (!targetArg) throw new Error("Missing target directory. Usage: mero-ui verify <dir> [--strict-version]");
|
|
307
|
+
const targetDir = resolve(targetArg);
|
|
308
|
+
const manifestPath = join(targetDir, "MERO.json");
|
|
309
|
+
let manifest;
|
|
310
|
+
try {
|
|
311
|
+
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
312
|
+
} catch (error) {
|
|
313
|
+
io.stderr(`Failed to read ${manifestPath}: ${error.message}\n`);
|
|
314
|
+
return 1;
|
|
315
|
+
}
|
|
316
|
+
if (!manifest || typeof manifest !== "object" || !manifest.files || typeof manifest.files !== "object") {
|
|
317
|
+
io.stderr(`Invalid manifest in ${manifestPath}: missing "files" map.\n`);
|
|
318
|
+
return 1;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const pkg = await readPkg();
|
|
322
|
+
const errors = [];
|
|
323
|
+
if (options.strictVersion && manifest.version !== pkg.version) {
|
|
324
|
+
errors.push(`Version mismatch: MERO.json records ${manifest.version}, installed package is ${pkg.version}.`);
|
|
325
|
+
}
|
|
326
|
+
if (!Object.hasOwn(manifest.files, "LICENSE.txt")) {
|
|
327
|
+
errors.push("Manifest is missing required LICENSE.txt entry.");
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const sameVersion = manifest.version === pkg.version;
|
|
331
|
+
let expectedSources = null;
|
|
332
|
+
if (sameVersion) {
|
|
333
|
+
try {
|
|
334
|
+
const families = resolveFamilies(Array.isArray(manifest.families) ? manifest.families : ["core"]);
|
|
335
|
+
const plan = expectedBundlePlan(families, Boolean(manifest.minified));
|
|
336
|
+
expectedSources = new Map(plan.map(item => [item.destName, item]));
|
|
337
|
+
for (const item of plan) {
|
|
338
|
+
if (!Object.hasOwn(manifest.files, item.destName)) {
|
|
339
|
+
errors.push(`Manifest is missing expected family file: ${item.destName}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
} catch (error) {
|
|
343
|
+
errors.push(`Invalid families in MERO.json: ${error.message}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const entries = Object.entries(manifest.files);
|
|
348
|
+
for (const [name, expected] of entries) {
|
|
349
|
+
const filePath = safeTargetPath(targetDir, name);
|
|
350
|
+
if (!filePath) {
|
|
351
|
+
errors.push(`Invalid manifest path: ${name}`);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
let actual;
|
|
355
|
+
try {
|
|
356
|
+
actual = await readFile(filePath);
|
|
357
|
+
} catch {
|
|
358
|
+
errors.push(`Missing file: ${name}`);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const actualHash = sha256Hex(actual);
|
|
362
|
+
if (actualHash !== expected?.sha256) {
|
|
363
|
+
errors.push(`Checksum mismatch for ${name}: expected ${expected?.sha256}, got ${actualHash}`);
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (typeof expected.bytes === "number" && actual.byteLength !== expected.bytes) {
|
|
367
|
+
errors.push(`Byte-length mismatch for ${name}: expected ${expected.bytes}, got ${actual.byteLength}`);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (sameVersion) {
|
|
371
|
+
const planned = expectedSources?.get(name);
|
|
372
|
+
const sourceRel = planned?.sourceRel ?? expected.source;
|
|
373
|
+
if (typeof sourceRel !== "string" || !sourceRel) {
|
|
374
|
+
errors.push(`Missing package source metadata for ${name}`);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (planned && expected.source && expected.source !== planned.sourceRel) {
|
|
378
|
+
errors.push(`Source mismatch for ${name}: manifest lists ${expected.source}, expected ${planned.sourceRel}`);
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const pkgFile = resolve(pkgRoot, sourceRel);
|
|
382
|
+
const relToPkg = relative(pkgRoot, pkgFile);
|
|
383
|
+
if (relToPkg.startsWith("..") || !await fileExists(pkgFile)) {
|
|
384
|
+
errors.push(`Missing package source for ${name}: ${sourceRel} was not found in installed package`);
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const pkgBytes = await readFile(pkgFile);
|
|
388
|
+
if (!actual.equals(pkgBytes)) {
|
|
389
|
+
errors.push(`Package drift for ${name}: differs from installed ${sourceRel}`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (errors.length > 0) {
|
|
395
|
+
for (const message of errors) io.stderr(`ERROR: ${message}\n`);
|
|
396
|
+
return 1;
|
|
397
|
+
}
|
|
398
|
+
io.stdout(`OK: verified ${entries.length} files in ${targetDir} (${manifest.package || pkg.name} ${manifest.version})\n`);
|
|
399
|
+
return 0;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
async function cmdUpgrade(targetArg, options, io) {
|
|
403
|
+
if (!targetArg) throw new Error("Missing target directory. Usage: mero-ui upgrade <dir> [--with ...] [--minified]");
|
|
404
|
+
const targetDir = resolve(targetArg);
|
|
405
|
+
const manifestPath = join(targetDir, "MERO.json");
|
|
406
|
+
let previous;
|
|
407
|
+
try {
|
|
408
|
+
previous = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
409
|
+
} catch (error) {
|
|
410
|
+
io.stderr(`Failed to read ${manifestPath}: ${error.message}\n`);
|
|
411
|
+
return 1;
|
|
412
|
+
}
|
|
413
|
+
if (!previous || typeof previous !== "object" || !previous.files || typeof previous.files !== "object") {
|
|
414
|
+
io.stderr(`Invalid manifest in ${manifestPath}: missing "files" map.\n`);
|
|
415
|
+
return 1;
|
|
416
|
+
}
|
|
417
|
+
const prevFiles = Object.keys(previous.files);
|
|
418
|
+
for (const oldName of prevFiles) {
|
|
419
|
+
if (!safeTargetPath(targetDir, oldName)) {
|
|
420
|
+
io.stderr(`Error: Refusing upgrade because ${manifestPath} contains an unsafe file path: ${oldName}\n`);
|
|
421
|
+
return 1;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const pkg = await readPkg();
|
|
426
|
+
const prevVersion = previous.version || "0.0.0";
|
|
427
|
+
const families = options.withFamilies.length > 0
|
|
428
|
+
? resolveFamilies(options.withFamilies)
|
|
429
|
+
: resolveFamilies(Array.isArray(previous.families) ? previous.families : ["core"]);
|
|
430
|
+
const minified = options.minified !== undefined ? options.minified : Boolean(previous.minified);
|
|
431
|
+
|
|
432
|
+
const { manifest, orderedAssets } = await writeBundle(targetDir, pkg, families, minified);
|
|
433
|
+
for (const oldName of prevFiles) {
|
|
434
|
+
if (!Object.hasOwn(manifest.files, oldName)) {
|
|
435
|
+
const safePath = safeTargetPath(targetDir, oldName);
|
|
436
|
+
if (safePath) await rm(safePath, { force: true });
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
io.stdout(`Upgraded ${targetDir}: ${prevVersion} -> ${pkg.version} (${Object.keys(manifest.files).length} files)\n`);
|
|
441
|
+
const changelogPath = join(pkgRoot, "CHANGELOG.md");
|
|
442
|
+
if (await fileExists(changelogPath)) {
|
|
443
|
+
const changelog = await readFile(changelogPath, "utf8");
|
|
444
|
+
const sections = extractChangelogNotices(changelog, prevVersion, pkg.version);
|
|
445
|
+
if (sections.length > 0) {
|
|
446
|
+
io.stdout(`\nReview before deploying (Breaking / Deprecated since ${prevVersion}):\n`);
|
|
447
|
+
for (const section of sections) {
|
|
448
|
+
io.stdout(` ${section.heading}\n`);
|
|
449
|
+
for (const notice of section.notices) {
|
|
450
|
+
io.stdout(` ${notice}\n`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
} else {
|
|
454
|
+
io.stdout(`No Breaking or Deprecated changelog entries since ${prevVersion}.\n`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (options.withFamilies.length > 0 || options.minified !== undefined) {
|
|
458
|
+
io.stdout(`\nUpdated HTML <head>:\n${renderHtmlSnippet(orderedAssets, options.baseUrl)}\n`);
|
|
459
|
+
}
|
|
460
|
+
return 0;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export async function runCli(argv, io = { stdout: text => process.stdout.write(text), stderr: text => process.stderr.write(text) }) {
|
|
464
|
+
let parsed;
|
|
465
|
+
try {
|
|
466
|
+
parsed = parseArgs(argv);
|
|
467
|
+
} catch (error) {
|
|
468
|
+
io.stderr(`Error: ${error.message}\n`);
|
|
469
|
+
return 1;
|
|
470
|
+
}
|
|
471
|
+
if (parsed.help || parsed.positionals[0] === "help" || (parsed.positionals.length === 0 && !parsed.version)) {
|
|
472
|
+
io.stdout(USAGE);
|
|
473
|
+
return 0;
|
|
474
|
+
}
|
|
475
|
+
if (parsed.version) {
|
|
476
|
+
const pkg = await readPkg();
|
|
477
|
+
io.stdout(`${pkg.name} ${pkg.version}\n`);
|
|
478
|
+
return 0;
|
|
479
|
+
}
|
|
480
|
+
const [command, target] = parsed.positionals;
|
|
481
|
+
try {
|
|
482
|
+
if (command === "init") return await cmdInit(target, parsed, io);
|
|
483
|
+
if (command === "verify") return await cmdVerify(target, parsed, io);
|
|
484
|
+
if (command === "upgrade") return await cmdUpgrade(target, parsed, io);
|
|
485
|
+
io.stderr(`Unknown command: ${command}\n\n${USAGE}`);
|
|
486
|
+
return 1;
|
|
487
|
+
} catch (error) {
|
|
488
|
+
io.stderr(`Error: ${error.message}\n`);
|
|
489
|
+
return 1;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function isMainEntry() {
|
|
494
|
+
if (!process.argv[1]) return false;
|
|
495
|
+
try {
|
|
496
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
497
|
+
} catch {
|
|
498
|
+
return resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url));
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (isMainEntry()) {
|
|
503
|
+
const code = await runCli(process.argv.slice(2));
|
|
504
|
+
process.exitCode = code;
|
|
505
|
+
}
|