2023-07-17 19:17:59 -05:00
|
|
|
import fs from 'node:fs/promises';
|
2023-03-06 09:55:44 -05:00
|
|
|
import { loremIpsumHtml, loremIpsumMd } from './_util.js';
|
|
|
|
|
|
|
|
// Map of files to be generated and tested for rendering.
|
|
|
|
// Ideally each content should be similar for comparison.
|
2024-02-14 10:14:05 -05:00
|
|
|
const renderFiles = {
|
|
|
|
'components/ListItem.astro': `\
|
2023-03-06 09:55:44 -05:00
|
|
|
---
|
2024-02-14 10:14:05 -05:00
|
|
|
const { className, item, attrs } = Astro.props;
|
|
|
|
const nested = item !== 0;
|
|
|
|
---
|
|
|
|
<li class={className}>
|
|
|
|
<a
|
|
|
|
href={item}
|
|
|
|
aria-current={item === 0}
|
|
|
|
class:list={[{ large: !nested }, className]}
|
|
|
|
{...attrs}
|
|
|
|
>
|
|
|
|
<span>{item}</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
`,
|
|
|
|
'components/Sublist.astro': `\
|
|
|
|
---
|
|
|
|
import ListItem from '../components/ListItem.astro';
|
|
|
|
const { items } = Astro.props;
|
2023-03-06 09:55:44 -05:00
|
|
|
const className = "text-red-500";
|
|
|
|
const style = { color: "red" };
|
|
|
|
---
|
2024-02-14 10:14:05 -05:00
|
|
|
<ul style={style}>
|
|
|
|
{items.map((item) => (
|
|
|
|
<ListItem className={className} item={item} attrs={{}} />
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
`,
|
|
|
|
'pages/astro.astro': `\
|
|
|
|
---
|
|
|
|
const className = "text-red-500";
|
|
|
|
const style = { color: "red" };
|
|
|
|
const items = Array.from({ length: 10000 }, (_, i) => ({i}));
|
|
|
|
---
|
2023-03-06 09:55:44 -05:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>My Site</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1 class={className + ' text-lg'}>List</h1>
|
2024-02-14 10:14:05 -05:00
|
|
|
<ul style={style}>
|
|
|
|
{items.map((item) => (
|
|
|
|
<li class={className}>
|
|
|
|
<a
|
|
|
|
href={item.i}
|
|
|
|
aria-current={item.i === 0}
|
|
|
|
class:list={[{ large: item.i === 0 }, className]}
|
|
|
|
{...({})}
|
|
|
|
>
|
|
|
|
<span>{item.i}</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
2023-03-06 09:55:44 -05:00
|
|
|
${Array.from({ length: 1000 })
|
|
|
|
.map(() => `<p>${loremIpsumHtml}</p>`)
|
|
|
|
.join('\n')}
|
|
|
|
</body>
|
|
|
|
</html>`,
|
2024-02-14 10:14:05 -05:00
|
|
|
'pages/md.md': `\
|
2023-03-06 09:55:44 -05:00
|
|
|
# List
|
|
|
|
|
|
|
|
${Array.from({ length: 1000 }, (_, i) => i)
|
|
|
|
.map((v) => `- ${v}`)
|
|
|
|
.join('\n')}
|
|
|
|
|
|
|
|
${Array.from({ length: 1000 })
|
|
|
|
.map(() => loremIpsumMd)
|
|
|
|
.join('\n\n')}
|
|
|
|
`,
|
2024-02-14 10:14:05 -05:00
|
|
|
'pages/mdx.mdx': `\
|
2023-03-06 09:55:44 -05:00
|
|
|
export const className = "text-red-500";
|
|
|
|
export const style = { color: "red" };
|
|
|
|
export const items = Array.from({ length: 1000 }, (_, i) => i);
|
|
|
|
|
|
|
|
# List
|
|
|
|
|
|
|
|
<ul style={style}>
|
|
|
|
{items.map((item) => (
|
|
|
|
<li class={className}>{item}</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
${Array.from({ length: 1000 })
|
|
|
|
.map(() => loremIpsumMd)
|
|
|
|
.join('\n\n')}
|
|
|
|
`,
|
|
|
|
};
|
|
|
|
|
2024-02-14 10:14:05 -05:00
|
|
|
export const renderPages = [];
|
2024-02-14 10:15:02 -05:00
|
|
|
for (const file of Object.keys(renderFiles)) {
|
|
|
|
if (file.startsWith('pages/')) {
|
2024-02-14 10:14:05 -05:00
|
|
|
renderPages.push(file.replace('pages/', ''));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 09:55:44 -05:00
|
|
|
/**
|
|
|
|
* @param {URL} projectDir
|
|
|
|
*/
|
|
|
|
export async function run(projectDir) {
|
|
|
|
await fs.rm(projectDir, { recursive: true, force: true });
|
|
|
|
await fs.mkdir(new URL('./src/pages', projectDir), { recursive: true });
|
2024-02-14 10:14:05 -05:00
|
|
|
await fs.mkdir(new URL('./src/components', projectDir), { recursive: true });
|
2023-03-06 09:55:44 -05:00
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
Object.entries(renderFiles).map(([name, content]) => {
|
2024-02-14 10:14:05 -05:00
|
|
|
return fs.writeFile(new URL(`./src/${name}`, projectDir), content, 'utf-8');
|
2023-03-06 09:55:44 -05:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await fs.writeFile(
|
|
|
|
new URL('./astro.config.js', projectDir),
|
|
|
|
`\
|
|
|
|
import { defineConfig } from 'astro/config';
|
2023-03-06 21:52:47 -05:00
|
|
|
import timer from '@benchmark/timer';
|
2023-03-06 09:55:44 -05:00
|
|
|
import mdx from '@astrojs/mdx';
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
integrations: [mdx()],
|
|
|
|
output: 'server',
|
|
|
|
adapter: timer(),
|
|
|
|
});`,
|
|
|
|
'utf-8'
|
|
|
|
);
|
|
|
|
}
|