mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
The legacy build injected this file into the dist folder, however that's not possible under bazel so files are copied to a new directory.
31 lines
946 B
JavaScript
31 lines
946 B
JavaScript
#!/usr/bin/env node
|
|
|
|
// Imports
|
|
const {readFileSync, writeFileSync} = require('fs');
|
|
const {join, resolve} = require('path');
|
|
|
|
// Constants
|
|
const SOURCE_404_BODY_PATH = resolve(process.argv[2]);
|
|
const BUILD_OUTPUT_DIR = resolve(process.argv[3]);
|
|
const DEST_404_PAGE_PATH = resolve(process.argv[4]);
|
|
|
|
// Run
|
|
_main();
|
|
|
|
// Functions - Definitions
|
|
function _main() {
|
|
const srcIndexPath = join(BUILD_OUTPUT_DIR, 'index.html');
|
|
|
|
const srcIndexContent = readFileSync(srcIndexPath, 'utf8');
|
|
const src404BodyContent = readFileSync(SOURCE_404_BODY_PATH, 'utf8').trim();
|
|
const dst404PageContent = srcIndexContent
|
|
.replace(/(<body>)[\s\S]+(<\/body>)/, `$1\n ${src404BodyContent}\n$2`);
|
|
|
|
if (dst404PageContent === srcIndexContent) {
|
|
throw new Error(
|
|
'Failed to generate \'404.html\'. ' +
|
|
'The content of \'index.html\' does not match the expected pattern.');
|
|
}
|
|
|
|
writeFileSync(DEST_404_PAGE_PATH, dst404PageContent);
|
|
}
|