-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml.js
135 lines (127 loc) · 4.73 KB
/
xml.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const { capitalise, transform } = require('./utils')
function makeDebugXML(extensions) {
return (
`<?xml version="1.0" encoding="UTF-8"?>
<ExtensionList>
${extensions.map((ext) => {
return `<Extension Id="${ext.id}">
<HostList>
${Object.keys(ext.debug).map((host) => {
return `<Host Name="${host}" Port="${ext.debug[host]}" />`
}).join('\n')}
</HostList>
</Extension>`}).join('\n')}
</ExtensionList>`
)
}
function makeManifestXML(options) {
let {
bundle,
version,
extensions,
hosts,
pkgVersion,
} = options
if (bundle.version === undefined && pkgVersion === undefined) {
console.log('Requires `version` in `package.json` or `cep.bundle`')
process.exit(-1)
}
extensions = extensions.map((ext) => {
if (ext.type === 'Custom' && !ext.geometry) {
return {
...ext,
geometry: {
size: {
width: 1,
height: 1,
}
}
}
}
return ext
})
const geoMissing = extensions.map((ext) => {
if (ext.type !== 'Custom' && !ext.geometry) {
return `Requires \`geometry\` in extension \`${ext.id}\``
}
}).filter((msg) => msg)
if (geoMissing.length) {
geoMissing.forEach((error) => console.log(error))
process.exit(-1)
}
return (
`<?xml version="1.0" encoding="UTF-8"?>
<ExtensionManifest
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
ExtensionBundleId="${bundle.id}"
ExtensionBundleName="${bundle.name}"
ExtensionBundleVersion="${bundle.version || pkgVersion}"
Version="${version}"
>
<ExtensionList>
${extensions.map((ext) => `<Extension Id="${ext.id}" Version="${ext.version || bundle.version || pkgVersion}" />`).join('\n')}
</ExtensionList>
<ExecutionEnvironment>
<HostList>
${Object.keys(hosts).map((host) => `<Host Name="${host}" Version="${hosts[host]}" />`).join('\n')}
</HostList>
<LocaleList>
<Locale Code="All"/>
</LocaleList>
<RequiredRuntimeList>
<RequiredRuntime Name="CSXS" Version="${version}" />
</RequiredRuntimeList>
</ExecutionEnvironment>
<DispatchInfoList>
${extensions.map((ext) => {
return `<Extension Id="${ext.id}">
<DispatchInfo>
<Resources>
<MainPath>${ext.main}</MainPath>
${ext.script ? `<ScriptPath>${ext.script}</ScriptPath>` : ''}
${ext.params?.length ?
`<CEFCommandLine>
${ext.params.map((param) => `<Parameter>${param}</Parameter>`).join('\n')}
</CEFCommandLine>` : ''}
</Resources>
<Lifecycle>
<AutoVisible>${
ext.type === 'Custom' && ext.autovisible === undefined
? false
: ext.autovisible !== undefined
? ext.autovisible
: true
}</AutoVisible>
${ext.events?.length ?
`<StartOn>
${ext.events.map((event) => `<Event>${event}</Event>`).join('\n')}
</StartOn>` : ''}
</Lifecycle>
<UI>
<Type>${ext.type}</Type>
${ext.menu ? `<Menu>${ext.menu}</Menu>` : ''}
<Geometry>
${Object.keys(ext.geometry).map((geo) => {
return `<${capitalise(geo)}>
<Height>${ext.geometry[geo].height}</Height>
<Width>${ext.geometry[geo].width}</Width>
</${capitalise(geo)}>`
}).join('\n')}
</Geometry>
${ext.icons && Object.keys(ext.icons).length ?
`<Icons>
${Object.keys(ext.icons).map((icon) => {
return `<Icon Type="${transform(icon)}">${ext.icons[icon]}</Icon>`
}).join('\n')}
</Icons>` : ''}
</UI>
</DispatchInfo>
</Extension>`}).join('\n')}
</DispatchInfoList>
</ExtensionManifest>`
)
}
module.exports = {
makeDebugXML,
makeManifestXML,
}