Skip to content

Commit

Permalink
actions: use PackageHaxelib script
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed Mar 13, 2024
1 parent 61dd01f commit 996c882
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 20 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/haxelib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: krdlab/setup-haxe@v1
with:
haxe-version: 4.3.4
- name: Package Haxelib
working-directory: haxelib
run: haxe haxelib.hxml
- uses: actions/upload-artifact@v4
with:
name: feathersui-formatters-haxelib
path: |
src/
haxelib.json
README.md
LICENSE
NOTICE
CHANGELOG.md
path: bin/haxelib/
if-no-files-found: error
67 changes: 54 additions & 13 deletions haxelib/PackageHaxelib.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Feathers UI
Copyright 2020 Bowler Hat LLC. All Rights Reserved.
Copyright 2024 Bowler Hat LLC. All Rights Reserved.
This program is free software. You can redistribute and/or modify it in
accordance with the terms of the accompanying license agreement.
Expand All @@ -17,13 +17,21 @@ import sys.io.File;

class PackageHaxelib {
public static function main():Void {
final destDir = FileSystem.absolutePath("../bin/haxelib");
if (FileSystem.exists(destDir)) {
deleteDir(destDir);
}
FileSystem.createDirectory(destDir);

copyFile(FileSystem.absolutePath("../haxelib.json"), destDir);
copyFile(FileSystem.absolutePath("../README.md"), destDir);
copyFile(FileSystem.absolutePath("../CHANGELOG.md"), destDir);
copyFile(FileSystem.absolutePath("../LICENSE"), destDir);
copyFile(FileSystem.absolutePath("../NOTICE"), destDir);
copyDir(FileSystem.absolutePath("../src"), destDir);

var entries = new List<Entry>();
addFile(FileSystem.absolutePath("../haxelib.json"), entries);
addFile(FileSystem.absolutePath("../README.md"), entries);
addFile(FileSystem.absolutePath("../CHANGELOG.md"), entries);
addFile(FileSystem.absolutePath("../LICENSE"), entries);
addFile(FileSystem.absolutePath("../NOTICE"), entries);
addDirectory(FileSystem.absolutePath("../src"), true, entries);
addDirectory(destDir, entries);

var jsonContent = File.getContent("../haxelib.json");
var json = Json.parse(jsonContent);
Expand All @@ -44,12 +52,47 @@ class PackageHaxelib {
zip.write(entries);
}

private static function copyFile(filePath:String, destDir:String):Void {
var fileName = Path.withoutDirectory(filePath);
File.copy(filePath, Path.join([destDir, fileName]));
}

private static function copyDir(directoryPath:String, destParentDir:String):Void {
var dirName = Path.withoutDirectory(directoryPath);
var destDirPath = Path.join([destParentDir, dirName]);
FileSystem.createDirectory(destDirPath);
for (fileName in FileSystem.readDirectory(directoryPath)) {
var filePath = Path.join([directoryPath, fileName]);
if (FileSystem.isDirectory(filePath)) {
copyDir(filePath, destDirPath);
} else {
// extra files on macOS that should be skipped
if (fileName == ".DS_Store") {
continue;
}
copyFile(filePath, destDirPath);
}
}
}

private static function deleteDir(directoryPath:String):Void {
for (fileName in FileSystem.readDirectory(directoryPath)) {
var filePath = Path.join([directoryPath, fileName]);
if (FileSystem.isDirectory(filePath)) {
deleteDir(filePath);
} else {
FileSystem.deleteFile(filePath);
}
}
FileSystem.deleteDirectory(directoryPath);
}

private static function addFile(filePath:String, result:List<Entry>):Void {
addFileInternal(filePath, Path.directory(filePath), result);
}

private static function addDirectory(directoryPath:String, recursive:Bool, result:List<Entry>):Void {
addDirectoryInternal(directoryPath, Path.directory(directoryPath), recursive, result);
private static function addDirectory(directoryPath:String, result:List<Entry>):Void {
addDirectoryInternal(directoryPath, directoryPath, result);
}

private static function addFileInternal(filePath:String, relativeToDirPath:String, result:List<Entry>):Void {
Expand All @@ -66,13 +109,11 @@ class PackageHaxelib {
});
}

private static function addDirectoryInternal(directoryPath:String, relativeTo:String, recursive:Bool, result:List<Entry>):Void {
private static function addDirectoryInternal(directoryPath:String, relativeTo:String, result:List<Entry>):Void {
for (fileName in FileSystem.readDirectory(directoryPath)) {
var filePath = Path.join([directoryPath, fileName]);
if (FileSystem.isDirectory(filePath)) {
if (recursive) {
addDirectoryInternal(filePath, relativeTo, true, result);
}
addDirectoryInternal(filePath, relativeTo, result);
} else {
addFileInternal(filePath, relativeTo, result);
}
Expand Down

0 comments on commit 996c882

Please sign in to comment.