-
Notifications
You must be signed in to change notification settings - Fork 14
How to create a generator
Added in version: 0.6
A generator is simply a clojure source file in the script/generators directory. The file must have a certain name and include a specific function or the generate.clj script will not be able to find it.
As an example, let’s make a hello-world generator which will simply print out “Hello World!” when called. Our hello-world generator file must be called “hello_world_generator.clj” and be placed in the script/generators directory.
Since hello_world_generator.clj is in the script/generators directory, it’s namespace must be:
(ns generators.hello-world-generator)
All generators must contain a function called “generate” which takes a single parameter usually called params. Params is the list of all command line options passed to the generate command after the name of your generator.
Our hello world generate function will simply print hello world to the screen. The complete hello world generator looks like:
(ns generators.hello-world-generator) (defn #^{ :doc "Simply prints \"Hello World!\" to the console." } generate [params] (println "Hello World!"))
To run your generator, use:
./run.bat script/generate.clj hello-world
You should see something like the following printed to your console:
.\lib\*;.\vendor;.\app;.\config;.\script;.\db;.\test Initializing environment... INFO [conjure.server.server]: Initializing server... DEBUG [flavors.h2]: Executing query: ["SELECT * FROM sessions LIMIT 1"] DEBUG [flavors.h2]: Create table: :sessions with specs: (("id" "INT" "NOT NULL" "AUTO_INCREMENT" "PRIMARY KEY") ["created_at" "TIMESTAMP"] ("session_id" "VARCHA R(255)") ["data" "TEXT"]) INFO [conjure.server.server]: Server Initialized. INFO [conjure.server.server]: Initializing plugins... INFO [conjure.server.server]: Plugins initialized. Hello World!