Permalink
Browse files

add task to generate new cookbooks

  • Loading branch information...
hollow committed May 8, 2012
1 parent 19c103e commit bd5863be1c9e7c9717f74c71885092adfae71961
Showing with 43 additions and 1 deletion.
  1. +3 −1 config/rake.rb
  2. +40 −0 tasks/generate.rake
View
@@ -35,9 +35,11 @@
end
# directories for entities
+BAGS_DIR = File.expand_path(File.join(TOPDIR, "databags"))
+COOKBOOKS_DIR = File.expand_path(File.join(TOPDIR, "cookbooks"))
NODES_DIR = File.expand_path(File.join(TOPDIR, "nodes"))
ROLES_DIR = File.expand_path(File.join(TOPDIR, "roles"))
-BAGS_DIR = File.expand_path(File.join(TOPDIR, "databags"))
+SITE_COOKBOOKS_DIR = File.expand_path(File.join(TOPDIR, "site-cookbooks"))
# documentation directories
DOC_DIR = File.expand_path(File.join(TOPDIR, "documentation"))
View
@@ -0,0 +1,40 @@
+require "highline/import"
+
+namespace :generate do
+
+ desc "Generate a cookbook skeleton"
+ task :cookbook do
+ name = ask('Cookbook name: ') do |q|
+ q.validate = /^\w+$/
+ end
+
+ description = ask('Cookbook description: ')
+
+ maintainer = %x(git config user.name).chomp
+ maintainer_email = %x(git config user.email).chomp
+
+ cb_path = File.join(COOKBOOKS_DIR, name)
+ FileUtils.mkdir_p(cb_path)
+
+ File.open(File.join(cb_path, "metadata.rb"), "w") do |f|
+ f.write <<EOS
+description "#{description}"
+
+maintainer "#{maintainer}"
+maintainer_email "#{maintainer_email}"
+license "Apache v2.0"
+EOS
+ end
+
+ FileUtils.mkdir_p(File.join(cb_path, "recipes"))
+
+ %w(files templates).each do |d|
+ FileUtils.mkdir_p(File.join(cb_path, d, "default"))
+ end
+
+ File.open(File.join(cb_path, "recipes", "default.rb"), "w") do |f|
+ f.write "# add some resources here\n"
+ end
+ end
+
+end

0 comments on commit bd5863b

Please sign in to comment.