Multiple Files

Last updated 2 months ago

AarKay also provides you a feature where you can generate multiple files from a single Datafile.

Let's rename MyFirstPlugin.swift.stencil to SwiftFile.swift.stencil and create a new Templatefile with a name KotlinFile.kt.stencil and content as follows

class {{ name }} {
var age: Int = {{ age }}
constructor() {
<aarkay constructor{{ name }}>

Now, add the following code inside your MyFirstPlugin.swift file after the line /// AarKayEnd :-. This is to make sure the code we are writing doesn't get overwritten the next time we update our plugin.

/// AarKayEnd: -
extension MyFirstPlugin {
public func generatedfiles() -> [Generatedfile] {
var swiftFile = rk_generatedfile()
swiftFile.template = "SwiftFile" = "iOS"
var kotlinFile = rk_generatedfile()
kotlinFile.template = "KotlinFile" = "Android"
return [swiftFile, kotlinFile]

Here we are created two Generatedfile object from the default Generatedfile object rk_generatedfile().

We override the name of the Template and the directory to generate files to.

Now run the command sh scripts/run.

We see now both swift and kotlin files are created from the same Datafile we used.