CodeGenerator Module
Provides generator functionality for generating client stubs for other languauges
Hop can utilize its knowledge of your APIs to generate client side stubs for various languages. This module provides the core functionality for generators in such a way that a new generator can be built with relative ease.
- Implemeneted generators can be found under /gen in the Hop root directory
To use a generator
Hop tries to make it easy to generate client side code, to do so we use a command line utilility 'hopjs-gen'
To generate client side stubs for android for a specific website:
hopjs-gen --url http://localhost:3000/ android --outputDir output/ --package com.foo
You might first want to make sure HopJS is installed locally
npm install -g hopjs
Creating a new generator
- Create a new directory under /gen - the directory will be the name of your generator
- Create a generator.json (see the android/generator.json for an example)
- Define some number of templates
Generators work by:
- Asking for any required command line options as defiend in generator.json:demand and generator.json:optional
- Fetching an API definition from URL/_hopjs/api.json
- Loading any required utility functions as defined in generator.json:required
- Determining the type of gernerator as specified by generator.json:generates
- If the generator type is 'file' then file pointed to by generator.json:template will be evaluated with { Objects, Models (and options passed in via the commandline ) }
- If the generator type is 'dir' then dir pointed to by generator.json:templateDir will be evaluated * Files which have the basename _object will be evaluted one for each defined object with { object (and options passed in via the commandline ) } * Files which have the basename _model will be evaluted one for each defined model with { model (and options passed in via the commandline ) }
generator.json:translatePath can be used for determining how templates get translated into the resulting output directory
This module provides the following classes:
