Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ window.__ModuleLoader__.load({ id: 'ming-life', factory: (require) => {
const STORE_KEY = 'dsh.ming-life.v1'
const API = '/api/ming-life'
const WORKBENCH_ID = 'ming-life'
// Must equal package.json and workbench.json; tests/test-original-adapter.mjs checks it.
const WORKBENCH_VERSION = '0.1.1'

const css = `
.ml-btn{width:100%;height:32px;display:flex;align-items:center;gap:8px;padding:0 9px;border:0;border-radius:8px;
Expand Down Expand Up @@ -395,7 +397,7 @@ window.__ModuleLoader__.load({ id: 'ming-life', factory: (require) => {
ctx.effect(() => ctx.desktopWorkbenches.register({
id: WORKBENCH_ID, title: '玄学人生工作台', icon: '☯', panelTitle: '人生档案',
description: '本地排盘、人生档案与原版自动解读流程。',
version: '1.2.0', author: 'dataelement / liqingb0220-stack', embedded: true,
version: WORKBENCH_VERSION, author: 'dataelement / liqingb0220-stack', embedded: true,
initialization: 'empty', layout: { businessSide: 'left', businessWidth: 0.65 }
}, Panel))
ctx.effect(() => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"scripts",
"tests",
"cordis.patch.yml",
"workbench.json",
"README.md",
"LICENSE",
"vite.config.js",
Expand Down
5 changes: 4 additions & 1 deletion scripts/check-distribution.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ try {
assert.equal(packs.length, 1)
execFileSync('tar', ['-xzf', path.join(directory, packs[0]), '-C', directory])
const root = path.join(directory, 'package')
for (const file of ['package.json', 'dsh/index.js', 'dsh/engines.mjs', 'lib/client.js', 'cordis.patch.yml', 'dist/index.html']) {
for (const file of ['package.json', 'dsh/index.js', 'dsh/engines.mjs', 'lib/client.js', 'cordis.patch.yml', 'workbench.json', 'dist/index.html']) {
assert.ok((await stat(path.join(root, file))).isFile(), `Missing packaged file: ${file}`)
}
const manifest = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'))
assert.equal(manifest.name, 'ming-life')
const workbench = JSON.parse(await readFile(path.join(root, 'workbench.json'), 'utf8'))
assert.equal(workbench.id, 'ming-life')
assert.equal(workbench.version, manifest.version)
assert.equal(manifest.repository?.url, 'git+https://github.com/dataelement/dsh-ming-life.git')
assert.equal(manifest.exports?.['./client'], './lib/client.js')
assert.equal(manifest.dsh?.bundle?.patch, './cordis.patch.yml')
Expand Down
21 changes: 21 additions & 0 deletions tests/test-original-adapter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,24 @@ test('host assets and data routes fail closed through native authentication', as
assert.equal(status, 401)
}
})

test('registration, package.json and workbench.json agree on ID and version', async () => {
const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'))
const manifest = JSON.parse(await readFile(new URL('../workbench.json', import.meta.url), 'utf8'))
let descriptor
const ctx = { effect: fn => fn(), sessions: { list: { getSnapshot: () => ({}), subscribe: () => () => {} }, scope: () => ({ get: () => null }) },
desktopWorkbenches: { getSnapshot: () => ({ state: { added: [], sessionBindings: {} } }), register: value => { descriptor = value; return () => {} } } }
let plugin
vm.runInNewContext(source, {
window: { location: { origin: 'http://local' }, __ModuleLoader__: { load: spec => { plugin = spec.factory(() => ({ createElement() {} })) } } },
document: { createElement: () => ({ dataset: {} }), head: { appendChild() {} }, querySelector: () => null },
localStorage: { getItem: () => '{}', setItem() {} }, fetch: async () => ({ ok: true, json: async () => ({ projects: [] }) }),
setTimeout: () => 1, clearTimeout() {}, setInterval: () => 1, clearInterval() {}
})
plugin.apply(ctx)
assert.equal(descriptor.version, pkg.version)
assert.equal(manifest.version, pkg.version)
assert.equal(manifest.id, descriptor.id)
assert.equal(manifest.icon, descriptor.icon)
assert.ok(pkg.files.includes('workbench.json'))
})
14 changes: 14 additions & 0 deletions workbench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"schemaVersion": 1,
"id": "ming-life",
"title": "玄学人生工作台",
"description": "本地排盘、人生档案与原版自动解读流程。",
"version": "0.1.1",
"icon": "☯",
"entry": "./lib/client.js",
"compatibility": {
"desktopWorkbenches": "^0.1.0",
"harness": "^0.1.5-rc.2"
},
"initialization": "empty"
}
Loading