Skip to content

Commit

Permalink
Updated the conjure script flow project to work with flows and services.
Browse files Browse the repository at this point in the history
  • Loading branch information
macourtney committed Jul 23, 2012
1 parent b7c28d9 commit 7b32f1e
Show file tree
Hide file tree
Showing 23 changed files with 405 additions and 393 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(ns conjure.script.destroyers.flow-destroyer
(:require [clojure.tools.logging :as logging]
[conjure.flow.util :as util]
[conjure.script.destroyers.flow-test-destroyer :as flow-test-destroyer]))

(defn
#^{:doc "Prints out how to use the destroy flow command."}
usage []
(println "You must supply a service (Like hello-world).")
(println "Usage: ./run.sh script/destroy.clj flow <service>"))

(defn
#^{:doc "Destroys the flow file from the given service."}
destroy-flow-file [service silent]
(if service
(if-let [flows-directory (util/find-flows-directory)]
(if-let [flow-file (util/find-flow-file flows-directory service)]
(let [is-deleted (.delete flow-file)]
(logging/info (str "File " (.getName flow-file) (if is-deleted " destroyed." " not destroyed."))))
(logging/info "Flow file not found. Doing nothing."))
(do
(logging/error (str "Could not find flows directory.: " flows-directory))
(logging/error "Command ignored.")))
(when (not silent) (usage))))

(defn
#^{:doc "Destroys a flow file for the service name given in params."}
destroy [params]
(destroy-flow-file (first params) false))

(defn
#^{:doc "Destroys all of the files created by the flow_generator."}
destroy-all-dependencies
[{ :keys [service actions silent] :or { actions (), silent false } }]
(destroy-flow-file service silent)
(flow-test-destroyer/destroy-all-dependencies service silent))
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(ns conjure.script.destroyers.flow-test-destroyer
(:require [clojure.tools.logging :as logging]
[conjure.core.test.util :as util]
[clojure.tools.file-utils :as file-utils]))

(defn
#^{:doc "Prints out how to use the destroy flow test command."}
usage []
(println "You must supply a service (Like hello-world).")
(println "Usage: ./run.sh script/destroy.clj flow-test <service>"))

(defn
#^{:doc "Destroys the flow file from the given service."}
destroy-flow-test-file [service silent]
(if service
(if-let [functional-test-directory (util/find-functional-test-directory)]
(if-let [functional-test-file (util/functional-test-file service functional-test-directory)]
(let [is-deleted (.delete functional-test-file)]
(logging/info (str "File " (.getName functional-test-file) (if is-deleted " destroyed." " not destroyed.")))
(when is-deleted (file-utils/delete-if-empty functional-test-directory)))
(logging/info "Flow test file not found. Doing nothing."))
(do
(logging/info "Could not find the functional test directory.")
(logging/info "Command ignored.")))
(usage)))

(defn
#^{:doc "Destroys a flow test file for the service name given in params."}
destroy [params]
(destroy-flow-test-file (first params) false))

(defn
#^{:doc "Destroys all of the files created by the flow_test_generator."}
destroy-all-dependencies
([service silent]
(destroy-flow-test-file service silent)))

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
(ns conjure.script.generators.flow-generator
(:require [clojure.tools.logging :as logging]
[clojure.string :as str-utils]
[conjure.flow.builder :as builder]
[conjure.flow.util :as util]
[clojure.tools.file-utils :as file-utils]
[conjure.script.generators.flow-test-generator :as flow-test-generator]))

(defn
#^{ :doc "Prints out how to use the generate flow command." }
usage []
(println "You must supply a service name (Like hello-world).")
(println "Usage: ./run.sh script/generate.clj flow <service> [action]*"))

(defn
#^{ :doc "Generates the action function for the given action." }
generate-action-function [action]
(str "(def-action " action "
(bind))"))

(defn
#^{ :doc "Generates the action functions block for a flow file." }
generate-all-action-functions [actions]
(str-utils/join "\n\n" (map generate-action-function actions)))

(defn
#^{ :doc "Generates the content of the given flow file." }
generate-flow-content
([service flow-content] (generate-flow-content service flow-content nil))
([service flow-content requires]
(str "(ns " (util/flow-namespace service) "
(:use [conjure.flow.base])" (when requires (str "\n (:require " requires ")")) ")
" flow-content)))

(defn
#^{ :doc "Creates a flow file with the given File and file content." }
create-flow-files
[{ :keys [service flow-content actions silent] :or { silent false } }]
(if-let [flows-directory (util/find-flows-directory)]
(do
(when-let [flow-file (builder/create-flow-file
{ :service service,
:flows-directory flows-directory,
:silent silent })]
(file-utils/write-file-content flow-file flow-content))
(flow-test-generator/generate-functional-test service actions silent))
(logging/error "Could not find the flows directory")))

(defn
#^{ :doc "Generates the flow content and saves it into the given flow file." }
generate-file-content
[{ :keys [service actions silent] :or { silent false } }]
(create-flow-files
{ :service service
:flow-content (generate-flow-content service (generate-all-action-functions actions))
:actions actions
:silent silent }))

(defn
#^{ :doc "Creates the flow file associated with the given service." }
generate-flow-file
[{ :keys [service actions silent] :or { actions (), silent false } }]
(if (and service actions)
(generate-file-content { :service service, :actions actions, :silent silent })
(when (not silent)
(usage))))

(defn
#^{ :doc "Generates a flow file for the service name and actions in params." }
generate [params]
(generate-flow-file { :service (first params), :actions (rest params) }))
Loading

0 comments on commit 7b32f1e

Please sign in to comment.