Do not copy template files if identical to target, do not process matching template paths multiple times
This commit is contained in:
@@ -185,7 +185,7 @@ class FileHelper {
|
|||||||
|
|
||||||
if (_isText) {
|
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 fileContents:String = File.getContent (source);
|
||||||
var template:Template = new Template (fileContents);
|
var template:Template = new Template (fileContents);
|
||||||
@@ -195,6 +195,19 @@ class FileHelper {
|
|||||||
replace: function (_, s, sub, by) return StringTools.replace(s, sub, by)
|
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 {
|
try {
|
||||||
|
|
||||||
var fileOutput:FileOutput = File.write (destination, true);
|
var fileOutput:FileOutput = File.write (destination, true);
|
||||||
@@ -418,11 +431,20 @@ class FileHelper {
|
|||||||
|
|
||||||
public static function recursiveCopyTemplate (templatePaths:Array<String>, source:String, destination:String, context:Dynamic = null, process:Bool = true, warnIfNotFound:Bool = true) {
|
public static function recursiveCopyTemplate (templatePaths:Array<String>, 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,6 +131,89 @@ class PathHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function findTemplateRecursive (templatePaths:Array<String>, path:String, warnIfNotFound:Bool = true, destinationPaths:Array<String> = null):Array<String> {
|
||||||
|
|
||||||
|
var paths = findTemplates (templatePaths, path, warnIfNotFound);
|
||||||
|
if (paths.length == 0) return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (FileSystem.isDirectory (paths[0])) {
|
||||||
|
|
||||||
|
var templateFiles = new Array<String> ();
|
||||||
|
var templateMatched = new Map<String, Bool> ();
|
||||||
|
|
||||||
|
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<String>, source:String, templateFiles:Array<String>, templateMatched:Map<String, Bool>, destinationPaths:Array<String>):Void {
|
||||||
|
|
||||||
|
var files:Array<String>;
|
||||||
|
|
||||||
|
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<String>, path:String, warnIfNotFound:Bool = true):Array<String> {
|
public static function findTemplates (templatePaths:Array<String>, path:String, warnIfNotFound:Bool = true):Array<String> {
|
||||||
|
|
||||||
var matches = [];
|
var matches = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user