summaryrefslogtreecommitdiff
path: root/benchmark/make-project/server-stress-default.js
blob: 1724f8f82593ca9cbaae036978812deeca2229b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import fs from 'node:fs/promises';
import { loremIpsum } from './_util.js';

/**
 * @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 });
	await fs.mkdir(new URL('./src/components', projectDir), { recursive: true });

	await fs.writeFile(
		new URL('./src/pages/index.astro', projectDir),
		`\
---
import Paragraph from '../components/Paragraph.astro'
const content = "${loremIpsum}"
---

<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width" />
		<meta name="generator" content={Astro.generator} />
		<title>Astro</title>
	</head>
	<body>
		<h1>Astro</h1>
		<div>
			${Array.from({ length: 100 })
				.map(() => '<p>{content}</p>')
				.join('\n')}
		</div>
		<div>
			${Array.from({ length: 50 })
				.map((_, i) => '<Paragraph num={' + i + '} str={content} />')
				.join('\n')}
		</div>
	</body>
</html>`,
		'utf-8',
	);

	await fs.writeFile(
		new URL('./src/components/Paragraph.astro', projectDir),
		`<div>{Astro.props.num} {Astro.props.str}</div>`,
		'utf-8',
	);

	await fs.writeFile(
		new URL('./astro.config.js', projectDir),
		`\
import { defineConfig } from 'astro/config';
import nodejs from '@astrojs/node';

export default defineConfig({
	output: 'server',
	adapter: nodejs({ mode: 'standalone' }),
});`,
		'utf-8',
	);
}