Sha256: 64be8c11a6ed3c6e66ba383cd9377ae6e2360f86e06a68fe3f749067c58ef625

Contents?: true

Size: 1.89 KB

Versions: 4

Compression:

Stored size: 1.89 KB

Contents

require 'linecook/commands/command'
require 'linecook/cookbook'
require 'linecook/package'
require 'fileutils'
require 'yaml'

module Linecook
  module Commands
    
    # :startdoc::desc generates a package
    #
    # Generates the package specified at
    # 'project_dir/packages/package_name.yml'.  The package file should be a
    # YAML files that specifies a package env.  The full path to package file
    # can be given instead of package name using the --file option.
    #
    # If a cookbook file is present in the project_dir then it will be used to
    # resolve resources available to the package.  See the env command to
    # interrogate a package env.
    class Package < Command
      config :project_dir, '.', :short => :d              # the project directory
      config :force, false, :short => :f, &c.flag         # force creation
      config :quiet, false, &c.flag                       # silence output
      
      def process(package_file, package_dir=nil)
        package_dir ||= default_package_dir(package_file)
        package_dir = File.expand_path(package_dir)
        package = Linecook::Package.init(package_file, project_dir)
        
        dependencies = package_dependencies(package) + [package_file]
        if force || !FileUtils.uptodate?(package_dir, dependencies)
          package.build
          package.export(package_dir)
          $stdout.puts package_dir unless quiet
        end
        
        package_dir
      end
      
      def package_dependencies(package)
        dependencies = []
        package.manifest.values.collect do |resources|
          dependencies.concat resources.values
        end
        
        $LOAD_PATH.each do |path|
          dependencies.concat Dir.glob("#{path}/**/*.rb")
        end
        dependencies
      end
      
      def default_package_dir(package_file)
        package_file.chomp(File.extname(package_file))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
linecook-1.2.1 lib/linecook/commands/package.rb
linecook-1.2.0 lib/linecook/commands/package.rb
linecook-1.1.0 lib/linecook/commands/package.rb
linecook-1.0.0 lib/linecook/commands/package.rb