build-script.md
June 13, 2024 · View on GitHub
Build Script Documentation
This build script is designed for a Node.js environment to automate the processing of YAML files within the contracts directory and generate corresponding HTML documentation files. It outputs these files into a build directory while preserving the original folder structure. The script also generates an overview HTML file that provides links to all the generated HTML documents, arranged according to the directory structure.
Overview
- Source Directory:
contracts - Output Directory:
build - Ignored Directories:
_base tmf,_examples,assets - Features:
- Recursively reads all YAML files from the
contractsdirectory, excluding specified directories. - Generates an HTML file for each YAML file using EJS templates.
- Retains the original subfolder structure in the output directory.
- Copies the entire
contractsdirectory to thebuilddirectory as_contracts. - Creates an overview HTML file in the
builddirectory that links to each HTML document, reflecting the folder hierarchy.
- Recursively reads all YAML files from the
Requirements
- Node.js: Ensure Node.js is installed on your system.
- Dependencies: The script uses
yaml,ejs, and nativefsandpathmodules. Dependencies can be installed via npm:npm install
Usage
- Place the script: Ensure the script
build.jsis placed at the root of your project. - Run the script: Execute the script using Node.js by running:
npm run build # node build.js - Check the output: The generated HTML files will be available in the
builddirectory.
Script Details
-
processFileFunction: Reads a YAML file, parses it using theyamlmodule, and generates an HTML file based on the EJS template. The HTML file includes the title and version from the YAML'sinfosection and the relative path to the original YAML file, now pointing to its new location in_contracts. -
walkDirFunction: Recursively traverses thecontractsdirectory, processing each YAML file and skipping ignored directories. -
generateOverviewFunction: Compiles an HTML file that serves as an index, providing links to all processed HTML documents. The links are structured to reflect the directory hierarchy of the original YAML files. -
copyContractsFunction: Copies thecontractsdirectory tobuild/_contracts, ensuring that the original YAML files are also available in the output directory for reference.
File Structure Example
project-root/
│
├── contracts/ # Source YAML files
│ ├── service ordering/
│ │ └── tmf641-servicenow.0.3.0.yaml
│ └── work order/
│ └── tmf697-mulesoft-servicenow.0.1.0.yaml
│
├── build/ # Output HTML files and copied contracts
│ ├── service ordering/
│ │ └── tmf641-servicenow.0.3.0.html
│ ├── work order/
│ │ └── tmf697-mulesoft-servicenow.0.1.0.html
│ ├── _contracts/ # Copied YAML files
│ │ ├── service ordering/
│ │ │ └── tmf641-servicenow.0.3.0.yaml
│ │ └── work order/
│ │ └── tmf697-mulesoft-servicenow.0.1.0.yaml
│ └── index.html # Overview file
│
└── scripts/build.js # Build script