Skip to content

Yeoman Generator

Harshil Jani edited this page Aug 12, 2022 · 1 revision

The entry point of the Generator is index.js file inside the generator/ directory.

Taking the Inputs

The prompting() method is used for taking the Input from the user while running the generator. It will take set of inputs and based on it conditionally, It will generate the files further.

We take two inputs from the user and store them in a variable. api_type and registry. The api_type has three Options as Input parameters. Users can select one of it to proceed further. Next we have registry variable which will take the Title of the Registry to be displayed on the DashBoard.

Generating the Required Files

We have writing() constructor for the generation of the required files based on conditions. From the API type which we took from the user, If it is SunBird-RC then we will generate the Files only from Sunbird-RC. But, If it is either REST or GraphQL then we can generate only the general admin. We pass the File locations and Folder names in order to create new files. In the general-purpose admin we have one extra variable which is server type. So, If the admin is based on REST then it will use json-server on port 5000 or else if it is graphql then it will use json-graphql-server on port 8000.

Other variable passed into the constructors can be accessed in our templates by using Templating syntax like <%=varibale%>. So, We pass in the varibale values in the templates using this notation.