A command-line interface tool for generating protocol-specific code snippets from Web of Things Thing Descriptions (TDs).
- Interactive and one-line command modes
- Deterministic Support for multiple programming languages and libraries
- AI-powered code generation for not yet available cases (ChatGPT, Gemini, Llama)
- TD input via file of text editor
- Multiple output options (console of file)
-
Clone the repository using Git:
git clone https://github.com/SergioCasCeb/code-generator.git
-
Navigate to the project directory:
cd code-generator -
Install all project dependencies:
npm install
-
Link the project globally to make the
generate-codecommand available on your system:npm link
This allows you to run the
generate-codecommand anywhere in your terminal.
The CLI can be used in two modes: interactive and one-line command
Run the CLI in interactive mode:
generate-code -iThe interactive mode guides you through the following steps:
- Choose TD input method (file or text editor)
- Select an affordance
- Choose a form index (optional)
- Select and operation
- Choose between deterministic or AI-powered generation (If a protocol is not supported AI is selected by default)
- Select programming language
- Select library
- Choose output type (console or file)
Finally, after generating the code, the interactive mode also returns the equivalent options to run the CLI in the one-line mode.
For automated workflows, use the one-line command mode:
-i, --interactive: Run CLI in interactive mode-t, --td <path>: Path to the Thing Description file-a, --affordance <name>: Affordance to use-f, --form-index <index>: Form index to use-o, --operation <name>: Operation to perform-l, --language <name>: Programming language-L, --library <name>: Library to use--ai: Use AI generation--tool <name>: AI tool to use (ChatGPT, Gemini, Llama)-O, --output <type>: Output type (console or file)-h, --help: Display help information-V, --version: Display version number
Generate code utilizing the deterministic generator
generate-code --td ./calculator.td.jsonld -a result -f 0 -o readproperty -l javascript -L node-wot -O consoleGenerate code utilizing the AI generator
generate-code --td ./calculator.td.jsonld -a result -f 0 -o readproperty -l javascript -L axios --ai --tool chatgpt -O console- JSON (.json)
- JSON-LD (.jsonld)
- Text (.txt)
Deterministic:
-
JavaScript
- Fetch
- node-wot
- modbus-serial
-
Python
- Requests
No restrictions when using AI generation.
The generated code is printed directly to the console in simple text format. AI generation adds markdown syntax to the code.
A new folder called generator-ouput is created within the project and the generated code is saved to a file with the following naming convention <affordance>_<operation>_<language>.<extension>