-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
pluginOptionsSchema.js
307 lines (296 loc) · 10.7 KB
/
pluginOptionsSchema.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
export default function pluginOptionSchema({ Joi }) {
/* Descriptions copied from or based on documentation at https://developer.mozilla.org/en-US/docs/Web/Manifest
*
* Currently based on https://www.w3.org/TR/2020/WD-appmanifest-20201019/
* and the August 4th 2020 version of https://w3c.github.io/manifest-app-info/
*/
const platform = Joi.string()
.optional()
.empty(``)
.valid(
`narrow`,
`wide`,
`chromeos`,
`ios`,
`kaios`,
`macos`,
`windows`,
`windows10x`,
`xbox`,
`chrome_web_store`,
`play`,
`itunes`,
`microsoft`,
`webapp`
) //https://w3c.github.io/manifest-app-info/#platform-member
.description(`The platform on which the application can be found.`)
const FingerPrint = Joi.object().keys({
type: Joi.string()
.required()
.description(`syntax and semantics are platform-defined`),
value: Joi.string()
.required()
.description(`syntax and semantics are platform-defined`),
})
const ImageResource = Joi.object().keys({
sizes: Joi.string()
.optional()
.description(`A string containing space-separated image dimensions`),
src: Joi.string()
.required()
.description(
`The path to the image file. If src is a relative URL, the base URL will be the URL of the manifest.`
),
type: Joi.string()
.optional()
.description(
`A hint as to the media type of the image. The purpose of this member is to allow a user agent to quickly ignore images with media types it does not support.`
),
})
const ManifestImageResource = ImageResource.keys({
purpose: Joi.string()
.optional()
.description(
`Defines the purpose of the image, for example if the image is intended to serve some special purpose in the context of the host OS.`
),
})
const ShortcutItem = Joi.object().keys({
name: Joi.string()
.required()
.description(
`The name member of a ShortcutItem is a string that represents the name of the shortcut as it is usually displayed to the user in a context menu. `
),
short_name: Joi.string()
.optional()
.description(
`The short_name member of a ShortcutItem is a string that represents a short version of the name of the shortcut. `
),
description: Joi.string()
.optional()
.description(
`The description member of a ShortcutItem is a string that allows the developer to describe the purpose of the shortcut. `
),
url: Joi.string()
.required()
.description(
`The url member of a ShortcutItem is a URL within scope of a processed manifest that opens when the associated shortcut is activated. `
),
icons: Joi.array()
.optional()
.items(ManifestImageResource)
.description(
`The icons member of an ShortcutItem member serve as iconic representations of the shortcut in various contexts. `
),
})
const ExternalApplicationResource = Joi.object()
.keys({
platform: platform.required(),
url: Joi.string()
.uri()
.description(`The URL at which the application can be found.`),
id: Joi.string().description(
`The ID used to represent the application on the specified platform.`
),
min_version: Joi.string()
.optional()
.description(
`The minimum version of the application that is considered related to this web app.`
),
fingerprints: Joi.array()
.optional()
.items(FingerPrint)
.description(
`Each Fingerprints represents a set of cryptographic fingerprints used for verifying the application.`
),
})
.or(`url`, `id`)
/**
* This only includes items in the draft, but allows unknown keys in params
* @see https://w3c.github.io/web-share-target/
*/
const ShareTarget = Joi.object().keys({
action: Joi.string()
.uri({ allowRelative: true })
.required()
.description(`The URL for the web share target.`),
method: Joi.string()
.optional()
.description(`The HTTP request method for the web share target`),
enctype: Joi.string()
.optional()
.description(
`Specifies how the share data is encoded in the body of a POST request. It is ignored when method is "GET"`
),
params: Joi.object()
.required()
.keys({
title: Joi.string()
.optional()
.description(
`The name of the query parameter used for the title of the document being shared`
),
text: Joi.string()
.optional()
.description(
`The name of the query parameter used for the arbitrary text that forms the body of the message being shared`
),
url: Joi.string()
.optional()
.description(
`The name of the query parameter used for the URL string referring to a resource being shared`
),
})
// Allow unknown keys, because the spec is an unofficial draft and Google already seems to have added support for keys that are not in the spec
.unknown(true),
})
const WebAppManifest = Joi.object().keys({
background_color: Joi.string()
.optional()
.description(
`The background_color member defines a placeholder background color for the application page to display before its stylesheet is loaded.`
),
categories: Joi.array()
.items(Joi.string().empty(``))
.optional()
.description(
`The categories member is an array of strings defining the names of categories that the application supposedly belongs to.`
),
description: Joi.string()
.optional()
.description(
`The description member is a string in which developers can explain what the application does. `
),
dir: Joi.string()
.optional()
.valid(`auto`, `ltr`, `rtl`)
.description(
`The base direction in which to display direction-capable members of the manifest.`
),
display: Joi.string()
.optional()
.valid(`fullscreen`, `standalone`, `minimal-ui`, `browser`)
.description(
`The display member is a string that determines the developers’ preferred display mode for the website`
),
iarc_rating_id: Joi.string()
.guid()
.optional()
.description(
`The iarc_rating_id member is a string that represents the International Age Rating Coalition (IARC) certification code of the web application.`
),
icons: Joi.array()
.optional()
.items(ManifestImageResource)
.description(
`The icons member specifies an array of objects representing image files that can serve as application icons for different contexts.`
),
lang: Joi.string()
.optional()
.description(
`The lang member is a string containing a single language tag.`
),
name: Joi.string()
.optional()
.description(
`The name member is a string that represents the name of the web application as it is usually displayed to the user.`
),
orientation: Joi.string()
.optional()
.valid(
`any`,
`natural`,
`landscape`,
`landscape-primary`,
`landscape-secondary`,
`portrait`,
`portrait-primary`,
`portrait-secondary`
) // From: https://www.w3.org/TR/screen-orientation/#screenorientation-interface
.description(
`The orientation member defines the default orientation for all the website's top-level browsing contexts`
),
prefer_related_applications: Joi.boolean()
.optional()
.description(
`The prefer_related_applications member is a boolean value that specifies that applications listed in related_applications should be preferred over the web application.`
),
related_applications: Joi.array()
.optional()
.items(ExternalApplicationResource)
.description(
`The related_applications field is an array of objects specifying native applications that are installable by, or accessible to, the underlying platform.`
),
share_target: ShareTarget.optional().description(
`Allows websites to declare themselves as web share targets, which can receive shared content from either the Web Share API, or system events (e.g., shares from native apps).`
),
scope: Joi.string()
.optional()
.description(
`The scope member is a string that defines the navigation scope of this web application's application context.`
),
screenshots: Joi.array()
.optional()
.items(
ManifestImageResource.keys({
label: Joi.string()
.optional()
.description(
`The label member is a string that serves as the accessible name of that screenshots object.`
),
platform: platform,
})
)
.description(
`The screenshots member defines an array of screenshots intended to showcase the application.`
),
short_name: Joi.string()
.optional()
.description(
`The short_name member is a string that represents the name of the web application displayed to the user if there is not enough space to display name.`
),
shortcuts: Joi.array()
.optional()
.items(ShortcutItem)
.description(
`Each ShortcutItem represents a link to a key task or page within a web app. `
),
start_url: Joi.string()
.optional()
.description(
`The start_url member is a string that represents the start URL of the web application.`
),
theme_color: Joi.string()
.optional()
.description(
`The theme_color member is a string that defines the default theme color for the application.`
),
})
const GatsbyPluginOptions = Joi.object()
.keys({
icon: Joi.string(),
legacy: Joi.boolean().default(true),
theme_color_in_head: Joi.boolean().default(true),
cache_busting_mode: Joi.string()
.valid(`none`, `query`, `name`)
.default(`query`),
crossOrigin: Joi.string()
.valid(`anonymous`, `use-credentials`)
.default(`anonymous`),
include_favicon: Joi.boolean().default(true),
icon_options: ManifestImageResource.keys({
src: Joi.string().forbidden(),
sizes: Joi.string().forbidden(),
}),
localize: Joi.array()
.items(
WebAppManifest.keys({
lang: Joi.required(),
start_url: Joi.required(),
})
)
.description(`Used for localizing your WebAppManifest`),
})
.or(`icon`, `icons`)
.with(`localize`, `lang`)
return WebAppManifest.concat(GatsbyPluginOptions)
}