| 1 |
import haxe.crypto.Crc32; |
| 2 |
import haxe.zip.Entry; |
| 3 |
import haxe.zip.Writer; |
| 4 |
import haxe.zip.Tools; |
| 5 |
|
| 6 |
import sys.io.File; |
| 7 |
import sys.FileSystem; |
| 8 |
import haxelib.client.Main.VERSION; |
| 9 |
import haxelib.Data.Infos; |
| 10 |
|
| 11 |
using StringTools; |
| 12 |
|
| 13 |
class Package { |
| 14 |
static var outPath = "package.zip"; |
| 15 |
|
| 16 |
static function main() { |
| 17 |
checkVersion(); |
| 18 |
switch Sys.systemName() { |
| 19 |
case 'Windows': |
| 20 |
zipWindows(); |
| 21 |
case _: |
| 22 |
var exitCode = Sys.command('zip', ['-r', outPath, 'src/haxelib', 'haxelib.json', 'run.n', 'README.md']); |
| 23 |
Sys.exit(exitCode); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
static function zipWindows() { |
| 28 |
var entries = new List<Entry>(); |
| 29 |
|
| 30 |
function add(path:String, ?target:String) { |
| 31 |
if (!FileSystem.exists(path)) |
| 32 |
throw 'Invalid path: $path'; |
| 33 |
|
| 34 |
if (target == null) |
| 35 |
target = path; |
| 36 |
|
| 37 |
if (FileSystem.isDirectory(path)) { |
| 38 |
for (item in FileSystem.readDirectory(path)) |
| 39 |
add(path + "/" + item, target + "/" + item); |
| 40 |
} else { |
| 41 |
Sys.println("Adding " + target); |
| 42 |
var bytes = File.getBytes(path); |
| 43 |
var entry:Entry = { |
| 44 |
fileName: target, |
| 45 |
fileSize: bytes.length, |
| 46 |
fileTime: FileSystem.stat(path).mtime, |
| 47 |
compressed: false, |
| 48 |
dataSize: 0, |
| 49 |
data: bytes, |
| 50 |
crc32: Crc32.make(bytes), |
| 51 |
} |
| 52 |
Tools.compress(entry, 9); |
| 53 |
entries.add(entry); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
for (file in FileSystem.readDirectory("src/haxelib")) |
| 58 |
if (file != "server") |
| 59 |
add('src/haxelib/$file'); |
| 60 |
|
| 61 |
add("haxelib.json"); |
| 62 |
add("run.n"); |
| 63 |
add("README.md"); |
| 64 |
|
| 65 |
Sys.println("Saving to " + outPath); |
| 66 |
var out = File.write(outPath, true); |
| 67 |
var writer = new Writer(out); |
| 68 |
writer.write(entries); |
| 69 |
out.close(); |
| 70 |
} |
| 71 |
|
| 72 |
static function checkVersion() { |
| 73 |
var runVersion = { |
| 74 |
var p = new sys.io.Process("neko", ["run.n", "version"]); |
| 75 |
var v = p.stdout.readAll().toString().trim(); |
| 76 |
p.close(); |
| 77 |
v; |
| 78 |
} |
| 79 |
var json:Infos = haxe.Json.parse(sys.io.File.getContent("haxelib.json")); |
| 80 |
|
| 81 |
// Version output examples: |
| 82 |
// - 3.4.0 |
| 83 |
// - 3.4.0 (6b9c8851036fb012c0e188bc27da07999b663b4f - dirty) |
| 84 |
if (!runVersion.startsWith(json.version)) { |
| 85 |
Sys.println('Error: Version in haxelib.json (${json.version}) does not match `neko run.n version` ($runVersion)'); |
| 86 |
Sys.exit(1); |
| 87 |
} |
| 88 |
|
| 89 |
if (runVersion.indexOf("dirty") >= 0) { |
| 90 |
Sys.println('Error: run.n was compiled with dirty source'); |
| 91 |
Sys.exit(1); |
| 92 |
} |
| 93 |
} |
| 94 |
} |