Skip to content

Commit 60bd1fe

Browse files
committed
feat: Added generic display message method to the reporter. Added messaging after all save file paths for imports.
1 parent 51aa606 commit 60bd1fe

File tree

6 files changed

+48
-32
lines changed

6 files changed

+48
-32
lines changed

src/orchestrators/apply.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ProcessName, ctx } from '../events/context.js';
22
import { Reporter } from '../ui/reporters/reporter.js';
3+
import { sleep } from '../utils/index.js';
34
import { PlanOrchestrator } from './plan.js';
45

56
export interface ApplyArgs {
@@ -30,6 +31,11 @@ export const ApplyOrchestrator = {
3031
await pluginManager.apply(project, filteredPlan);
3132
ctx.processFinished(ProcessName.APPLY);
3233

33-
await reporter.displayApplyComplete([]);
34+
reporter.displayMessage(`
35+
🎉 Finished applying 🎉
36+
Open a new terminal or source '.zshrc' for the new changes to be reflected`);
37+
38+
// Need to sleep to wait for the message to display before we exit
39+
await sleep(100);
3440
},
3541
};

src/orchestrators/import.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DependencyMap, PluginManager } from '../plugins/plugin-manager.js';
99
import { PromptType, Reporter } from '../ui/reporters/reporter.js';
1010
import { FileUtils } from '../utils/file.js';
1111
import { FileModificationCalculator, ModificationType } from '../utils/file-modification-calculator.js';
12+
import { sleep } from '../utils/index.js';
1213
import { InitializeOrchestrator } from './initialize.js';
1314

1415
export type RequiredParameters = Map<string, RequiredParameter[]>;
@@ -114,14 +115,6 @@ export class ImportOrchestrator {
114115
}
115116
}
116117

117-
private static async parse(path: string): Promise<Project> {
118-
ctx.subprocessStarted(SubProcessName.PARSE);
119-
const project = await CodifyParser.parse(path);
120-
ctx.subprocessFinished(SubProcessName.PARSE);
121-
122-
return project
123-
}
124-
125118
private static async validate(typeIds: string[], project: Project, pluginManager: PluginManager, dependencyMap: DependencyMap): Promise<void> {
126119
ctx.subprocessStarted(SubProcessName.VALIDATE)
127120

@@ -158,10 +151,16 @@ ${JSON.stringify(unsupportedTypeIds)}`);
158151
} else if (promptResult === 'In a new file') {
159152
const newFileName = await ImportOrchestrator.generateNewImportFileName();
160153
await ImportOrchestrator.saveNewFile(newFileName, importResult);
154+
} else if (promptResult === 'No') {
161155
}
162156
}
163157

164-
private static async updateExistingFile(reporter: Reporter, filePath: string, importResult: ImportResult, resourceInfoList: ResourceInfo[]): Promise<void> {
158+
private static async updateExistingFile(
159+
reporter: Reporter,
160+
filePath: string,
161+
importResult: ImportResult,
162+
resourceInfoList: ResourceInfo[]
163+
): Promise<void> {
165164
const existing = await CodifyParser.parse(filePath);
166165
ImportOrchestrator.attachResourceInfo(importResult.result, resourceInfoList);
167166
ImportOrchestrator.attachResourceInfo(existing.resourceConfigs, resourceInfoList);
@@ -172,13 +171,31 @@ ${JSON.stringify(unsupportedTypeIds)}`);
172171
resource
173172
})));
174173

174+
// No changes to be made
175+
if (result.diff === '') {
176+
reporter.displayMessage('\nNo changes are needed! Exiting...')
177+
178+
// Wait for the message to display before we exit
179+
await sleep(100);
180+
process.exit(0);
181+
}
182+
175183
reporter.displayFileModification(result.diff);
176184
const shouldSave = await reporter.promptConfirmation(`Save to file (${filePath})?`);
177185
if (!shouldSave) {
186+
reporter.displayMessage('\nSkipping save! Exiting...');
187+
188+
// Wait for the message to display before we exit
189+
await sleep(100);
178190
process.exit(0);
179191
}
180192

181193
await FileUtils.writeFile(filePath, result.newFile);
194+
195+
reporter.displayMessage('\n🎉 Imported completed and saved to file 🎉');
196+
197+
// Wait for the message to display before we exit
198+
await sleep(100);
182199
}
183200

184201
private static async saveNewFile(filePath: string, importResult: ImportResult): Promise<void> {

src/ui/components/default-component.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export function DefaultComponent(props: {
3737
}, []);
3838

3939
return <Box flexDirection="column">
40+
{
41+
renderStatus === RenderStatus.DISPLAY_MESSAGE && (
42+
<Text>{renderData as string}</Text>
43+
)
44+
}
4045
{
4146
renderStatus === RenderStatus.PROGRESS && (
4247
<ProgressDisplay emitter={spinnerEmitter} eventType="data"/>
@@ -70,15 +75,6 @@ export function DefaultComponent(props: {
7075
</Box>
7176
)
7277
}
73-
{
74-
renderStatus === RenderStatus.APPLY_COMPLETE && (
75-
<Box flexDirection="column">
76-
<Text> </Text>
77-
<Text>🎉 Finished applying 🎉</Text>
78-
<Text>Open a new terminal or source '.zshrc' for the new changes to be reflected</Text>
79-
</Box>
80-
)
81-
}
8278
{
8379
renderStatus === RenderStatus.SUDO_PROMPT && (
8480
<Box flexDirection="column">

src/ui/reporters/default-reporter.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ResourceConfig } from '../../entities/resource-config.js';
1010
import { ResourceInfo } from '../../entities/resource-info.js';
1111
import { Event, ProcessName, SubProcessName, ctx } from '../../events/context.js';
1212
import { ImportResult } from '../../orchestrators/import.js';
13-
import { sleep } from '../../utils/index.js';
1413
import { SudoUtils } from '../../utils/sudo.js';
1514
import { DefaultComponent } from '../components/default-component.js';
1615
import { ProgressState, ProgressStatus } from '../components/progress/progress-display.js';
@@ -102,6 +101,7 @@ export class DefaultReporter implements Reporter {
102101

103102
displayImportResult(importResult: ImportResult): void {
104103
this.updateRenderState(RenderStatus.DISPLAY_IMPORT_RESULT, importResult);
104+
store.set(store.progressState, null);
105105
}
106106

107107
async promptSudo(pluginName: string, data: SudoRequestData, secureMode: boolean): Promise<SudoRequestResponseData> {
@@ -123,6 +123,10 @@ export class DefaultReporter implements Reporter {
123123
this.progressState = null;
124124
}
125125

126+
displayMessage(message: string) {
127+
this.updateRenderState(RenderStatus.DISPLAY_MESSAGE, message);
128+
}
129+
126130
async promptConfirmation(message: string): Promise<boolean> {
127131
const result = await this.updateStateAndAwaitEvent<boolean>(
128132
() => this.updateRenderState(RenderStatus.PROMPT_CONFIRMATION, message),
@@ -147,11 +151,6 @@ export class DefaultReporter implements Reporter {
147151
return result
148152
}
149153

150-
async displayApplyComplete(messages: string[]): Promise<void> {
151-
this.updateRenderState(RenderStatus.APPLY_COMPLETE, messages);
152-
await sleep(100); // This gives the renderer enough time to complete before the prompt exits
153-
}
154-
155154
displayFileModification(diff: string) {
156155
this.updateRenderState(RenderStatus.DISPLAY_FILE_MODIFICATION, diff);
157156
}

src/ui/reporters/reporter.ts

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

33
import { Plan } from '../../entities/plan.js';
4-
import { ImportResult, RequiredParameters, UserSuppliedParameters } from '../../orchestrators/import.js';
5-
import { DebugReporter } from './debug-reporter.js';
4+
import { ImportResult } from '../../orchestrators/import.js';
65
import { DefaultReporter } from './default-reporter.js';
7-
import { PlainReporter } from './plain-reporter.js';
86
import { ResourceInfo } from '../../entities/resource-info.js';
97
import { ResourceConfig } from '../../entities/resource-config.js';
108

@@ -41,8 +39,6 @@ export enum PromptType {
4139
}
4240

4341
export interface Reporter {
44-
displayApplyComplete(message: string[]): Promise<void> | void;
45-
4642
displayPlan(plan: Plan): void
4743

4844
promptConfirmation(message: string): Promise<boolean>
@@ -56,6 +52,8 @@ export interface Reporter {
5652
displayImportResult(importResult: ImportResult): void;
5753

5854
displayFileModification(diff: string): void
55+
56+
displayMessage(message: string): void
5957
}
6058

6159
export enum ReporterType {

src/ui/store/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { atom, createStore, getDefaultStore, Setter, Getter, Atom, WritableAtom } from 'jotai'
1+
import { atom, getDefaultStore, Atom, WritableAtom } from 'jotai'
22

33
import { ProgressState } from '../components/progress/progress-display.js';
44

@@ -15,8 +15,8 @@ export enum RenderStatus {
1515
IMPORT_PROMPT,
1616
PROMPT_CONFIRMATION,
1717
PROMPT_OPTIONS,
18-
APPLY_COMPLETE,
1918
SUDO_PROMPT,
19+
DISPLAY_MESSAGE
2020
}
2121

2222
export const store = new class {

0 commit comments

Comments
 (0)