-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbannerize.js
45 lines (42 loc) · 1.53 KB
/
bannerize.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
#!/usr/bin/env node
const fs = require('fs');
const packageJson = require('./package.json');
// const args = process.argv.slice(2);
try {
const packages = {
app: require('./package.json'),
core: require('@vivocha/client-interaction-core/package.json'),
layout: require('@vivocha/client-interaction-layout/package.json')
}
const today = (new Date()).toString();
const buildinfo = {
"built": today,
"interactionCore": packages.core.version,
"interactionLayout": packages.layout.version,
"version": packages.app.version
};
const builddata = `
<script type="text/javascript">
const build = ${JSON.stringify(buildinfo)};
</script>
<!--
--------------------------------------------------
Vivocha Interaction App ${packages.app.version}
interaction-core: ${packages.core.version}
interaction-layout: ${packages.layout.version}
built: ${today}
--------------------------------------------------
-->`;
const mainHtmlPath = './dist/main.html';
const mainHtml = fs.readFileSync(mainHtmlPath, "utf-8");
const updatedMainHtml = mainHtml.replace(/(\n<\/body>)/, `${builddata}$1`);
fs.writeFileSync(mainHtmlPath, updatedMainHtml);
console.log('bannerize: updated main.html');
delete packageJson['scripts'];
delete packageJson['devDependencies'];
delete packageJson['dependencies'];
fs.writeFileSync('dist/package.json', JSON.stringify(packageJson, undefined, 2));
console.log('bannerize: updated package.json');
} catch (e) {
console.warn('bannerize: main.html not updated', e);
}