Skip to content

eehah5ru/lein-filegen-ng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lein-filegen

A Leiningen plugin that generates files based on the instructions in project.clj.

This is useful for generating artefacts outside of src such as configuration files etc.

Usage

Use this for project-level plugins:

Put [lein-filegen "0.0.1"] into the :plugins vector of your project.clj.

Configuration

To use lein-filegen you'll need to add a :filegen vector into your project.clj.

The filegen vector contains a hash which prescribes how to generate a file. It needs to know:

  • :target file to generate
  • :data from which to generate the file
  • :template-fn to transform the data into the string which will be written to the file
  • :requires, an optional argument to require any namespaces for the template-fn to work

In full it looks something like this:

:filegen [{:data {:environment ~(System/getenv "ENVIRONMENT")
                  :database-url ~(System/getenv "DATABASE_URL")
                  :version ~(fn [p] (:version p))}
             :requires '[clojure.data.json :refer [write-str]]
             :template-fn ~(fn [project data] (write-str data))
             :target "resources/configuration/config.json"}]

The above takes the data and converts it to a json file.

As it's a vector filegen can take multiple hash instructions for different files.

Run

$ lein filegen

License

Copyright (c) 2017 Nicolay Spesivtsev Copyright (c) 2014 Thoughtworks Inc

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Leiningen plugin to generate files

Resources

License

Stars

Watchers

Forks

Packages

No packages published