Skip to content

Instantly share code, notes, and snippets.

@AxGord
Created August 14, 2022 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AxGord/626b80cfa65f67743073f4cf9e32ef18 to your computer and use it in GitHub Desktop.
Save AxGord/626b80cfa65f67743073f4cf9e32ef18 to your computer and use it in GitHub Desktop.
Post TypeScript to Haxe convert
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