diff --git a/run.n b/run.n index 452e6f137..19b82b189 100644 Binary files a/run.n and b/run.n differ diff --git a/script/src/RunScript.hx b/script/src/RunScript.hx index 9c1e8f631..61ad10e9c 100644 --- a/script/src/RunScript.hx +++ b/script/src/RunScript.hx @@ -7,20 +7,83 @@ import sys.io.File; import sys.io.Process; import sys.FileSystem; +import helpers.*; +import project.Haxelib; -class RunScript { +class RunScript { + + public static function process_command( args:Array ) { + //fetch the commands + var command = args[0]; + var data = args[1]; + var data2 = (args.length > 2) ? args[2] : ''; + + switch(command) { + case "create": + var sample = data; + var name = data2; + + var samples_path = PathHelper.getHaxelib (new Haxelib ("haxelab")) + 'samples/'; + var sample_path = samples_path + sample + '/'; + + if(FileSystem.exists(sample_path)) { + //now check if they can make this here + var output_folder = (name!='') ? name : sample; + var output_path = cwd + output_folder; + + if(FileSystem.exists(output_path)) { + throw "Cannot create `" + sample + "` here, as that folder already exists!"; + } else { + trace(' - creating template at ' + output_path); + FileHelper.recursiveCopy(sample_path, output_path); + trace('Done!'); + } + } else { + throw "Sample project not found at : " + sample_path; + } + + return true; + default: + return false; + } + + return false; + } + + public static var cwd : String = './'; public static function main() { //take all args and forward them to build tools var args = Sys.args(); //get the current folder - var cwd = args[args.length-1]; - //remove it from the used args + cwd = args[args.length-1]; + //remove the CWD from the args args = args.splice(0,args.length-1); - //make a full command line - var full_args = [ "run", "openfl-tools" ].concat(args); - //enforce the folder to the current on - Sys.setCwd(cwd); - //and then execute - return Sys.command("haxelib", full_args); + + if(args.length-1 > 0) { + + var local_command = process_command(args); + + if(!local_command) { + + //make a full command line + var full_args = [ "run", "openfl-tools" ].concat(args); + //enforce the folder to the current on + Sys.setCwd(cwd); + //and then execute + return Sys.command("haxelib", full_args); + } + + } else { + Sys.println(""); + Sys.println(" lime build tools 1.0.1"); + Sys.println(" commands : "); + Sys.println("\ttest \n\t Build and run"); + Sys.println("\tbuild \n\t Build"); + Sys.println("\tcreate \n\t Create a copy of inside pwd"); + Sys.println(""); + return 0; + } //if we have enough args + + return 0; } }