Home / File/ git.ts — astro Source File

git.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 6 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  86455456_bee6_f020_bc22_ec5ab2dbdbe1["git.ts"]
  0d2ed6a4_ba13_53b9_91e8_1ccbdcaac22b["../messages.js"]
  86455456_bee6_f020_bc22_ec5ab2dbdbe1 --> 0d2ed6a4_ba13_53b9_91e8_1ccbdcaac22b
  e51f17cb_f71d_9bde_fbf6_41f051063da5["./shell.js"]
  86455456_bee6_f020_bc22_ec5ab2dbdbe1 --> e51f17cb_f71d_9bde_fbf6_41f051063da5
  6d4ff623_63ed_2360_85a7_197d38173f66["./actions/context.js"]
  86455456_bee6_f020_bc22_ec5ab2dbdbe1 --> 6d4ff623_63ed_2360_85a7_197d38173f66
  e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"]
  86455456_bee6_f020_bc22_ec5ab2dbdbe1 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  86455456_bee6_f020_bc22_ec5ab2dbdbe1 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  44da03af_fba3_824c_9c9c_2685d1d33d31["cli-kit"]
  86455456_bee6_f020_bc22_ec5ab2dbdbe1 --> 44da03af_fba3_824c_9c9c_2685d1d33d31
  style 86455456_bee6_f020_bc22_ec5ab2dbdbe1 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 { error, info, title } from '../messages.js';
import { shell } from '../shell.js';
import type { Context } from './context.js';

export async function git(
	ctx: Pick<Context, 'cwd' | 'git' | 'yes' | 'prompt' | 'dryRun' | 'tasks'>,
) {
	if (fs.existsSync(path.join(ctx.cwd, '.git'))) {
		await info('Nice!', `Git has already been initialized`);
		return;
	}
	let _git = ctx.git ?? ctx.yes;
	if (_git === undefined) {
		({ git: _git } = await ctx.prompt({
			name: 'git',
			type: 'confirm',
			label: title('git'),
			message: `Initialize a new git repository?`,
			hint: 'optional',
			initial: true,
		}));
	}

	if (ctx.dryRun) {
		await info('--dry-run', `Skipping Git initialization`);
	} else if (_git) {
		ctx.tasks.push({
			pending: 'Git',
			start: 'Git initializing...',
			end: 'Git initialized',
			while: () =>
				init({ cwd: ctx.cwd }).catch((e) => {
					error('error', e);
					process.exit(1);
				}),
		});
	} else {
		await info(
			ctx.yes === false ? 'git [skip]' : 'Sounds good!',
			`You can always run ${color.reset('git init')}${color.dim(' manually.')}`,
		);
	}
}

async function init({ cwd }: { cwd: string }) {
	try {
		await shell('git', ['init'], { cwd, stdio: 'ignore' });
		await shell('git', ['add', '-A'], { cwd, stdio: 'ignore' });
		await shell(
			'git',
			[
				'commit',
				'-m',
				'"Initial commit from Astro"',
				'--author="houston[bot] <astrobot-houston@users.noreply.github.com>"',
			],
			{ cwd, stdio: 'ignore' },
		);
	} catch {}
}

Domain

Subdomains

Functions

Dependencies

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

Frequently Asked Questions

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