Skip to content

Commit 77ab652

Browse files
committed
docs: add JSDoc comments to init.ts functions for CI docstring coverage
1 parent e461e45 commit 77ab652

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

src/commands/init.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ const TRANSLATIONS: Record<string, Record<TranslationKey, string>> = {
161161
},
162162
};
163163

164+
/**
165+
* 根据语言获取对应的翻译文本
166+
* @param lang - 语言代码('en' | 'zh')
167+
* @param key - 翻译键
168+
* @returns 对应语言的翻译文本,找不到时回退到英文
169+
*/
164170
function t(lang: string, key: TranslationKey): string {
165171
return TRANSLATIONS[lang]?.[key] ?? TRANSLATIONS.en[key];
166172
}
@@ -175,6 +181,12 @@ const COMET_BANNER = [
175181
` OpenSpec + Superpowers Workflow `,
176182
].join('\n');
177183

184+
/**
185+
* 交互式选择安装范围(项目级或全局)
186+
* @param options - 初始化选项
187+
* @param lang - 当前语言
188+
* @returns 选中的安装范围
189+
*/
178190
async function selectScope(options: InitOptions, lang: string): Promise<InstallScope> {
179191
if (options.scope) return options.scope;
180192
if (options.yes) return 'project';
@@ -188,6 +200,11 @@ async function selectScope(options: InitOptions, lang: string): Promise<InstallS
188200
});
189201
}
190202

203+
/**
204+
* 交互式选择语言
205+
* @param options - 初始化选项
206+
* @returns 选中的语言配置
207+
*/
191208
async function selectLanguage(options: InitOptions): Promise<LanguageConfig> {
192209
if (options.language) {
193210
return LANGUAGES.find((l) => l.id === options.language) ?? LANGUAGES[0];
@@ -202,6 +219,13 @@ async function selectLanguage(options: InitOptions): Promise<LanguageConfig> {
202219
return LANGUAGES.find((l) => l.id === langId) ?? LANGUAGES[0];
203220
}
204221

222+
/**
223+
* 交互式选择要安装的平台
224+
* @param detected - 已检测到的平台集合
225+
* @param options - 初始化选项
226+
* @param lang - 当前语言
227+
* @returns 选中的平台 ID 列表
228+
*/
205229
async function selectPlatforms(detected: Set<string>, options: InitOptions, lang: string): Promise<string[]> {
206230
const choices = PLATFORMS.map((p) => ({
207231
name: `${p.name}${detected.has(p.id) ? ` (${t(lang, 'detected')})` : ''}`,
@@ -217,6 +241,13 @@ async function selectPlatforms(detected: Set<string>, options: InitOptions, lang
217241
return checkbox({ message: t(lang, 'selectPlatforms'), choices, required: true });
218242
}
219243

244+
/**
245+
* 单个组件已存在时,询问用户是否覆盖
246+
* @param componentName - 组件名称
247+
* @param platformName - 平台名称
248+
* @param lang - 当前语言
249+
* @returns 用户选择:覆盖或跳过
250+
*/
220251
async function promptOverwriteChoice(
221252
componentName: string,
222253
platformName: string,
@@ -230,6 +261,13 @@ async function promptOverwriteChoice(
230261
],
231262
});
232263
}
264+
/**
265+
* 批量组件已存在时,询问用户批量覆盖、跳过或逐个选择
266+
* @param platformName - 平台名称
267+
* @param components - 已存在的组件列表
268+
* @param lang - 当前语言
269+
* @returns 用户选择:全部覆盖 / 全部跳过 / 逐个选择
270+
*/
233271
async function promptBulkOverwriteChoice(
234272
platformName: string,
235273
components: string[],
@@ -245,6 +283,13 @@ async function promptBulkOverwriteChoice(
245283
});
246284
}
247285

286+
/**
287+
* 根据批量覆盖选择结果应用 action 到组件计划
288+
* @param plan - 原始组件计划
289+
* @param choice - 批量选择结果(排除 'choose')
290+
* @param hasExisting - 各组件是否已存在
291+
* @returns 更新后的组件计划
292+
*/
248293
function applyBulkOverwriteChoice<T extends ComponentPlan>(
249294
plan: T,
250295
choice: Exclude<BulkOverwriteChoice, 'choose'>,
@@ -261,6 +306,12 @@ function applyBulkOverwriteChoice<T extends ComponentPlan>(
261306
};
262307
}
263308

309+
/**
310+
* 根据现有状态和选项解析安装动作
311+
* @param hasExisting - 目标是否已存在
312+
* @param options - 初始化选项
313+
* @returns 解析后的动作:install / overwrite / skip
314+
*/
264315
function resolveAction(
265316
hasExisting: boolean,
266317
options: InitOptions,
@@ -272,6 +323,12 @@ function resolveAction(
272323
return 'install';
273324
}
274325

326+
/**
327+
* 显示安装结果摘要
328+
* @param results - 各平台的安装结果
329+
* @param scope - 安装范围
330+
* @param lang - 当前语言
331+
*/
275332
function displaySummary(results: PlatformResult[], scope: InstallScope, lang: string): void {
276333
const scopeLabel = scope === 'global' ? os.homedir() : 'project';
277334

@@ -322,6 +379,11 @@ function displaySummary(results: PlatformResult[], scope: InstallScope, lang: st
322379
console.log(` ${t(lang, 'getStartedTweak')}\n`);
323380
}
324381

382+
/**
383+
* 执行 Comet 初始化命令:选择语言、范围、平台并安装各组件
384+
* @param targetPath - 目标路径
385+
* @param options - 初始化选项
386+
*/
325387
export async function initCommand(targetPath: string, options: InitOptions = {}): Promise<void> {
326388
const projectPath = path.resolve(targetPath);
327389
const log = options.json ? () => undefined : console.log;

0 commit comments

Comments
 (0)