https://github.com/angular/angular
Raw File
Tip revision: 5db7b4c354d812938aa247a18154d6a61948547c authored by atscott on 14 October 2020, 20:33:19 UTC
release: cut the v10.1.6 release
Tip revision: 5db7b4c
build-404-page.js
#!/usr/bin/env node

// Imports
const {readFileSync, writeFileSync} = require('fs');
const {join, resolve} = require('path');

// Constants
const SRC_DIR = resolve(__dirname, '../src');
const DIST_DIR = resolve(__dirname, '../dist');

// Run
_main();

// Functions - Definitions
function _main() {
  const srcIndexPath = join(DIST_DIR, 'index.html');
  const src404BodyPath = join(SRC_DIR, '404-body.html');
  const dst404PagePath = join(DIST_DIR, '404.html');

  const srcIndexContent = readFileSync(srcIndexPath, 'utf8');
  const src404BodyContent = readFileSync(src404BodyPath, 'utf8');
  const dst404PageContent = srcIndexContent.replace(/<body>[\s\S]+<\/body>/, src404BodyContent);

  if (dst404PageContent === srcIndexContent) {
    throw new Error(
        'Failed to generate \'404.html\'. ' +
        'The content of \'index.html\' does not match the expected pattern.');
  }

  writeFileSync(dst404PagePath, dst404PageContent);
}
back to top