Home / File/ flags.ts — astro Source File

flags.ts — astro Source File

Architecture documentation for flags.ts, a typescript file in the astro codebase. 4 imports, 1 dependents.

File typescript CoreAstro RenderingEngine 4 imports 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  8828cc9b_aa85_f4ba_73cb_ae49780007d3["flags.ts"]
  d3861967_b647_84d2_ff48_15013353bd56["../core/logger/core.js"]
  8828cc9b_aa85_f4ba_73cb_ae49780007d3 --> d3861967_b647_84d2_ff48_15013353bd56
  23f7d7cd_59bf_0643_9f11_6d90ab431fb7["../core/logger/node.js"]
  8828cc9b_aa85_f4ba_73cb_ae49780007d3 --> 23f7d7cd_59bf_0643_9f11_6d90ab431fb7
  c32d12e2_d85e_28c0_eea7_9b29629857e0["../types/public/config.js"]
  8828cc9b_aa85_f4ba_73cb_ae49780007d3 --> c32d12e2_d85e_28c0_eea7_9b29629857e0
  efd0f150_4239_ba62_fbb9_bcf24bd27236["yargs-parser"]
  8828cc9b_aa85_f4ba_73cb_ae49780007d3 --> efd0f150_4239_ba62_fbb9_bcf24bd27236
  f944bfaf_ee24_132b_6a8e_a0701c4da227["PostComment.tsx"]
  f944bfaf_ee24_132b_6a8e_a0701c4da227 --> 8828cc9b_aa85_f4ba_73cb_ae49780007d3
  style 8828cc9b_aa85_f4ba_73cb_ae49780007d3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Arguments } from 'yargs-parser';
import { Logger, type LogOptions } from '../core/logger/core.js';
import { nodeLogDestination } from '../core/logger/node.js';
import type { AstroInlineConfig } from '../types/public/config.js';

// Alias for now, but allows easier migration to node's `parseArgs` in the future.
export type Flags = Arguments;

/** @deprecated Use AstroConfigResolver instead */
export function flagsToAstroInlineConfig(flags: Flags): AstroInlineConfig {
	return {
		// Inline-only configs
		configFile: typeof flags.config === 'string' ? flags.config : undefined,
		mode: typeof flags.mode === 'string' ? flags.mode : undefined,
		logLevel: flags.verbose ? 'debug' : flags.silent ? 'silent' : undefined,
		force: flags.force ? true : undefined,

		// Astro user configs
		root: typeof flags.root === 'string' ? flags.root : undefined,
		site: typeof flags.site === 'string' ? flags.site : undefined,
		base: typeof flags.base === 'string' ? flags.base : undefined,
		outDir: typeof flags.outDir === 'string' ? flags.outDir : undefined,
		server: {
			port: typeof flags.port === 'number' ? flags.port : undefined,
			host:
				typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined,
			open:
				typeof flags.open === 'string' || typeof flags.open === 'boolean' ? flags.open : undefined,
			allowedHosts:
				typeof flags.allowedHosts === 'string'
					? flags.allowedHosts.split(',')
					: typeof flags.allowedHosts === 'boolean' && flags.allowedHosts === true
						? flags.allowedHosts
						: [],
		},
	};
}

/**
 * The `logging` is usually created from an `AstroInlineConfig`, but some flows like `add`
 * doesn't read the AstroConfig directly, so we create a `logging` object from the CLI flags instead.
 */
export function createLoggerFromFlags(flags: Flags): Logger {
	const logging: LogOptions = {
		dest: nodeLogDestination,
		level: 'info',
	};

	if (flags.verbose) {
		logging.level = 'debug';
	} else if (flags.silent) {
		logging.level = 'silent';
	}

	return new Logger(logging);
}

Domain

Subdomains

Types

Dependencies

  • ../core/logger/core.js
  • ../core/logger/node.js
  • ../types/public/config.js
  • yargs-parser

Frequently Asked Questions

What does flags.ts do?
flags.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 flags.ts?
flags.ts defines 2 function(s): createLoggerFromFlags, flagsToAstroInlineConfig.
What does flags.ts depend on?
flags.ts imports 4 module(s): ../core/logger/core.js, ../core/logger/node.js, ../types/public/config.js, yargs-parser.
What files import flags.ts?
flags.ts is imported by 1 file(s): PostComment.tsx.
Where is flags.ts in the architecture?
flags.ts is located at packages/astro/src/cli/flags.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/cli).

Analyze Your Own Codebase

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

Try Supermodel Free