{"id":45138945,"url":"https://github.com/hhpack/codegen","last_synced_at":"2026-02-20T00:30:26.730Z","repository":{"id":56984209,"uuid":"104617139","full_name":"hhpack/codegen","owner":"hhpack","description":"Library code generator for Hack","archived":false,"fork":false,"pushed_at":"2019-04-30T06:49:45.000Z","size":100,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-24T18:55:04.969Z","etag":null,"topics":["code-generator","hacklang","hhvm"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hhpack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-24T03:54:18.000Z","updated_at":"2024-04-24T18:55:04.970Z","dependencies_parsed_at":"2022-08-21T12:20:24.540Z","dependency_job_id":null,"html_url":"https://github.com/hhpack/codegen","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/hhpack/codegen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fcodegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fcodegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fcodegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fcodegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hhpack","download_url":"https://codeload.github.com/hhpack/codegen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpack%2Fcodegen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29637407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T22:32:43.237Z","status":"ssl_error","status_checked_at":"2026-02-19T22:32:38.330Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generator","hacklang","hhvm"],"created_at":"2026-02-20T00:30:26.110Z","updated_at":"2026-02-20T00:30:26.715Z","avatar_url":"https://github.com/hhpack.png","language":"Shell","readme":"# Codegen\n\n[![CircleCI](https://circleci.com/gh/hhpack/codegen/tree/master.svg?style=svg)](https://circleci.com/gh/hhpack/codegen/tree/master)\n\nThis package provides cli program to generate source code.  \nYou can map generators to **namespaces** in the configuration file.  \n\n## Basic usage\n\n### Create a generator configuration file\n\nCreate a configuration file that specifies the generator class.  \nIn the configuration file, you define the namespace and generator linkage.  \n\n```hack\nnamespace MyPackage\\Generators;\n\nuse HHPack\\Codegen\\Contract\\{NamedGenerator, GeneratorProvider};\nuse HHPack\\Codegen\\HackTest\\{TestClassGenerator};\nuse HHPack\\Codegen\\Project\\{PackageClassGenerator};\nuse function HHPack\\Codegen\\Cli\\{define_generator, namespace_of};\n\nfinal class Generators implements GeneratorProvider {\n  const LIB = 'HHPack\\\\Codegen\\\\Example';\n  const LIB_TEST = 'HHPack\\\\Codegen\\\\Example\\\\Test';\n\n  public function generators(): Iterator\u003cNamedGenerator\u003e {\n    /**\n     * vendor/bin/codegen lib:class LibClass\n     */\n    yield define_generator(\"lib:class\", \"generate library class file.\")\n      -\u003emapTo(\n        namespace_of(static::LIB, 'example/src')\n          -\u003emap(PackageClassGenerator::class),\n      );\n\n    /**\n     * vendor/bin/codegen lib:testclass LibClassTest\n     */\n    yield define_generator(\"lib:testclass\", \"generate test class file.\")\n      -\u003emapTo(\n        namespace_of(static::LIB_TEST, 'example/test')\n          -\u003emap(TestClassGenerator::class),\n      );\n  }\n}\n```\n\n### Append autoload settings to hh_autoload.json\n\nSet the path to read the generator in **devRoots**.  \nPlease refer to [hhvm-autoload](https://github.com/hhvm/hhvm-autoload/blob/master/composer.json) for hh_autoload.json.\n\n```json\n{\n  \"roots\": \"src\",\n  \"devRoots\": \"/path/to/\"\n}\n```\n\n### Generate class file for package\n\nThe name of the generator is specified as the first argument, and the class name is specified as the second argument.\n\n```shell\nvendor/bin/codegen [GEN_NANE] LibClass\n```\n\n## Custom Generator\n\nIf you want to use your own generator, implement **ClassFileGeneratable**.\n\n```hack\nuse HHPack\\Codegen\\{GenerateClassFile};\nuse HHPack\\Codegen\\Contract\\{ClassFileGeneratable};\nuse Facebook\\HackCodegen\\{ICodegenFactory, CodegenFile, CodegenClass};\n\nfinal class CustomClassGenerator implements ClassFileGeneratable {\n\n  public function __construct(private ICodegenFactory $cg) {}\n\n  public static function from(ICodegenFactory $factory): this {\n    return new self($factory);\n  }\n\n  public function generate(GenerateClassFile $target): CodegenFile {\n    return\n      $this-\u003ecg\n        -\u003ecodegenFile($target-\u003efileName())\n        -\u003esetNamespace($target-\u003ebelongsNamespace())\n        -\u003eaddClass($this-\u003eclassOf($target-\u003ename()));\n  }\n\n  private function classOf(string $className): CodegenClass {\n    return $this-\u003ecg-\u003ecodegenClass($className)-\u003esetIsFinal(true);\n  }\n\n}\n```\n\nYou only need to specify it in the generator definition.  \nIn the example below, you can generate code with the command **vendor/bin/codegen myproject:loader MyLoader**.\n\n```\nyield define_generator(\"myproject:loader\", \"generate loader class file.\")\n  -\u003emapTo(\n    namespace_of('MyProject\\Loader', 'MyProject/Loader')\n      -\u003emap(CustomClassGenerator::class) // Map generator to namespace\n    );\n```\n\n## Run the test\n\nThe test can be executed with the following command.\n\n```shell\ncomposer update\ncomposer test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhpack%2Fcodegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhhpack%2Fcodegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhpack%2Fcodegen/lists"}