kitchen-cabinet 1.1.1 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d58227e726c5b26286ae825e07f5713753491e7
4
- data.tar.gz: b573cdb8c5753e37a9db8165d9bcc4c1711c2c27
3
+ metadata.gz: 47b7cc6c79c82d35d205d6ee9385b2cbc5f62686
4
+ data.tar.gz: 6ccfb49f7fe889a1846ae95baa3900a083423cd7
5
5
  SHA512:
6
- metadata.gz: f821af56fdb1e45ab1a9188fc90b1f3a1fa435b8b40f9b907669caee2e0e1b9be2a0ba20a4d9333b762b13d3fe051bd0daa0e12fb307c55d5dcf71fbf97cbd59
7
- data.tar.gz: d1eb4145f93c8c0bc02031d38439d14e04697bf0935fcd55b37ed94ec4366b493e11cdedf13186822e339ea742a27646ba4faa80260d9a023b1927b2d9db4364
6
+ metadata.gz: c09ff07834a45d5e2d62bbab614c312a5fb89a943877bf321f94d0845b3648fcb45765d4ecc8d211a389131efa9914d7ad537d8ea77bf55a5899ee7f232c1e05
7
+ data.tar.gz: 55f504888bdc1a3d3b63a4cf6031955dca30c7a220b6176083fbfedb53ababcca7b1f29ecdafdf37d39e68be1a2e9ac6ebc64b0f51e07b14e580d4745febe301
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v1.2.0:
2
+
3
+ * Run commands from current directory if not otherwise specified with -o
4
+ * Added `cabinet update` to update cookbook the cookbook you are currently in.
5
+ * Updated config files (.coverage, JetBrains files to gitignore and chefignore, etc)
6
+
1
7
  ## v1.1.1:
2
8
 
3
9
  * Refactored code
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- ## kitchen-cabinet
2
- ----
1
+ kitchen-cabinet
2
+ ===============
3
+ [![Build Status](https://travis-ci.org/onehealth/kitchen-cabinet.png)](https://travis-ci.org/onehealth/kitchen-cabinet) [![Dependency Status](https://gemnasium.com/onehealth/kitchen-cabinet.png)](https://gemnasium.com/onehealth/kitchen-cabinet) [![Code Climate](https://codeclimate.com/github/onehealth/kitchen-cabinet.png)](https://codeclimate.com/github/onehealth/kitchen-cabinet) [![Gem Version](https://badge.fury.io/rb/kitchen-cabinet.png)](http://badge.fury.io/rb/kitchen-cabinet)
3
4
 
4
5
  About
5
- =====
6
+ -----
6
7
 
7
8
  Inspiration for this gem was taken from [meez](https://github.com/paulczar/meez). It creates an opinionated cookbook complete with testing suites.
8
9
 
data/bin/cabinet CHANGED
@@ -5,6 +5,7 @@ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib
5
5
 
6
6
  require 'optparse'
7
7
  require 'kitchen-cabinet/cabinet'
8
+ require 'kitchen-cabinet/error'
8
9
  require 'fileutils'
9
10
 
10
11
  options = {}
@@ -25,7 +26,7 @@ opt_parser = OptionParser.new do |opt|
25
26
  opt.on('-m', '--email EMAIL', 'The email address for the individual who maintains the cookbook.') do |email|
26
27
  options[:email] = email
27
28
  end
28
- opt.on('-u', '--update', "Update the Gemfile, Chefignore, Guardfile (and other config files that don't change much) of an existing project") do
29
+ opt.on('-u', '--update', 'Update the Gemfile, Chefignore, Guardfile, rubocop.yml, and the Strainerfile.') do
29
30
  options[:update] = true
30
31
  end
31
32
  opt.on('-h', '--help', 'help') do
@@ -37,45 +38,53 @@ end
37
38
 
38
39
  opt_parser.parse!
39
40
 
40
- if ARGV.empty?
41
- puts opt_parser
42
- exit
43
- end
41
+ Error.opt_error('Please specify some options.', opt_parser) if ARGV.empty?
44
42
 
45
43
  cookbook_name = ARGV.pop
46
44
 
47
- def opt_error(message, opt_parser)
48
- puts ''
49
- puts message
50
- puts ''
51
- puts opt_parser
52
- exit
53
- end
54
-
55
45
  if options[:path].respond_to?(:to_str)
56
46
  path = File.join(options[:path], cookbook_name)
47
+ cookbook_path = path
57
48
  else
58
- puts opt_error('Specify a path!', opt_parser)
49
+ options[:path] = Dir.getwd
50
+ puts options[:path] + ' this is the expected path'
51
+ path = Dir.getwd
52
+ cookbook_path = File.join(path, cookbook_name)
53
+ puts cookbook_path + ' this is the cookbook_path'
54
+ end
55
+
56
+ if cookbook_name == 'update'
57
+ require 'kitchen-cabinet/update'
58
+ # path = Dir.getwd
59
+ metadata = File.join(cookbook_path, 'metadata.rb')
60
+ puts path
61
+ puts metadata
62
+ if File.exists?(metadata)
63
+ cookbook_name = File.basename(File.expand_path(File.dirname(__FILE__)))
64
+ Update.update_cookbook(cookbook_name, options, cookbook_path)
65
+ exit
66
+ else
67
+ puts Error.opt_error('Specify a path or run from within the cookbook folder!', opt_parser)
68
+ end
59
69
  end
60
70
 
61
71
  if options[:update]
62
- opt_error("You need to create #{cookbook_name} first!") unless File.exists?(path)
72
+ Error.opt_error('You need to create the cookbook first!', opt_parser) unless File.exists?(cookbook_path)
63
73
  unless options[:path].respond_to?(:to_str) && (cookbook_name.is_a? String)
64
- opt_error('Make sure you specify -o and a cookbook name!', opt_parser)
74
+ Error.opt_error('Make sure you specify -o and a cookbook name!', opt_parser)
65
75
  end
66
76
  if cookbook_name
67
- puts "Updating #{cookbook_name}..."
68
- puts 'Gemfile, Chefignore, and Guardfile are up to date.'
69
- Cabinet.update_cookbook(cookbook_name, options, path)
77
+ require 'kitchen-cabinet/update'
78
+ Update.update_cookbook(cookbook_name, options, cookbook_path)
70
79
  exit
71
80
  else
72
- opt_error('Define a path with `-o` and a cookbook name!', opt_parser)
81
+ Error.opt_error('Define a path with `-o` and a cookbook name!', opt_parser)
73
82
  end
74
83
  elsif cookbook_name
75
- Cabinet.init(cookbook_name, options, path)
84
+ Cabinet.init(cookbook_name, options, cookbook_path)
76
85
  puts "Cookbook #{cookbook_name} created successfully"
77
86
  puts 'Next steps...'
78
- puts " $ cd #{File.join(options[:path], cookbook_name)}"
87
+ puts " $ cd #{cookbook_path}"
79
88
  puts ' $ bundle install'
80
89
  puts ' $ bundle exec berks install'
81
90
  puts ' $ bundle exec strainer test'
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "kitchen-cabinet"
3
- s.version = '1.1.1'
3
+ s.version = '1.2.0'
4
4
  s.date = Time.now.strftime("%Y-%m-%d")
5
5
  s.homepage = 'https://github.com/onehealth/kitchen-cabinet'
6
6
  s.summary = 'Initializes a chef cookbook repo with relevant tools'
@@ -6,106 +6,75 @@
6
6
  class Cabinet
7
7
  require 'fileutils'
8
8
  require 'erubis'
9
- def self.init(cookbook_name, options, path)
10
- init_chef(cookbook_name, options, path)
11
- init_git(cookbook_name, options, path)
12
- init_berkshelf(cookbook_name, options, path)
13
- init_kitchen(cookbook_name, options, path)
14
- init_chefspec(cookbook_name, options, path)
15
- init_serverspec(cookbook_name, options, path)
16
- write_configs(cookbook_name, options, path)
9
+ def self.init(cookbook_name, options, cookbook_path)
10
+ init_chef(cookbook_name, options, cookbook_path)
11
+ init_git(cookbook_name, options, cookbook_path)
12
+ init_berkshelf(cookbook_name, options, cookbook_path)
13
+ init_kitchen(cookbook_name, cookbook_path)
14
+ init_spec(cookbook_name, cookbook_path)
15
+ write_configs(cookbook_name, options, cookbook_path)
17
16
  end
18
17
 
19
- def self.init_chef(cookbook_name, options, path)
18
+ def self.init_chef(cookbook_name, options, cookbook_path)
20
19
  tool = 'chef'
21
20
  puts "* Initializing #{tool}"
22
21
  require 'chef/knife/cookbook_create'
23
22
  create_cookbook = Chef::Knife::CookbookCreate.new
24
23
  create_cookbook.name_args = [cookbook_name]
25
24
  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'
25
+ create_cookbook.config[:cookbook_copyright] = options[:copyright] || 'YOUR_COMPANY_NAME'
26
+ create_cookbook.config[:cookbook_license] = options[:license] || 'YOUR_EMAIL'
27
+ create_cookbook.config[:cookbook_email] = options[:email] || 'none'
29
28
  create_cookbook.run
30
29
  %w{ metadata.rb recipes/default.rb }.each do |file|
31
30
  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) }
31
+ contents = "\# Encoding: utf-8\n#{File.read(File.join(cookbook_path, file))}"
32
+ File.open(File.join(cookbook_path, file), 'w') { |f| f.write(contents) }
34
33
  end
35
34
  end
36
35
 
37
- def self.init_git(cookbook_name, options, path)
36
+ def self.init_git(cookbook_name, options, cookbook_path)
38
37
  tool = 'git'
39
38
  puts "* Initializing #{tool}"
40
39
  require 'git'
41
- Git.init(path, repository: path)
40
+ Git.init(cookbook_path, repository: cookbook_path)
42
41
  end
43
42
 
44
- def self.init_berkshelf(cookbook_name, options, path)
43
+ def self.init_berkshelf(cookbook_name, options, cookbook_path)
45
44
  tool = 'berkshelf'
46
45
  puts "* Initializing #{tool}"
47
46
  require 'berkshelf'
48
47
  require 'berkshelf/base_generator'
49
48
  require 'berkshelf/init_generator'
50
49
  Berkshelf::InitGenerator.new(
51
- [path],
50
+ [cookbook_path],
52
51
  skip_test_kitchen: true,
53
52
  skip_vagrant: true
54
53
  ).invoke_all
55
54
  end
56
55
 
57
- def self.init_kitchen(cookbook_name, options, path)
56
+ def self.init_kitchen(cookbook_name, cookbook_path)
58
57
  tool = 'kitchen'
59
58
  puts "* Initializing #{tool}"
60
59
  require 'kitchen'
61
60
  require 'kitchen/generator/init'
62
- Kitchen::Generator::Init.new([], {}, destination_root: path).invoke_all
61
+ Kitchen::Generator::Init.new([], {}, destination_root: cookbook_path).invoke_all
63
62
  end
64
63
 
65
- def self.init_chefspec(cookbook_name, options, path)
66
- tool = 'chefspec'
67
- puts "* Initializing #{tool}"
68
- spec_path = File.join(path, 'spec')
69
- FileUtils.mkdir_p(spec_path)
70
- @spec = %w(spec_helper.rb default_spec.rb)
71
- @spec.each do |spec|
72
- spec_path = File.join(path, 'spec')
73
- tname = File.read(File.join(File.dirname(File.expand_path(__FILE__)), "templates/chefspec/#{spec}.eruby"))
74
- eruby = Erubis::Eruby.new(tname)
75
- File.open(File.join(spec_path, "#{spec}"), 'w') { |f| f.write(eruby.result(:cookbook_name => cookbook_name)) }
76
- end
77
- end
78
-
79
- def self.init_serverspec(cookbook_name, options, path)
80
- tool = 'serverspec'
81
- puts "* Initializing #{tool}"
82
- spec_path = File.join(path, 'test', 'integration', 'default', 'serverspec')
83
- FileUtils.mkdir_p(spec_path)
84
- @spec = %w(spec_helper.rb default_spec.rb)
85
- @spec.each do |spec|
86
- spec_path = File.join(path, 'spec')
87
- tname = File.read(File.join(File.dirname(File.expand_path(__FILE__)), "templates/serverspec/#{spec}.eruby"))
88
- eruby = Erubis::Eruby.new(tname)
89
- File.open(File.join(spec_path, "#{spec}"), 'w') { |f| f.write(eruby.result(:cookbook_name => cookbook_name)) }
64
+ def self.init_spec(cookbook_name, cookbook_path)
65
+ require 'kitchen-cabinet/spec'
66
+ @tool = %w(chefspec serverspec)
67
+ @tool.each do |tool|
68
+ Spec.install_specs(tool, cookbook_path, cookbook_name)
90
69
  end
91
70
  end
92
71
 
93
- def self.write_configs(cookbook_name, options, path)
72
+ def self.write_configs(cookbook_name, options, cookbook_path)
94
73
  @template = %w(chefignore .gitignore Gemfile Berksfile .kitchen.yml Guardfile Strainerfile .rubocop.yml)
95
74
  puts 'this is the ' + cookbook_name + ' cookbook.'
75
+ require 'kitchen-cabinet/config'
96
76
  @template.each do |template|
97
- tname = File.read(File.join(File.dirname(File.expand_path(__FILE__)), "templates/#{template}.eruby"))
98
- eruby = Erubis::Eruby.new(tname)
99
- File.open(File.join(path, "#{template}"), 'w') { |f| f.write(eruby.result(:cookbook_name => cookbook_name)) }
100
- end
101
- end
102
-
103
- def self.update_cookbook(cookbook_name, options, path)
104
- @template = %w(chefignore Gemfile Guardfile Strainerfile .rubocop.yml)
105
- @template.each do |template|
106
- tname = File.read(File.join(File.dirname(File.expand_path(__FILE__)), "templates/#{template}.eruby"))
107
- eruby = Erubis::Eruby.new(tname)
108
- File.open(File.join(path, "#{template}"), 'w') { |f| f.write(eruby.result(:cookbook_name => cookbook_name)) }
77
+ Initconfig.write_config(cookbook_name, options, cookbook_path, template)
109
78
  end
110
79
  end
111
80
  end
@@ -0,0 +1,8 @@
1
+ # Writes configs for cabinet and update.
2
+ class Initconfig
3
+ def self.write_config(cookbook_name, options, cookbook_path, template)
4
+ tname = File.read(File.join(File.dirname(File.expand_path(__FILE__)), "templates/#{template}.eruby"))
5
+ eruby = Erubis::Eruby.new(tname)
6
+ File.open(File.join(cookbook_path, "#{template}"), 'w') { |f| f.write(eruby.result(:cookbook_name => cookbook_name)) }
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+
4
+ # The error class responds with a helpful message whenever you do something
5
+ # that breaks kitchen-cabinet.
6
+ class Error
7
+ def self.opt_error(message, opt_parser)
8
+ puts ''
9
+ puts message
10
+ puts ''
11
+ puts opt_parser
12
+ exit
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+
4
+ # Removes duplication of code between chefspec and serverspec installs.
5
+ class Spec
6
+ def self.install_specs(tool, cookbook_path, cookbook_name)
7
+ @spec = %w(spec_helper.rb default_spec.rb)
8
+ if tool == 'chefspec'
9
+ spec_path = File.join(cookbook_path, 'spec')
10
+ elsif tool == 'serverspec'
11
+ spec_path = File.join(cookbook_path, 'test', 'integration', 'default', 'serverspec')
12
+ end
13
+ puts "* Initializing #{tool}"
14
+ @spec.each do |spec|
15
+ FileUtils.mkdir_p(spec_path)
16
+ tname = File.read(File.join(File.dirname(File.expand_path(__FILE__)), "templates/#{tool}/#{spec}.eruby"))
17
+ eruby = Erubis::Eruby.new(tname)
18
+ File.open(File.join(spec_path, "#{spec}"), 'w') { |f| f.write(eruby.result(:cookbook_name => cookbook_name)) }
19
+ end
20
+ end
21
+ end
@@ -7,6 +7,12 @@ Berksfile.lock
7
7
  .*.sw[a-z]
8
8
  *.un~
9
9
  /cookbooks
10
+ .coverage
11
+
12
+ # JetBrains
13
+ .idea/workspace.xml
14
+ .idea/tasks.xml
15
+ .idea/dataSources.ids
10
16
 
11
17
  # Bundler
12
18
  Gemfile.lock
@@ -30,6 +30,7 @@ tmtags
30
30
  .project
31
31
  .settings
32
32
  mkmf.log
33
+ .idea/*
33
34
 
34
35
  ## COMPILED ##
35
36
  ##############
@@ -56,6 +57,7 @@ Procfile
56
57
  .kitchen.yml
57
58
  .kitchen/*
58
59
  .rubocop.yml
60
+ .coverage/*
59
61
 
60
62
  # SCM #
61
63
  #######
@@ -96,4 +98,4 @@ Vagrantfile
96
98
 
97
99
  # Travis #
98
100
  ##########
99
- .travis.yml
101
+ .travis.yml
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+
4
+ # The Update class helps you maintain the versions and config of your cookbook creation tools
5
+ class Update
6
+ def self.update_cookbook(cookbook_name, options, cookbook_path)
7
+ @template = %w(chefignore Gemfile Guardfile Strainerfile .rubocop.yml)
8
+ require 'kitchen-cabinet/config'
9
+ puts "Updating #{cookbook_name}..."
10
+ @template.each do |template|
11
+ Initconfig.write_config(cookbook_name, options, cookbook_path, template)
12
+ puts "#{template} is up to date!"
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-cabinet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Price
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -193,6 +193,9 @@ files:
193
193
  - bin/cabinet
194
194
  - kitchen-cabinet.gemspec
195
195
  - lib/kitchen-cabinet/cabinet.rb
196
+ - lib/kitchen-cabinet/config.rb
197
+ - lib/kitchen-cabinet/error.rb
198
+ - lib/kitchen-cabinet/spec.rb
196
199
  - lib/kitchen-cabinet/templates/.gitignore.eruby
197
200
  - lib/kitchen-cabinet/templates/.kitchen.yml.eruby
198
201
  - lib/kitchen-cabinet/templates/.rubocop.yml.eruby
@@ -205,6 +208,7 @@ files:
205
208
  - lib/kitchen-cabinet/templates/chefspec/spec_helper.rb.eruby
206
209
  - lib/kitchen-cabinet/templates/serverspec/default_spec.rb.eruby
207
210
  - lib/kitchen-cabinet/templates/serverspec/spec_helper.rb.eruby
211
+ - lib/kitchen-cabinet/update.rb
208
212
  - spec/cabinet_spec.rb
209
213
  - spec/spec_helper.rb
210
214
  homepage: https://github.com/onehealth/kitchen-cabinet