Home / File/ project-name.ts — astro Source File

project-name.ts — astro Source File

Architecture documentation for project-name.ts, a typescript file in the astro codebase. 5 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 5 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  5e62c00c_3931_b38d_250d_e3ed87297fa7["project-name.ts"]
  0d2ed6a4_ba13_53b9_91e8_1ccbdcaac22b["../messages.js"]
  5e62c00c_3931_b38d_250d_e3ed87297fa7 --> 0d2ed6a4_ba13_53b9_91e8_1ccbdcaac22b
  6d4ff623_63ed_2360_85a7_197d38173f66["./actions/context.js"]
  5e62c00c_3931_b38d_250d_e3ed87297fa7 --> 6d4ff623_63ed_2360_85a7_197d38173f66
  9e384fab_5963_6177_cc37_4ddd0448e624["./shared.js"]
  5e62c00c_3931_b38d_250d_e3ed87297fa7 --> 9e384fab_5963_6177_cc37_4ddd0448e624
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  5e62c00c_3931_b38d_250d_e3ed87297fa7 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  44da03af_fba3_824c_9c9c_2685d1d33d31["cli-kit"]
  5e62c00c_3931_b38d_250d_e3ed87297fa7 --> 44da03af_fba3_824c_9c9c_2685d1d33d31
  style 5e62c00c_3931_b38d_250d_e3ed87297fa7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import path from 'node:path';
import { color, generateProjectName } from '@astrojs/cli-kit';
import { info, log, title } from '../messages.js';
import type { Context } from './context.js';

import { isEmpty, toValidName } from './shared.js';

export async function projectName(
	ctx: Pick<Context, 'yes' | 'dryRun' | 'prompt' | 'projectName' | 'exit'> & { cwd?: string },
) {
	await checkCwd(ctx.cwd);

	if (!ctx.cwd || !isEmpty(ctx.cwd)) {
		if (ctx.cwd && !isEmpty(ctx.cwd)) {
			await info('Hmm...', `${color.reset(`"${ctx.cwd}"`)}${color.dim(` is not empty!`)}`);
		}

		if (ctx.yes) {
			ctx.projectName = generateProjectName();
			ctx.cwd = `./${ctx.projectName}`;
			await info('dir', `Project created at ./${ctx.projectName}`);
			return;
		}

		const { name } = await ctx.prompt({
			name: 'name',
			type: 'text',
			label: title('dir'),
			message: 'Where should we create your new project?',
			initial: `./${generateProjectName()}`,
			validate(value: string) {
				if (!isEmpty(value)) {
					return `Directory is not empty!`;
				}
				// Check for non-printable characters
				if (value.match(/[^\x20-\x7E]/g) !== null)
					return `Invalid non-printable character present!`;
				return true;
			},
		});

		ctx.cwd = name!.trim();
		ctx.projectName = toValidName(name!);
		if (ctx.dryRun) {
			await info('--dry-run', 'Skipping project naming');
			return;
		}
	} else {
		let name = ctx.cwd;
		if (name === '.' || name === './') {
			const parts = process.cwd().split(path.sep);
			name = parts[parts.length - 1];
		} else if (name.startsWith('./') || name.startsWith('../')) {
			const parts = name.split('/');
			name = parts[parts.length - 1];
		}
		ctx.projectName = toValidName(name);
	}

	if (!ctx.cwd) {
		ctx.exit(1);
	}
}

async function checkCwd(cwd: string | undefined) {
	const empty = cwd && isEmpty(cwd);
	if (empty) {
		log('');
		await info('dir', `Using ${color.reset(cwd)}${color.dim(' as project directory')}`);
	}

	return empty;
}

Domain

Subdomains

Dependencies

  • ../messages.js
  • ./actions/context.js
  • ./shared.js
  • cli-kit
  • node:path

Frequently Asked Questions

What does project-name.ts do?
project-name.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 project-name.ts?
project-name.ts defines 2 function(s): checkCwd, projectName.
What does project-name.ts depend on?
project-name.ts imports 5 module(s): ../messages.js, ./actions/context.js, ./shared.js, cli-kit, node:path.
Where is project-name.ts in the architecture?
project-name.ts is located at packages/create-astro/src/actions/project-name.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