Extract Vocabulary API code generator into @fedify/vocab-tools package
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
-
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)
- Extract all code from
@fedify/vocab-runtime: Runtime utilities needed by generated vocabulary code- Extract runtime dependencies from
packages/fedify/src/runtime/that are used by vocabulary
- Extract runtime dependencies from
- Publish both packages to npm and JSR
-
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
-
CLI integration:
- Add a new subcommand to the existing
fedifyCLI:fedify generate-vocab - The CLI command would use the
@fedify/vocab-toolspackage internally - Example usage:
fedify generate-vocab --input ./vocab-schemas/ --output ./generated/ - The generated code would automatically import from
@fedify/vocab-runtimeinstead of requiring a runtime path
- Add a new subcommand to the existing
-
Migration path:
- Update the existing
deno task codegento use the new packages - Ensure backward compatibility during the transition
- Update documentation to reflect the new workflow
- Update the existing
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/clipackage would need to add@fedify/vocab-toolsas 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 Can I take this issue?
@2chanhaeng Assigned!