diff --git a/aio/BUILD.bazel b/aio/BUILD.bazel index ee2a493c18c..99e2fd4a70e 100644 --- a/aio/BUILD.bazel +++ b/aio/BUILD.bazel @@ -191,6 +191,32 @@ architect( tags = ["no-remote-exec"], ) +npm_package_bin( + name = "404-page", + outs = ["404.html"], + args = [ + "$(execpath src/404-body.html)", + "$(execpath :build)", + "$@", + ], + data = [ + "src/404-body.html", + ":build", + ], + tool = "//aio/scripts:build-404-page", +) + +copy_to_directory( + name = "build-with-404", + srcs = [ + ":404-page", + ":build", + ], + replace_prefixes = { + "build": "", + }, +) + architect_test( name = "test", args = [ diff --git a/aio/scripts/BUILD.bazel b/aio/scripts/BUILD.bazel index 7e16626d9f2..3784d760b4b 100644 --- a/aio/scripts/BUILD.bazel +++ b/aio/scripts/BUILD.bazel @@ -24,3 +24,8 @@ js_library( "@aio_npm//@angular-devkit/architect-cli", ], ) + +nodejs_binary( + name = "build-404-page", + entry_point = "build-404-page.js", +) diff --git a/aio/scripts/build-404-page.js b/aio/scripts/build-404-page.js index a618447c732..8eaa63daced 100644 --- a/aio/scripts/build-404-page.js +++ b/aio/scripts/build-404-page.js @@ -5,20 +5,19 @@ const {readFileSync, writeFileSync} = require('fs'); const {join, resolve} = require('path'); // Constants -const SRC_DIR = resolve(__dirname, '../src'); -const DIST_DIR = resolve(__dirname, '../dist'); +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(DIST_DIR, 'index.html'); - const src404BodyPath = join(SRC_DIR, '404-body.html'); - const dst404PagePath = join(DIST_DIR, '404.html'); + const srcIndexPath = join(BUILD_OUTPUT_DIR, 'index.html'); const srcIndexContent = readFileSync(srcIndexPath, 'utf8'); - const src404BodyContent = readFileSync(src404BodyPath, 'utf8').trim(); + const src404BodyContent = readFileSync(SOURCE_404_BODY_PATH, 'utf8').trim(); const dst404PageContent = srcIndexContent .replace(/()[\s\S]+(<\/body>)/, `$1\n ${src404BodyContent}\n$2`); @@ -28,5 +27,5 @@ function _main() { 'The content of \'index.html\' does not match the expected pattern.'); } - writeFileSync(dst404PagePath, dst404PageContent); + writeFileSync(DEST_404_PAGE_PATH, dst404PageContent); }