Generators

Overview

Slate Kit comes with a command line tool to serve as a project generator. This is simply a Kotlin executable jar packaged as a Java Application via gradle that can be executed on the command line with bash/batch scripts. The application takes a template comprised of a instructions, along with files/folders that are copied to a new destinated folder representing the app/project to create. The files contain placeholder values that replaced the name of the app aamong other variables. This is a minimal version of nodejs yeoman or python cookie-cutter

    
    slatekit new app -name="Sample1" -package="mycompany.apps"
    

The Slate Kit project generator is a java app ( packaged as a Java application via gradle ) and is composed of containing 3 things:

Item Type Example Desc
1 Scripts slatekit and slatekit.bat For running the commands
2 Settings conf/env.conf For various settings ( locations )
3 Templates templates/slatekit/app Templates for each project type



Setup

Step Action Notes
1 Download Download the Slate Kit tools by git cloning the tools git repo to your local machine.
E.g. sample folder could be ~/tools/slatekit
2 Path The generator is 1 project in tools and is stored in a sub directory called generator.
Add the path to Slate Kit Generator~/tools/slatekit/generator to your PATH ( e.g. ~/.bash_profile or /etc/paths )
3 Config Now you just have to configure 2 settings in the ~/tools/slatekit/conf/env.conf file.
  1. Set the generation.source to the location of the templates folder in the repo.
  2. Set the generation.output to the location of the gen folder in the repo.
    // Path to the templates
    generation.source = ~/tools/slatekit/templates

    // Path to the generated projects
    generation.output = ~/tools/slatekit/gen
    


Usage

You can generate a new project by running slatekit with the appropriate commands. You can then run the generated app via gradle

Step Action Notes
1 Create To create a new project just cd to the Slate Kit folder and run the commands.

    # FORMAT: slatekit new {TYPE} -name={NAME} -package={PACKAGE}
    # @name = name of application / folder name
    # @package = the kotlin package name for the app
    
    :> cd ~/tools/slatekit/generator
    :> slatekit new app -name="MyApp1" -package="mycompany.apps"
    
2 Build The new project will be created in the SLATE_KIT_HOME/generator/gen folder. You can then cd into that to build it.

    # ~/tools/slatekit
    :> cd gen/MyApp1
    :> gradle build
    
3 Run Once the project is built, you can simply run with gradle ( as a quick test ).

    :> gradle run
    


Future

These are the features to be added in the future to further enhance/customize the project generation.

Name Type Desc Example
gen.output Variable Customize the output directory of generated project ~/myapps/app1
sk.version Variable Customize the Slate Kit Version 1.0.1
kt.version Variable Customize the Kotlin Version 1.3.6
Templates Feature Downloading of templates from Git or remote sources n/a

Back to top



Generators

These are all the types of project generators available by default from Slate Kit. These are the most common type of Applications or services corresponding to the architecture components available from Slate Kit.

APP

Generates a new Slate Kit stand-alone application with support command line args, environments, configs, logging, help usage and more. Refer to the App component and example: Example_App.kt.

    :> cd ~/tools/slatekit/generator

    :> slatekit new app -name="MyApp1" -package="company1.apps"
    
    # Now build and run via gradle
    :> cd gen/MyApp1
    :> gradle build
    :> gradle run
    

Back to top



API

Generates a new API project for hosting HTTP/Web APIs. APIs in Slate Kit are considered Universal in the sense that you write them once and they are available as both HTTP/Web APIs ( in the form of RPCs ) and also available on the CLI. Also refer to the APIs component.

    :> cd ~/tools/slatekit/generator
    
    slatekit new api -name="MyAPI1" -package="company1.apis"
    
    # Now build and run via gradle
    :> cd gen/MyApp1
    :> gradle build
    :> gradle run
    


Back to top



CLI

Generates a CLI ( Command Line Interface ) application. The CLI in Slate Kit can host Slate Kit APIs. Also refer to the CLI component and example: Example_CLI.kt.

    :> cd ~/tools/slatekit/generator
    
    slatekit new cli -name="MyCLI1" -package="company1.apps"
    
    # Now build and run via gradle
    :> cd gen/MyApp1
    :> gradle build
    :> gradle run
    

Back to top



JOB

Generates a new background job that can be gracefully started, stopped, paused, resumed. They can also be run in “pages”, or process items from queues. Refer to the Jobs component and example: Example_Jobs.kt.

    :> cd ~/tools/slatekit/generator
    
    slatekit new job -name="MyJob1" -package="company1.jobs"
    

For the Job, you can run the different job types by passing -job.name to the arguments for gradle/java. E.g.

    
    cd gen/MyJob1
    gradle build

    # To run the One Time Job sample
    gradle run --args='-job.name=single'

    # To run the Paged Job sample
    gradle run --args='-job.name=paging'

    # To run the Queue Job sample
    gradle run --args='-job.name=queued'

    # To run the Worker Sample
    gradle run --args='-job.name=worker'
    


Back to top



LIB

Generates an empty gradle library project with some Slate Kit library references.

    :> cd ~/tools/slatekit/generator
    
    slatekit new lib -name="MyLib1" -package="company1.libs"
    
    # Now build and run via gradle
    :> cd gen/MyApp1
    :> gradle build
    :> gradle run
    

Back to top



SQL

    :> cd ~/tools/slatekit/generator
    
    slatekit new sql -name="MyApp1" -package="company1.apps"
    
    # Now build and run via gradle
    :> cd gen/MyApp1
    :> gradle build
    :> gradle run
    

Back to top