diff --git a/lime/tools/helpers/FileHelper.hx b/lime/tools/helpers/FileHelper.hx index 7f0f29a60..1276b2a18 100644 --- a/lime/tools/helpers/FileHelper.hx +++ b/lime/tools/helpers/FileHelper.hx @@ -185,7 +185,7 @@ class FileHelper { if (_isText) { - LogHelper.info ("", " - \x1b[1mCopying template file:\x1b[0m " + source + " \x1b[3;37m->\x1b[0m " + destination); + //LogHelper.info ("", " - \x1b[1mProcessing template file:\x1b[0m " + source + " \x1b[3;37m->\x1b[0m " + destination); var fileContents:String = File.getContent (source); var template:Template = new Template (fileContents); @@ -195,6 +195,19 @@ class FileHelper { replace: function (_, s, sub, by) return StringTools.replace(s, sub, by) }); + try { + + if (FileSystem.exists (destination)) { + + var existingContent = File.getContent (destination); + if (result == existingContent) return; + + } + + } catch (e:Dynamic) {} + + LogHelper.info ("", " - \x1b[1mCopying template file:\x1b[0m " + source + " \x1b[3;37m->\x1b[0m " + destination); + try { var fileOutput:FileOutput = File.write (destination, true); @@ -418,11 +431,20 @@ class FileHelper { public static function recursiveCopyTemplate (templatePaths:Array, source:String, destination:String, context:Dynamic = null, process:Bool = true, warnIfNotFound:Bool = true) { - var paths = PathHelper.findTemplates (templatePaths, source, warnIfNotFound); + var destinations = []; + var paths = PathHelper.findTemplateRecursive (templatePaths, source, warnIfNotFound, destinations); - for (path in paths) { + if (paths != null) { - recursiveCopy (path, destination, context, process); + PathHelper.mkdir (destination); + + for (i in 0...paths.length) { + + var itemDestination = PathHelper.combine (destination, destinations[i]); + + copyFile (paths[i], itemDestination, context, process); + + } } diff --git a/lime/tools/helpers/PathHelper.hx b/lime/tools/helpers/PathHelper.hx index bd047ed1d..cccb3ae54 100644 --- a/lime/tools/helpers/PathHelper.hx +++ b/lime/tools/helpers/PathHelper.hx @@ -131,6 +131,89 @@ class PathHelper { } + public static function findTemplateRecursive (templatePaths:Array, path:String, warnIfNotFound:Bool = true, destinationPaths:Array = null):Array { + + var paths = findTemplates (templatePaths, path, warnIfNotFound); + if (paths.length == 0) return null; + + try { + + if (FileSystem.isDirectory (paths[0])) { + + var templateFiles = new Array (); + var templateMatched = new Map (); + + paths.reverse (); + + findTemplateRecursive_ (paths, "", templateFiles, templateMatched, destinationPaths); + return templateFiles; + + } + + } catch (e:Dynamic) {} + + paths.splice (0, paths.length - 1); + + if (destinationPaths != null) { + + destinationPaths.push (paths[0]); + + } + + return paths; + + } + + + private static function findTemplateRecursive_ (templatePaths:Array, source:String, templateFiles:Array, templateMatched:Map, destinationPaths:Array):Void { + + var files:Array; + + for (templatePath in templatePaths) { + + try { + + files = FileSystem.readDirectory (templatePath + source); + + for (file in files) { + + if (file.substr (0, 1) != ".") { + + var itemSource = source + "/" + file; + + if (!templateMatched.exists (itemSource)) { + + templateMatched.set (itemSource, true); + + if (FileSystem.isDirectory (templatePath + itemSource)) { + + findTemplateRecursive_ (templatePaths, itemSource, templateFiles, templateMatched, destinationPaths); + + } else { + + templateFiles.push (templatePath + itemSource); + + if (destinationPaths != null) { + + destinationPaths.push (itemSource); + + } + + } + + } + + } + + } + + } catch (e:Dynamic) {} + + } + + } + + public static function findTemplates (templatePaths:Array, path:String, warnIfNotFound:Bool = true):Array { var matches = [];