Skip to content

Generate Ballerina By Examples

praneesha edited this page Jun 28, 2022 · 10 revisions

Overview

A script is used to take the source of the Ballerina By Examples (BBEs) from the ballerina-distribution repository as the input and generates the HTML files to be published on the Ballerina website.

Set up the prerequisites

  1. Download and install Node.js.

  2. Navigate to the directory, which includes the script.

    Note: The scripts can be found in the bbe-generation-v2 branch.

cd ./.github/scripts/bbe
  1. Install the dependencies.
npm install
  1. Navigate back to the root of the repo.
cd ../../..

Delete the existing BBE HTML files

You can do either of the below.

  1. Delete all the HTML files located in the ./learn/by-examples directory excluding the 404.html and index.html files by executing the command below.
find ./learn/by-example -type f \( -name "*.html" ! -name "404.html" ! -name "index.html" \) -delete
  1. Delete only the BBEs that you want to update from the ./learn/by-examples directory.

Run the script

The markdownConverter.js script is used to convert the BBE content written in markdown to HTML.

Location from root of the website repo ./.github/scripts/bbe/markdownConverter.js
Inputs 1. Location of the examples directory.
2. Location of the output to be saved.
Outputs HTML files corresponding to the markdown BBE files.

From the root of the ballerina-dev-website repository, run the script using Node.js.

node ./.github/scripts/bbe/markdownConverter.js <relative_path_to_examples> <relative_path_for_output_HTMLs>

By default, the arguments of the above command will have the values below.

  • <relative_path_to_examples> = “./examples”
  • <relative_path_for_output_HTMLs> = “./learn/by-example”

An example command would be as follows.

node ./.github/scripts/bbe/markdownConverter.js "../ballerina-distribution/examples" "./learn/by-example"

Note: Generated output BBE HTML files will be saved in the specified directory.

Verify on the Ballerina website

Deploy the generated HTML files on the Ballerina website by replacing the <ballerina-dev-website>/learn/by-example directory and verify your changes locally.