Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow deletion of stale templates. #28

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/hxp/System.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class System
private static var _hostPlatform:HostPlatform;
private static var _isText:Map<String, Bool>;
private static var _processorCores:Int = 0;
private static var _templates:Array<String> = [];

private static function __init__():Void
{
Expand Down Expand Up @@ -201,6 +202,8 @@ class System

if (process && context != null)
{
_templates.push(destination);

if (_isText.exists(extension) && !_isText.get(extension))
{
copyIfNewer(source, destination);
Expand Down Expand Up @@ -362,6 +365,24 @@ class System
catch (e:Dynamic) {}
}

public static function deleteStaleTemplates(targetDirectory:String)
{
var templatesFile = Path.combine(targetDirectory, ".templates");
if (FileSystem.exists(templatesFile))
{
for (template in File.getContent(templatesFile).split("\n"))
{
if (_templates.indexOf(template) < 0)
{
deleteFile(template);
}
}
}

File.saveContent(templatesFile, _templates.join("\n"));
_templates.resize(0);
}

private static function findTemplateRecursive_(templatePaths:Array<String>, source:String, templateFiles:Array<String>, templateMatched:Map<String, Bool>,
destinationPaths:Array<String>):Void
{
Expand Down