mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build(bazel): build aio 404 page under bazel
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.
This commit is contained in:
committed by
Joey Perrott
parent
d9a29e426a
commit
adffd3fdf7
@@ -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 = [
|
||||
|
||||
@@ -24,3 +24,8 @@ js_library(
|
||||
"@aio_npm//@angular-devkit/architect-cli",
|
||||
],
|
||||
)
|
||||
|
||||
nodejs_binary(
|
||||
name = "build-404-page",
|
||||
entry_point = "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(/(<body>)[\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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user