This commit is contained in:
2021-08-12 12:54:52 -06:00
parent b121018a8b
commit 033325455a
2 changed files with 21 additions and 0 deletions

View File

@@ -77,6 +77,7 @@ class Kiss {
"enumerate" => Symbol("Prelude.enumerate"), "enumerate" => Symbol("Prelude.enumerate"),
"assertProcess" => Symbol("Prelude.assertProcess"), "assertProcess" => Symbol("Prelude.assertProcess"),
"random" => Symbol("Std.random"), "random" => Symbol("Std.random"),
"walkDirectory" => Symbol("Prelude.walkDirectory"),
// These work with (apply) because they are added as "opAliases" in Macros.kiss: // These work with (apply) because they are added as "opAliases" in Macros.kiss:
"min" => Symbol("Prelude.min"), "min" => Symbol("Prelude.min"),
"max" => Symbol("Prelude.max"), "max" => Symbol("Prelude.max"),

View File

@@ -11,6 +11,9 @@ import js.node.Buffer;
#elseif sys #elseif sys
import sys.io.Process; import sys.io.Process;
#end #end
#if (sys || hxnodejs)
import sys.FileSystem;
#end
#if python #if python
import python.lib.subprocess.Popen; import python.lib.subprocess.Popen;
import python.Bytearray; import python.Bytearray;
@@ -373,6 +376,23 @@ class Prelude {
private static var kissProcess:Process = null; private static var kissProcess:Process = null;
#end #end
public static function walkDirectory(basePath, directory, processFile:(String) -> Void, processSubdirectory:(String) -> Void) {
#if (sys || hxnodejs)
for (fileOrFolder in FileSystem.readDirectory(joinPath(basePath, directory))) {
switch (fileOrFolder) {
case folder if (FileSystem.isDirectory(joinPath(basePath, directory, folder))):
var subdirectory = joinPath(directory, folder);
processSubdirectory(subdirectory);
walkDirectory(basePath, subdirectory, processFile, processSubdirectory);
case file:
processFile(joinPath(directory, file));
}
}
#else
throw "Can't walk a directory on this target.";
#end
}
/** /**
* On Sys targets and nodejs, Kiss can be converted to hscript at runtime * On Sys targets and nodejs, Kiss can be converted to hscript at runtime
* NOTE on non-nodejs targets, after the first time calling this function, * NOTE on non-nodejs targets, after the first time calling this function,