Functions

The following functions are available globally.

  • Copies the file at the specified source path and pastes it at the destination path.

    Declaration

    func copy(from srcPath: String, to dstPath: String) -> Bool

    Parameters

    srcPath

    The relative path to the file within the template.

    dstPath

    The path at which the file is pasted. If this path begins with a / it is interpreted as an absolute path, otherwise it is interpreted relative to the outputFolderPath.

    Return Value

    true if the file was copied, false otherwise.

  • Creates a new directory, including intermediate directories if necessary.

    Declaration

    func mkdir(_ path: String) -> Bool

    Parameters

    path

    The path of the directory to create. If this path begins with a / it is interpreted as an absolute path, otherwise it is interpreted relative to the outputFolderPath.

    Return Value

    true if the directory was successfully created, false otherwise.

  • Reads the contents of the specified file.

    Declaration

    func read(contentsOf path: String) -> String

    Parameters

    path

    The relative path to the file within the template.

    Return Value

    A string representing the contents of the file.

  • Deletes the file at the specified path.

    Declaration

    func rm(_ path: String) -> Bool

    Parameters

    path

    The path to the file to delete. If this path begins with a / it is interpreted as an absolute path, otherwise it is interpreted relative to the outputFolderPath.

    Return Value

    true if the file was successfully deleted, false otherwise.

  • Moves the file at the specified path to the trash.

    Declaration

    func trash(_ path: String) -> Bool

    Parameters

    path

    The path to the file to move to the trash. If this path begins with a / it is interpreted as an absolute path, otherwise it is interpreted relative to the outputFolderPath.

    Return Value

    true if the file was successfully moved to the trash, false otherwise.

  • Writes data to the file at a specified path.

    Declaration

    func write(data: Data, to path: String) -> Bool

    Parameters

    data

    The data to write to the file.

    path

    The path to the file to write to. If this path begins with a / it is interpreted as an absolute path, otherwise it is interpreted relative to the outputFolderPath.

    Return Value

    true if the data was successfully written to the file, false otherwise.