Getting Started - CLI

CLI Usage

General usage:

If you have installed Mooltipage using npm as described in the previous sections, then all CLI functions can be accessed by the command "npx mooltipage". You can execute "npx cli --help" for a brief listing of available options and command usage.

Building a single page:

The simplest usage of Mooltipage is to compile a single page. This command will take an input HTML file and overwrite it with the compiled HTML output: It is possible to repeatedly call this command with different pages to compile a larger project, but the CLI provided a better solution that will be described next. It is also possible to save the generated HTML to an alternate location. That will be explained later in this document.

Building multiple pages:

Mooltipage is designed for use in projects involving multiple HTML pages, so the CLI includes support for compiling multiple pages at once. When using Mooltipage in this way, the internal cache will be shared between pages. This can greatly speed up page compilation, especially in projects with a large number of frequently-used fragments. To compile multiple pages, simply provide multiple paths to the CLI. Each file will be compiled and overwritten in-place.

Building a directory:

To avoid needing to specify all pages in a project, it is possible to target a directory or even multiple directories instead of targeting files directly. For each input path that resolves to a directory, Mooltipage will recursively search for and include all HTML files found under that path. Any combination of files and directories can be provided. For example: Be careful, Mooltipage will include ALL files that end with ".html", even if they are not pages. When compiling from a directory, make sure to place all non-page HTML (such as fragments) in another location.

Specifying the input path:

By default Mooltipage uses the current working directory to resolve external references. Fragments, data paths, and script files are all examples of references. If the CLI is not executed from the correct directory, or the reference paths were created relative to a different location, then this can result in build errors. To avoid this, specify the base input directory using the "--inPath" option. To compile a project with the source located in "/src", use the following command: With the above command, a reference to "styles.css" from index.html will resolve to "src/styles.css", which is the correct path. If inPath had not been specified, then the path would have resolved to "styles.css" which is incorrect.

Saving to a different location:

In many cases, it is important or even essential to not overwrite the source files. This can be accomplished by providing an output directory and passing the path to Mooltipage. The output path for a page will be created by joining the output directory with the relative path from the input directory to that directory. For example, with input path "src" and output path "dist/html", the page "src/folder/index.html" will be saved to "dist/html/folder/index.html" The command to build that example would be:

Formatting the output HTML:

The Mooltipage compiler does not manipulate whitespace, which typically results in very ugly generated HTML. To counter this, Mooltipage includes a basic HTML formatter. By default, the formatter is set to "pretty" mode which attempts to format the output HTML for human readability. This is great for debugging, but production HTML should be minimized for performance. The HTML formatter supports this through the "minimized" mode. Additionally, there is a "none" mode that turns off all formatting. The none mode can be used in case of formatting errors, or to improve performance in build pipelines that utilize an external HTML processor.
Either of these commands can be used to build pretty HTML: This command will minify the output HTML: And finally, this command will disable formatting:

Recompiling pages when changed:

During web development, it is common to make repeated small tweaks to a file until a page looks exactly right. By default, this means rebuilding the entire site for each change. Large projects can take a long time to build which leads to a very slow and uncomfortable development experience. To counter this, Mooltipage includes "watch mode" which will instantly detect and compile changes to any project file. Watch mode preserves internal caches as much as possible and only recompiles the exact pages impacted by a change. To enable watch mode, add the "--watch" parameter to the CLI arguments, like this: