lucid.distribute code repackaging and distribution

Author: Chris Zheng  (z@caudate.me)
Date: 29 June 2017
Repository: https://www.github.com/zcaudate/lucidity
Version: 1.3.13

1    Introduction

lucid.distribute allows for splitting up a large project codebase into smaller distributions to enable better reuse.

1.1    Installation

Add to project.clj dependencies:

[im.chit/lucid.distribute "1.3.13"]

All functionality is in the lucid.distribute namespace:

(use 'lucid.distribute)

2    API



clean ^

deletes the interim directory

v 1.2
(defn clean
  ([]
   (clean (project/project)))
  ([project]
   (fs/delete (common/interim-path project))))
link
(clean (project/project)) ;;=> deletes the `target/interim` directory

deploy ^

installs all subpackages according to `:distribute` key

v 1.2
(defn deploy
  ([] (deploy (project/project)))
  ([project]
   (deploy project (manifest/manifest project)))
  ([project manifest]
   (deploy project manifest {}))
  ([project manifest opts]
   (let [packages (split/split project manifest)]
     (doseq [id packages]
       (println "nDeploying" id)
       (try (-> (common/interim-path project)
                (str "/branches/" id "/project.clj")
                (project/project)
                (package/deploy-project opts))
            (catch Throwable t
              (println t)
              (println "FAILED for " id))))
     
     (println "nDeploying Root")
     (-> (common/interim-path project)
         (str "/root/project.clj")
         (project/project)
         (package/deploy-project opts)))))
link
(deploy (project/project))

deploy-current ^

installs all in the current project

v 1.2
(defn deploy-current
  ([]
   (deploy-current {}))
  ([opts]
   (let [project  (project/project)
         manifest (manifest/manifest project)]
     (deploy project manifest opts))))
link
(deploy-current {:authentication {:username "hello" :password "world"}})

install ^

installs all subpackages according to `:distribute` key

v 1.2
(defn install
  ([] (install (project/project)))
  ([project]
   (install project (manifest/manifest project)))
  ([project manifest]
   (let [packages (split/split project manifest)]
     (doseq [id packages]
       (println "nInstalling" id)
       (-> (common/interim-path project)
           (str "/branches/" id "/project.clj")
           (project/project)
           (package/install-project)))
     
     (println "nInstalling Root")
     (-> (common/interim-path project)
         (str "/root/project.clj")
         (project/project)
         (package/install-project)))))
link
(install (project/project))

manifest ^

creates a manifest for further processing

v 1.2
(defn manifest
  ([] (manifest (project/project)))
  ([project]
   (let [_     (fs/delete (:root project) {:include [".DS_Store"]})
         cfgs (or (-> project :distribute :files) *default-config*)
         cfgs (if (vector? cfgs) cfgs [cfgs])
         
         filemap   (->> cfgs
                        (map #(build-filemap (:root project)
                                             (merge (select-keys project [:jar-exclusions]) %)))
                        (apply merge-with set/union))
         i-deps (merge-with set/union
                            (internal/resource-dependencies cfgs)
                            (internal/find-all-module-dependencies filemap))
         ex-deps  (external/find-all-external-imports filemap i-deps project)
         ks       (keys filemap)
         branches (mapv #(create-branch-entry project filemap i-deps ex-deps %) ks)]
     {:root (create-root-entry project branches)
      :branches (zipmap ks branches)})))
link
(-> (project/project "example/distribute.advance/project.clj") (manifest) :root) => (contains {:name 'blah :artifact "blah" :group "blah" :version "0.1.0-SNAPSHOT" :dependencies (contains '[[org.clojure/clojure "1.6.0"] [im.chit/vinyasa.maven "0.3.1"] [blah/blah.common "0.1.0-SNAPSHOT"] [blah/blah.core "0.1.0-SNAPSHOT"] [blah/blah.util.array "0.1.0-SNAPSHOT"] [blah/blah.util.data "0.1.0-SNAPSHOT"] [blah/blah.web "0.1.0-SNAPSHOT"] [blah/blah.jvm "0.1.0-SNAPSHOT"] [blah/blah.resources "0.1.0-SNAPSHOT"]] :in-any-order)})

split ^

splits up current project to put in the interim directory

v 1.2
(defn split
  ([]
   (split (project/project)))
  ([project]
   (split project (manifest/manifest project)))
  ([project manifest]
   (clean project)
   (let [packages (->> manifest sort/topsort-branch-deps
                       flatten
                       distinct
                       (map :id))]
     (println "nAll Packages:" packages)
     (split-scaffold project manifest)
     (split-all-files project manifest)
     (split-project-files project manifest)
     packages)))
link
(split (project/project)) ;;=> look in `target/interim` for changes