update at 2026-03-17 10:37:27
This commit is contained in:
@@ -6,13 +6,28 @@ const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const distDir = path.resolve(currentDir, '../dist');
|
||||
const manifestPath = path.join(distDir, 'dashboard-manifest.json');
|
||||
const clockRegionPath = path.join(distDir, 'clock-region.json');
|
||||
const themesSourcePath = path.resolve(currentDir, '../config/themes.json');
|
||||
const themesDistPath = path.join(distDir, 'themes.json');
|
||||
const themesDir = path.join(distDir, 'themes');
|
||||
const dashboardBaseUrl = 'https://shell.biboer.cn:20001';
|
||||
|
||||
const defaultClockRegion = {
|
||||
x: 313,
|
||||
y: 0,
|
||||
width: 220,
|
||||
height: 220,
|
||||
};
|
||||
const themesSource = JSON.parse(fs.readFileSync(themesSourcePath, 'utf8'));
|
||||
const generatedAt = new Date().toISOString();
|
||||
const defaultVariant = themesSource.themes.find((theme) => theme.id === themesSource.defaultThemeId)?.variants?.[themesSource.defaultOrientation];
|
||||
const defaultDeviceClock = defaultVariant ? toDeviceClock(defaultVariant, themesSource.defaultOrientation) : null;
|
||||
const defaultClockRegion = defaultVariant
|
||||
? {
|
||||
x: defaultDeviceClock.x,
|
||||
y: defaultDeviceClock.y,
|
||||
width: defaultDeviceClock.width,
|
||||
height: defaultDeviceClock.height,
|
||||
}
|
||||
: {
|
||||
x: 313,
|
||||
y: 0,
|
||||
width: 220,
|
||||
height: 220,
|
||||
};
|
||||
|
||||
const clockRegion = fs.existsSync(clockRegionPath)
|
||||
? {
|
||||
@@ -22,10 +37,15 @@ const clockRegion = fs.existsSync(clockRegionPath)
|
||||
: defaultClockRegion;
|
||||
|
||||
const manifest = {
|
||||
theme: {
|
||||
id: themesSource.defaultThemeId,
|
||||
orientation: themesSource.defaultOrientation,
|
||||
themesUrl: `${dashboardBaseUrl}/themes.json`,
|
||||
},
|
||||
background: {
|
||||
path: 'kindlebg.png',
|
||||
url: 'https://shell.biboer.cn:20001/kindlebg.png',
|
||||
updatedAt: new Date().toISOString(),
|
||||
url: `${dashboardBaseUrl}/kindlebg.png`,
|
||||
updatedAt: generatedAt,
|
||||
refreshIntervalMinutes: 120,
|
||||
},
|
||||
clockRegion,
|
||||
@@ -45,6 +65,67 @@ const manifest = {
|
||||
},
|
||||
};
|
||||
|
||||
const themesIndex = {
|
||||
updatedAt: generatedAt,
|
||||
defaultThemeId: themesSource.defaultThemeId,
|
||||
defaultOrientation: themesSource.defaultOrientation,
|
||||
themes: themesSource.themes.map((theme) => ({
|
||||
id: theme.id,
|
||||
label: theme.label,
|
||||
configUrl: `${dashboardBaseUrl}/themes/${theme.id}.json`,
|
||||
orientations: Object.keys(theme.variants),
|
||||
})),
|
||||
};
|
||||
|
||||
function toDeviceClock(variant, orientation) {
|
||||
if (orientation !== 'landscape') {
|
||||
return {
|
||||
...variant.clock,
|
||||
rotationDegrees: 0,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...variant.clock,
|
||||
x: variant.viewport.height - (variant.clock.y + variant.clock.height),
|
||||
y: variant.clock.x,
|
||||
width: variant.clock.height,
|
||||
height: variant.clock.width,
|
||||
rotationDegrees: 90,
|
||||
};
|
||||
}
|
||||
|
||||
function buildThemeConfig(theme) {
|
||||
return {
|
||||
id: theme.id,
|
||||
label: theme.label,
|
||||
updatedAt: generatedAt,
|
||||
variants: Object.fromEntries(
|
||||
Object.entries(theme.variants).map(([orientation, variant]) => [
|
||||
orientation,
|
||||
{
|
||||
devicePlacement: variant.devicePlacement,
|
||||
background: {
|
||||
path: variant.backgroundPath,
|
||||
url: `${dashboardBaseUrl}/${variant.backgroundPath}`,
|
||||
refreshIntervalMinutes: 120,
|
||||
},
|
||||
clock: toDeviceClock(variant, orientation),
|
||||
},
|
||||
]),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
fs.mkdirSync(distDir, { recursive: true });
|
||||
fs.mkdirSync(themesDir, { recursive: true });
|
||||
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
|
||||
fs.writeFileSync(themesDistPath, `${JSON.stringify(themesIndex, null, 2)}\n`, 'utf8');
|
||||
|
||||
for (const theme of themesSource.themes) {
|
||||
const themePath = path.join(themesDir, `${theme.id}.json`);
|
||||
fs.writeFileSync(themePath, `${JSON.stringify(buildThemeConfig(theme), null, 2)}\n`, 'utf8');
|
||||
}
|
||||
|
||||
console.log(`Wrote ${manifestPath}`);
|
||||
console.log(`Wrote ${themesDistPath}`);
|
||||
|
||||
Reference in New Issue
Block a user