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

Implement System.onTouchFile. #35

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
38 changes: 37 additions & 1 deletion src/hxp/System.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class System
private static var _hostArchitecture:HostArchitecture;
private static var _hostPlatform:HostPlatform;
private static var _isText:Map<String, Bool>;
private static var _onTouchFile:Array<String -> Bool -> Void> = [];
private static var _processorCores:Int = 0;

private static function __init__():Void
Expand Down Expand Up @@ -140,6 +141,8 @@ class System
{
runCommand(path, "zip", ["-r", Path.relocatePath(targetPath, path), "./"]);
}

dispatchTouch(targetPath);
#end
}

Expand Down Expand Up @@ -222,6 +225,8 @@ class System
{
// Log.info ("", " - \x1b[1mProcessing template file:\x1b[0m " + source + " \x1b[3;37m->\x1b[0m " + destination);

dispatchTouch(destination, true);

var fileContents:String = File.getContent(source);
var template:Template = new Template(fileContents);
var result:String = template.execute(context,
Expand Down Expand Up @@ -274,7 +279,7 @@ class System

public static function copyIfNewer(source:String, destination:String)
{
// allFiles.push (destination);
dispatchTouch(destination);

if (!isNewer(source, destination))
{
Expand Down Expand Up @@ -551,6 +556,8 @@ class System

public static function linkFile(source:String, destination:String, symbolic:Bool = true, overwrite:Bool = false)
{
dispatchTouch(destination);

if (!isNewer(source, destination))
{
return;
Expand Down Expand Up @@ -910,6 +917,8 @@ class System
System.mkdir(Path.directory(destination));
Log.info("", " - \x1b[1mRenaming file:\x1b[0m " + source + " \x1b[3;37m->\x1b[0m " + destination);

dispatchTouch(destination);

try
{
File.copy(source, destination);
Expand Down Expand Up @@ -938,6 +947,8 @@ class System
{
if (FileSystem.exists(sourcePath))
{
dispatchTouch(sourcePath);

var output = File.getContent(sourcePath);

var index = output.indexOf(replaceString);
Expand Down Expand Up @@ -1402,14 +1413,39 @@ class System

public static function writeBytes(bytes:Bytes, path:String):Void
{
dispatchTouch(path);

File.saveBytes(path, bytes);
}

public static function writeText(text:String, path:String):Void
{
dispatchTouch(path);

File.saveContent(path, text);
}

// Events

private static function dispatchTouch(path:String, ?isTemplate:Bool = false):Void
{
for (callback in _onTouchFile)
{
callback(path, isTemplate);
}
}

/**
Registers the given callback to be called whenever this class creates or
modifies a file. This can be used to build a list of non-stale files.
@param callback A callback, taking a file path as its first argument
and whether the file is a template as its second.
**/
public static inline function onTouchFile(callback:String -> Bool -> Void):Void
{
_onTouchFile.push(callback);
}

// Get & Set Methods

private static function get_hostArchitecture():HostArchitecture
Expand Down
Loading