Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tools/build.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/usr/bin/env zx

import { chalk } from 'zx';
import { applyPatches, buildAIO, copyLocalizedFiles, copyRobots, modifySitemap, resetBuildDir } from './lib/common.mjs';
import {
applyPatches,
buildAIO,
copyLocalizedFiles,
remove404HTML,
copyRobots,
modifySitemap,
resetBuildDir,
} from './lib/common.mjs';

try {
console.log(chalk.green('==== setup ===='));
Expand Down Expand Up @@ -38,5 +46,6 @@ async function build() {

async function postBuild() {
await copyRobots();
await remove404HTML();
await modifySitemap();
}
10 changes: 9 additions & 1 deletion tools/lib/common.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { watch } from 'chokidar';
import { resolve } from 'node:path';
import { $, cd, chalk, glob, within } from 'zx';
import { initDir, cpRf, exists, sed } from './fileutils.mjs';
import { initDir, cpRf, exists, sed, rmrf, rename } from './fileutils.mjs';

const rootDir = resolve(__dirname, '../');
const aiojaDir = resolve(rootDir, 'aio-ja');
Expand Down Expand Up @@ -102,3 +102,11 @@ export async function modifySitemap() {
const sitemapPath = resolve(outDir, 'dist/bin/aio/build/generated/sitemap.xml');
await sed(sitemapPath, 'angular.io', 'angular.jp');
}

// copy _redirects
export async function remove404HTML() {
await $`chmod -R +w ${resolve(outDir, 'dist/bin/aio/build')}`;
const from = resolve(outDir, 'dist/bin/aio/build/404.html');
const to = resolve(outDir, 'dist/bin/aio/build/_404.html');
await rename(from, to);
}
5 changes: 5 additions & 0 deletions tools/lib/fileutils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ export async function sed(path, pattern, replacement) {
const newContent = content.replaceAll(pattern, replacement);
await writeFile(path, newContent, 'utf-8');
}

export async function rename(oldPath, newPath) {
await cp(oldPath, newPath);
await rm(oldPath);
}