diff --git a/cli/src/index.ts b/cli/src/index.ts index 7d16f027..410ab572 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -1,3 +1,15 @@ +/** + * VuePress Theme Plume CLI Entry Point + * + * VuePress Theme Plume CLI 入口文件 + * + * This module provides command-line interface for creating and initializing + * VuePress projects with vuepress-theme-plume. + * + * 本模块提供用于创建和初始化 VuePress 项目的命令行接口。 + * + * @module cli + */ import cac from 'cac' import { version } from '../package.json' import { Mode } from './constants.js' diff --git a/cli/src/locales/en.ts b/cli/src/locales/en.ts index 37181d16..6ecbdb62 100644 --- a/cli/src/locales/en.ts +++ b/cli/src/locales/en.ts @@ -1,5 +1,10 @@ import type { Locale } from '../types.js' +/** + * English locale configuration for CLI prompts and messages. + * + * CLI 提示和消息的英语本地化配置。 + */ export const en: Locale = { 'question.root': 'Where would you want to initialize VuePress?', 'question.site.name': 'Site Name:', diff --git a/cli/src/locales/index.ts b/cli/src/locales/index.ts index 133b7b48..fdddbf16 100644 --- a/cli/src/locales/index.ts +++ b/cli/src/locales/index.ts @@ -2,6 +2,15 @@ import type { Langs, Locale } from '../types.js' import { en } from './en.js' import { zh } from './zh.js' +/** + * Locale configurations for different languages. + * + * 不同语言的本地化配置。 + * + * Maps language codes to their respective locale strings. + * + * 将语言代码映射到相应的本地化字符串。 + */ export const locales: Record = { 'zh-CN': zh, 'en-US': en, diff --git a/cli/src/locales/zh.ts b/cli/src/locales/zh.ts index e5aa7fc4..ea73f717 100644 --- a/cli/src/locales/zh.ts +++ b/cli/src/locales/zh.ts @@ -1,5 +1,10 @@ import type { Locale } from '../types.js' +/** + * Chinese (Simplified) locale configuration for CLI prompts and messages. + * + * CLI 提示和消息的简体中文本地化配置。 + */ export const zh: Locale = { 'question.root': '您想在哪里初始化 VuePress?', 'question.site.name': '站点名称:', diff --git a/cli/src/packageJson.ts b/cli/src/packageJson.ts index 461b89b0..e7d13455 100644 --- a/cli/src/packageJson.ts +++ b/cli/src/packageJson.ts @@ -5,6 +5,14 @@ import _sortPackageJson from 'sort-package-json' import { Mode } from './constants.js' import { readJsonFile, resolve } from './utils/index.js' +/** + * Sort package.json fields in a consistent order. + * + * 按一致顺序排序 package.json 字段。 + * + * @param json - Package.json object to sort / 要排序的 package.json 对象 + * @returns Sorted package.json object / 排序后的 package.json 对象 + */ function sortPackageJson(json: Record) { return _sortPackageJson(json, { sortOrder: ['name', 'type', 'version', 'private', 'description', 'packageManager', 'author', 'license', 'scripts', 'devDependencies', 'dependencies', 'pnpm'], @@ -111,12 +119,29 @@ export async function createPackageJson( } } +/** + * Get user information from git global configuration. + * + * 从 git 全局配置获取用户信息。 + * + * @returns User information object with username and email / 包含用户名和邮箱的用户信息对象 + * @throws Error if git command fails / 如果 git 命令失败则抛出错误 + */ async function getUserInfo() { const { output: username } = await spawn('git', ['config', '--global', 'user.name']) const { output: email } = await spawn('git', ['config', '--global', 'user.email']) return { username, email } } +/** + * Get the version of a package manager. + * + * 获取包管理器的版本。 + * + * @param pkg - Package manager name (npm, yarn, pnpm) / 包管理器名称 + * @returns Version string of the package manager / 包管理器的版本字符串 + * @throws Error if package manager command fails / 如果包管理器命令失败则抛出错误 + */ async function getPackageManagerVersion(pkg: string) { const { output } = await spawn(pkg, ['--version']) return output diff --git a/cli/src/run.ts b/cli/src/run.ts index 70d82729..4617465f 100644 --- a/cli/src/run.ts +++ b/cli/src/run.ts @@ -78,6 +78,15 @@ export async function run(mode: Mode, root?: string): Promise { } } +/** + * Resolve prompt result into final configuration data. + * + * 将提示结果解析为最终配置数据。 + * + * @param result - Prompt result from user input / 用户输入的提示结果 + * @param mode - Operation mode (init or create) / 操作模式(初始化或创建) + * @returns Resolved configuration data / 解析后的配置数据 + */ function resolveData(result: PromptResult, mode: Mode): ResolvedData { return { ...result, diff --git a/cli/src/utils/getPackageManager.ts b/cli/src/utils/getPackageManager.ts index 6a7d566b..9a1951f0 100644 --- a/cli/src/utils/getPackageManager.ts +++ b/cli/src/utils/getPackageManager.ts @@ -1,6 +1,19 @@ import type { PackageManager } from '../types.js' import process from 'node:process' +/** + * Detect the current package manager from environment variables. + * + * 从环境变量检测当前使用的包管理器。 + * + * @returns The detected package manager name / 检测到的包管理器名称 + * @example + * // When using pnpm + * const pm = getPackageManager() // returns 'pnpm' + * + * // When using npm + * const pm = getPackageManager() // returns 'npm' + */ export function getPackageManager(): PackageManager { const name = process.env?.npm_config_user_agent || 'npm' return name.split('/')[0] as PackageManager