This commit is contained in:
parent
670d90cb15
commit
f85aca7d58
43 changed files with 202 additions and 97 deletions
|
|
@ -11,6 +11,36 @@ function copyDir(source, destination) {
|
|||
fs.cpSync(source, destination, { recursive: true });
|
||||
}
|
||||
|
||||
function listHtmlFiles(dir) {
|
||||
return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
||||
const fullPath = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
return listHtmlFiles(fullPath);
|
||||
}
|
||||
return entry.isFile() && entry.name.endsWith(".html") ? [fullPath] : [];
|
||||
});
|
||||
}
|
||||
|
||||
function materializeExtensionlessHtmlRoutes() {
|
||||
let routes = 0;
|
||||
|
||||
for (const filePath of listHtmlFiles(distRoot)) {
|
||||
const relativePath = path.relative(distRoot, filePath);
|
||||
const extensionlessPath = relativePath.replace(/\.html$/, "");
|
||||
const destination = path.join(distRoot, extensionlessPath, "index.html");
|
||||
|
||||
if (path.resolve(destination) === path.resolve(filePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
||||
fs.copyFileSync(filePath, destination);
|
||||
routes += 1;
|
||||
}
|
||||
|
||||
return routes;
|
||||
}
|
||||
|
||||
for (const dir of staticDirs) {
|
||||
copyDir(path.join(repoRoot, dir), path.join(distRoot, dir));
|
||||
}
|
||||
|
|
@ -30,4 +60,7 @@ if (fs.existsSync(adminIndexSource)) {
|
|||
fs.copyFileSync(adminIndexSource, adminIndexDestination);
|
||||
}
|
||||
|
||||
const extensionlessRoutes = materializeExtensionlessHtmlRoutes();
|
||||
|
||||
console.log(`Copied ${staticDirs.join(", ")} into dist/.`);
|
||||
console.log(`Materialized ${extensionlessRoutes} extensionless HTML route aliases.`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue