Home / File/ template.ts — astro Source File

template.ts — astro Source File

Architecture documentation for template.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 6 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  33b7e98e_3257_427a_5948_5ab38c474d26["template.ts"]
  0d2ed6a4_ba13_53b9_91e8_1ccbdcaac22b["../messages.js"]
  33b7e98e_3257_427a_5948_5ab38c474d26 --> 0d2ed6a4_ba13_53b9_91e8_1ccbdcaac22b
  6d4ff623_63ed_2360_85a7_197d38173f66["./actions/context.js"]
  33b7e98e_3257_427a_5948_5ab38c474d26 --> 6d4ff623_63ed_2360_85a7_197d38173f66
  e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"]
  33b7e98e_3257_427a_5948_5ab38c474d26 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  33b7e98e_3257_427a_5948_5ab38c474d26 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  44da03af_fba3_824c_9c9c_2685d1d33d31["cli-kit"]
  33b7e98e_3257_427a_5948_5ab38c474d26 --> 44da03af_fba3_824c_9c9c_2685d1d33d31
  9102ecaa_9fd5_d51e_8099_abc23a789fc9["giget-core"]
  33b7e98e_3257_427a_5948_5ab38c474d26 --> 9102ecaa_9fd5_d51e_8099_abc23a789fc9
  style 33b7e98e_3257_427a_5948_5ab38c474d26 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from 'node:fs';
import path from 'node:path';
import { color } from '@astrojs/cli-kit';
import { downloadTemplate } from '@bluwy/giget-core';
import { error, info, title } from '../messages.js';
import type { Context } from './context.js';

/**
 * Removes sections from README content that are marked with HTML template markers.
 *
 * Template marker format:
 * <!-- ASTRO:REMOVE:START -->
 * Content to remove
 * <!-- ASTRO:REMOVE:END -->
 */
export function removeTemplateMarkerSections(content: string): string {
	// Pattern to match HTML template marker sections
	const pattern = /<!--\s*ASTRO:REMOVE:START\s*-->[\s\S]*?<!--\s*ASTRO:REMOVE:END\s*-->/gi;

	let result = content.replace(pattern, '');

	// Clean up extra whitespace that might be left behind
	// Replace multiple consecutive newlines with at most 2 newlines
	result = result.replace(/\n{3,}/g, '\n\n');

	return result;
}

/**
 * Processes a template README file by removing template marker sections and
 * replacing package manager references.
 */
export function processTemplateReadme(content: string, packageManager: string): string {
	// Remove sections marked with template markers
	let processed = removeTemplateMarkerSections(content);

	// Replace package manager references if not npm
	if (packageManager !== 'npm') {
		processed = processed
			.replace(/\bnpm run\b/g, packageManager)
			.replace(/\bnpm\b/g, packageManager);
	}

	return processed;
}

export async function template(
	ctx: Pick<Context, 'template' | 'prompt' | 'yes' | 'dryRun' | 'exit' | 'tasks'>,
) {
	if (!ctx.template && ctx.yes) ctx.template = 'basics';

	if (ctx.template) {
		await info('tmpl', `Using ${color.reset(ctx.template)}${color.dim(' as project template')}`);
	} else {
		const { template: tmpl } = await ctx.prompt({
			name: 'template',
			type: 'select',
			label: title('tmpl'),
			message: 'How would you like to start your new project?',
			initial: 'basics',
// ... (143 more lines)

Domain

Subdomains

Dependencies

  • ../messages.js
  • ./actions/context.js
  • cli-kit
  • giget-core
  • node:fs
  • node:path

Frequently Asked Questions

What does template.ts do?
template.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in template.ts?
template.ts defines 6 function(s): FILES_TO_UPDATE.package.json, copyTemplate, getTemplateTarget, processTemplateReadme, removeTemplateMarkerSections, template.
What does template.ts depend on?
template.ts imports 6 module(s): ../messages.js, ./actions/context.js, cli-kit, giget-core, node:fs, node:path.
Where is template.ts in the architecture?
template.ts is located at packages/create-astro/src/actions/template.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/create-astro/src/actions).

Analyze Your Own Codebase

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

Try Supermodel Free