Skip to content

Commit

Permalink
(PUP-1977) Update puppet module generate to create metadata.json
Browse files Browse the repository at this point in the history
Prior to this commit, running `puppet module generate` would create a Modulefile with the appropriate metadata, from which a metadata.json file would be generated when you ran `puppet module build`.  Since we're migrating away from the Modulefile as the canonical source of metadata (as per PE-3117), this commit will instead generate an equivalent metadata.json file when the module is created.
  • Loading branch information
pvande committed Mar 18, 2014
1 parent efc18dd commit 7d78de2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
16 changes: 15 additions & 1 deletion lib/puppet/module_tool/applications/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ class Generator < Application

def initialize(full_module_name, options = {})
begin
@metadata = Metadata.new.update('name' => full_module_name, 'version' => '0.0.1')
@metadata = Metadata.new.update(
'name' => full_module_name,
'version' => '0.0.1',
'dependencies' => [
{ :name => 'puppetlabs-stdlib', :version_range => '>= 1.0.0' }
]
)

# These are used in the generation of the metadata.json file t
# simulate an ordered hash. In particular, the keys listed below are
# promoted to the top of the serialized hash for human-friendliness.
#
# This particularly works around the lack of ordered hashes in 1.8.7.
@hash = @metadata.to_hash
@remaining_keys = @hash.keys - %w[ name version author summary license source ]
rescue ArgumentError
msg = "Could not generate directory #{full_module_name.inspect}, you must specify a dash-separated username and module name."
raise $!, msg, $!.backtrace
Expand Down
11 changes: 0 additions & 11 deletions lib/puppet/module_tool/skeleton/templates/generator/Modulefile.erb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": <%= @hash['name'].to_json %>,
"version": <%= @hash['version'].to_json %>,
"author": <%= @hash['author'].to_json %>,
"summary": <%= @hash['summary'].to_json %>,
"license": <%= @hash['license'].to_json %>,
"source": <%= @hash['source'].to_json %>,
<%= @remaining_keys.map { |k| "#{k.to_json}: #{PSON.pretty_generate(@hash[k])}" }.join(",\n").gsub(/^/, ' ') %>
}

0 comments on commit 7d78de2

Please sign in to comment.