lib/linecook/commands/package.rb in linecook-0.6.2 vs lib/linecook/commands/package.rb in linecook-1.0.0

- old
+ new

@@ -1,39 +1,57 @@ require 'linecook/commands/command' require 'linecook/cookbook' -require 'linecook/recipe' +require 'linecook/package' +require 'fileutils' require 'yaml' module Linecook module Commands - # ::desc generates a package + # :startdoc::desc generates a package # - # 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 :cookbook_dir, '.', :short => :d # the cookbook directory - config :force, false, :short => :f, &c.flag # force creation + 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(source, target=nil) - target ||= default_target(source) + 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) - if File.exists?(target) - if force - FileUtils.rm_r(target) - else - raise "already exists: #{target}" - end + 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 - log :create, File.basename(target) + package_dir + end + + def package_dependencies(package) + dependencies = [] + package.manifest.values.collect do |resources| + dependencies.concat resources.values + end - env = Linecook::Cookbook.init(cookbook_dir).env(source) - Linecook::Recipe.build(env).export(target) + $LOAD_PATH.each do |path| + dependencies.concat Dir.glob("#{path}/**/*.rb") + end + dependencies end - def default_target(source) - source.chomp(File.extname(source)) + def default_package_dir(package_file) + package_file.chomp(File.extname(package_file)) end end end end \ No newline at end of file