Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

codegen

A macro tool to generate externs from your code for JavaScript and TypeScript.
https://github.com/yar3333/haxe-codegen

To install, run:

haxelib install codegen 2.1.2 

See using Haxelib in Haxelib documentation for more information.

README.md

codegen

A macro tool to generate haxe externs and typescript definitions from existing haxe source code.

Useful if you want to split your project into several separate-compiled parts and you want to have common api (extern classes).

Usage

Compile your haxe project with -lib codegen and one of the generation macro:

# generate haxe extern classes:
--macro CodeGen.haxeExtern(?outPath,?nodeModule,?filterFile,?mapperFile)

# generate typescript extern classes:
--macro CodeGen.typescriptExtern(?outPath,?filterFile,?mapperFile)

Arguments details:

  • outPath - path to output directory (for haxeExtern) or output file (for typescriptExtern);
  • nodeModule - used to generate @:jsRequire meta for exposed classes (for haxeExtern);
  • filterFile - path to a text file with lines prefixed with "+" to include or "-" to exclude specified package/type (one per line);
  • mapperFile - path to a text file with lines in 'FromType => ToType' format (use to map types).

Example build.hxml

--library mylib 
--classpath src
--main Main
--js dummy.js
--library codegen
--macro CodeGen.haxeExtern('out','my-npm-module')

Filter file example:

+mypack
# comment
-mypack.ClassToExclude

Mapper file example:

mypack.MyTypeA => mypack.MyType1
# comment
mypack.MyTypeB => mypack.MyType2

Additional options

By default CodeGen produce externs for types included for compilation and marked with @:expose meta. You can use @:noapi to force type/field excluding. To customize generation process, use next compiler options before CodeGen.haxeExtern / CodeGen.typescriptExtern:

# use to include private class members into output
--macro CodeGen.includePrivateMembers()

# add @:expose for all classes inside specified package and subpackages
--macro CodeGen.exposeToRoot('mypack')

# include myPackA and myPackB.MyClass into generation
--macro CodeGen.include('myPackA myPackB.MyClass')

# exclude myPackA and myPackB.MyClass from generation
--macro CodeGen.exclude('myPackA myPackB')

# map package myPackA to package myPackB in output
--macro CodeGen.map('myPackA','myPackB')

# map class myPackA.MyClassA to class myPackB.MyClassB in output
--macro CodeGen.map('myPackA.MyClassA','myPackB.MyClassB')

# cleanup: remove `@mymeta` from output (types)
--macro CodeGen.removeTypeMeta('mymeta')

# cleanup: remove `@mymeta` from output (fields)
--macro CodeGen.removeFieldMeta('mymeta')

# copy specified module to output as is (for typescript ignored)
--macro CodeGen.copyAfterGeneration("mypack.MyClass")
Contributors
yar3333
Version
2.1.2
Published
1 year ago
License
LGPL

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub