Home / Function/ run() — astro Function Reference

run() — astro Function Reference

Architecture documentation for the run() function in mdx-cc2.js from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  f9d7763c_c0da_52ba_af7d_0debde8e24bd["run()"]
  964f968e_3873_5ce6_d47e_1117389e1f46["mdx-cc2.js"]
  f9d7763c_c0da_52ba_af7d_0debde8e24bd -->|defined in| 964f968e_3873_5ce6_d47e_1117389e1f46
  style f9d7763c_c0da_52ba_af7d_0debde8e24bd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

benchmark/make-project/mdx-cc2.js lines 7–80

export async function run(projectDir) {
	await fs.rm(projectDir, { recursive: true, force: true });
	await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true });
	await fs.mkdir(new URL('./data/blog', projectDir), { recursive: true });
	await fs.mkdir(new URL('./src/content', projectDir), { recursive: true });
	await fs.copyFile(new URL('./image.jpg', import.meta.url), new URL('./image.jpg', projectDir));

	const promises = [];

	for (let i = 0; i < 10000; i++) {
		const content = `\
# Article ${i}

${loremIpsumMd}

![image ${i}](../../image.jpg)

`;
		promises.push(
			fs.writeFile(new URL(`./data/blog/article-${i}.mdx`, projectDir), content, 'utf-8'),
		);
	}

	await fs.writeFile(
		new URL(`./src/content.config.ts`, projectDir),
		/*ts */ `
		import { defineCollection } from 'astro:content';
		import { z } from 'astro/zod';

		const blog = defineCollection({
			loader: glob({ pattern: '*', base: './data/blog' }),
		});
		
		export const collections = { blog }

		`,
	);

	await fs.writeFile(
		new URL(`./src/pages/blog/[...slug].astro`, projectDir),
		`\
---
import { getCollection, render } from 'astro:content';
export async function getStaticPaths() {
  const blogEntries = await getCollection('blog');
  return blogEntries.map(entry => ({
    params: { slug: entry.id }, props: { entry },
  }));
}
const { entry } = Astro.props;
const { Content } = await render(entry);

---
<h1>{entry.data.title}</h1>
<Content />
`,
		'utf-8',
	);

	await Promise.all(promises);

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

import mdx from '@astrojs/mdx';

export default defineConfig({
  integrations: [mdx()],
});`,
		'utf-8',
	);
}

Subdomains

Frequently Asked Questions

What does run() do?
run() is a function in the astro codebase, defined in benchmark/make-project/mdx-cc2.js.
Where is run() defined?
run() is defined in benchmark/make-project/mdx-cc2.js at line 7.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free