fix: show setup destination paths

This commit is contained in:
Andrey Avtomonov 2026-05-13 14:26:52 +02:00
parent b75576279c
commit bb4a2d0c43
2 changed files with 23 additions and 5 deletions

View file

@ -3,6 +3,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { initKtxProject, parseKtxProjectConfig, readKtxSetupState } from '@ktx/context/project';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { gray } from './io/symbols.js';
import { type KtxSetupProjectPromptAdapter, runKtxSetupProjectStep } from './setup-project.js';
function makeIo(options: { stdoutIsTty?: boolean } = {}) {
@ -37,6 +38,12 @@ function makePromptAdapter(options: { choice?: string; choices?: string[]; textV
} satisfies KtxSetupProjectPromptAdapter;
}
function defaultSubfolderLabel(parentDir: string): string {
const childName = 'ktx-project';
const childDir = join(parentDir, childName);
return `New subfolder (${gray(childDir.slice(0, -childName.length))}${childName})`;
}
describe('setup project step', () => {
let tempDir: string;
@ -143,8 +150,11 @@ describe('setup project step', () => {
expect.objectContaining({
message: 'Where should KTX create the project?',
options: [
expect.objectContaining({ value: 'current', label: 'Current directory' }),
expect.objectContaining({ value: 'new-default', label: 'New subfolder (./ktx-project)' }),
expect.objectContaining({ value: 'current', label: `Current directory (${projectDir})` }),
expect.objectContaining({
value: 'new-default',
label: defaultSubfolderLabel(projectDir),
}),
expect.objectContaining({ value: 'new-custom', label: 'Custom path' }),
expect.objectContaining({ value: 'exit', label: 'Exit' }),
],
@ -174,7 +184,10 @@ describe('setup project step', () => {
expect.objectContaining({
message: 'Where should KTX create the project?',
options: expect.arrayContaining([
expect.objectContaining({ value: 'new-default', label: 'New subfolder (./ktx-project)' }),
expect.objectContaining({
value: 'new-default',
label: defaultSubfolderLabel(startDir),
}),
]),
}),
);

View file

@ -12,6 +12,7 @@ import {
serializeKtxProjectConfig,
} from '@ktx/context/project';
import type { KtxCliIo } from './cli-runtime.js';
import { gray } from './io/symbols.js';
import { withMenuOptionsSpacing, withTextInputNavigation } from './prompt-navigation.js';
import { withSetupInterruptConfirmation } from './setup-interrupt.js';
@ -321,6 +322,10 @@ export async function runKtxSetupProjectStep(
const prompts = deps.prompts ?? createClackSetupProjectPromptAdapter();
const defaultProjectDir = join(projectDir, DEFAULT_NEW_PROJECT_FOLDER_NAME);
const defaultProjectDirLabel = [
gray(defaultProjectDir.slice(0, -DEFAULT_NEW_PROJECT_FOLDER_NAME.length)),
DEFAULT_NEW_PROJECT_FOLDER_NAME,
].join('');
io.stdout.write(
'│ Use Up/Down to move, Enter to confirm the current selection, choose Back to return to the previous step, Ctrl+C to exit.\n',
);
@ -328,8 +333,8 @@ export async function runKtxSetupProjectStep(
const choice = await prompts.select({
message: 'Where should KTX create the project?',
options: [
{ value: 'current', label: 'Current directory' },
{ value: 'new-default', label: 'New subfolder (./ktx-project)' },
{ value: 'current', label: `Current directory (${projectDir})` },
{ value: 'new-default', label: `New subfolder (${defaultProjectDirLabel})` },
{ value: 'new-custom', label: 'Custom path' },
...(args.allowBack ? [{ value: 'back', label: 'Back' }] : []),
...(args.allowBack ? [] : [{ value: 'exit', label: 'Exit' }]),