meez 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +15 -0
  2. data/bin/meez +50 -0
  3. data/lib/meez/meez.rb +234 -0
  4. metadata +91 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTY5ZmI4OWRjOWI5YjZiNTg2YzQ4ODljMmM0YjIzY2NkYWUxZTZlNQ==
5
+ data.tar.gz: !binary |-
6
+ NWJhM2MwMDljODA4ZTI3N2I0MjU2OGJkMzBiNDI3OTIyMGQyY2Y3Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTgyYjI2MTQ5NjcyODlkMTMyZGNjODJlN2ZiNDRkOWYwOGRhNThlODkzNjZk
10
+ MjU2OWI0N2M0NjdmYjQyZTRlNWIwMmVjY2QyNjVlZWNhZTZlYWNhYzEyMWVl
11
+ NmJlYzdiZjNkYzNhNTk3NDcxMzRmZDFkNjk2ZTg3NDMzZWM4ZTI=
12
+ data.tar.gz: !binary |-
13
+ MDM0ZTI5N2I0ZjVmYzA5ZjY1Y2FkMWY4MGFlZTg4MDE1ODY5ZTVmY2Q1NWEz
14
+ YTY2ZDRjNTBjODg3MGUzNmRiY2RkODkyODlhYmRiYzU0OWFkMGMxM2E1NDlk
15
+ ZDQxNzgxM2U0YTk0YzAxYjE5N2U2YTRiMzMzOWEwMzVhNWIxZGY=
data/bin/meez ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+
4
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
5
+
6
+ require 'optparse'
7
+ require 'meez/meez'
8
+
9
+ options = {}
10
+
11
+ opt_parser = OptionParser.new do |opt|
12
+ opt.banner = 'Usage: meez [options] <cookbook name>'
13
+ opt.separator ''
14
+ opt.separator 'Options'
15
+ opt.on('-o', '--cookbook-path USERNAME', 'The directory where the cookbook will be created') do |path|
16
+ options[:path] = path
17
+ end
18
+ opt.on('-C', '--copyright COPYRIGHT_HOLDER', 'The name of the copyright holder.') do |copyright|
19
+ options[:copyright] = copyright
20
+ end
21
+ opt.on('-I', '--license LICENSE', 'The type of license under which a cookbook is distributed: apachev2, gplv2, gplv3, mit, or none (default).') do |license|
22
+ options[:license] = license
23
+ end
24
+ opt.on('-m', '--email EMAIL', 'The email address for the individual who maintains the cookbook.') do |email|
25
+ options[:email] = email
26
+ end
27
+ opt.on('-h', '--help', 'help') do
28
+ options[:help] = true
29
+ puts opt_parser
30
+ end
31
+ end
32
+
33
+ opt_parser.parse!
34
+
35
+ cookbook_name = ARGV.pop
36
+
37
+ unless options[:help]
38
+ if cookbook_name
39
+ Meez.init(cookbook_name, options)
40
+ puts "Cookbook #{cookbook_name} created successfully"
41
+ puts 'Next steps...'
42
+ puts " $ cd #{File.join(options[:path], cookbook_name)}"
43
+ puts ' $ bundle install'
44
+ puts ' $ bundle exec berks install'
45
+ puts ' $ bundle exec strainer test'
46
+ else
47
+ puts 'Need to specify a cookbook'
48
+ puts opt_parser
49
+ end
50
+ end
data/lib/meez/meez.rb ADDED
@@ -0,0 +1,234 @@
1
+ # Encoding: utf-8
2
+ # The main Meez driver
3
+ class Meez
4
+ require 'fileutils'
5
+
6
+ def self.init(cookbook_name, options)
7
+ init_cookbook(cookbook_name, options)
8
+ init_berkshelf(cookbook_name, options)
9
+ init_strainer(cookbook_name, options)
10
+ init_knife(cookbook_name, options)
11
+ init_rubocop(cookbook_name, options)
12
+ init_foodcritic(cookbook_name, options)
13
+ init_chefspec(cookbook_name, options)
14
+ init_serverspec(cookbook_name, options)
15
+ init_kitchenci(cookbook_name, options)
16
+ #bundle_install(cookbook_name, options)
17
+ end
18
+
19
+ def self.init_cookbook(cookbook_name, options)
20
+ require 'chef/knife/cookbook_create'
21
+ puts '* Initializing Cookbook'
22
+ path = File.join(options[:path], cookbook_name)
23
+ create_cookbook = Chef::Knife::CookbookCreate.new
24
+ create_cookbook.name_args = [cookbook_name]
25
+ create_cookbook.config[:cookbook_path] = options[:path]
26
+ create_cookbook.config[:cookbook_copyright] = options[:copyright] || 'YOUR_COMPANY_NAME'
27
+ create_cookbook.config[:cookbook_license] = options[:license] || 'YOUR_EMAIL'
28
+ create_cookbook.config[:cookbook_email] = options[:email] || 'none'
29
+ create_cookbook.run
30
+ %w{ metadata.rb recipes/default.rb }.each do |file|
31
+ puts "\tRewriting #{file}"
32
+ contents = "# Encoding: utf-8\n#{File.read(File.join(path, file))}"
33
+ File.open(File.join(path, file), 'w') { |f| f.write(contents) }
34
+ end
35
+ end
36
+
37
+ def self.init_git(cookbook_name, options)
38
+ puts '* Initializing GIT repo'
39
+ path = File.join(options[:path], cookbook_name)
40
+ require 'git'
41
+ Git.init( path, { repository: path } )
42
+ end
43
+
44
+ def self.init_berkshelf(cookbook_name, options)
45
+ puts '* Initializing Berkshelf'
46
+ path = File.join(options[:path], cookbook_name)
47
+ gem 'berkshelf', '~> 2.0.11'
48
+ require 'berkshelf'
49
+ require 'berkshelf/base_generator'
50
+ require 'berkshelf/init_generator'
51
+ Berkshelf::InitGenerator.new(
52
+ [path],
53
+ {
54
+ skip_test_kitchen: true
55
+ }
56
+ ).invoke_all
57
+ File.open(File.join(path, 'Berksfile'), 'a') { |f| f.write("metadata\n") }
58
+ end
59
+
60
+ def self.init_kitchenci(cookbook_name, options)
61
+ puts '* Initializing Test Kitchen'
62
+ path = File.join(options[:path], cookbook_name)
63
+ require 'kitchen'
64
+ require 'kitchen/generator/init'
65
+ Kitchen::Generator::Init.new([], {}, destination_root: path).invoke_all
66
+ File.open(File.join(path, 'Strainerfile'), 'a') { |f| f.write("kitchen: bundle exec kitchen test --destroy=always\n") }
67
+ File.open(File.join(path, '.kitchen.yml'), 'w') do |file|
68
+ contents = <<-EOF
69
+ ---
70
+ driver:
71
+ name: vagrant
72
+
73
+ provisioner:
74
+ name: chef_solo
75
+
76
+ platforms:
77
+ - name: ubuntu-12.04
78
+
79
+ suites:
80
+ - name: default
81
+ run_list: recipe[#{cookbook_name}::default]
82
+ attributes:
83
+ EOF
84
+ file.write(contents)
85
+ end
86
+ end
87
+
88
+ def self.init_chefspec(cookbook_name, options)
89
+ puts '* Initializing Chef Spec'
90
+ path = File.join(options[:path], cookbook_name)
91
+ spec_path = File.join(path, 'spec')
92
+ Dir.mkdir(spec_path, 0755)
93
+ puts "\tCreating #{File.join(spec_path, 'spec_helper.rb')}"
94
+
95
+ File.open(File.join(spec_path, 'spec_helper.rb'), 'w') do |file|
96
+ contents = <<-EOF
97
+ # Encoding: utf-8
98
+ require 'chefspec'
99
+ require 'chefspec/berkshelf'
100
+
101
+ ::LOG_LEVEL = :fatal
102
+ ::UBUNTU_OPTS = {
103
+ platform: 'ubuntu',
104
+ version: '12.04',
105
+ log_level: ::LOG_LEVEL
106
+ }
107
+ ::CHEFSPEC_OPTS = {
108
+ log_level: ::LOG_LEVEL
109
+ }
110
+
111
+ def stub_resources
112
+ end
113
+
114
+ at_exit { ChefSpec::Coverage.report! }
115
+ EOF
116
+ file.write(contents)
117
+ end
118
+
119
+ puts "\tCreating #{File.join(spec_path, 'default_spec.rb')}"
120
+ File.open(File.join(spec_path, 'default_spec.rb'), 'w') do |file|
121
+ contents = <<-EOF
122
+ # Encoding: utf-8
123
+
124
+ require_relative 'spec_helper'
125
+
126
+ describe '#{cookbook_name}::default' do
127
+ describe 'ubuntu' do
128
+ before do
129
+ @chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS)
130
+ stub_resources
131
+ @chef_run.converge '#{cookbook_name}::default'
132
+ end
133
+
134
+ it 'writes some tests' do
135
+ pending 'or it gets the hose again'
136
+ end
137
+
138
+ end
139
+ end
140
+ EOF
141
+ file.write(contents)
142
+ end
143
+
144
+ puts "\tAppend Gemfile"
145
+ File.open(File.join(path, 'Gemfile'), 'a') { |f| f.write("gem 'chefspec', '~> 3.1.4'\n") }
146
+ File.open(File.join(path, 'Strainerfile'), 'a') { |f| f.write("chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/spec\n") }
147
+ end
148
+
149
+ def self.init_strainer(cookbook_name, options)
150
+ puts '* Initializing Strainer'
151
+ path = File.join(options[:path], cookbook_name)
152
+ puts "\tCreating #{File.join(path, 'Strainerfile')}"
153
+ File.open(File.join(path, 'Strainerfile'), 'w') { |f| f.write("# Strainerfile\n") }
154
+ puts "\tAppend Gemfile"
155
+ File.open(File.join(path, 'Gemfile'), 'a') { |f| f.write("gem 'strainer', '~> 3.3.0'\n") }
156
+ end
157
+
158
+ def self.init_rubocop(cookbook_name, options)
159
+ puts '* Initializing Rubocop'
160
+ path = File.join(options[:path], cookbook_name)
161
+ puts "\tAppend Gemfile"
162
+ File.open(File.join(path, 'Gemfile'), 'a') { |f| f.write("gem 'rubocop', '~> 0.16.0'\n") }
163
+ puts "\tAppend Strainerfile"
164
+ File.open(File.join(path, 'Strainerfile'), 'a') { |f| f.write("rubocop: bundle exec rubocop $COOKBOOK\n") }
165
+ end
166
+
167
+ def self.init_knife(cookbook_name, options)
168
+ puts '* Initializing Knife'
169
+ path = File.join(options[:path], cookbook_name)
170
+ puts "\tAppend Gemfile"
171
+ File.open(File.join(path, 'Gemfile'), 'a') { |f| f.write("gem 'chef', '~> 11.8.0'\n") }
172
+ puts "\tAppend Strainerfile"
173
+ File.open(File.join(path, 'Strainerfile'), 'a') { |f| f.write("knife test: bundle exec knife cookbook test $COOKBOOK\n") }
174
+ end
175
+
176
+ def self.init_foodcritic(cookbook_name, options)
177
+ puts '* Initializing Food Critic'
178
+ path = File.join(options[:path], cookbook_name)
179
+ puts "\tAppend Gemfile"
180
+ File.open(File.join(path, 'Gemfile'), 'a') { |f| f.write("gem 'foodcritic', '~> 3.0.0'\n") }
181
+ puts "\tAppend Strainerfile"
182
+ File.open(File.join(path, 'Strainerfile'), 'a') { |f| f.write("foodcritic: bundle exec foodcritic -f any $SANDBOX/$COOKBOOK\n") }
183
+ end
184
+
185
+ def self.init_serverspec(cookbook_name, options)
186
+ puts '* Initializing Server Spec'
187
+ path = File.join(options[:path], cookbook_name)
188
+ spec_path = File.join(path, 'test', 'integration', 'default', 'serverspec')
189
+ FileUtils.mkdir_p(spec_path)
190
+ puts "\t Creating #{File.join(spec_path, 'spec_helper.rb')}"
191
+
192
+ File.open(File.join(spec_path, 'spec_helper.rb'), 'w') do |file|
193
+ contents = <<-EOF
194
+ # Encoding: utf-8
195
+ require 'serverspec'
196
+
197
+ include Serverspec::Helper::Exec
198
+ include Serverspec::Helper::DetectOS
199
+
200
+ RSpec.configure do |c|
201
+ c.before :all do
202
+ c.path = '/sbin:/usr/bin'
203
+ end
204
+ end
205
+ EOF
206
+ file.write(contents)
207
+ end
208
+
209
+ puts "\tCreating #{File.join(spec_path, 'default_spec.rb')}"
210
+ File.open(File.join(spec_path, 'default_spec.rb'), 'w') do |file|
211
+ contents = <<-EOF
212
+ # Encoding: utf-8
213
+
214
+ require_relative 'spec_helper'
215
+
216
+ describe 'default' do
217
+ it { pending 'write some tests' }
218
+ end
219
+ EOF
220
+ file.write(contents)
221
+ end
222
+
223
+ puts "\tAppend Gemfile"
224
+ File.open(File.join(path, 'Gemfile'), 'a') { |f| f.write("gem 'serverspec', '~> 0.14.2'\n") }
225
+ end
226
+
227
+ def self.bundle_install(cookbook_name, options)
228
+ require 'bundler'
229
+ puts '* Running bundle install'
230
+ path = File.join(options[:path], cookbook_name)
231
+ puts "\t append .gitignore"
232
+ Bundler.with_clean_env { exec({ 'BUNDLE_GEMFILE' => '/tmp/test/Gemfile' }, 'bundle install') }
233
+ end
234
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meez
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Czarkowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chef
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 11.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 11.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-kitchen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.1
55
+ description: ! 'berkshelf + chefspec + test kitchen + strainer + foodcritic + server
56
+ spec
57
+
58
+ '
59
+ email: paul.czarkowski@rackspace.com
60
+ executables:
61
+ - meez
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - lib/meez/meez.rb
66
+ - bin/meez
67
+ homepage: http://github.com/paulczar/meez
68
+ licenses:
69
+ - apache2
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.1.10
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: initializes chef cookbook with TDD framework
91
+ test_files: []