Created
August 14, 2022 08:52
-
-
Save AxGord/626b80cfa65f67743073f4cf9e32ef18 to your computer and use it in GitHub Desktop.
Post TypeScript to Haxe convert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys.io.File; | |
using StringTools; | |
final path: String = '../src/'; | |
final ext: String = '.hx'; | |
final map: Map<String, Array<String>> = [ | |
'native package name' => ['Path to file, without extension'] | |
]; | |
final marker1: String = 'extern class'; | |
final marker2: String = '@:enum extern'; | |
function main() { | |
for (native => files in map) for (file in files) { | |
Sys.print('Post gen $file - '); | |
final native: String = native.endsWith('.') ? native + file.substr(file.lastIndexOf('/') + 1) : native; | |
file = path + file + ext; | |
final c: String = File.getContent(file); | |
var index: Int = c.indexOf(marker1); | |
if (index == -1) index = c.indexOf(marker2); | |
if (index == -1) { | |
Sys.stderr().writeString('Extern class not founded'); | |
Sys.exit(1); | |
} | |
File.saveContent(file, c.substr(0, c.lastIndexOf('\n', index) + 1) + '@:native(\'$native\') ' + c.substr(index)); | |
Sys.println('File changed'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment