20 lines
1.0 KiB
JavaScript
20 lines
1.0 KiB
JavaScript
// Headless bring-up shared by the CLI and the tests.
|
|
import { readFile } from 'node:fs/promises';
|
|
import { join, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { Desktop } from './desktop.mjs';
|
|
import { createPlatform } from './platform.mjs';
|
|
import { tokensFromJson } from './theme.mjs';
|
|
import { nodeLoader } from './loader-node.mjs';
|
|
|
|
export const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
|
|
export async function bootDesktop({ configPath = join(ROOT, 'config', 'desktop.json'), now, buildDir = join(ROOT, 'build') } = {}) {
|
|
const config = JSON.parse(await readFile(configPath, 'utf8'));
|
|
const apps = JSON.parse(await readFile(join(ROOT, 'config', 'apps.json'), 'utf8'));
|
|
const themeJson = JSON.parse(await readFile(join(ROOT, 'config', 'themes', `${config.theme}.json`), 'utf8'));
|
|
const platform = createPlatform({ apps, tokens: tokensFromJson(themeJson), now });
|
|
const desktop = await new Desktop({ config, loader: nodeLoader(buildDir), platform }).start();
|
|
return { desktop, platform, config };
|
|
}
|