-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-entrypoints.js
34 lines (28 loc) · 1.02 KB
/
get-entrypoints.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
// Read asseet-manifest.js from supplied path from command line arg,
// and prints MAIN_CSS and MAIN_JS values, in .env file style.
// The output can be used to define env vars
const DOMAIN = process.env.DOMAIN;
const ROOT_PATH = process.env.ROOT_PATH;
const fs = require('fs');
const myArgs = process.argv.slice(2);
const assetManifest = JSON.parse(fs.readFileSync(myArgs[0], 'utf8'));
if (!assetManifest.entrypoints) {
throw 'No entrypoint found';
}
if (!assetManifest.entrypoints) {
throw 'entrypoints prop not found in asset manifest';
}
if (assetManifest.entrypoints.length !== 2) {
throw 'Unexpected entrypoint array size (expecting 2)';
}
for (const i of assetManifest.entrypoints) {
if (i.endsWith('.css')) {
const MAIN_CSS = `${DOMAIN}/${ROOT_PATH}/${i}`;
console.log(`MAIN_CSS="${MAIN_CSS}"`);
} else if (i.endsWith('.js')) {
const MAIN_JS = `${DOMAIN}/${ROOT_PATH}/${i}`;
console.log(`MAIN_JS="${MAIN_JS}"`);
} else {
throw 'Unknown entry file type';
}
}