djt-codegen
raw JSON → 1.0.1 verified Fri May 01 auth: no javascript
A templated code generation tool for the Dart-to-JS-Transpiler (DJT) ecosystem. Current stable version 1.0.1, released occasionally. It generates JavaScript and TypeScript declaration files from a schema definition, targeting DJT transpilation workflows. Differentiates by providing a simple CLI for schema-to-output transformation with DTS support.
Common errors
error Error: Cannot find module 'djt-codegen' ↓
cause Package not installed or missing from node_modules.
fix
Run 'yarn add djt-codegen' or 'npm install djt-codegen'.
error SyntaxError: Unexpected token 'export' ↓
cause Using CommonJS require with an ESM-only package.
fix
Use import syntax or update Node to version that supports ESM.
Warnings
gotcha The -dts flag generates TypeScript definitions but may not cover all schema features. ↓
fix Manually verify generated DTS files for completeness.
gotcha Schema file must be valid JavaScript exporting a schema object; JSON files not supported. ↓
fix Ensure schema file uses module.exports = { ... } syntax.
Install
npm install djt-codegen yarn add djt-codegen pnpm add djt-codegen Imports
- generate wrong
const generate = require('djt-codegen').generatecorrectimport { generate } from 'djt-codegen' - default wrong
const djtCodegen = require('djt-codegen')correctimport djtCodegen from 'djt-codegen' - CodegenOptions
import { CodegenOptions } from 'djt-codegen'
Quickstart
// Run via CLI (recommended):
// yarn djt-codegen -s ./schema.js -o ./lib.js -dts ./lib.d.ts
// Or programmatically (if package exports API):
import { generate } from 'djt-codegen';
const fs = require('fs');
const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf8'));
generate({ schema, output: './lib.js', dts: './lib.d.ts' });