diff --git a/lib/puppet/face/module_tool/build.rb b/lib/puppet/face/module_tool/build.rb index 87e6aff33..58bf1e16a 100644 --- a/lib/puppet/face/module_tool/build.rb +++ b/lib/puppet/face/module_tool/build.rb @@ -1,35 +1,34 @@ Puppet::Face.define(:module_tool, '1.0.0') do action(:build) do summary "Build a module release package." description <<-EOT Build a module release archive file by processing the Modulefile in the module directory. The release archive file will be stored in the pkg directory of the module directory. EOT returns "Pathname object representing the path to the release archive." examples <<-EOT Build a module release from within the module directory: $ puppet module_tool build Build a module release from outside the module directory: $ puppet module_tool build /path/to/module EOT arguments "" when_invoked do |path, options| - root_path = Puppet::Module::Tool.find_module_root(path) - Puppet::Module::Tool::Applications::Builder.run(root_path, options) + Puppet::Module::Tool::Applications::Builder.run(path, options) end when_rendering :console do |return_value| # Get the string representation of the Pathname object and print it to # the console. return_value.to_s end end end diff --git a/lib/puppet/module_tool/applications/builder.rb b/lib/puppet/module_tool/applications/builder.rb index adf66a2b7..251b91882 100644 --- a/lib/puppet/module_tool/applications/builder.rb +++ b/lib/puppet/module_tool/applications/builder.rb @@ -1,91 +1,91 @@ require 'fileutils' module Puppet::Module::Tool module Applications class Builder < Application def initialize(path, options = {}) - @path = File.expand_path(path) + @path = File.expand_path(Puppet::Module::Tool.find_module_root(path)) @pkg_path = File.join(@path, 'pkg') super(options) end def run load_modulefile! create_directory copy_contents add_metadata Puppet.notice "Building #{@path} for release" tar gzip relative = Pathname.new(File.join(@pkg_path, filename('tar.gz'))).relative_path_from(Pathname.new(Dir.pwd)) # Return the Pathname object representing the path to the release # archive just created. This return value is used by the module_tool # face build action, and displayed to on the console using the to_s # method. # # Example return value: # # # relative end private def filename(ext) ext.sub!(/^\./, '') "#{metadata.release_name}.#{ext}" end def tar tar_name = filename('tar') Dir.chdir(@pkg_path) do FileUtils.rm tar_name rescue nil unless system "tar -cf #{tar_name} #{metadata.release_name}" raise SystemExit, "Could not create #{tar_name}" end end end def gzip Dir.chdir(@pkg_path) do FileUtils.rm filename('tar.gz') rescue nil unless system "gzip #{filename('tar')}" raise SystemExit, "Could not compress #{filename('tar')}" end end end def create_directory FileUtils.mkdir(@pkg_path) rescue nil if File.directory?(build_path) FileUtils.rm_rf(build_path) end FileUtils.mkdir(build_path) end def copy_contents Dir[File.join(@path, '*')].each do |path| case File.basename(path) when *Puppet::Module::Tool::ARTIFACTS next else FileUtils.cp_r path, build_path end end end def add_metadata File.open(File.join(build_path, 'metadata.json'), 'w') do |f| f.write(PSON.pretty_generate(metadata)) end end def build_path @build_path ||= File.join(@pkg_path, metadata.release_name) end end end end