forked from Rosetta/landing
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
import { copyFile, mkdir } from 'node:fs/promises';
|
|
import { dirname, resolve } from 'node:path';
|
|
|
|
const root = process.cwd();
|
|
const outputDirectory = resolve(root, 'dist');
|
|
const serverDirectory = resolve(root, 'dist', 'server');
|
|
const appShell = resolve(outputDirectory, 'index.html');
|
|
const browserRoutes = [
|
|
'encryption',
|
|
'privacy',
|
|
'proto',
|
|
'proto/docs',
|
|
'rcc',
|
|
'support',
|
|
'terms',
|
|
];
|
|
|
|
await mkdir(serverDirectory, { recursive: true });
|
|
await copyFile(
|
|
resolve(root, 'worker', 'index.js'),
|
|
resolve(serverDirectory, 'index.js'),
|
|
);
|
|
|
|
// Emit both clean-URL and directory-index shells for every client-side route.
|
|
// The directory copy also supports basic Nginx static configurations that do
|
|
// not rewrite missing paths to the root application shell.
|
|
await Promise.all(
|
|
browserRoutes.map(async (route) => {
|
|
const routeFile = resolve(outputDirectory, `${route}.html`);
|
|
const routeDirectory = resolve(outputDirectory, route);
|
|
|
|
await mkdir(dirname(routeFile), { recursive: true });
|
|
await mkdir(routeDirectory, { recursive: true });
|
|
await copyFile(appShell, routeFile);
|
|
await copyFile(appShell, resolve(routeDirectory, 'index.html'));
|
|
}),
|
|
);
|