Transformer Item
A transformer takes zero or more inputs and produces one or more output artifacts from them. The following transformer creates one output file from one input file:
Transformer { inputs: "raw_input.txt" Artifact { filePath: "processed_input.txt" fileTags: "processed_file" } prepare: { var cmd = new JavaScriptCommand(); cmd.description = "Processing '" + input.filePath + "'"; cmd.highlight = "codegen"; cmd.sourceCode = function() { var file = new TextFile(input.filePath); var content = file.readAll(); file.close() content = content.replace(/\r\n/g, "\n"); file = new TextFile(output.filePath, TextFile.WriteOnly); file.truncate(); file.write(content); file.close(); } return cmd; } }
This example exhibits some interesting features of transformers:
- If there is only one input file, the property
input
is available as syntactic sugar forinputs[0]
. - The filenames of the output artifacts are available as
outputs
. If there is only one of these, it can be referred to it asoutput
.
A Transformer
is always attached to a Product
, possibly indirectly via a Module
.
Transformer Properties
Property | Type | Default | Description |
---|---|---|---|
inputs | stringList | empty list | The list of inputs to the transformer. |
prepare | list of Javascript commands | empty list | The commands that the transformer runs. These typically read from the input files and write to the output files in some way. |
condition | bool | true | If true, the transformer is enabled, otherwise it does nothing. |
explicitlyDependsOn | stringList | undefined | A list of file tags. All output artifacts of this transformer will have a dependency to all artifacts with the given file tags. |
alwaysRun | bool | false | If true, the transformer's commands are always executed, even if all output artifacts are up to date. |