assertProcess support nodejs ChildProcess

This commit is contained in:
2021-07-26 15:09:14 -06:00
parent 2bf035df86
commit 4e617102f2
5 changed files with 47 additions and 39 deletions

View File

@@ -367,8 +367,8 @@ class Prelude {
#if (!macro && hxnodejs)
var kissProcess = ChildProcess.spawnSync("haxelib", ["run", "kiss", "convert", "--all", "--hscript"], {input: '${kissStr}\n'});
if (kissProcess.status != 0) {
var error:String = kissProcess.stderr;
throw 'failed to convert ${kissStr} to hscript: ${error}';
var error:Buffer = kissProcess.stderr;
throw 'failed to convert ${kissStr} to hscript: ${error.toString()}';
}
var output:Buffer = kissProcess.stdout;
return output.toString();
@@ -392,4 +392,28 @@ class Prelude {
throw "Can't convert Kiss to HScript on this target.";
#end
}
public static function assertProcess(command:String, args:Array<String>):String {
#if sys
var p = new Process(command, args);
switch (p.exitCode()) {
case 0:
return p.stdout.readAll().toString().trim();
default:
throw p.stderr.readAll().toString().trim();
}
#elseif hxnodejs
var p = ChildProcess.spawnSync(command, args);
switch (p.status) {
case 0:
var output:Buffer = p.stdout;
return output.toString();
default:
var error:String = p.stderr;
throw error;
}
#else
throw "Can't run a subprocess on this target."
#end
}
}