mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-30 21:30:05 -06:00
tweaked script node
This commit is contained in:
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
using FileFlows.Plugin;
|
||||
using Jint;
|
||||
using Jint.Runtime;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -71,13 +72,28 @@ internal class JavascriptExecutor
|
||||
})
|
||||
.SetValue("Logger", args.Logger)
|
||||
.SetValue("Variables", args.Variables)
|
||||
.SetValue("Flow", args);
|
||||
.SetValue("Flow", args)
|
||||
.SetValue(nameof(FileInfo), new Func<string, FileInfo>((string file) => new FileInfo(file)))
|
||||
.SetValue(nameof(DirectoryInfo), new Func<string, DirectoryInfo>((string path) => new DirectoryInfo(path))); ;
|
||||
foreach (var arg in execArgs.AdditionalArguments)
|
||||
engine.SetValue(arg.Key, arg.Value);
|
||||
|
||||
var result = int.Parse(engine.Evaluate(tcode).ToObject().ToString());
|
||||
return result;
|
||||
}
|
||||
catch(JavaScriptException ex)
|
||||
{
|
||||
// print out the code block for debugging
|
||||
int lineNumber = 0;
|
||||
var lines = execArgs.Code.Split('\n');
|
||||
string pad = "D" + (lines.ToString().Length);
|
||||
args.Logger.DLog("Code: " + Environment.NewLine +
|
||||
string.Join("\n", lines.Select(x => (++lineNumber).ToString("D3") + ": " + x)));
|
||||
|
||||
args.Logger?.ELog($"Failed executing script [{ex.LineNumber}, {ex.Column}]: {ex.Message}");
|
||||
return -1;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
args.Logger?.ELog("Failed executing function: " + ex.Message + Environment.NewLine + ex.StackTrace);
|
||||
|
||||
@@ -45,7 +45,8 @@ public class ScriptNode:Node
|
||||
var execArgs = new JavascriptExecutionArgs
|
||||
{
|
||||
Args = args,
|
||||
Code = Code + "\n\n" + entryPoint
|
||||
//Code = ("try\n{\n\t" + Code.Replace("\n", "\n\t") + "\n\n\t" + entryPoint + "\n} catch (err) { \n\tLogger.ELog(`Error in script [${err.line}]: ${err}`);\n\treturn -1;\n}").Replace("\t", " ")
|
||||
Code = (Code + "\n\n" + entryPoint).Replace("\t", " ").Trim()
|
||||
};
|
||||
|
||||
if (script.Parameters?.Any() == true)
|
||||
|
||||
Reference in New Issue
Block a user