diff --git a/apps/remix-ide/src/app/tabs/script-runner-ui.tsx b/apps/remix-ide/src/app/tabs/script-runner-ui.tsx
index 61ea29c316..793db0cf42 100644
--- a/apps/remix-ide/src/app/tabs/script-runner-ui.tsx
+++ b/apps/remix-ide/src/app/tabs/script-runner-ui.tsx
@@ -1,9 +1,10 @@
import { IframePlugin, IframeProfile, ViewPlugin } from '@remixproject/engine-web'
import * as packageJson from '../../../../../package.json'
import React from 'react' // eslint-disable-line
-import { ScriptRunnerUI } from '@remix-scriptrunner' // eslint-disable-line
+import { customScriptRunnerConfig, Dependency, ScriptRunnerUI } from '@remix-scriptrunner' // eslint-disable-line
import { Profile } from '@remixproject/plugin-utils'
import { Engine } from '@remixproject/engine'
+import axios from 'axios'
const profile = {
name: 'scriptRunnerBridge',
@@ -98,10 +99,42 @@ export class ScriptRunnerUIPlugin extends ViewPlugin {
this.emit('info', data)
}
+ async buildScriptRunner(dependencies: Dependency[]) {
+ console.log('buildScriptRunner', dependencies)
+ }
+
+ async loadCustomConfig(){
+ console.log('loadCustomConfig')
+ await this.call('fileManager', 'open', 'script.config.json')
+ const content = await this.call('fileManager', 'readFile', 'script.config.json')
+ return JSON.parse(content)
+ }
+
+ async saveCustomConfig(content: customScriptRunnerConfig){
+ console.log('saveCustomConfig', content)
+ await this.call('fileManager', 'writeFile', 'script.config.json', JSON.stringify(content, null, 2))
+ }
+
+ async activateCustomScriptRunner(config: customScriptRunnerConfig){
+ console.log('activateCustomScriptRunner', config)
+ // post config to localhost:4000 using axios
+ const result = await axios.post('http://localhost:4000/build', config)
+ console.log(result)
+ if(result.data.hash) {
+ await this.loadScriptRunner(result.data.hash)
+ }
+ return result.data.hash
+ }
+
render() {
return (
-
+
)
}
diff --git a/libs/remix-ui/scriptrunner/src/index.ts b/libs/remix-ui/scriptrunner/src/index.ts
index be8e8bb09c..a1683b6b22 100644
--- a/libs/remix-ui/scriptrunner/src/index.ts
+++ b/libs/remix-ui/scriptrunner/src/index.ts
@@ -1 +1,2 @@
-export { ScriptRunnerUI } from './lib/script-runner-ui';
\ No newline at end of file
+export { ScriptRunnerUI } from './lib/script-runner-ui';
+export * from './types';
\ No newline at end of file
diff --git a/libs/remix-ui/scriptrunner/src/lib/custom-script-runner.tsx b/libs/remix-ui/scriptrunner/src/lib/custom-script-runner.tsx
new file mode 100644
index 0000000000..78ccb7cedd
--- /dev/null
+++ b/libs/remix-ui/scriptrunner/src/lib/custom-script-runner.tsx
@@ -0,0 +1,159 @@
+import React, { useEffect, useState } from "react";
+import { Accordion, Card, Button } from "react-bootstrap";
+import axios from "axios";
+import { customScriptRunnerConfig, Dependency, ProjectConfiguration } from "../types";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { faTrash } from "@fortawesome/free-solid-svg-icons";
+
+export interface ScriptRunnerUIProps {
+ // build custom script runner
+ buildScriptRunner: (dependencies: Dependency[]) => void;
+ publishedConfigurations: ProjectConfiguration[];
+ loadCustomConfig: () => any;
+ saveCustomConfig(content: customScriptRunnerConfig): void;
+ activateCustomScriptRunner(config: customScriptRunnerConfig): string;
+ addCustomConfig(config: ProjectConfiguration) : void;
+}
+
+export const CustomScriptRunner = (props: ScriptRunnerUIProps) => {
+ const [dependencies, setDependencies] = useState([]);
+ const [name, setName] = useState('');
+ const [alias, setAlias] = useState('');
+ const [version, setVersion] = useState('');
+ const [baseConfig, setBaseConfig] = useState('default');
+ const [loading, setLoading] = useState(false);
+
+ const handleAddDependency = () => {
+ if (name.trim() && version.trim()) {
+ const newDependency: Dependency = { name, version, import: true, alias };
+ setDependencies([...dependencies, newDependency]);
+ setName('');
+ setVersion('');
+ } else {
+ alert('Please fill out both name and version.');
+ }
+ };
+
+ const handleRemoveDependency = (index: number) => {
+ const updatedDependencies = dependencies.filter((_, i) => i !== index);
+ setDependencies(updatedDependencies);
+ };
+
+ const handleSaveToFile = () => {
+ const fileData = JSON.stringify(dependencies, null, 2);
+ console.log(fileData, baseConfig);
+ const customConfig: customScriptRunnerConfig = { baseConfiguration: baseConfig, dependencies };
+ console.log(customConfig);
+ props.saveCustomConfig(customConfig);
+ };
+
+ const loadFromFile = async () => {
+ const fileData: customScriptRunnerConfig = await props.loadCustomConfig();
+ console.log(fileData);
+ setDependencies(fileData.dependencies);
+ setBaseConfig(fileData.baseConfiguration);
+ }
+
+ const activateCustomConfig = async () => {
+ console.log('activate');
+ const customConfig: customScriptRunnerConfig = { baseConfiguration: baseConfig, dependencies };
+ console.log(customConfig);
+ setLoading(true);
+ const loadedConfig = await props.activateCustomScriptRunner(customConfig);
+ console.log(loadedConfig);
+ const newConfig: ProjectConfiguration = {
+ name: loadedConfig,
+ publish: true,
+ description: `Extension of ${baseConfig}`,
+ dependencies: dependencies,
+ replacements: {}
+ };
+ console.log(newConfig);
+ props.addCustomConfig(newConfig);
+ setLoading(false);
+ }
+
+ const onSelectBaseConfig = (e: React.ChangeEvent) => {
+ setBaseConfig(e.target.value);
+ }
+
+ if (loading) {
+ return
+ }
+
+ return (
+
+
Custom configuration
+
+
+
+
+ setName(e.target.value)}
+ style={{ marginRight: '10px' }}
+ />
+ setAlias(e.target.value)} />
+ setVersion(e.target.value)}
+ />
+
+
+
+ {dependencies.length > 0 && (
+
+ )}
+
+ {dependencies.length > 0 && (
+
)}
+
+ );
+}
\ No newline at end of file
diff --git a/libs/remix-ui/scriptrunner/src/lib/script-runner-ui.tsx b/libs/remix-ui/scriptrunner/src/lib/script-runner-ui.tsx
index b7af4a207c..bde50bac7b 100644
--- a/libs/remix-ui/scriptrunner/src/lib/script-runner-ui.tsx
+++ b/libs/remix-ui/scriptrunner/src/lib/script-runner-ui.tsx
@@ -1,22 +1,28 @@
import React, { useEffect, useState } from "react";
import { Accordion, Card, Button } from "react-bootstrap";
import axios from "axios";
-import { ProjectConfiguration } from "./types";
+import { customScriptRunnerConfig, Dependency, ProjectConfiguration } from "../types";
import { FormattedMessage } from "react-intl";
import { faCheck, faToggleOn } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Profile } from "@remixproject/plugin-utils";
import { IframeProfile, ViewProfile } from "@remixproject/engine-web";
import { Plugin } from "@remixproject/engine";
+import { CustomScriptRunner } from "./custom-script-runner";
export interface ScriptRunnerUIProps {
// Add your props here
loadScriptRunner: (name: string) => void;
+ // build custom script runner
+ buildScriptRunner: (dependencies: Dependency[]) => void;
+ loadCustomConfig: () => any;
+ saveCustomConfig(content: customScriptRunnerConfig): void;
+ activateCustomScriptRunner(config: customScriptRunnerConfig): string;
}
export const ScriptRunnerUI = (props: ScriptRunnerUIProps) => {
const { loadScriptRunner } = props;
- const [configurations, setConfigurations] = useState([]);
+ const [configurations, setConfigurations] = useState([]);
const [activeKey, setActiveKey] = useState('default');
const [activeConfig, setActiveConfig] = useState('default');
@@ -41,23 +47,34 @@ export const ScriptRunnerUI = (props: ScriptRunnerUIProps) => {
loadScriptRunner(key)
};
- // Filter out unpublished configurations
- const publishedConfigurations = configurations.filter((config) => config.publish);
+ const addCustomConfig = (config: ProjectConfiguration) => {
+ if(configurations.find((c) => c.name === config.name)) {
+ return;
+ }
+ setConfigurations([...configurations, config]);
+ setActiveConfig(config.name);
+ }
+
return (
- {publishedConfigurations.map((config: ProjectConfiguration, index) => (
+ {configurations.filter((config) => config.publish).map((config: ProjectConfiguration, index) => (
-
- {config.name}
+
+ {config.name}
handleSelect(config.name)} className="pointer px-2">
- {activeConfig !== config.name ?
- :
-
- }
+ {activeConfig !== config.name ?
+ :
+
+ }
@@ -75,7 +92,13 @@ export const ScriptRunnerUI = (props: ScriptRunnerUIProps) => {
>
))}
-
+
config.publish)}
+ buildScriptRunner={props.buildScriptRunner} />
);
};
diff --git a/libs/remix-ui/scriptrunner/src/lib/types.ts b/libs/remix-ui/scriptrunner/src/types/index.ts
similarity index 78%
rename from libs/remix-ui/scriptrunner/src/lib/types.ts
rename to libs/remix-ui/scriptrunner/src/types/index.ts
index ff093b428b..85a88ce447 100644
--- a/libs/remix-ui/scriptrunner/src/lib/types.ts
+++ b/libs/remix-ui/scriptrunner/src/types/index.ts
@@ -18,3 +18,8 @@ export interface Dependency {
dependencies: Dependency[];
replacements: Replacements;
}
+
+ export interface customScriptRunnerConfig {
+ baseConfiguration: string;
+ dependencies: Dependency[];
+ }
\ No newline at end of file