fedify icon indicating copy to clipboard operation
fedify copied to clipboard

Extract Vocabulary API code generator into @fedify/vocab-tools package

Open dahlia opened this issue 3 months ago • 2 comments

Summary

Currently, the Vocabulary API code generator resides in packages/fedify/src/codegen/ and is tightly coupled with the main Fedify library. This code generator is only compatible with Deno, which limits its usability for developers who want to extend Activity Vocabulary with custom types (#207) or use the vocabulary in non-Deno environments.

As part of the broader effort to extract the vocabulary into separate packages (#437), we need to extract the code generator into its own package that can be used independently across different JavaScript runtimes.

Proposed changes

  1. Create new packages:

    • @fedify/vocab-tools (or @fedify/vocab-codegen): Code generation tools
      • Extract all code from packages/fedify/src/codegen/ into this package
      • Make it runtime-agnostic (support Deno, Node.js, and Bun)
    • @fedify/vocab-runtime: Runtime utilities needed by generated vocabulary code
      • Extract runtime dependencies from packages/fedify/src/runtime/ that are used by vocabulary
    • Publish both packages to npm and JSR
  2. Key features the package should provide:

    • Programmatic API for code generation that can be used by other tools
    • Support for custom vocabulary extensions
    • Compatible with all major JavaScript runtimes
  3. CLI integration:

    • Add a new subcommand to the existing fedify CLI: fedify generate-vocab
    • The CLI command would use the @fedify/vocab-tools package internally
    • Example usage: fedify generate-vocab --input ./vocab-schemas/ --output ./generated/
    • The generated code would automatically import from @fedify/vocab-runtime instead of requiring a runtime path
  4. Migration path:

    • Update the existing deno task codegen to use the new packages
    • Ensure backward compatibility during the transition
    • Update documentation to reflect the new workflow

Implementation considerations

  • The current codegen uses Deno-specific APIs (file system operations, etc.) that need to be abstracted
  • Need to ensure the generated code remains compatible with existing Fedify vocabulary classes
  • The @fedify/cli package would need to add @fedify/vocab-tools as a dependency
  • Consider providing a migration guide for existing users of the internal codegen
  • Determine which runtime utilities need to be extracted to @fedify/vocab-runtime

dahlia avatar Sep 21 '25 08:09 dahlia

@dahlia Can I take this issue?

2chanhaeng avatar Sep 21 '25 08:09 2chanhaeng

@2chanhaeng Assigned!

dahlia avatar Sep 21 '25 08:09 dahlia