PHPackages                             hhpack/codegen - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hhpack/codegen

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hhpack/codegen
==============

Library code generator for Hack

0.4.0(7y ago)13MITShell

Since Oct 1Pushed 7y agoCompare

[ Source](https://github.com/hhpack/codegen)[ Packagist](https://packagist.org/packages/hhpack/codegen)[ RSS](/packages/hhpack-codegen/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (9)Versions (12)Used By (0)

Codegen
=======

[](#codegen)

[![CircleCI](https://camo.githubusercontent.com/c5b16826644477416868c27bae2e890933a390000b05b23532165524b7e99746/68747470733a2f2f636972636c6563692e636f6d2f67682f68687061636b2f636f646567656e2f747265652f6d61737465722e7376673f7374796c653d737667)](https://circleci.com/gh/hhpack/codegen/tree/master)

This package provides cli program to generate source code.
You can map generators to **namespaces** in the configuration file.

Basic usage
-----------

[](#basic-usage)

### Create a generator configuration file

[](#create-a-generator-configuration-file)

Create a configuration file that specifies the generator class.
In the configuration file, you define the namespace and generator linkage.

```
namespace MyPackage\Generators;

use HHPack\Codegen\Contract\{NamedGenerator, GeneratorProvider};
use HHPack\Codegen\HackTest\{TestClassGenerator};
use HHPack\Codegen\Project\{PackageClassGenerator};
use function HHPack\Codegen\Cli\{define_generator, namespace_of};

final class Generators implements GeneratorProvider {
  const LIB = 'HHPack\\Codegen\\Example';
  const LIB_TEST = 'HHPack\\Codegen\\Example\\Test';

  public function generators(): Iterator {
    /**
     * vendor/bin/codegen lib:class LibClass
     */
    yield define_generator("lib:class", "generate library class file.")
      ->mapTo(
        namespace_of(static::LIB, 'example/src')
          ->map(PackageClassGenerator::class),
      );

    /**
     * vendor/bin/codegen lib:testclass LibClassTest
     */
    yield define_generator("lib:testclass", "generate test class file.")
      ->mapTo(
        namespace_of(static::LIB_TEST, 'example/test')
          ->map(TestClassGenerator::class),
      );
  }
}
```

### Append autoload settings to hh\_autoload.json

[](#append-autoload-settings-to-hh_autoloadjson)

Set the path to read the generator in **devRoots**.
Please refer to [hhvm-autoload](https://github.com/hhvm/hhvm-autoload/blob/master/composer.json) for hh\_autoload.json.

```
{
  "roots": "src",
  "devRoots": "/path/to/"
}
```

### Generate class file for package

[](#generate-class-file-for-package)

The name of the generator is specified as the first argument, and the class name is specified as the second argument.

```
vendor/bin/codegen [GEN_NANE] LibClass
```

Custom Generator
----------------

[](#custom-generator)

If you want to use your own generator, implement **ClassFileGeneratable**.

```
use HHPack\Codegen\{GenerateClassFile};
use HHPack\Codegen\Contract\{ClassFileGeneratable};
use Facebook\HackCodegen\{ICodegenFactory, CodegenFile, CodegenClass};

final class CustomClassGenerator implements ClassFileGeneratable {

  public function __construct(private ICodegenFactory $cg) {}

  public static function from(ICodegenFactory $factory): this {
    return new self($factory);
  }

  public function generate(GenerateClassFile $target): CodegenFile {
    return
      $this->cg
        ->codegenFile($target->fileName())
        ->setNamespace($target->belongsNamespace())
        ->addClass($this->classOf($target->name()));
  }

  private function classOf(string $className): CodegenClass {
    return $this->cg->codegenClass($className)->setIsFinal(true);
  }

}
```

You only need to specify it in the generator definition.
In the example below, you can generate code with the command **vendor/bin/codegen myproject:loader MyLoader**.

```
yield define_generator("myproject:loader", "generate loader class file.")
  ->mapTo(
    namespace_of('MyProject\Loader', 'MyProject/Loader')
      ->map(CustomClassGenerator::class) // Map generator to namespace
    );

```

Run the test
------------

[](#run-the-test)

The test can be executed with the following command.

```
composer update
composer test
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~88 days

Total

10

Last Release

2572d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/70c299d6d6015ee714954aa05e4d0e9c7b1d31318a5d7db5e9bb4e1f70f78afc?d=identicon)[holyshared](/maintainers/holyshared)

---

Top Contributors

[![holyshared](https://avatars.githubusercontent.com/u/167190?v=4)](https://github.com/holyshared "holyshared (93 commits)")

---

Tags

code-generatorhacklanghhvmpackagegeneratorhhvmhack

### Embed Badge

![Health badge](/badges/hhpack-codegen/health.svg)

```
[![Health](https://phpackages.com/badges/hhpack-codegen/health.svg)](https://phpackages.com/packages/hhpack-codegen)
```

###  Alternatives

[composer/satis

Simple Repository Generator

3.3k1.4M17](/packages/composer-satis)[okipa/laravel-table

Generate tables from Eloquent models.

56752.8k](/packages/okipa-laravel-table)[melihovv/laravel-package-generator

A laravel package generator

14434.7k1](/packages/melihovv-laravel-package-generator)[okipa/laravel-form-components

Ready-to-use and customizable form components.

198.0k1](/packages/okipa-laravel-form-components)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
