mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-02 20:35:50 -05:00
theme sheet order
This commit is contained in:
@@ -17,7 +17,6 @@ _ide_helper_models.php
|
||||
.phpstorm.meta.php
|
||||
.yarn
|
||||
public/assets/manifest.json
|
||||
public/assets/core-classes.json
|
||||
|
||||
# For local development with docker
|
||||
# Remove if we ever put the Dockerfile in the repo
|
||||
|
||||
+15
-19
@@ -79,9 +79,11 @@ While the last command runs on a panel with `APP_DEBUG=true`, a stylesheet chang
|
||||
without a reload, and any other change reloads them. To try a theme without switching everyone to it,
|
||||
skip `p:theme:activate` and choose **Preview for me** on **Admin > Themes**.
|
||||
|
||||
At this level you edit only `src/theme.css`. It starts with `@import '@pterodactyl/sdk/theme-entry.css';`,
|
||||
the panel's whole stylesheet: Tailwind, the tokens, and every class the panel uses. Your rules come after
|
||||
it, so they win. Write plain Tailwind with no prefix.
|
||||
At this level you edit only `src/theme.css`. The panel links its own stylesheet, then the theme's, so your
|
||||
rules win. A stylesheet of plain CSS, such as tokens and `[data-ui]` selectors, needs nothing else. The
|
||||
scaffold's starts with `@import '@pterodactyl/sdk/theme-entry.css';`, which a theme that uses Tailwind
|
||||
classes or `@theme` keeps: it builds the panel's stylesheet with the theme's classes added, so its
|
||||
utilities are ordered with the panel's. Write plain Tailwind with no prefix.
|
||||
|
||||
### What the build writes
|
||||
|
||||
@@ -89,8 +91,8 @@ it, so they win. Write plain Tailwind with no prefix.
|
||||
|
||||
| File | What it is |
|
||||
| --- | --- |
|
||||
| `theme.css` | The stylesheet the panel links in place of its own. |
|
||||
| `theme.json` | What the build was made from: the panel's classes and SDK, the views the theme overrides, and its parents' builds. Doctor and the panel check it. |
|
||||
| `theme.css` | The stylesheet the panel links after its own. |
|
||||
| `theme.json` | The parent themes the stylesheet was built over. Doctor and the panel check it. |
|
||||
| `theme-source.css` and `classes.txt` | The theme's own CSS and the classes its files use, which the build of a [child theme](#building-on-another-theme) brings in. |
|
||||
| `client.js` | From level 2 on, the theme's JavaScript. |
|
||||
|
||||
@@ -98,8 +100,7 @@ it, so they win. Write plain Tailwind with no prefix.
|
||||
|
||||
A **token** is a CSS custom property the panel's classes read. Set one and everything that reads it
|
||||
changes: `--primary` colours primary buttons and selected items, `--radius` sets every rounded corner,
|
||||
and `--spacing` scales every padding, margin and gap. [Tokens](#tokens) lists them all, each with the
|
||||
primitives and views classic reads it in, so you can tell what a change reaches before you make it.
|
||||
and `--spacing` scales every padding, margin and gap. [Tokens](#tokens) lists them all with their roles.
|
||||
|
||||
The colour classes are roles such as `bg-card` and `text-muted-foreground`. Of Tailwind's palette only
|
||||
`white` and `black` remain (`text-white`, `bg-black/15`). Add a colour of your own in `@theme`:
|
||||
@@ -1031,7 +1032,8 @@ test of the chain.
|
||||
```
|
||||
<!-- /sample -->
|
||||
|
||||
The panel links one stylesheet, the nearest in the chain, so a child's stylesheet carries its parents'.
|
||||
The panel links its own stylesheet, then the nearest theme stylesheet in the chain, so a child's stylesheet
|
||||
carries its parents'.
|
||||
A child's build reads `theme.extends`, finds each parent's build, and brings in its `theme-source.css` and
|
||||
`classes.txt` ([what the build writes](#what-the-build-writes)), oldest first, right after the SDK's
|
||||
import. The child's `src/theme.css` stays one import and its own rules, and can use the parents'
|
||||
@@ -1062,9 +1064,8 @@ utilities, variants and fonts:
|
||||
|
||||
The build looks for each parent first in `<extensions>/<id>`, where `extensions` is the panel's extensions
|
||||
directory passed to `defineThemeConfig` (the scaffold writes it), then in `node_modules/<id>`, for a parent
|
||||
installed as a dependency. It records the build of each parent in `dist/theme.json`. Doctor, pack and enable
|
||||
refuse a child built without its parents, and doctor warns when a parent was rebuilt since; rebuild the
|
||||
child then. A parent's `@plugin` is loaded from the child's packages, so install the same plugins.
|
||||
installed as a dependency. It lists the parents it built over in `dist/theme.json`, and doctor, pack and
|
||||
enable refuse a child built without them. Rebuild the child when a parent changes. A parent's `@plugin` is loaded from the child's packages, so install the same plugins.
|
||||
|
||||
The child's tests render the chain with `themes`, importing each parent's built entry, which
|
||||
`pterodactylTestAliases({ extensions })` finds where the build does and the SDK types:
|
||||
@@ -1199,9 +1200,8 @@ rendered = renderView('layout.app', {
|
||||
|
||||
### Doctor and pack
|
||||
|
||||
`npm run doctor` runs `p:extension:doctor` on the theme: the manifest, the build, view names,
|
||||
whether the stylesheet was built against this panel's classes, and for a child theme, over the
|
||||
current builds of its parents.
|
||||
`npm run doctor` runs `p:extension:doctor` on the theme: the manifest, the build, and for a child
|
||||
theme, whether the stylesheet was built over its parents.
|
||||
|
||||
`npm run pack` writes a `.pteroext` archive to install on another panel, replacing an earlier one;
|
||||
`.gitignore` leaves archives out of the repository. The build writes no source maps, which would embed
|
||||
@@ -1253,10 +1253,6 @@ What a theme can rely on when it draws behind or around the panel, such as a bac
|
||||
`[extensions] "<layer id>" failed in view "<view>": <error>`.
|
||||
- **Safe mode.** Opening any page with `?safe_mode=1` renders that session with classic and no extension
|
||||
bundles; `?safe_mode=0` leaves it. The Themes page links to both.
|
||||
- **Stylesheet fallback.** `dist/theme.json` records the hash of the panel classes the stylesheet was
|
||||
built with. When the panel's differ because the panel was updated after the build, the panel links its
|
||||
own stylesheet and the theme's over it, so classes added since still exist. Doctor and pack warn;
|
||||
rebuilding with the panel's SDK makes the theme's stylesheet the only one again.
|
||||
- **Compatibility.** An active theme whose `requires` no longer match after an update is marked failed
|
||||
on the Extensions page, and every page renders classic until it is updated.
|
||||
|
||||
@@ -1268,7 +1264,7 @@ disabled or removed.
|
||||
Declare `requires.panel` and `requires.sdk` (`>=2.0.0-beta.5 <3.0`). During the 2.0 betas, view names,
|
||||
models, parts and fixtures, and the primitives' parts and state, can change in any beta. Build against
|
||||
the SDK of the panel you target. After updating it, `npm run typecheck` catches a changed model field
|
||||
and `npm run doctor` an overridden view that no longer exists; then rebuild. From 2.0, additions to the
|
||||
or an overridden view that no longer exists; then rebuild. From 2.0, additions to the
|
||||
contract are minor versions and removals major.
|
||||
|
||||
## Reference
|
||||
|
||||
@@ -32,34 +32,6 @@ it('compiles the stylesheets of the level samples', async () => {
|
||||
expect(await compile('settings/src/theme.css')).toContain("[data-sunrise-density='compact']");
|
||||
}, 120_000);
|
||||
|
||||
it('builds the sample theme entry and records the views it overrides', async () => {
|
||||
const outDir = mkdtempSync(resolve(tmpdir(), 'aurora-build-'));
|
||||
try {
|
||||
await build({
|
||||
...defineThemeConfig({ entry: resolve(aurora, 'src/theme.tsx'), outDir }),
|
||||
configFile: false,
|
||||
logLevel: 'silent',
|
||||
});
|
||||
|
||||
const info = JSON.parse(readFileSync(resolve(outDir, 'theme.json'), 'utf8'));
|
||||
|
||||
expect(info.views).toEqual([
|
||||
'layout.auth',
|
||||
'auth.loginForm',
|
||||
'layout.app',
|
||||
'layout.server',
|
||||
'server.power',
|
||||
'page.server.console',
|
||||
'server.terminal',
|
||||
'server.stats',
|
||||
'dashboard.serverList',
|
||||
'dashboard.serverCard',
|
||||
]);
|
||||
} finally {
|
||||
rmSync(outDir, { recursive: true, force: true });
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
it("builds the child theme sample over Aurora's stylesheet and classes", async () => {
|
||||
const extensions = mkdtempSync(resolve(tmpdir(), 'extensions-'));
|
||||
const child = resolve(samples, 'child-theme');
|
||||
@@ -100,8 +72,8 @@ it("builds the child theme sample over Aurora's stylesheet and classes", async (
|
||||
expect(css).toMatch(/font-family:\s*['"]?Aurora Sans/);
|
||||
expect(css.search(/data-sunset-glow=['"]?true['"]?\]\s*\.glass/)).toBeGreaterThan(css.search(/\.glass\s*\{/));
|
||||
expect(css.search(/\.glass\s*\{/)).toBeGreaterThan(-1);
|
||||
expect(JSON.parse(readFileSync(resolve(extensions, 'aurora-sunset/dist/theme.json'), 'utf8')).parents).toEqual({
|
||||
aurora: JSON.parse(parent('theme.json')).build,
|
||||
expect(JSON.parse(readFileSync(resolve(extensions, 'aurora-sunset/dist/theme.json'), 'utf8'))).toEqual({
|
||||
parents: ['aurora'],
|
||||
});
|
||||
} finally {
|
||||
rmSync(extensions, { recursive: true, force: true });
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* The panel stylesheet: tokens, base styles, custom variants and utilities, and component CSS.
|
||||
* The panel builds it from resources/scripts/assets/tailwind.css; a theme builds it from
|
||||
* theme-entry.css with its own classes added, and that build replaces the panel's.
|
||||
* The panel builds it from resources/scripts/assets/tailwind.css; a theme that uses Tailwind builds
|
||||
* it from theme-entry.css with its own classes added, and the panel links that build after its own.
|
||||
*/
|
||||
@import 'tailwindcss';
|
||||
@import './theme-tokens.css';
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
/*
|
||||
* Theme entry point. A theme's src/theme.css starts with
|
||||
* Theme entry point. The panel links its own stylesheet, then the theme's. A theme stylesheet that
|
||||
* uses Tailwind starts with
|
||||
*
|
||||
* @import '@pterodactyl/sdk/theme-entry.css';
|
||||
*
|
||||
* which builds the panel stylesheet together with every class the panel's own markup uses
|
||||
* (core-classes.txt, generated with the panel and shipped in this package) and, through
|
||||
* Tailwind's source detection, the theme's own. Write unprefixed Tailwind after it.
|
||||
* Tailwind's source detection, the theme's own, so the theme's utilities are ordered with the
|
||||
* panel's. Write unprefixed Tailwind after it. A stylesheet of plain CSS needs no import.
|
||||
*/
|
||||
@import './panel.css';
|
||||
@source './core-classes.txt';
|
||||
|
||||
Vendored
-1
@@ -20,7 +20,6 @@ export interface ThemeBootstrap {
|
||||
schemes: ThemeScheme[];
|
||||
safeMode: boolean;
|
||||
preview: boolean;
|
||||
stylesheetFallback: boolean;
|
||||
}
|
||||
export declare const getBootstrapUser: () => UserData | undefined;
|
||||
export declare const endBootstrapSession: () => void;
|
||||
|
||||
+24
-74
@@ -19,7 +19,6 @@ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from
|
||||
import { createRequire } from 'node:module';
|
||||
import { dirname, isAbsolute, parse, relative, resolve, sep } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { parseAst } from 'vite';
|
||||
import { packageRoot, themeParents } from './theme-chain.mjs';
|
||||
|
||||
/** Modules provided by the panel's import map - never bundled into extensions. */
|
||||
@@ -72,40 +71,7 @@ const extensionStyles = () => ({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* The view names a `defineTheme({ views: { ... } })` call lists, when they are plain keys;
|
||||
* null when the call is there but its views cannot be read without running it.
|
||||
*/
|
||||
function definedViews(program) {
|
||||
const found = [];
|
||||
const key = (property) =>
|
||||
property.type === 'Property' && !property.computed ? String(property.key.name ?? property.key.value) : null;
|
||||
const read = (theme) => {
|
||||
if (theme?.type !== 'ObjectExpression' || theme.properties.some((property) => key(property) === null)) {
|
||||
return null;
|
||||
}
|
||||
const views = theme.properties.find((property) => key(property) === 'views');
|
||||
if (views === undefined) return [];
|
||||
const keys = views.value.type === 'ObjectExpression' ? views.value.properties.map(key) : [null];
|
||||
|
||||
return keys.includes(null) ? null : keys;
|
||||
};
|
||||
const visit = (node) => {
|
||||
if (Array.isArray(node)) return node.forEach(visit);
|
||||
if (!node || typeof node.type !== 'string') return;
|
||||
const callee = node.type === 'CallExpression' ? node.callee : null;
|
||||
if ((callee?.type === 'Identifier' ? callee.name : callee?.property?.name) === 'defineTheme') {
|
||||
found.push(read(node.arguments[0]));
|
||||
}
|
||||
for (const value of Object.values(node)) if (value && typeof value === 'object') visit(value);
|
||||
};
|
||||
visit(program);
|
||||
return found;
|
||||
}
|
||||
|
||||
const sdkDirectory = fileURLToPath(new URL('.', import.meta.url));
|
||||
const sdkVersion = () => JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version;
|
||||
const digest = (...parts) => createHash('sha256').update(parts.join('\0')).digest('hex').slice(0, 16);
|
||||
const quote = (value) => JSON.stringify(value);
|
||||
|
||||
/** A path a stylesheet in `from` can reference `to` by, with forward slashes. */
|
||||
@@ -198,16 +164,15 @@ function ownStylesheet(file, { postcss, asset, sources }, seen = new Set()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The theme build: dist/theme.json, which the panel reads to decide whether the theme stylesheet can
|
||||
* replace its own, and what a child theme builds on, dist/theme-source.css and dist/classes.txt.
|
||||
* When the theme extends others, their stylesheets and classes come into its own after the SDK's.
|
||||
* The theme build: what a child theme builds on, dist/theme-source.css and dist/classes.txt, and
|
||||
* dist/theme.json, which lists the parents the stylesheet was built over. When the theme extends
|
||||
* others, their stylesheets and classes come into its own after the SDK's.
|
||||
*/
|
||||
function themeBuild({ entry, stylesheet, extensions }, inherited) {
|
||||
let config;
|
||||
let root;
|
||||
let sheet;
|
||||
let parents = [];
|
||||
let views = [];
|
||||
|
||||
return [
|
||||
{
|
||||
@@ -222,20 +187,22 @@ function themeBuild({ entry, stylesheet, extensions }, inherited) {
|
||||
root = packageRoot(from) ?? from;
|
||||
},
|
||||
buildStart() {
|
||||
parents = sheet ? themeParents({ root, extensions }).map((parent) => inherit(this, parent)) : [];
|
||||
parents = sheet
|
||||
? themeParents({ root, extensions })
|
||||
.map((parent) => inherit(this, parent))
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
},
|
||||
transform(code, id) {
|
||||
if (id.split('?')[0] !== sheet || !parents.some((parent) => parent.build)) return null;
|
||||
if (id.split('?')[0] !== sheet || !parents.length) return null;
|
||||
|
||||
const postcss = dependency(root, 'postcss');
|
||||
const css = postcss.parse(code, { from: sheet });
|
||||
const imports = parents
|
||||
.filter((parent) => parent.build)
|
||||
.map(
|
||||
(parent) =>
|
||||
`@import ${quote(cssPath(dirname(sheet), parent.stylesheet))};\n` +
|
||||
`@source ${quote(cssPath(dirname(sheet), parent.classes))};`
|
||||
);
|
||||
const imports = parents.map(
|
||||
(parent) =>
|
||||
`@import ${quote(cssPath(dirname(sheet), parent.stylesheet))};\n` +
|
||||
`@source ${quote(cssPath(dirname(sheet), parent.classes))};`
|
||||
);
|
||||
const inherited = postcss.parse(`/* The themes this one extends, oldest first. */\n${imports.join('\n')}`).nodes;
|
||||
const sdk = css.nodes.find(
|
||||
(node) => node.type === 'atrule' && node.name === 'import' && /^\s*(?:url\(\s*)?['"]?@pterodactyl\/sdk\//.test(node.params)
|
||||
@@ -248,14 +215,6 @@ function themeBuild({ entry, stylesheet, extensions }, inherited) {
|
||||
{
|
||||
name: 'pterodactyl-theme-build-info',
|
||||
enforce: 'post',
|
||||
buildStart() {
|
||||
views = [];
|
||||
},
|
||||
transform(code, id) {
|
||||
if (!id.includes('/node_modules/') && /\bdefineTheme\b/.test(code))
|
||||
views.push(...definedViews(parseAst(code)));
|
||||
return null;
|
||||
},
|
||||
generateBundle(_options, bundle) {
|
||||
for (const chunk of Object.values(bundle)) {
|
||||
if (
|
||||
@@ -296,16 +255,7 @@ function themeBuild({ entry, stylesheet, extensions }, inherited) {
|
||||
],
|
||||
});
|
||||
const classes = `${[...new Set(scanner.scan())].sort().join('\n')}\n`;
|
||||
const manifest = new URL('./core-classes.txt', import.meta.url);
|
||||
const info = {
|
||||
core: existsSync(manifest)
|
||||
? createHash('sha256').update(readFileSync(manifest)).digest('hex').slice(0, 16)
|
||||
: null,
|
||||
sdk: sdkVersion(),
|
||||
...(views.length === 1 && views[0] !== null ? { views: views[0] } : {}),
|
||||
build: digest(source, classes),
|
||||
...(parents.length ? { parents: Object.fromEntries(parents.map(({ id, build }) => [id, build])) } : {}),
|
||||
};
|
||||
const info = { parents: parents.map(({ id }) => id) };
|
||||
this.emitFile({ type: 'asset', fileName: 'theme-source.css', source });
|
||||
this.emitFile({ type: 'asset', fileName: 'classes.txt', source: classes });
|
||||
this.emitFile({ type: 'asset', fileName: 'theme.json', source: `${JSON.stringify(info, null, 4)}\n` });
|
||||
@@ -315,16 +265,16 @@ function themeBuild({ entry, stylesheet, extensions }, inherited) {
|
||||
|
||||
/**
|
||||
* A parent's build, its stylesheet copied into Vite's cache with absolute url()s: Tailwind inlines
|
||||
* imports without rebasing their urls, and rebuilds when an imported file changes.
|
||||
* imports without rebasing their urls, and rebuilds when an imported file changes. Null for a
|
||||
* parent with neither styles nor JavaScript, which gives the child nothing to build over.
|
||||
*/
|
||||
function inherit(context, parent) {
|
||||
const dist = (file) => resolve(parent.directory, 'dist', file);
|
||||
if (!parent.manifest.ui && !parent.manifest.theme?.stylesheet) return { ...parent, build: null };
|
||||
if (!parent.manifest.ui && !parent.manifest.theme?.stylesheet) return null;
|
||||
|
||||
const info = existsSync(dist('theme.json')) ? JSON.parse(readFileSync(dist('theme.json'), 'utf8')) : null;
|
||||
if (!info?.build || !existsSync(dist('theme-source.css')) || !existsSync(dist('classes.txt'))) {
|
||||
if (!existsSync(dist('theme-source.css')) || !existsSync(dist('classes.txt'))) {
|
||||
throw new Error(
|
||||
`Theme "${parent.id}" in ${parent.directory} has no build to extend: build it with @pterodactyl/sdk ${sdkVersion()}, which writes dist/theme-source.css and dist/classes.txt.`
|
||||
`Theme "${parent.id}" in ${parent.directory} has no build to extend: build it with @pterodactyl/sdk, which writes dist/theme-source.css and dist/classes.txt.`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -339,17 +289,17 @@ function themeBuild({ entry, stylesheet, extensions }, inherited) {
|
||||
mkdirSync(dirname(copy), { recursive: true });
|
||||
writeFileSync(copy, text);
|
||||
}
|
||||
for (const file of ['theme.json', 'theme-source.css', 'classes.txt']) context.addWatchFile(dist(file));
|
||||
for (const file of ['theme-source.css', 'classes.txt']) context.addWatchFile(dist(file));
|
||||
inherited.add(`${relative(config.root, dist('')).split(sep).join('/')}/`);
|
||||
|
||||
return { ...parent, build: info.build, stylesheet: copy, classes: dist('classes.txt') };
|
||||
return { ...parent, stylesheet: copy, classes: dist('classes.txt') };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a theme: `entry` (optional) to dist/client.js with the shared modules external and
|
||||
* no stylesheet loader, `stylesheet` to dist/theme.css with Tailwind, and dist/theme.json,
|
||||
* dist/theme-source.css and dist/classes.txt for themes that extend this one.
|
||||
* no stylesheet loader, `stylesheet` to dist/theme.css with Tailwind, dist/theme-source.css and
|
||||
* dist/classes.txt for themes that extend this one, and dist/theme.json, which lists its parents.
|
||||
* When extension.json extends another theme, its stylesheet and classes are built in after the
|
||||
* SDK's. Parents are found in `extensions` (the panel's extensions directory), then node_modules.
|
||||
* `sourcemap` is off: a map embeds the theme's sources, so turn it on only for builds you keep.
|
||||
|
||||
@@ -42,17 +42,7 @@ it('builds a theme entry without a style loader, its stylesheet and its build in
|
||||
expect(dist('client.js')).toContain('from"@pterodactyl/sdk/theme"');
|
||||
expect(dist('client.js')).not.toContain('document.head.append');
|
||||
expect(dist('theme.css')).toContain('.aurora-frame');
|
||||
const info = JSON.parse(dist('theme.json'));
|
||||
|
||||
// The core class manifest is generated with the panel build, so a bare checkout has none.
|
||||
expect(info.core === null || /^[a-f0-9]{16}$/.test(info.core)).toBe(true);
|
||||
expect(info).toEqual({
|
||||
core: info.core,
|
||||
sdk: JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version,
|
||||
views: ['layout.app', 'page', 'server.power'],
|
||||
build: info.build,
|
||||
});
|
||||
expect(info.build).toMatch(/^[a-f0-9]{16}$/);
|
||||
expect(JSON.parse(dist('theme.json'))).toEqual({ parents: [] });
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
@@ -119,7 +109,7 @@ it('ships its own stylesheet and class candidates for the themes that extend it'
|
||||
expect(font).toBeDefined();
|
||||
expect(theme.dist('theme.css')).toContain(`url(./${font})`);
|
||||
expect(theme.dist('classes.txt').split('\n')).toEqual(expect.arrayContaining(['glow', 'sm:rounded-3xl']));
|
||||
expect(JSON.parse(theme.dist('theme.json'))).not.toHaveProperty('parents');
|
||||
expect(JSON.parse(theme.dist('theme.json'))).toEqual({ parents: [] });
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
@@ -131,7 +121,6 @@ it("builds a child theme over its parent's stylesheet and classes, which it reco
|
||||
const child = themePackage(resolve(directory, 'child'));
|
||||
const parent = (path: string, contents: string | Buffer) => child.write(`../extensions/parent/${path}`, contents);
|
||||
parent('extension.json', JSON.stringify({ id: 'parent', type: 'theme', theme: { stylesheet: 'dist/theme.css' } }));
|
||||
parent('dist/theme.json', JSON.stringify({ core: null, build: '0123456789abcdef' }));
|
||||
parent('dist/Brand.AbCd1234.woff2', Buffer.alloc(8192, 1));
|
||||
parent('dist/classes.txt', 'glow\nsm:rounded-3xl\n');
|
||||
parent(
|
||||
@@ -149,7 +138,7 @@ it("builds a child theme over its parent's stylesheet and classes, which it reco
|
||||
expect(css.indexOf('.child-rule')).toBeGreaterThan(css.indexOf('.parent-rule'));
|
||||
// The parent's font is copied from its build under the name its build hashed, not hashed again.
|
||||
expect(css).toContain('url(./Brand.AbCd1234.woff2)');
|
||||
expect(JSON.parse(child.dist('theme.json')).parents).toEqual({ parent: '0123456789abcdef' });
|
||||
expect(JSON.parse(child.dist('theme.json'))).toEqual({ parents: ['parent'] });
|
||||
|
||||
rmSync(resolve(directory, 'extensions/parent/dist/theme-source.css'));
|
||||
await expect(child.build(options)).rejects.toThrow('Theme "parent" in');
|
||||
@@ -180,17 +169,9 @@ it('ships no source map, which would embed the theme sources, unless asked to',
|
||||
}
|
||||
});
|
||||
|
||||
it('leaves out views it cannot read without running the theme, and builds a stylesheet-only theme', async () => {
|
||||
it('builds a stylesheet-only theme', async () => {
|
||||
const directory = mkdtempSync(resolve(tmpdir(), 'theme-build-'));
|
||||
try {
|
||||
const computed = await buildTheme(directory, {
|
||||
'theme.css': '.a { color: red; }',
|
||||
'theme.jsx':
|
||||
"import { defineTheme } from '@pterodactyl/sdk/theme'; const views = {}; export default defineTheme({ views });",
|
||||
});
|
||||
expect(JSON.parse(computed('theme.json'))).not.toHaveProperty('views');
|
||||
|
||||
rmSync(resolve(directory, 'dist'), { recursive: true, force: true });
|
||||
const stylesheet = await buildTheme(directory, { 'theme.css': '.b { color: blue; }' }, false);
|
||||
expect(stylesheet('theme.css')).toContain('.b');
|
||||
expect(() => stylesheet('client.js')).toThrow();
|
||||
|
||||
@@ -21,7 +21,6 @@ export interface ThemeBootstrap {
|
||||
schemes: ThemeScheme[];
|
||||
safeMode: boolean;
|
||||
preview: boolean;
|
||||
stylesheetFallback: boolean;
|
||||
}
|
||||
|
||||
interface ExtendedWindow extends Window {
|
||||
@@ -79,7 +78,6 @@ const classicTheme: ThemeBootstrap = {
|
||||
schemes: ['dark'],
|
||||
safeMode: false,
|
||||
preview: false,
|
||||
stylesheetFallback: false,
|
||||
};
|
||||
|
||||
export const getBootstrapTheme = (): ThemeBootstrap => ({
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Writes every Tailwind class candidate in the panel's markup to packages/sdk/core-classes.txt,
|
||||
// which a theme stylesheet sources so it can replace the panel's, and the list's hash beside
|
||||
// the build, where Blade compares it with a theme's dist/theme.json.
|
||||
// Writes every Tailwind class candidate in the panel's markup to packages/sdk/core-classes.txt, which
|
||||
// theme-entry.css sources so a theme's Tailwind build orders its utilities with the panel's.
|
||||
import { Scanner } from '@tailwindcss/oxide';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { mkdirSync, writeFileSync } from 'node:fs';
|
||||
import { writeFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = fileURLToPath(new URL('..', import.meta.url));
|
||||
@@ -13,11 +11,5 @@ const scanner = new Scanner({
|
||||
{ base: `${root}resources/views`, pattern: '**/*.blade.php', negated: false },
|
||||
],
|
||||
});
|
||||
const contents = `${[...new Set(scanner.scan())].sort().join('\n')}\n`;
|
||||
|
||||
writeFileSync(`${root}packages/sdk/core-classes.txt`, contents);
|
||||
mkdirSync(`${root}public/assets`, { recursive: true });
|
||||
writeFileSync(
|
||||
`${root}public/assets/core-classes.json`,
|
||||
`${JSON.stringify({ hash: createHash('sha256').update(contents).digest('hex').slice(0, 16) })}\n`
|
||||
);
|
||||
writeFileSync(`${root}packages/sdk/core-classes.txt`, `${[...new Set(scanner.scan())].sort().join('\n')}\n`);
|
||||
|
||||
Reference in New Issue
Block a user