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
srcPathThe relative path to the file within the template.
dstPathThe 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 theoutputFolderPath
.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
pathThe 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 theoutputFolderPath
.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
pathThe 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
pathThe 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 theoutputFolderPath
.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
pathThe 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 theoutputFolderPath
.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
dataThe data to write to the file.
pathThe 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 theoutputFolderPath
.Return Value
true
if the data was successfully written to the file,false
otherwise.