Skip to content

Commit 5d9b8be

Browse files
committed
feat: Added improvements to import and init saving of results
1 parent 6c96b0a commit 5d9b8be

File tree

7 files changed

+17
-19
lines changed

7 files changed

+17
-19
lines changed

src/orchestrators/import.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,19 +470,15 @@ ${JSON.stringify(unsupportedTypeIds)}`);
470470
private static async generateNewImportFileName(): Promise<string> {
471471
const cwd = process.cwd();
472472

473-
// Save codify to a new folder so it doesn't interfere with the current project
474-
const folderPath = path.join(cwd, 'codify-imports')
475-
await FileUtils.createFolder(folderPath)
476-
477-
let fileName = path.join(folderPath, 'import.codify.jsonc')
473+
let fileName = path.join(cwd, 'import.codify.jsonc')
478474
let counter = 1;
479475

480476
while (true) {
481477
if (!(await FileUtils.fileExists(fileName))) {
482478
return fileName;
483479
}
484480

485-
fileName = path.join(folderPath, `import-${counter}.codify.jsonc`);
481+
fileName = path.join(cwd, `import-${counter}.codify.jsonc`);
486482
counter++;
487483
}
488484
}

src/orchestrators/init.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import chalk from 'chalk';
2+
import { tildify } from 'codify-plugin-lib';
23
import path from 'node:path';
34

45
import { PluginInitOrchestrator } from '../common/initialize-plugins.js';
@@ -82,10 +83,11 @@ Enjoy!
8283

8384
while (!isValidSaveLocation) {
8485
input = (await reporter.promptInput(
85-
`Where to save the new Codify configs? ${chalk.grey.dim('(leave blank for ~/codify.jsonc)')}`,
86-
error ? `Invalid location: ${input} already exists` : undefined)
86+
`Where to save the new Codify configs? ${chalk.grey.dim(`(leave blank for ${tildify(process.cwd())}/codify.jsonc)`)}`,
87+
error ? `Invalid location: ${input} already exists` : undefined,
88+
`${tildify(process.cwd())}/codify.jsonc`)
8789
)
88-
input = input ? input : '~/codify.jsonc';
90+
input = input ?? `${process.cwd()}/codify.jsonc`;
8991

9092
locationToSave = path.resolve(untildify(resolvePathWithVariables(input)));
9193

src/ui/components/default-component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function DefaultComponent(props: {
158158
<Box flexDirection='column'>
159159
<Text bold>{(renderData as any).prompt}</Text>
160160
{ (renderData as any).error && (<Text color='red'>{(renderData as any).error}</Text>) }
161-
<TextInput onSubmit={(result) => emitter.emit(RenderEvent.PROMPT_RESULT, result)} placeholder='~/codify.jsonc' />
161+
<TextInput onSubmit={(result) => emitter.emit(RenderEvent.PROMPT_RESULT, result)} placeholder={(renderData as any).placeholder} />
162162
</Box>
163163
)
164164
}

src/ui/reporters/default-reporter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ export class DefaultReporter implements Reporter {
6969
)
7070
}
7171

72-
async promptInput(prompt: string, error?: string, validation?: () => Promise<boolean>, autoComplete?: (input: string) => string[]): Promise<string> {
72+
async promptInput(prompt: string, error?: string, placeholder?: string): Promise<string> {
7373
return this.updateStateAndAwaitEvent<string>(
74-
() => this.updateRenderState(RenderStatus.PROMPT_INPUT, { prompt, error }),
74+
() => this.updateRenderState(RenderStatus.PROMPT_INPUT, { prompt, error, placeholder }),
7575
RenderEvent.PROMPT_RESULT,
7676
)
7777
}

src/ui/reporters/plain-reporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class PlainReporter implements Reporter {
107107

108108
async displayProgress(): Promise<void> {}
109109

110-
async promptInput(prompt: string, error?: string, validation?: () => Promise<boolean>, autoComplete?: (input: string) => string[]): Promise<string> {
110+
async promptInput(prompt: string, error?: string): Promise<string> {
111111
return new Promise((resolve) => {
112112
this.rl.question(prompt + (error ? chalk.red(`\n${error} `) : ''), (answer) => resolve(answer));
113113
});

src/ui/reporters/reporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface Reporter {
5353

5454
promptInitResultSelection(availableTypes: string[]): Promise<string[]>;
5555

56-
promptInput(prompt: string, error?: string, validation?: () => Promise<boolean>, autoComplete?: (input: string) => string[]): Promise<string>;
56+
promptInput(prompt: string, error?: string, placeholder?: string): Promise<string>;
5757

5858
promptConfirmation(message: string): Promise<boolean>
5959

test/orchestrator/mocks/reporter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { SpawnStatus, SudoRequestData, SudoRequestResponseData } from 'codify-schemas';
1+
import { SudoRequestData } from 'codify-schemas';
22

33
import { Plan } from '../../../src/entities/plan.js';
44
import { ResourceConfig } from '../../../src/entities/resource-config.js';
55
import { ResourceInfo } from '../../../src/entities/resource-info.js';
6+
import { FileModificationResult } from '../../../src/generators/index.js';
67
import { ImportResult } from '../../../src/orchestrators/import.js';
78
import { prettyFormatPlan } from '../../../src/ui/plan-pretty-printer.js';
89
import { PromptType, Reporter } from '../../../src/ui/reporters/reporter.js';
9-
import { FileModificationResult } from '../../../src/utils/file-modification-calculator.js';
1010

1111
export interface MockReporterConfig {
1212
validatePlan?: (plan: Plan) => Promise<void> | void;
@@ -15,7 +15,7 @@ export interface MockReporterConfig {
1515
promptConfirmation?: () => boolean;
1616
promptOptions?: (message: string, options: string[]) => number;
1717
promptUserForValues?: (resourceInfo: ResourceInfo[]) => Promise<ResourceConfig[]> | ResourceConfig[];
18-
promptInput?: (prompt: string, error?: string | undefined, validation?: (() => Promise<boolean>) | undefined, autoComplete?: ((input: string) => string[]) | undefined) => Promise<string>
18+
promptInput?: (prompt: string, error?: string | undefined) => Promise<string>
1919
promptInitResultSelection?: (availableTypes: string[]) => Promise<string[]> | string[];
2020
hide?: () => void;
2121
displayImportResult?: (importResult: ImportResult, showConfigs: boolean) => Promise<void> | void;
@@ -48,8 +48,8 @@ export class MockReporter implements Reporter {
4848
return (await this.config?.promptInitResultSelection?.(availableTypes)) ?? [];
4949
}
5050

51-
async promptInput(prompt: string, error?: string | undefined, validation?: (() => Promise<boolean>) | undefined, autoComplete?: ((input: string) => string[]) | undefined): Promise<string> {
52-
return (await this.config?.promptInput?.(prompt, error, validation)) ?? '';
51+
async promptInput(prompt: string, error?: string | undefined): Promise<string> {
52+
return (await this.config?.promptInput?.(prompt, error)) ?? '';
5353
}
5454

5555
async promptPressKeyToContinue(message?: string | undefined): Promise<void> {}

0 commit comments

Comments
 (0)