Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codify.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"default": "../codify-homebrew-plugin/src/index.ts"
}
},
{ "type": "terraform" },
{
"type": "homebrew",
"taps": [
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/default-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { ImportResultComponent } from './import/import-result.js';
import { ImportParametersForm } from './import/index.js';
import { PlanComponent } from './plan/plan.js';
import { ProgressDisplay, ProgressState } from './progress/progress-display.js';

Check failure on line 13 in src/ui/components/default-component.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find module './progress/progress-display.js' or its corresponding type declarations.

const spinnerEmitter = new EventEmitter();

Expand Down Expand Up @@ -97,7 +97,7 @@
return <Box flexDirection="column">
{
([RenderState.APPLY_COMPLETE, RenderState.APPLYING, RenderState.GENERATING_PLAN].includes(state)) && progressState && !hideProgress && (
<ProgressDisplay emitter={spinnerEmitter} eventType="data" progress={progressState}/>
<ProgressDisplay />
)
}
{
Expand Down
6 changes: 3 additions & 3 deletions src/ui/components/plan/plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import { ResourceText } from './resource-text.js';
export function PlanComponent(props: {
plan: Plan,
}) {
const filteredPlan = props.plan.filterNoopResources();
const { plan } = props;

return <Box flexDirection="column">
<Box borderColor="green" borderStyle="round">
<Text>Codify Plan</Text>
</Box>
<Text>Path: {props.plan.project.path}</Text>
<Text>Path: {plan.project.path}</Text>
<Text>The following actions will be performed: </Text>
<Text> </Text>
<Box flexDirection="column" marginLeft={1}>{
filteredPlan.resources.map((p, idx) =>
plan.resources.map((p, idx) =>
<Box flexDirection="column" key={idx} marginBottom={1}>
<ResourceText plan={p}/>
<Text>{prettyFormatResourcePlan(p)}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box } from 'ink';
import EventEmitter from 'node:events';
import React from 'react';

import Spinner from './spinner.js';
import Spinner from './Spinner.js';

export enum ProgressStatus {
IN_PROGRESS,
Expand Down
113 changes: 113 additions & 0 deletions src/ui/components/progress/progress-subscriber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Subscribes to the global ctx event bus and translates
import { ctx, Event, ProcessName, SubProcessName } from '../../../events/context.js';
import { ProgressStatus } from './ProgressDisplay.js';

Check failure on line 3 in src/ui/components/progress/progress-subscriber.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Import declaration conflicts with local declaration of 'ProgressStatus'.

const ProgressLabelMapping = {
[ProcessName.APPLY]: 'Codify apply',
[ProcessName.PLAN]: 'Codify plan',
[ProcessName.DESTROY]: 'Codify destroy',
[ProcessName.IMPORT]: 'Codify import',
[SubProcessName.APPLYING_RESOURCE]: 'Applying resource',
[SubProcessName.GENERATE_PLAN]: 'Refresh states and generating plan',
[SubProcessName.INITIALIZE_PLUGINS]: 'Initializing plugins',
[SubProcessName.PARSE]: 'Parsing configs',
[SubProcessName.VALIDATE]: 'Validating configs',
[SubProcessName.GET_REQUIRED_PARAMETERS]: 'Getting required parameters',
[SubProcessName.IMPORT_RESOURCE]: 'Importing resource'
}

enum ProgressStatus {
IN_PROGRESS,
FINISHED,
}

export interface ProgressState {
name: string,
label: string;
status: ProgressStatus;
subProgresses: Array<{
name: string,
label: string;
status: ProgressStatus;
}> | null;
}

export class DefaultReporterProgressSubscriber {
private listeners: Array<(newState: ProgressState | null, eventType: Event) => void> = [];
private state: ProgressState | null = null;

constructor() {
ctx.on(Event.PROCESS_START, (name) => this.onProcessStartEvent(name))
ctx.on(Event.PROCESS_FINISH, (name) => this.onProcessFinishEvent(name))
ctx.on(Event.SUB_PROCESS_START, (name, additionalName) => this.onSubprocessStartEvent(name, additionalName));
ctx.on(Event.SUB_PROCESS_FINISH, (name, additionalName) => this.onSubprocessFinishEvent(name, additionalName))
}

onUpdate(fn: (newState: ProgressState | null, eventType: Event) => void) {
this.listeners.push(fn);
}

private flushUpdate(eventType: Event) {
this.state = structuredClone(this.state);
this.listeners.forEach((listener) => listener(this.state, eventType));
}

private onProcessStartEvent(name: ProcessName): void {
const label = ProgressLabelMapping[name];

// log(`${label} started`)
this.state = {
label: label + '...',
name,
status: ProgressStatus.IN_PROGRESS,
subProgresses: [],
}
this.flushUpdate(Event.PROCESS_START);
}

private onProcessFinishEvent(name: ProcessName): void {
const label = ProgressLabelMapping[name];

// log(`${label} finished successfully`)
this.state!.status = ProgressStatus.FINISHED;
this.flushUpdate(Event.PROCESS_FINISH)
}

private onSubprocessStartEvent(name: SubProcessName, additionalName?: string): void {
const label = ProgressLabelMapping[name] + (additionalName

Check failure on line 77 in src/ui/components/progress/progress-subscriber.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Element implicitly has an 'any' type because expression of type 'SubProcessName' can't be used to index type '{ apply: string; plan: string; destroy: string; import: string; apply_resource: string; generate_plan: string; initialize_plugins: string; parse: string; validate: string; get_required_parameters: string; import_resource: string; }'.
? ' ' + additionalName
: ''
);

// log(`${label} started`)

this.state?.subProgresses?.push({
label,
name: name + additionalName,
status: ProgressStatus.IN_PROGRESS,
})

this.flushUpdate(Event.SUB_PROCESS_START);
}

private onSubprocessFinishEvent(name: SubProcessName, additionalName?: string): void {
const label = ProgressLabelMapping[name] + (additionalName

Check failure on line 94 in src/ui/components/progress/progress-subscriber.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Element implicitly has an 'any' type because expression of type 'SubProcessName' can't be used to index type '{ apply: string; plan: string; destroy: string; import: string; apply_resource: string; generate_plan: string; initialize_plugins: string; parse: string; validate: string; get_required_parameters: string; import_resource: string; }'.
? ' ' + additionalName
: ''
);

const subProgress = this.state
?.subProgresses
?.find((p) => p.name === name + additionalName);

if (!subProgress) {
return;
}

subProgress.status = ProgressStatus.FINISHED;

this.flushUpdate(Event.SUB_PROCESS_FINISH);

// log(`${label} finished successfully`)
}
}
12 changes: 12 additions & 0 deletions src/ui/components/sections/CompletionSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Box, Text } from 'ink';
import React from 'react';

export function CompletionSection() {
return (
<Box flexDirection="column">
<Text> </Text>
<Text>🎉 Finished applying 🎉</Text>
<Text>Open a new terminal or source '.zshrc' for the new changes to be reflected</Text>
</Box>
);
}
15 changes: 15 additions & 0 deletions src/ui/components/sections/SudoSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Box } from 'ink';
import { RenderEvent } from '../../reporters/reporter.js';
import React from 'react';
import { PasswordInput } from '@inkjs/ui';

export function SudoSection() {
return <Box flexDirection="column">
<Text>Password:</Text>

Check failure on line 8 in src/ui/components/sections/SudoSection.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

'Text' cannot be used as a JSX component.
{/* Use sudoAttemptCount as a hack to reset password input between attempts */}
<PasswordInput key={sudoAttemptCount} onSubmit={(password) => {

Check failure on line 10 in src/ui/components/sections/SudoSection.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'sudoAttemptCount'.
emitter.emit(RenderEvent.PROMPT_SUDO_RESULT, password);

Check failure on line 11 in src/ui/components/sections/SudoSection.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find name 'emitter'.
}}/>
</Box>

}
1 change: 0 additions & 1 deletion src/ui/reporters/default-reporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { ImportResult, RequiredParameters, UserSuppliedParameters } from '../../orchestrators/import.js';
import { SudoUtils } from '../../utils/sudo.js';
import { DefaultComponent } from '../components/default-component.js';
import { ProgressState, ProgressStatus } from '../components/progress/progress-display.js';

Check failure on line 12 in src/ui/reporters/default-reporter.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot find module '../components/progress/progress-display.js' or its corresponding type declarations.
import { DisplayPlanStateTransition, RenderEvent, RenderState, Reporter } from './reporter.js';

const ProgressLabelMapping = {
Expand Down Expand Up @@ -144,7 +144,6 @@

this.log(`${label} finished successfully`)
this.renderEmitter.emit(RenderEvent.PROGRESS_UPDATE, this.progressState);

}

private onSubprocessStartEvent(name: SubProcessName, additionalName?: string): void {
Expand All @@ -171,7 +170,7 @@

const subProgress = this.progressState
?.subProgresses
?.find((p) => p.name === name + additionalName);

Check failure on line 173 in src/ui/reporters/default-reporter.tsx

View workflow job for this annotation

GitHub Actions / build-and-test

Parameter 'p' implicitly has an 'any' type.

if (!subProgress) {
return;
Expand Down
Loading
Loading