Skip to content

Commit

Permalink
Update the build system [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Aug 30, 2024
1 parent 36d7bee commit d5f3c45
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 62 deletions.
17 changes: 15 additions & 2 deletions scripts/Clean.hx
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import sys.FileSystem;
using Lambda;
using haxe.io.Path;

/** Deletes all generated files. **/
function main() {
["lib", "res"].filter(FileSystem.exists).iter(Tools.removeDirectory);
Tools.cleanDirectory("var");
["lib", "res"].filter(FileSystem.exists).iter(removeDirectory);
cleanDirectory("var");
}

/** Recursively deletes all files in the specified `directory`. **/
function cleanDirectory(directory: String) for (entry in FileSystem.readDirectory(directory).filter(entry -> entry != ".gitkeep")) {
final path = Path.join([directory, entry]);
FileSystem.isDirectory(path) ? removeDirectory(path) : FileSystem.deleteFile(path);
}

/** Recursively deletes the specified `directory`. **/
function removeDirectory(directory: String) {
cleanDirectory(directory);
FileSystem.deleteDirectory(directory);
}
49 changes: 48 additions & 1 deletion scripts/Publish.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
//! --class-path src --library tink_core
import free_mobile.Platform;
import haxe.crypto.Crc32;
import haxe.zip.Entry;
import haxe.zip.Writer;
import sys.FileSystem;
import sys.io.File;
using Lambda;
using haxe.io.Path;
using haxe.zip.Tools;

/** Publishes the package. **/
function main() {
Tools.compress(["CHANGELOG.md", "LICENSE.md", "README.md", "haxelib.json", "src"], "var/haxelib.zip");
compress(["CHANGELOG.md", "LICENSE.md", "README.md", "haxelib.json", "src"], "var/haxelib.zip");
Sys.command("haxelib submit var/haxelib.zip");
for (action in ["tag", "push origin"]) Sys.command('git $action v${Platform.packageVersion}');
}

/** Creates a ZIP archive from the specified file system entities. **/
private function compress(sources: Array<String>, destination: String) {
final output = File.write(destination);
final writer = new Writer(output);

var entries = [];
for (source in sources) entries = entries.concat(FileSystem.isDirectory(source) ? compressDirectory(source) : [compressFile(source)]);
writer.write(entries.list());
output.close();
}

/** Compresses the content of the specified `directory` in ZIP format. **/
private function compressDirectory(directory: String) {
var entries = [];
for (entry in FileSystem.readDirectory(directory)) {
final path = Path.join([directory, entry]);
entries = entries.concat(FileSystem.isDirectory(path) ? compressDirectory(path) : [compressFile(path)]);
}

return entries;
}

/** Compresses the specified `file` in ZIP format. **/
private function compressFile(file: String) {
final bytes = File.getBytes(file);
final entry: Entry = {
compressed: false,
crc32: Crc32.make(bytes),
data: bytes,
dataSize: bytes.length,
fileName: file,
fileSize: bytes.length,
fileTime: FileSystem.stat(file).mtime
};

entry.compress(9);
return entry;
}
59 changes: 0 additions & 59 deletions scripts/Tools.hx

This file was deleted.

0 comments on commit d5f3c45

Please sign in to comment.