compilation
API / @publicodes/tools / compilation
Compile a model from a source
`getModelFromSource`
allows to compile a set of Publicodes
files into a `RawRules`
that can be used by the Publicodes `Engine`
.
Note that it supports the importer!
syntax to import other Publicodes rules from
NPM packages —
see Imports rules from a NPM package.
Usage
import { getModelFromSource } from '@publicodes/tools/compilation'
const model = getModelFromSource(
'data/**/*.publicodes', // could simply be 'data'
{
ignore: ['data/test/**'],
verbose: true
},
)
Import rules from a NPM package
To import rules from a packaged Publicodes model, you need to specify the following syntax :
importer!:
depuis:
nom: <npm_package_name>
source: <path_to_the_model_file> (optional)
url: <url_to_the_package_documentation> (optional)
dans: <namespace> (optional)
les règles:
- <rule_name_from_the_npm_package>
- <rule_name_from_the_npm_package>:
<attr_to_overwrite>: <value>
...
...
When compiling , each YAML entry importer!
will be replaced by all imported rules and
their dependencies by `getModelFromSource`
.
See
compilation.ImportMacro | `ImportMacro`
for more details.
Note
By default if no source
is specified, the model is assumed to be
compiled `RawRules`
into <package_name>.model.json
in the NPM package root folder.
If no dans
is specified, the rules will be imported in a namespace corresponding
to the package name (nom
).
Functions
Function | Description |
---|---|
getModelFromSource | Aggregates all rules from the rules folder into a single json object (the model) with the resolved dependencies. |
normalizeSourcePaths | - |
resolveImports | Resolves the importer! macro inside a publicode file if any. |
Type Aliases
Type alias | Description |
---|---|
GetModelFromSourceOptions | Options for the getModelFromSource function. |