47 lines
2.5 KiB
JavaScript
47 lines
2.5 KiB
JavaScript
import { readFile } from 'node:fs/promises'
|
|
import { createRequire } from 'node:module'
|
|
import { homedir } from 'node:os'
|
|
import { dirname, join, resolve } from 'node:path'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
const profileDir = resolve(process.env.DSH_PROFILE_DIR ?? join(homedir(), '.dsh', 'profiles', 'desktop'))
|
|
const profilePath = join(profileDir, 'package.json')
|
|
const profile = JSON.parse(await readFile(profilePath, 'utf8'))
|
|
|
|
function assert(condition, message) {
|
|
if (!condition) throw new Error(message)
|
|
}
|
|
|
|
for (const name of ['dsh-sansheng-liubu-mode', 'dsh-sansheng-liubu-panel']) {
|
|
assert(profile.dependencies?.[name]?.startsWith('link:'), `${name} must be a link dependency`)
|
|
assert(profile.dsh?.profile?.bundles?.includes(name), `${name} must be listed in dsh.profile.bundles`)
|
|
}
|
|
|
|
const requireFromProfile = createRequire(join(profileDir, 'package.json'))
|
|
const modeManifestPath = requireFromProfile.resolve('dsh-sansheng-liubu-mode/package.json')
|
|
const panelManifestPath = requireFromProfile.resolve('dsh-sansheng-liubu-panel/package.json')
|
|
const modeManifest = JSON.parse(await readFile(modeManifestPath, 'utf8'))
|
|
const panelManifest = JSON.parse(await readFile(panelManifestPath, 'utf8'))
|
|
|
|
assert(modeManifest.dsh?.bundle?.patch, 'mode package must declare dsh.bundle.patch')
|
|
assert(panelManifest.dsh?.bundle?.patch, 'panel package must declare dsh.bundle.patch')
|
|
assert(panelManifest.dsh?.client?.platform === 'web', 'panel must declare a web client')
|
|
assert(panelManifest.dsh?.client?.inject?.length > 0, 'panel must declare client injections')
|
|
|
|
const mode = await import(pathToFileURL(join(dirname(modeManifestPath), modeManifest.main)).href)
|
|
const panel = await import(pathToFileURL(join(dirname(panelManifestPath), panelManifest.main)).href)
|
|
assert(typeof mode.apply === 'function', 'mode host entry must export apply')
|
|
assert(typeof panel.apply === 'function', 'panel host entry must export apply')
|
|
|
|
const clientSource = await readFile(join(dirname(panelManifestPath), 'lib', 'client.js'), 'utf8')
|
|
assert(clientSource.includes('id: "dsh-sansheng-liubu-panel"'), 'client bundle id must match the panel package name')
|
|
assert(clientSource.includes('"sidebar.panellist"'), 'client bundle must register the sidebar entry')
|
|
assert(clientSource.includes('name: "main"') && clientSource.includes('key: PANEL_ID'), 'client bundle must register the matching main panel')
|
|
|
|
console.log(JSON.stringify({
|
|
profile: profilePath,
|
|
mode: modeManifestPath,
|
|
panel: panelManifestPath,
|
|
bundles: profile.dsh.profile.bundles.filter((name) => name.startsWith('dsh-sansheng-')),
|
|
}, null, 2))
|