-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathmanifest.js
More file actions
42 lines (40 loc) · 1.21 KB
/
manifest.js
File metadata and controls
42 lines (40 loc) · 1.21 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
import { existsSync, readFileSync } from 'fs'
import path from 'path'
import files from './files'
import { generateIntegrity } from './integrities'
import { cdn } from './links'
import project from './project'
export default function generateManifest(server) {
if (files['manifest.webmanifest']) return files['manifest.webmanifest']
const file = path.join(process.cwd(), 'public', 'manifest.webmanifest')
if (existsSync(file)) {
return readFileSync(file, 'utf-8')
}
const json = {
name: project.name,
short_name: project.shortName || project.name,
theme_color: project.color,
background_color: project.backgroundColor || project.color,
display: project.display,
orientation: project.orientation,
scope: project.scope,
start_url: project.root,
icons: [],
splash_pages: null,
}
for (const size in project.icons) {
const icon = project.icons[size]
json.icons.push({
src: cdn(icon),
sizes: `${size}x${size}`,
type: 'image/png',
purpose: 'maskable any',
})
}
const manifest = JSON.stringify(json)
if (!server.less) {
generateIntegrity('manifest.webmanifest', manifest)
}
files['manifest.webmanifest'] = manifest
return manifest
}