Skip to content

Commit

Permalink
feat: work on the script node
Browse files Browse the repository at this point in the history
  • Loading branch information
yamankatby committed May 2, 2023
1 parent 11acaf0 commit 14d4ce7
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions src/components/Workflow/ScriptNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ import NodeParam from "./NodeParam/NodeParam";
import NodeParams from "./NodeParams";
import NodeToolbar from "./NodeToolbar";

export type ParamType =
| "string"
| "boolean"
| "number"
| "object"
| "array"
| "null"
| "any"
| "select"
| "steps";

interface ParamConfig {
/**
* Friendly name of the parameter (3-5 words). Limited to 40 characters,
Expand All @@ -28,6 +39,17 @@ interface ParamConfig {
* @example "The GitHub repository to create the issue in."
*/
description?: string;

/**
* Type of the parameter.
*
* This is used to determine how the parameter's input is rendered to the
* user and what type of value you'll receive in the action's `execute`
* function.
*
* @example "string"
*/
type: ParamType;
}

type Params = Record<string, ParamConfig>;
Expand Down Expand Up @@ -74,22 +96,32 @@ const ScriptNode: FC<IScriptNodeProps> = ({}) => {
[setName]
);

const [script, setScript] = useState("");
const [script, setScript] = useState(`export default function main() {
console.log("Hello World!");
}
`);

const [params, setParams] = useState<Params>({});
const [result, setResult] = useState<Params>({});

const [isEditing, setIsEditing] = useState(false);

useEffect(() => {
try {
const { code } = transform(script, {
const transformedScript = transform(script, {
transforms: ["imports", "typescript"],
});
const x = eval(`var exports = {}; \n${code} \nexports`);
setParams(x.params ?? {});
} catch (e) {
console.error(e);
}
}).code;

const scriptWithExports = `
var exports = {};
${transformedScript}
exports;`;

const { params, result } = eval(scriptWithExports);

setParams(params);
setResult(result);
} catch {}
}, [script]);

return (
Expand Down

0 comments on commit 14d4ce7

Please sign in to comment.