Skip to content
Library to programatically generate Hack code and write it to signed files
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin .hack-ify, fix, and test hh-codegen-verify-signatures Apr 17, 2019
docs Update gh-pages dependencies Feb 20, 2019
examples/dorm lint Apr 17, 2019
tests Support for rendering enums in CodegenFile Feb 28, 2019
.gitattributes add linguist language override (#114) Apr 18, 2019
.hhconfig be friendly with 3.30 Dec 14, 2018 Make use /bin/bash instead of /bin/sh Apr 17, 2019
.travis.yml travis notifications on slack Feb 21, 2019 add code of conduct Feb 20, 2019 License and readme Aug 6, 2015
LICENSE Relicense to MIT Apr 12, 2018
composer.json .hack-ify, fix, and test hh-codegen-verify-signatures Apr 17, 2019
composer.lock update dependencies Apr 12, 2019

Hack Codegen Build Status

Hack Codegen is a library for easily generating Hack code and writing it into signed files that prevent undesired modifications. The idea behind writing code that writes code is to raise the level of abstraction and reduce coupling. You can use your own way of describing a problem and generate the corresponding code. E.g. see examples/dorm. In this example, we use a schema to describe the structure of the data, and we use Hack Codegen to write the matching code.


The DORM example shows how to use the different aspects of the code generation in a simplified real-life example. The included tests also exemplify the usage of the different components.


Hack Codegen requires:

  • HHVM
  • Composer

Installing Hack Codegen

This package can be installed via composer:

composer require facebook/hack-codegen


Include the autoload file generated by composer and you are ready to start using it. For example:

require 'vendor/autoload.php';

use Facebook\HackCodegen\HackCodegenFactory;

$cg = new HackCodegenFactory(new HackCodegenConfig());

echo $cg->codegenFile('HelloWorld.php')
                Vector { 1, 2, 3 },
                Map { 'file' => '__FILE__', 'line' => '__LINE__' },
                Vector { Vector { 1, 2, 3 }, Vector { 4, 5, 6 } },
              ->addLine('echo "hello world\n";')


You can configure some options such as the maximum line width, spacing and headers by implementing IHackCodegenConfig and passing an instance to HackCodegenFactory's constructor.


Hack Codegen is MIT-licensed.

You can’t perform that action at this time.