Description

Simple extensible generic static generator.

Base concept is to create a context based on ContextContributors and pass this context to some handlebars template to render a text file (can be a HTML or not content).
A ContextContributor must implement io.yupiik.tools.generator.generic.contributor.ContextContributor interface and register itself in Yupiik Fusion IoC using a FusionModule ServiceLoader registration.

Similarly, io.yupiik.tools.generator.generic.helper.Helper can be registered as a fusion bean to add helpers to the rendering context in addition to the default ones.

TIP

it can also be used to generate a static javascript site dataset - the site being built elsewhere with rsbuild, esbuild or any friend and the generate just used to aggregate data and dump them as json using toJson helper.

Contributors

gitlab-commit

Calls a gitlab instance to fetch commits based on a project and branches list. The resulting object is an object keyed by the project id with the commits as value.

Configuration

branches (env: COMMIT_BRANCHES)

Branches to fetch (ref name). If set to all, it just fetches all commits from the repository. Default: java.util.List.of("main").

cacheProjects (env: COMMIT_CACHEPROJECTS)

Should projects be cached - in memory - when topics is set, useful if multiple contributors the same request. Enable when multiple contributors do the same request to do it only once. Default: false.

gitlab.baseUrl (env: COMMIT_GITLAB_BASEURL)

Base URL. Default: https://gitlab.com .

gitlab.headers (env: COMMIT_GITLAB_HEADERS)

HTTP headers to use as key=value form. Default: java.util.Map.of().

gitlab.timeout (env: COMMIT_GITLAB_TIMEOUT)

Request timeout in java Duration format. Default: PT30S.

since (env: COMMIT_SINCE)

If set a starting date for commits to not fetch the while dataset (YYYY-MM-DDTHH:MM:SSZ format). If starting with now- the end of the string is treated as a Period to parse and date is computed. Default: now-P6M.

statistics (env: COMMIT_STATISTICS)

Should statistics be fetched. Default: true.

topics (env: COMMIT_TOPICS)

Topics to filter when fetching commits based on a project filter. Default: java.util.List.of().

gitlab-environment

Calls a gitlab instance to fetch environments based on a project list. The resulting object is an object keyed by the project id with the environment as value.

Configuration

cacheProjects (env: ENVIRONMENT_CACHEPROJECTS)

Should projects be cached - in memory - when topics is set, useful if multiple contributors the same request. Enable when multiple contributors do the same request to do it only once. Default: false.

details (env: ENVIRONMENT_DETAILS)

Should details be fetched or just environment index is sufficient. Default: false.

gitlab.baseUrl (env: ENVIRONMENT_GITLAB_BASEURL)

Base URL. Default: https://gitlab.com .

gitlab.headers (env: ENVIRONMENT_GITLAB_HEADERS)

HTTP headers to use as key=value form. Default: java.util.Map.of().

gitlab.timeout (env: ENVIRONMENT_GITLAB_TIMEOUT)

Request timeout in java Duration format. Default: PT30S.

topics (env: ENVIRONMENT_TOPICS)

Topics to filter when fetching environments based on a project filter. Default: java.util.List.of().

gitlab-project

Calls a gitlab instance using its REST API to fetch a list of project.

Configuration

cache (env: PROJECT_CACHE)

Should projects be cached - in memory, useful if multiple contributors the same request. Enable when multiple contributors do the same request to do it only once. Default: false.

gitlab.baseUrl (env: PROJECT_GITLAB_BASEURL)

Base URL. Default: https://gitlab.com .

gitlab.headers (env: PROJECT_GITLAB_HEADERS)

HTTP headers to use as key=value form. Default: java.util.Map.of().

gitlab.timeout (env: PROJECT_GITLAB_TIMEOUT)

Request timeout in java Duration format. Default: PT30S.

topics (env: PROJECT_TOPICS)

Topics to filter when fetching projects. Default: java.util.List.of().

http

Enable to call a HTTP method to get a JSON response and map the result to contributed data.

Configuration

request.headers (env: REQUEST_HEADERS)

HTTP request headers in properties syntax. Default: java.util.Map.of().

request.httpVersion (env: REQUEST_HTTPVERSION)

HTTP version - as in java.net.http.HttpClient.Version. Default: HTTP_1_1.

request.method (env: REQUEST_METHOD)

HTTP verb. Default: GET.

request.payload (env: REQUEST_PAYLOAD)

HTTP request payload. Default: .

request.timeout (env: REQUEST_TIMEOUT)

HTTP request timeout in java Duration format. Default: PT30S.

request.uri (env: REQUEST_URI)

HTTP endpoint.

response.dataJsonPointer (env: RESPONSE_DATAJSONPOINTER)

JSON Pointer to extract data to contribute to the rendering context.If extracted value is not an object it will be wrapped in an object with value key. Note that if it point on nothing then an empty context is returned. Default: .

response.expectedStatus (env: RESPONSE_EXPECTEDSTATUS)

HTTP response list of status (comma separated) which are valid. Default: java.util.List.of(200).

java

WARNING
requires a JDK and not a simple JRE.

Enable to inject plain Java code to implement dynamically a contributor.

This is quite neat when dealing with complex logic and default contributors are not sufficient.

Configuration

code (env: CODE)

Code of the contributor contribute method. There are three implicit variables: configuration which is a Map<String, String> with the contributor configuration, executor which is the thread pool to use if needed and container which is Yupiik Fusion IoC if some other beans are needed. It must end with a return xxx with xxx a CompletionStage<Map<String, Object>>. For convenience, completedFuture is implicitly available as well as java.util. If it starts with file: the end of the string is a file path.

compilationClasspath (env: COMPILATIONCLASSPATH)

Enable to set the compilation classpath (for 3rd parties). If not set we try to inherit from current classloader one.

imports (env: IMPORTS)

Enable to set global imports to the generated class.

packageName (env: PACKAGENAME)

Package name override - else an internal package is used. Mainly useful to access package scope classes.

json

Simple contributor which loads some content from a JSON inline data or a file. If content is an array it is wrapped in a {value:...} object.

Configuration

data (env: DATA)

JSON content or a file path starting with file: (ex: file:/my/path.json).

Helpers

lowercase

Type: inline.

Lowercase the passed parameter (stringified using toString or null).

toJson

Type: inline.

Converts the passed parameter to a JSON string.

truncate

Type: inline.

Truncate a string based on a length. It takes two parameters, the value to truncate and the desired length (>=3).

uppercase

Type: inline.

Uppercase the passed parameter (stringified using toString or null).

Synopsis

generic-static-generator-sample
java ... io.yupiik.fusion.framework.api.main.Launcher \
    generic-static-generator \
    --contributors-$index-configuration ...\
    --contributors-$index-context-name ...\
    --contributors-$index-name ...\
    --output ...\
    --partials ...\
    --template ...\
    --threads ...

Parameters

--contributors-$index-configuration

Configuration to pass to the contributor.

--contributors-$index-context-name

Context name where the result will be available, if not set or empty contributor name is reused.

--contributors-$index-name

Name of the contributor to use.

--output

Where to write the output. STDOUT and STDERR are two specific values for the standard outputs.

--partials

Partials handlebars. If a value is starting with file: the end of the path is a file path used as source. If a key ends with /*.hb, all files in the directory are loaded as this - value is ignored.

--template

Handlebars template to render once the context is built. If starting with file: the end of the path is a file path used as source.

--threads

Size of the thread pool to run contribution in. Note that it is a scheduled executor so if executors use scheduled tasks it can need > 1.