-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-manifest.js
29 lines (23 loc) · 902 Bytes
/
build-manifest.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
const { readFileSync, writeFileSync } = require('fs');
function readManiestBluePrint() {
const manifestBlueprint = readFileSync('manifest.blueprint.json').toString();
return manifestBlueprint;
}
function readHtmlCspMeta() {
const htmlContents = readFileSync('index.html').toString();
const [, cspDirectives] = htmlContents.match(/<meta http-equiv="content-security-policy" content="(.+)">/);
return cspDirectives;
}
function generateManifest(blueprint, { csp }) {
const blueprintCspToken = '{{ContentSecurityPolicy}}';
const processed = blueprint.replace(blueprintCspToken, csp);
return processed;
}
function writeManifest(contents) {
writeFileSync('manifest.json', contents);
}
const blueprint = readManiestBluePrint();
const csp = readHtmlCspMeta();
const manifest = generateManifest(blueprint, { csp });
writeManifest(manifest);
console.log('🙌 Generated manifest.json');