Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m46s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m7s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m8s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m51s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m12s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m11s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m33s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
61 lines
3.1 KiB
JavaScript
61 lines
3.1 KiB
JavaScript
/**
|
||
* Erzeugt public/sdk/*.js: kleine ES-Module, auf die die Import Map des Portals zeigt.
|
||
* Sie reichen die Module weiter, die das Portal schon geladen hat (window.__inhaus.modules) –
|
||
* Plugins nutzen so dieselbe Vue-Instanz, denselben Router und dieselben Komponenten.
|
||
*
|
||
* npm run sdk (läuft auch in bin/build)
|
||
*/
|
||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||
|
||
const out = new URL('../public/sdk/', import.meta.url);
|
||
mkdirSync(out, { recursive: true });
|
||
|
||
const valid = (name) => /^[A-Za-z_$][\w$]*$/.test(name) && name !== 'default';
|
||
|
||
function shim(specifier, names, hasDefault) {
|
||
const list = [...new Set(names.filter(valid))].sort();
|
||
const lines = [
|
||
'// Automatisch erzeugt (scripts/generate-sdk-shims.mjs) – nicht von Hand ändern.',
|
||
`const m = window.__inhaus.modules[${JSON.stringify(specifier)}];`,
|
||
hasDefault ? 'export default m.default;' : '',
|
||
`export const { ${list.join(', ')} } = m;`,
|
||
'',
|
||
];
|
||
|
||
return lines.filter((line, i) => line !== '' || i === lines.length - 1).join('\n');
|
||
}
|
||
|
||
const vue = await import('vue');
|
||
writeFileSync(new URL('vue.js', out), shim('vue', Object.keys(vue), 'default' in vue && vue.default !== undefined));
|
||
|
||
// Inertia lässt sich ohne Browser nicht laden – Namen aus den Typdefinitionen lesen
|
||
const inertiaTypes = readFileSync(new URL('../node_modules/@inertiajs/vue3/types/index.d.ts', import.meta.url), 'utf8');
|
||
const inertiaNames = [...inertiaTypes.matchAll(/export\s+(?:\{([^}]*)\}|(?:declare\s+)?(?:const|function|class)\s+(\w+))/g)]
|
||
.flatMap((m) => (m[1] ? m[1].split(',').map((s) => s.trim().split(/\s+as\s+/).pop()) : [m[2]]))
|
||
.filter((n) => n && !/^type\s/.test(n));
|
||
writeFileSync(new URL('inertia.js', out), shim('@inertiajs/vue3', inertiaNames, false));
|
||
|
||
const ui = readFileSync(new URL('../resources/js/sdk/ui.js', import.meta.url), 'utf8');
|
||
const uiNames = [...ui.matchAll(/^export\s*\{([^}]*)\}/gm)].flatMap((m) => m[1].split(',').map((s) => s.trim().split(/\s+as\s+/).pop()));
|
||
writeFileSync(new URL('ui.js', out), shim('@inhaus/ui', uiNames, false));
|
||
|
||
// sdk/theme.css: Design-Tokens des Portals für Tailwind in Plugins (aus resources/css/app.css)
|
||
const appCss = readFileSync(new URL('../resources/css/app.css', import.meta.url), 'utf8');
|
||
const tokens = appCss.match(/@theme inline \{[\s\S]*?\n\}/)?.[0];
|
||
writeFileSync(new URL('../sdk/theme.css', import.meta.url), `/*
|
||
* Automatisch erzeugt (scripts/generate-sdk-shims.mjs) – Design-Tokens des Portals.
|
||
* In der style.css eines Plugins: @import "../../inhaus-sdk/theme.css";
|
||
* Farben, Ecken und Schrift folgen so dem Erscheinungsbild der Installation.
|
||
*
|
||
* Tailwind-Klassen in Plugins tragen das Präfix „ih:“ (z. B. ih:grid, ih:lg:grid-cols-2, ih:bg-brand).
|
||
* So kann das CSS eines Plugins nie die Klassen des Portals überschreiben.
|
||
* Nur Hilfsklassen – Grundstile (Preflight) bringt das Portal selbst mit.
|
||
*/
|
||
@import "tailwindcss/theme" layer(theme) prefix(ih);
|
||
@import "tailwindcss/utilities" layer(utilities);
|
||
@custom-variant dark (&:is(.dark *));
|
||
|
||
${tokens}
|
||
`);
|
||
|
||
console.log(`SDK-Module: vue (${Object.keys(vue).length}), @inertiajs/vue3 (${inertiaNames.length}), @inhaus/ui (${uiNames.length})`);
|