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 for inputs[0].
  • The filenames of the output artifacts are available as outputs. If there is only one of these, it can be referred to it as output.

A Transformer is always attached to a Product, possibly indirectly via a Module.

Transformer Properties

PropertyTypeDefaultDescription
inputsstringListempty listThe list of inputs to the transformer.
preparelist of Javascript commandsempty listThe commands that the transformer runs. These typically read from the input files and write to the output files in some way.
conditionbooltrueIf true, the transformer is enabled, otherwise it does nothing.
explicitlyDependsOnstringListundefinedA list of file tags. All output artifacts of this transformer will have a dependency to all artifacts with the given file tags.