-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
90 lines (77 loc) · 2.24 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
TOPDIR = File.dirname(__FILE__)
COMPANY_NAME = "bri@nfinney.com"
NEW_COOKBOOK_LICENSE = :apachev2
desc "Test the cookbooks for syntax errors"
task :test do
puts "** Testing your cookbooks for syntax errors"
Dir[ File.join(File.dirname(__FILE__), "**", "*.rb") ].each do |recipe|
print "Testing recipe #{recipe}: "
sh %{ruby -c #{recipe}} do |ok, res|
if ! ok
raise "Syntax error in #{recipe}"
end
end
end
end
desc "Create a new cookbook (with COOKBOOK=name)"
task :new_cookbook do
create_cookbook(TOPDIR)
create_readme(TOPDIR)
end
def create_cookbook(dir)
raise "Must provide a COOKBOOK=" unless ENV["COOKBOOK"]
puts "** Creating cookbook #{ENV["COOKBOOK"]}"
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "recipes")}"
unless File.exists?(File.join(dir, ENV["COOKBOOK"], "recipes", "default.rb"))
open(File.join(dir, ENV["COOKBOOK"], "recipes", "default.rb"), "w") do |file|
file.puts <<-EOH
#
# Cookbook Name:: #{ENV["COOKBOOK"]}
# Recipe:: default
#
# Copyright #{Time.now.year}, #{COMPANY_NAME}
#
EOH
case NEW_COOKBOOK_LICENSE
when :apachev2
file.puts <<-EOH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
EOH
when :none
file.puts <<-EOH
# All rights reserved - Do Not Redistribute
#
EOH
end
end
end
end
def create_readme(dir)
raise "Must provide a COOKBOOK=" unless ENV["COOKBOOK"]
puts "** Creating README for cookbook: #{ENV["COOKBOOK"]}"
unless File.exists?(File.join(dir, ENV["COOKBOOK"], "README.rdoc"))
open(File.join(dir, ENV["COOKBOOK"], "README.rdoc"), "w") do |file|
file.puts <<-EOH
= DESCRIPTION:
= REQUIREMENTS:
== Platform:
== Cookbooks:
= ATTRIBUTES:
= USAGE:
= LICENSE and AUTHOR:
EOH
end
end
end
task :default => [ :test ]