Files
gnatdashboard/webui/postbuild.js
Matthieu Eyraud 28f11c3b28 Transition WebUI to Angular 13
This commit transition the application to Angular 13, and refactors the
build process to use the Angular CLI instead of hacking a webpack config.

It also removes a lot of things: junk code, or features that are no longer
needed, like the following:

    * The Codepeer history view of the various runs is removed

    * The refresh review / add review buttons with their associated dialog
      are removed

Change-Id: I8adb19aa2ec8303aa23bd38a916fac35947ee69a
Depends-On: Ie50b0def8c0c2485f890eb46317b53b62b4382dd
TN: V316-059
2022-08-24 17:02:53 +00:00

38 lines
1.4 KiB
JavaScript

const cheerio = require('cheerio');
const fs = require('fs');
const indexFilePath = 'dist/webui/index.html';
console.log('After build script started...');
// read our index file
console.log('About to rewrite file: ', indexFilePath);
fs.readFile(indexFilePath, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
// load html into cheerio so we can manipulate DOM
const $ = cheerio.load(data);
// Angular now inserts a type="module" attribute in script tags. As we want to get a static index.html,
// we remove this attribute. Otherwise, the browser will emit cross-origin request to get the script, which
// violates the same origin policy in the browser (and prevents us from loading the script without launching
// a server).
$('html').find('script').removeAttr('type');
// As we are generating a static html page, we can't load scripts through HTTP request. Highlight.js
// relies on such a mechanism to load its scripts. To work around that, we will load the generated scripts
// preemptively, so that they are not loaded later through HTTP requests.
$('html').append(
'<script src=node_modules_highlight_js_es_core_js.js></script>'
);
$('html').append(
'<script src=node_modules_highlight_js_es_languages_ada_js.js></script>'
);
fs.writeFile(indexFilePath, $.html(), function (err) {
if (err) return console.log(err);
console.log('Successfully rewrote index html');
});
});