cookbook_creator 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cookbook_create +11 -0
  3. data/cookbook_creator.gemspec +33 -0
  4. data/lib/cookbook_creator/cli.rb +100 -0
  5. data/lib/cookbook_creator/config.rb +24 -0
  6. data/lib/cookbook_creator/config_loader.rb +157 -0
  7. data/lib/cookbook_creator/generator.rb +202 -0
  8. data/lib/cookbook_creator/helpers.rb +25 -0
  9. data/lib/cookbook_creator/main.rb +42 -0
  10. data/lib/cookbook_creator/null_logger.rb +70 -0
  11. data/lib/cookbook_creator/pathhelper.rb +33 -0
  12. data/lib/cookbook_creator/runner.rb +74 -0
  13. data/lib/cookbook_creator/skeletons/code_generator/files/default/Berksfile +3 -0
  14. data/lib/cookbook_creator/skeletons/code_generator/files/default/chefignore +100 -0
  15. data/lib/cookbook_creator/skeletons/code_generator/files/default/cookbook_readmes/README-policy.md +9 -0
  16. data/lib/cookbook_creator/skeletons/code_generator/files/default/cookbook_readmes/README.md +54 -0
  17. data/lib/cookbook_creator/skeletons/code_generator/files/default/gitignore +16 -0
  18. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/README.md +28 -0
  19. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/cookbooks/example/README.md +27 -0
  20. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/cookbooks/example/attributes/default.rb +7 -0
  21. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/cookbooks/example/metadata.rb +3 -0
  22. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +8 -0
  23. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/data_bags/README.md +58 -0
  24. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/data_bags/example/example_item.json +4 -0
  25. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/dot-chef-repo.txt +6 -0
  26. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/environments/README.md +9 -0
  27. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/environments/example.json +13 -0
  28. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/policies/README.md +24 -0
  29. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/roles/README.md +9 -0
  30. data/lib/cookbook_creator/skeletons/code_generator/files/default/repo/roles/example.json +13 -0
  31. data/lib/cookbook_creator/skeletons/code_generator/files/default/serverspec_spec_helper.rb +8 -0
  32. data/lib/cookbook_creator/skeletons/code_generator/files/default/spec_helper.rb +2 -0
  33. data/lib/cookbook_creator/skeletons/code_generator/files/default/spec_helper_policyfile.rb +2 -0
  34. data/lib/cookbook_creator/skeletons/code_generator/metadata.rb +8 -0
  35. data/lib/cookbook_creator/skeletons/code_generator/recipes/app.rb +97 -0
  36. data/lib/cookbook_creator/skeletons/code_generator/recipes/attribute.rb +12 -0
  37. data/lib/cookbook_creator/skeletons/code_generator/recipes/cookbook.rb +112 -0
  38. data/lib/cookbook_creator/skeletons/code_generator/recipes/cookbook_file.rb +24 -0
  39. data/lib/cookbook_creator/skeletons/code_generator/recipes/lwrp.rb +23 -0
  40. data/lib/cookbook_creator/skeletons/code_generator/recipes/policyfile.rb +8 -0
  41. data/lib/cookbook_creator/skeletons/code_generator/recipes/recipe.rb +27 -0
  42. data/lib/cookbook_creator/skeletons/code_generator/recipes/repo.rb +67 -0
  43. data/lib/cookbook_creator/skeletons/code_generator/recipes/template.rb +32 -0
  44. data/lib/cookbook_creator/skeletons/code_generator/templates/default/Berksfile.erb +3 -0
  45. data/lib/cookbook_creator/skeletons/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
  46. data/lib/cookbook_creator/skeletons/code_generator/templates/default/LICENSE.apache2.erb +201 -0
  47. data/lib/cookbook_creator/skeletons/code_generator/templates/default/LICENSE.gplv2.erb +339 -0
  48. data/lib/cookbook_creator/skeletons/code_generator/templates/default/LICENSE.gplv3.erb +674 -0
  49. data/lib/cookbook_creator/skeletons/code_generator/templates/default/LICENSE.mit.erb +21 -0
  50. data/lib/cookbook_creator/skeletons/code_generator/templates/default/README.md.erb +4 -0
  51. data/lib/cookbook_creator/skeletons/code_generator/templates/default/attribute.rb.erb +1 -0
  52. data/lib/cookbook_creator/skeletons/code_generator/templates/default/cookbook_file.erb +1 -0
  53. data/lib/cookbook_creator/skeletons/code_generator/templates/default/kitchen.yml.erb +25 -0
  54. data/lib/cookbook_creator/skeletons/code_generator/templates/default/library.rb.erb +7 -0
  55. data/lib/cookbook_creator/skeletons/code_generator/templates/default/metadata.rb.erb +7 -0
  56. data/lib/cookbook_creator/skeletons/code_generator/templates/default/provider.rb.erb +10 -0
  57. data/lib/cookbook_creator/skeletons/code_generator/templates/default/recipe.rb.erb +5 -0
  58. data/lib/cookbook_creator/skeletons/code_generator/templates/default/recipe_spec.rb.erb +20 -0
  59. data/lib/cookbook_creator/skeletons/code_generator/templates/default/repo/gitignore.erb +11 -0
  60. data/lib/cookbook_creator/skeletons/code_generator/templates/default/resource.rb.erb +7 -0
  61. data/lib/cookbook_creator/skeletons/code_generator/templates/default/serverspec_default_spec.rb.erb +9 -0
  62. data/lib/cookbook_creator/skeletons/code_generator/templates/default/template.erb +0 -0
  63. data/lib/skeletons/code_generator/files/default/Berksfile +3 -0
  64. data/lib/skeletons/code_generator/files/default/chefignore +100 -0
  65. data/lib/skeletons/code_generator/files/default/cookbook_readmes/README-policy.md +9 -0
  66. data/lib/skeletons/code_generator/files/default/cookbook_readmes/README.md +54 -0
  67. data/lib/skeletons/code_generator/files/default/gitignore +16 -0
  68. data/lib/skeletons/code_generator/files/default/repo/README.md +28 -0
  69. data/lib/skeletons/code_generator/files/default/repo/cookbooks/example/README.md +27 -0
  70. data/lib/skeletons/code_generator/files/default/repo/cookbooks/example/attributes/default.rb +7 -0
  71. data/lib/skeletons/code_generator/files/default/repo/cookbooks/example/metadata.rb +3 -0
  72. data/lib/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +8 -0
  73. data/lib/skeletons/code_generator/files/default/repo/data_bags/README.md +58 -0
  74. data/lib/skeletons/code_generator/files/default/repo/data_bags/example/example_item.json +4 -0
  75. data/lib/skeletons/code_generator/files/default/repo/dot-chef-repo.txt +6 -0
  76. data/lib/skeletons/code_generator/files/default/repo/environments/README.md +9 -0
  77. data/lib/skeletons/code_generator/files/default/repo/environments/example.json +13 -0
  78. data/lib/skeletons/code_generator/files/default/repo/policies/README.md +24 -0
  79. data/lib/skeletons/code_generator/files/default/repo/roles/README.md +9 -0
  80. data/lib/skeletons/code_generator/files/default/repo/roles/example.json +13 -0
  81. data/lib/skeletons/code_generator/files/default/serverspec_spec_helper.rb +8 -0
  82. data/lib/skeletons/code_generator/files/default/spec_helper.rb +2 -0
  83. data/lib/skeletons/code_generator/files/default/spec_helper_policyfile.rb +2 -0
  84. data/lib/skeletons/code_generator/metadata.rb +8 -0
  85. data/lib/skeletons/code_generator/recipes/app.rb +97 -0
  86. data/lib/skeletons/code_generator/recipes/attribute.rb +12 -0
  87. data/lib/skeletons/code_generator/recipes/cookbook.rb +94 -0
  88. data/lib/skeletons/code_generator/recipes/cookbook_file.rb +24 -0
  89. data/lib/skeletons/code_generator/recipes/lwrp.rb +23 -0
  90. data/lib/skeletons/code_generator/recipes/policyfile.rb +8 -0
  91. data/lib/skeletons/code_generator/recipes/recipe.rb +27 -0
  92. data/lib/skeletons/code_generator/recipes/repo.rb +67 -0
  93. data/lib/skeletons/code_generator/recipes/template.rb +32 -0
  94. data/lib/skeletons/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
  95. data/lib/skeletons/code_generator/templates/default/LICENSE.apache2.erb +201 -0
  96. data/lib/skeletons/code_generator/templates/default/LICENSE.gplv2.erb +339 -0
  97. data/lib/skeletons/code_generator/templates/default/LICENSE.gplv3.erb +674 -0
  98. data/lib/skeletons/code_generator/templates/default/LICENSE.mit.erb +21 -0
  99. data/lib/skeletons/code_generator/templates/default/Policyfile.rb.erb +25 -0
  100. data/lib/skeletons/code_generator/templates/default/README.md.erb +4 -0
  101. data/lib/skeletons/code_generator/templates/default/attribute.rb.erb +0 -0
  102. data/lib/skeletons/code_generator/templates/default/cookbook_file.erb +0 -0
  103. data/lib/skeletons/code_generator/templates/default/kitchen.yml.erb +21 -0
  104. data/lib/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb +32 -0
  105. data/lib/skeletons/code_generator/templates/default/metadata.rb.erb +7 -0
  106. data/lib/skeletons/code_generator/templates/default/provider.rb.erb +0 -0
  107. data/lib/skeletons/code_generator/templates/default/recipe.rb.erb +5 -0
  108. data/lib/skeletons/code_generator/templates/default/recipe_spec.rb.erb +20 -0
  109. data/lib/skeletons/code_generator/templates/default/repo/gitignore.erb +11 -0
  110. data/lib/skeletons/code_generator/templates/default/resource.rb.erb +0 -0
  111. data/lib/skeletons/code_generator/templates/default/serverspec_default_spec.rb.erb +9 -0
  112. data/lib/skeletons/code_generator/templates/default/template.erb +0 -0
  113. data/test.txt +0 -0
  114. metadata +119 -6
@@ -0,0 +1,4 @@
1
+ {
2
+ "id": "example_item",
3
+ "key": "value"
4
+ }
@@ -0,0 +1,6 @@
1
+ .chef-repo.txt
2
+ ==============
3
+
4
+ This file gives ChefDK's generators a hint that you are using a Chef Repo and
5
+ this is the root directory of your Chef Repo. ChefDK's generators use this to
6
+ generate code that is designed to work with the Chef Repo workflow.
@@ -0,0 +1,9 @@
1
+ Create environments here, in either the Role Ruby DSL (.rb) or JSON (.json) files. To install environments on the server, use knife.
2
+
3
+ For example, in this directory you'll find an example environment file called `example.json` which can be uploaded to the Chef Server:
4
+
5
+ knife environment from file environments/example.json
6
+
7
+ For more information on environments, see the Chef wiki page:
8
+
9
+ https://docs.chef.io/environments.html
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "example",
3
+ "description": "This is an example environment defined as JSON",
4
+ "chef_type": "environment",
5
+ "json_class": "Chef::Environment",
6
+ "default_attributes": {
7
+ },
8
+ "override_attributes": {
9
+ },
10
+ "cookbook_versions": {
11
+ "example": "= 1.0.0"
12
+ }
13
+ }
@@ -0,0 +1,24 @@
1
+ Create policyfiles here. When using a chef-repo, give your policyfiles
2
+ the same filename as the name set in the policyfile itself, and use the
3
+ `.rb` file extension.
4
+
5
+ Compile the policy with a command like this:
6
+
7
+ ```
8
+ chef install policies/my-app-frontend.rb
9
+ ```
10
+
11
+ This will create a lockfile `policies/my-app-frontend.lock.json`.
12
+
13
+ To update locked dependencies, run `chef update` like this:
14
+
15
+ ```
16
+ chef update policies/my-app-fronend.rb
17
+ ```
18
+
19
+ You can upload the policy (with associated cookbooks) to the server
20
+ using a command like:
21
+
22
+ ```
23
+ chef push staging policies/my-app-frontend.rb
24
+ ```
@@ -0,0 +1,9 @@
1
+ Create roles here, in either the Role Ruby DSL (.rb) or JSON (.json) files. To install roles on the server, use knife.
2
+
3
+ For example, in this directory you'll find an example role file called `example.json` which can be uploaded to the Chef Server:
4
+
5
+ knife role from file roles/example.json
6
+
7
+ For more information on roles, see the Chef wiki page:
8
+
9
+ https://docs.chef.io/essentials_roles.html
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "example",
3
+ "description": "This is an example role defined as JSON",
4
+ "chef_type": "role",
5
+ "json_class": "Chef::Role",
6
+ "default_attributes": {
7
+ },
8
+ "override_attributes": {
9
+ },
10
+ "run_list": [
11
+ "recipe[example]"
12
+ ]
13
+ }
@@ -0,0 +1,8 @@
1
+ require 'serverspec'
2
+
3
+ if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil?
4
+ set :backend, :exec
5
+ else
6
+ set :backend, :cmd
7
+ set :os, family: 'windows'
8
+ end
@@ -0,0 +1,2 @@
1
+ require 'chefspec'
2
+ require 'chefspec/berkshelf'
@@ -0,0 +1,2 @@
1
+ require 'chefspec'
2
+ require 'chefspec/policyfile'
@@ -0,0 +1,8 @@
1
+ name 'code_generator'
2
+ maintainer 'Chef Software, Inc.'
3
+ maintainer_email 'dev@chef.io'
4
+ license 'Apache 2 License'
5
+ description 'Generates Chef code for Chef DK'
6
+ long_description 'Generates Chef code for Chef DK'
7
+ version '0.1.0'
8
+
@@ -0,0 +1,97 @@
1
+
2
+
3
+ context = ChefDK::Generator.context
4
+ app_dir = File.join(context.app_root, context.app_name)
5
+ cookbooks_dir = context.cookbook_root
6
+ cookbook_dir = File.join(cookbooks_dir, context.cookbook_name)
7
+
8
+ # app root dir
9
+ directory app_dir
10
+
11
+ # Top level files
12
+
13
+ # TK
14
+ template "#{app_dir}/.kitchen.yml" do
15
+ source 'kitchen.yml.erb'
16
+ helpers(ChefDK::Generator::TemplateHelper)
17
+ end
18
+
19
+ directory "#{app_dir}/test/integration/default/serverspec" do
20
+ recursive true
21
+ end
22
+
23
+ directory "#{app_dir}/test/integration/helpers/serverspec" do
24
+ recursive true
25
+ end
26
+
27
+ cookbook_file "#{app_dir}/test/integration/helpers/serverspec/spec_helper.rb" do
28
+ source 'serverspec_spec_helper.rb'
29
+ action :create_if_missing
30
+ end
31
+
32
+ template "#{app_dir}/test/integration/default/serverspec/default_spec.rb" do
33
+ source 'serverspec_default_spec.rb.erb'
34
+ helpers(ChefDK::Generator::TemplateHelper)
35
+ action :create_if_missing
36
+ end
37
+
38
+ # README
39
+ template "#{app_dir}/README.md" do
40
+ helpers(ChefDK::Generator::TemplateHelper)
41
+ end
42
+
43
+ # Generated Cookbook:
44
+
45
+ # cookbook collection dir
46
+ directory cookbooks_dir
47
+
48
+ # cookbook collection dir
49
+ directory cookbook_dir
50
+
51
+ # metadata.rb
52
+ template "#{cookbook_dir}/metadata.rb" do
53
+ helpers(ChefDK::Generator::TemplateHelper)
54
+ end
55
+
56
+ # chefignore
57
+ cookbook_file "#{cookbook_dir}/chefignore"
58
+
59
+ # Berks
60
+ cookbook_file "#{cookbook_dir}/Berksfile"
61
+
62
+ # Recipes
63
+
64
+ directory "#{cookbook_dir}/recipes"
65
+
66
+ template "#{cookbook_dir}/recipes/default.rb" do
67
+ source "recipe.rb.erb"
68
+ helpers(ChefDK::Generator::TemplateHelper)
69
+ end
70
+
71
+ # Chefspec
72
+ directory "#{cookbook_dir}/spec/unit/recipes" do
73
+ recursive true
74
+ end
75
+
76
+ cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
77
+ action :create_if_missing
78
+ end
79
+
80
+ template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
81
+ source "recipe_spec.rb.erb"
82
+ helpers(ChefDK::Generator::TemplateHelper)
83
+ action :create_if_missing
84
+ end
85
+
86
+ # git
87
+ if context.have_git
88
+ if !context.skip_git_init
89
+ execute("initialize-git") do
90
+ command("git init .")
91
+ cwd app_dir
92
+ end
93
+ end
94
+ cookbook_file "#{app_dir}/.gitignore" do
95
+ source "gitignore"
96
+ end
97
+ end
@@ -0,0 +1,12 @@
1
+
2
+ context = ChefDK::Generator.context
3
+ cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
4
+ attribute_dir = File.join(cookbook_dir, "attributes")
5
+ attribute_path = File.join(cookbook_dir, "attributes", "#{context.new_file_basename}.rb")
6
+
7
+ directory attribute_dir
8
+
9
+ template attribute_path do
10
+ source "attribute.rb.erb"
11
+ helpers(ChefDK::Generator::TemplateHelper)
12
+ end
@@ -0,0 +1,94 @@
1
+ context = CookbookCreator::Generator.context
2
+ cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
3
+ p context.cookbook_root
4
+ p context.cookbook_name
5
+ exit
6
+
7
+ # cookbook root dir
8
+ directory cookbook_dir
9
+
10
+ # metadata.rb
11
+ template "#{cookbook_dir}/metadata.rb" do
12
+ helpers(CookbookCreator::Generator::TemplateHelper)
13
+ action :create_if_missing
14
+ end
15
+
16
+ # README
17
+ template "#{cookbook_dir}/README.md" do
18
+ helpers(CookbookCreator::Generator::TemplateHelper)
19
+ action :create_if_missing
20
+ end
21
+
22
+ # chefignore
23
+ cookbook_file "#{cookbook_dir}/chefignore"
24
+
25
+
26
+ # Berks
27
+ cookbook_file "#{cookbook_dir}/Berksfile" do
28
+ action :create_if_missing
29
+ end
30
+
31
+
32
+
33
+ # CookbookCreator & Serverspec
34
+ template "#{cookbook_dir}/.kitchen.yml" do
35
+
36
+ source 'kitchen.yml.erb'
37
+ helpers(CookbookCreator::Generator::TemplateHelper)
38
+ action :create_if_missing
39
+ end
40
+
41
+ directory "#{cookbook_dir}/test/integration/default/serverspec" do
42
+ recursive true
43
+ end
44
+
45
+ directory "#{cookbook_dir}/test/integration/helpers/serverspec" do
46
+ recursive true
47
+ end
48
+
49
+ cookbook_file "#{cookbook_dir}/test/integration/helpers/serverspec/spec_helper.rb" do
50
+ source 'serverspec_spec_helper.rb'
51
+ action :create_if_missing
52
+ end
53
+
54
+ template "#{cookbook_dir}/test/integration/default/serverspec/default_spec.rb" do
55
+ source 'serverspec_default_spec.rb.erb'
56
+ helpers(CookbookCreator::Generator::TemplateHelper)
57
+ action :create_if_missing
58
+ end
59
+
60
+ # Chefspec
61
+ directory "#{cookbook_dir}/spec/unit/recipes" do
62
+ recursive true
63
+ end
64
+
65
+ cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
66
+
67
+ source "spec_helper.rb"
68
+
69
+ action :create_if_missing
70
+ end
71
+
72
+ template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
73
+ source "recipe_spec.rb.erb"
74
+ helpers(CookbookCreator::Generator::TemplateHelper)
75
+ action :create_if_missing
76
+ end
77
+
78
+ # Recipes
79
+
80
+ directory "#{cookbook_dir}/recipes"
81
+
82
+ template "#{cookbook_dir}/recipes/default.rb" do
83
+ source "recipe.rb.erb"
84
+ helpers(CookbookCreator::Generator::TemplateHelper)
85
+ action :create_if_missing
86
+ end
87
+
88
+ # git
89
+ if context.have_git
90
+
91
+ cookbook_file "#{cookbook_dir}/.gitignore" do
92
+ source "gitignore"
93
+ end
94
+ end
@@ -0,0 +1,24 @@
1
+
2
+ context = ChefDK::Generator.context
3
+ cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
4
+ files_dir = File.join(cookbook_dir, "files", "default")
5
+ cookbook_file_path = File.join(cookbook_dir, "files", "default", "#{context.new_file_basename}")
6
+
7
+ directory files_dir do
8
+ recursive true
9
+ end
10
+
11
+ if source_file = context.content_source
12
+
13
+ file cookbook_file_path do
14
+ content(IO.read(source_file))
15
+ end
16
+
17
+ else
18
+
19
+ template cookbook_file_path do
20
+ source "cookbook_file.erb"
21
+ helpers(ChefDK::Generator::TemplateHelper)
22
+ end
23
+
24
+ end
@@ -0,0 +1,23 @@
1
+
2
+ context = ChefDK::Generator.context
3
+ cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
4
+
5
+ resource_dir = File.join(cookbook_dir, "resources")
6
+ resource_path = File.join(resource_dir, "#{context.new_file_basename}.rb")
7
+
8
+ provider_dir = File.join(cookbook_dir, "providers")
9
+ provider_path = File.join(provider_dir, "#{context.new_file_basename}.rb")
10
+
11
+ directory resource_dir
12
+
13
+ template resource_path do
14
+ source "resource.rb.erb"
15
+ helpers(ChefDK::Generator::TemplateHelper)
16
+ end
17
+
18
+ directory provider_dir
19
+
20
+ template provider_path do
21
+ source "provider.rb.erb"
22
+ helpers(ChefDK::Generator::TemplateHelper)
23
+ end
@@ -0,0 +1,8 @@
1
+
2
+ context = ChefDK::Generator.context
3
+ policyfile_path = File.join(context.policyfile_dir, "#{context.new_file_basename}.rb")
4
+
5
+ template policyfile_path do
6
+ source "Policyfile.rb.erb"
7
+ helpers(ChefDK::Generator::TemplateHelper)
8
+ end
@@ -0,0 +1,27 @@
1
+
2
+ context = ChefDK::Generator.context
3
+ cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
4
+ recipe_path = File.join(cookbook_dir, "recipes", "#{context.new_file_basename}.rb")
5
+ spec_helper_path = File.join(cookbook_dir, "spec", "spec_helper.rb")
6
+ spec_path = File.join(cookbook_dir, "spec", "unit", "recipes", "#{context.new_file_basename}_spec.rb")
7
+
8
+ # Chefspec
9
+ directory "#{cookbook_dir}/spec/unit/recipes" do
10
+ recursive true
11
+ end
12
+
13
+ cookbook_file spec_helper_path do
14
+ action :create_if_missing
15
+ end
16
+
17
+ template spec_path do
18
+ source "recipe_spec.rb.erb"
19
+ helpers(ChefDK::Generator::TemplateHelper)
20
+ action :create_if_missing
21
+ end
22
+
23
+ # Recipe
24
+ template recipe_path do
25
+ source "recipe.rb.erb"
26
+ helpers(ChefDK::Generator::TemplateHelper)
27
+ end
@@ -0,0 +1,67 @@
1
+ context = ChefDK::Generator.context
2
+ repo_dir = File.join(context.repo_root, context.repo_name)
3
+
4
+ # repo root dir
5
+ directory repo_dir
6
+
7
+ # Top level files
8
+ template "#{repo_dir}/LICENSE" do
9
+ source "LICENSE.#{context.license}.erb"
10
+ helpers(ChefDK::Generator::TemplateHelper)
11
+ action :create_if_missing
12
+ end
13
+
14
+ cookbook_file "#{repo_dir}/.chef-repo.txt" do
15
+ source "repo/dot-chef-repo.txt"
16
+ action :create_if_missing
17
+ end
18
+
19
+ cookbook_file "#{repo_dir}/README.md" do
20
+ source "repo/README.md"
21
+ action :create_if_missing
22
+ end
23
+
24
+ cookbook_file "#{repo_dir}/chefignore" do
25
+ source "chefignore"
26
+ action :create_if_missing
27
+ end
28
+
29
+ directories_to_create = %w{ cookbooks data_bags }
30
+
31
+ if context.use_roles
32
+ directories_to_create += %w{ roles environments }
33
+ else
34
+ directories_to_create += %w{ policies }
35
+ end
36
+
37
+ directories_to_create.each do |tlo|
38
+ remote_directory "#{repo_dir}/#{tlo}" do
39
+ source "repo/#{tlo}"
40
+ action :create_if_missing
41
+ end
42
+ end
43
+
44
+ cookbook_file "#{repo_dir}/cookbooks/README.md" do
45
+ if context.policy_only
46
+ source "cookbook_readmes/README-policy.md"
47
+ else
48
+ source "cookbook_readmes/README.md"
49
+ end
50
+ action :create_if_missing
51
+ end
52
+
53
+ # git
54
+ if context.have_git
55
+ if !context.skip_git_init
56
+ execute("initialize-git") do
57
+ command("git init .")
58
+ cwd repo_dir
59
+ not_if { File.exist?("#{repo_dir}/.gitignore") }
60
+ end
61
+ end
62
+ template "#{repo_dir}/.gitignore" do
63
+ source "repo/gitignore.erb"
64
+ helpers(ChefDK::Generator::TemplateHelper)
65
+ action :create_if_missing
66
+ end
67
+ end