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"
    


Setup

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


1. Download

Download the generator by git cloning the tools git repo to your local machine. E.g. sample folder could be ~/slatekit.


2. Config

Now you just have to configure 2 settings in the /slatekit/conf/env.conf file. Set the generation.source to the location of the templates folder in the repo. Set the generation.output to the location of the gen folder in the repo.

// Path to the templates
generation.source = usr://slatekit/templates

// Path to the generated projects
generation.output = usr://slatekit/gen



Usage

You can generate a new project by running slatekit with the appropriate commands. Sample structure is shown below

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
    
    :> ./slatekit new app -name="MyApp1" -package="mycompany.apps"
    


2: Build

The new project will be created in the SLATE_KIT_HOME/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 variables/inputs that will be added in the future to further customize the project generation.

Name Desc Example
gen.output Output directory of generated project ~/myapps/app1
sk.version Slate Kit Version 1.0.1
kt.version Kotlin Version 1.3.6


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.

    
    ./slatekit new app -name="MyApp1" -package="company1.apps"
    

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.

    
    ./slatekit new api -name="MyAPI1" -package="company1.apis"
    

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.

    
    ./slatekit new cli -name="MyCLI1" -package="company1.apps"
    

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 Job component and example: Example_Jobs.kt.

    
    ./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.

    
    ./slatekit new lib -name="MyLib1" -package="company1.libs"
    

Back to top



SQL

Generator for this type is coming soon. This will generate a new project containing data models, repositories and services to provide a DDD ( Domain Driven Design) approach to modeling and managing your data.

    
    ./slatekit new sql -name="MyApp1" -package="company1.apps"
    

Back to top