This repository was archived by the owner on Apr 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeta.ts
More file actions
64 lines (55 loc) · 1.58 KB
/
meta.ts
File metadata and controls
64 lines (55 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { PluginMetaInput } from '@zotero-plugin-registry/shared'
import path from 'node:path'
import fs from 'fs-extra'
import { PluginsRoot } from '../constant.ts'
/**
* Load and validate plugin meta.json
* @param pluginId The plugin directory name
* @returns Plugin metadata object
* @throws Error if meta.json is invalid or not found
*/
export async function loadPluginMeta(pluginId: string): Promise<PluginMetaInput> {
const pluginDir = path.join(PluginsRoot, pluginId)
const metaPath = path.join(pluginDir, 'meta.json')
if (!(await fs.pathExists(metaPath))) {
throw new Error(`meta.json not found for plugin ${pluginId}`)
}
const meta = (await fs.readJSON(metaPath)) as PluginMetaInput
// Validate required fields
if (!meta.id) {
throw new Error(`meta.json missing required field: id`)
}
if (meta.id !== pluginId) {
throw new Error(
`Plugin ID mismatch: meta.json has "${meta.id}" but directory is "${pluginId}"`,
)
}
// Check for updateUrl (required field)
if (!meta.updateUrl) {
throw new Error(`meta.json missing required field: updateUrl`)
}
// Validate tags if present
if (meta.tags && Array.isArray(meta.tags)) {
const validTags = new Set([
'favorite',
'metadata',
'interface',
'attachment',
'notes',
'reader',
'productivity',
'visualization',
'integration',
'ai',
'writing',
'developer',
'others',
])
for (const tag of meta.tags) {
if (!validTags.has(tag)) {
throw new Error(`Invalid tag: ${tag}`)
}
}
}
return meta
}