Skip to content
Open
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
2 changes: 2 additions & 0 deletions Classes/Command/EvaluateEelExpressionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function invokeCommand(string $argument, CommandContext $commandContext):
$result = $e->getMessage();
}

// TODO: Convert NodeInterfaces to a variant of NodeResults with all properties and technical details

return new CommandInvocationResult($success, $result);
}
}
22 changes: 11 additions & 11 deletions Resources/Private/JavaScript/Terminal/src/Terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { actions as terminalActions, selectors as terminalSelectors } from './ac

interface TerminalProps {
config: TerminalConfig;
user: TerminalUser;
siteNode: Node;
documentNode: Node;
focusedNodes: string[];
i18nRegistry: I18nRegistry;
terminalOpen: boolean;
toggleNeosTerminal: (visible?: boolean) => void;
handleServerFeedback: (feedback: FeedbackEnvelope) => void;
}

Expand All @@ -37,18 +39,16 @@ class Terminal extends React.PureComponent<TerminalProps> {
};

render() {
const { config } = this.props as TerminalProps;

return (
<CommandsProvider
siteNode={this.props.siteNode?.contextPath}
documentNode={this.props.documentNode?.contextPath}
focusedNode={this.props.focusedNodes?.length > 0 ? this.props.focusedNodes[0] : null}
i18nRegistry={this.props.i18nRegistry}
handleServerFeedback={this.props.handleServerFeedback}
config={config}
>
<ReplWrapper {...this.props} />
<CommandsProvider i18nRegistry={this.props.i18nRegistry}>
<ReplWrapper
config={this.props.config}
user={this.props.user}
siteNode={this.props.siteNode}
documentNode={this.props.documentNode}
terminalOpen={this.props.terminalOpen}
toggleNeosTerminal={this.props.toggleNeosTerminal}
/>
</CommandsProvider>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ interface ReplProps {
welcomeMessage?: string;
registrationKey?: RegistrationKey;
};
user: {
firstName: string;
lastName: string;
fullName: string;
};
user: TerminalUser;
siteNode: Node;
documentNode: Node;
className?: string;
theme?: Record<string, string>;
terminalOpen?: boolean;
toggleNeosTerminal: (visible?: boolean) => void;
Expand Down Expand Up @@ -56,35 +51,26 @@ const ReplWrapper: React.FC<ReplProps> = ({
const command = commands[commandName];

// Register command globally
window.NeosTerminal[commandName] = (...args) => invokeCommand(commandName, args);
window.NeosTerminal[commandName] = (...args: any[]) => invokeCommand(commandName, args);

carry[commandName] = {
...command,
description: translate(command.description ?? ''),
fn: (...args) => {
fn: async (...args: any[]) => {
const currentTerminal = terminal.current;
invokeCommand(commandName, args)
.then((result) => {
currentTerminal.state.stdout.pop();
let output = result;
if (!result) {
output = translate('command.empty');
}
currentTerminal.pushToStdout(output);
})
.catch((error) => {
console.error(
error,
translate(
'command.invocationError',
'An error occurred during invocation of the "{commandName}" command',
{ commandName }
)
);
currentTerminal.pushToStdout(translate('command.evaluating'));
let evaluatingMessageRemoved = false;
for await (const result of invokeCommand(commandName, args)) {
if (!evaluatingMessageRemoved) {
currentTerminal.state.stdout.pop();
currentTerminal.pushToStdout(translate('command.error'));
});
return translate('command.evaluating');
evaluatingMessageRemoved = true;
}
let output = result;
if (!result) {
output = translate('command.empty');
}
currentTerminal.pushToStdout(output);
}
},
};
return carry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface CommandInvocationResult {
const doInvokeCommand = async (
endPoint: string,
commandName: string,
args: string[],
argument: string,
siteNode: string = null,
focusedNode: string = null,
documentNode: string = null
Expand All @@ -27,7 +27,7 @@ const doInvokeCommand = async (
},
body: JSON.stringify({
commandName,
argument: args.join(' '),
argument,
siteNode,
focusedNode,
documentNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const fetchCommands = async (endPoint: string): Promise<{ success: boolean; resu
.then((data: CommandList) => {
return data;
})
.catch((error: Error) => {
.catch(() => {
return {
success: false,
result: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import * as React from 'react';
import React from 'react';
import { createContext, useCallback, useContext, useEffect, useState } from 'react';

import { FeedbackEnvelope, I18nRegistry, CommandList, NodeContextPath } from '../interfaces';
import doInvokeCommand from '../helpers/doInvokeCommand';
import { I18nRegistry, CommandList } from '../interfaces';
import logToConsole from '../helpers/logger';
import getTerminalCommandRegistry from '../registry/TerminalCommandRegistry';

interface CommandsContextProps {
children: React.ReactElement;
config: TerminalConfig;
siteNode: NodeContextPath;
documentNode: NodeContextPath;
focusedNode?: NodeContextPath;
i18nRegistry: I18nRegistry;
handleServerFeedback: (feedback: FeedbackEnvelope) => void;
}

interface CommandsContextValues {
commands: CommandList;
invokeCommand: (endPoint: string, param: string[]) => Promise<string>;
invokeCommand: (endPoint: string, param: string[]) => AsyncGenerator<string | JSX.Element, null, void>;
translate: (
id: string,
fallback?: string,
Expand All @@ -31,15 +25,7 @@ interface CommandsContextValues {
export const CommandsContext = createContext({} as CommandsContextValues);
export const useCommands = (): CommandsContextValues => useContext(CommandsContext);

export const CommandsProvider = ({
config,
children,
documentNode,
focusedNode,
siteNode,
i18nRegistry,
handleServerFeedback,
}: CommandsContextProps) => {
export const CommandsProvider = ({ children, i18nRegistry }: CommandsContextProps) => {
const [commands, setCommands] = useState<CommandList>({});

useEffect(() => {
Expand All @@ -60,51 +46,34 @@ export const CommandsProvider = ({
);

const invokeCommand = useCallback(
async (commandName: string, args: string[]): Promise<string> => {
async function* (commandName: string, args: string[]): AsyncGenerator<string | JSX.Element, null, void> {
const command = commands[commandName];

if (!command)
throw Error(
translate('command.doesNotExist', `The command {commandName} does not exist!`, { commandName })
);

// TODO: Use TerminalCommandRegistry for invocation - needs some refactoring
const { success, result, uiFeedback } = await doInvokeCommand(
config.invokeCommandEndPoint,
for await (const { success, view, message, options } of getTerminalCommandRegistry().invokeCommand(
commandName,
args,
siteNode,
focusedNode,
documentNode
);
let parsedResult = result;
let textResult = result;
// Try to prettify json results
try {
parsedResult = JSON.parse(result);
if (typeof parsedResult !== 'string') {
textResult = JSON.stringify(parsedResult, null, 2);
} else {
textResult = parsedResult;
}
} catch (e) {
/* empty */
}
logToConsole(
success ? 'log' : 'error',
translate('command.output', `"{commandName} {argument}":`, {
commandName,
argument: args.join(' '),
}),
parsedResult
);
// Forward server feedback to the Neos UI
if (uiFeedback) {
handleServerFeedback(uiFeedback);
args.join(' ')
)) {
logToConsole(
success ? 'log' : 'error',
translate('command.output', `"{commandName} {argument}":`, {
commandName,
argument: args.join(' '),
}),
message,
view,
options
);
yield view;
}
return textResult;

return;
},
[commands, siteNode, documentNode, focusedNode]
[commands]
);

return (
Expand Down
Loading