Permalink
Browse files

Added --package flag to treat packages and projects for development

  • Loading branch information...
1 parent 013bac3 commit 5291f072b7b70074213c5c0ad7bdd753bcdfbc98 @wagenet wagenet committed Sep 21, 2011
View
@@ -14,6 +14,7 @@ module BPM
autoload :Remote, 'bpm/remote'
autoload :Repository, 'bpm/repository'
autoload :Project, 'bpm/project'
+ autoload :PackageProject, 'bpm/package_project'
autoload :Rack, 'bpm/rack'
autoload :Server, 'bpm/server'
autoload :Pipeline, 'bpm/pipeline'
View
@@ -86,6 +86,7 @@ def help(*args)
method_option :version, :type => :string, :default => ">= 0", :aliases => ['-v'], :desc => 'Specify a version to install'
method_option :prerelease, :type => :boolean, :default => false, :aliases => ['--pre'], :desc => 'Install a prerelease version'
method_option :project, :type => :string, :default => nil, :aliases => ['-p'], :desc => 'Specify project location other than working directory'
+ method_option :package, :type => :boolean, :default => false, :desc => "Fetch for a package, instead of a project"
def fetch(*packages)
project = find_project(false) if packages.empty?
if project
@@ -145,6 +146,7 @@ def fetched(*packages)
method_option :prerelease, :type => :boolean, :default => false, :aliases => ['--pre'], :desc => 'Install a prerelease version'
method_option :development, :type => :boolean, :default => false, :aliases => ['--dev'], :desc => "Add as a development dependency"
method_option :mode, :type => :string, :default => :production, :aliases => ['-m'], :desc => "Build mode for compile"
+ method_option :package, :type => :boolean, :default => false, :desc => "Add to a package, instead of a project"
def add(*package_names)
# map to dependencies
if package_names.empty?
@@ -181,6 +183,7 @@ def add(*package_names)
LONGDESC
method_option :project, :type => :string, :default => nil, :aliases => ['-p'], :desc => 'Specify project location other than working directory'
method_option :mode, :type => :string, :default => :production, :aliases => ['-m'], :desc => "Build mode for compile"
+ method_option :package, :type => :boolean, :default => false, :desc => "Remove from a package, instead of a project"
def remove(*package_names)
# map to dependencies
@@ -208,6 +211,7 @@ def remove(*package_names)
method_option :mode, :type => :string, :default => :debug, :aliases => ['-m'], :desc => 'Build mode for compile'
method_option :project, :type => :string, :default => nil, :aliases => ['-p'], :desc => 'Specify project location other than working directory'
method_option :port, :type => :string, :default => '4020', :desc => "Port to host server on"
+ method_option :package, :type => :boolean, :default => false, :desc => "Preview a package, instead of a project"
def preview
project = find_project
project.verify_and_repair options[:mode], options[:verbose]
@@ -226,6 +230,7 @@ def preview
method_option :mode, :type => :string, :default => :production, :aliases => ['-m'], :desc => 'Build mode for compile'
method_option :project, :type => :string, :default => nil, :aliases => ['-p'], :desc => 'Specify project location other than working directory'
method_option :update, :type => :boolean, :default => false, :aliases => ['-u'], :desc => 'Updates dependencies to latest compatible version'
+ method_option :package, :type => :boolean, :default => false, :desc => "Rebuild package, instead of a project"
def rebuild
find_project.fetch_dependencies(true) if options[:update]
find_project.build options[:mode].to_sym, true
@@ -330,6 +335,8 @@ def yank(package)
:desc => 'List prerelease versions available (remote only)'
method_option :development, :type => :boolean, :default => false, :aliases => ['--dev'],
:desc => 'List development dependencies instead of runtime (local only)'
+ method_option :package, :type => :boolean, :default => false,
+ :desc => "List for a package, instead of a project"
def list(*packages)
if options[:remote]
remote = BPM::Remote.new
@@ -508,15 +515,16 @@ def report_arity_error(name)
end
def find_project(required=true)
+ klass = options[:package] ? BPM::PackageProject : BPM::Project
if options[:project]
project_path = File.expand_path options[:project]
- if required && !BPM::Project.is_project_root?(project_path)
+ if required && !klass.is_project_root?(project_path)
abort "#{project_path} does not appear to be managed by BPM"
else
- project = BPM::Project.new project_path
+ project = klass.new project_path
end
else
- project = BPM::Project.nearest_project Dir.pwd
+ project = klass.nearest_project Dir.pwd
if required && project.nil?
abort "You do not appear to be inside of a BPM project"
end
@@ -0,0 +1,17 @@
+module BPM
+ class PackageProject < Project
+ def self.project_file_path(path)
+ file = File.join(path, 'package.json')
+ File.exist?(file) ? file : nil
+ end
+
+ def self.is_project_json?(path)
+ json = JSON.load(File.read(path)) rescue nil
+ return !!json
+ end
+
+ def self.is_project_root?(path)
+ !!project_file_path(path)
+ end
+ end
+end
View
@@ -206,3 +206,18 @@
end
+describe "bpm add with a package" do
+ before do
+ goto_home
+ set_host
+ start_fake(FakeGemServer.new)
+ FileUtils.cp_r(package_fixture('spade'), '.')
+ cd home('spade')
+ end
+
+ it "should add dependency to package.json" do
+ File.read(home('spade', 'package.json')).should_not include('jquery')
+ bpm 'add', 'jquery', '--package' and wait
+ File.read(home('spade', 'package.json')).should include('jquery')
+ end
+end
@@ -141,3 +141,19 @@
end
end
+
+describe "bpm fetch with a package" do
+ before do
+ goto_home
+ set_host
+ start_fake(FakeGemServer.new)
+ FileUtils.cp_r(package_fixture('coffee-1.0.1.pre'), '.')
+ cd home('coffee-1.0.1.pre')
+ end
+
+ it "should fetch dependencies" do
+ "jquery-1.4.3".should_not be_fetched
+ bpm 'fetch', '--package' and wait
+ "jquery-1.4.3".should be_fetched
+ end
+end
View
@@ -114,3 +114,18 @@
end
end
+
+describe "bpm list with a package" do
+ before do
+ goto_home
+ set_host
+ start_fake(FakeGemServer.new)
+ FileUtils.cp_r(package_fixture('coffee-1.0.1.pre'), '.')
+ cd home('coffee-1.0.1.pre')
+ end
+
+ it "should list package dependencies" do
+ bpm 'list', '--package'
+ stdout.read.should include('jquery')
+ end
+end
@@ -8,3 +8,15 @@
# i.e. spade:format
end
+
+describe "bpm preview with a package" do
+ before do
+ goto_home
+ set_host
+ start_fake(FakeGemServer.new)
+ FileUtils.cp_r(package_fixture('spade'), '.')
+ cd home('spade')
+ end
+
+ it "should preview package"
+end
@@ -81,3 +81,23 @@
it "should remove development dependencies"
end
+
+describe "bpm remove with a package" do
+ before do
+ goto_home
+ set_host
+ start_fake(FakeGemServer.new)
+ FileUtils.cp_r(package_fixture('coffee-1.0.1.pre'), '.')
+ cd home('coffee-1.0.1.pre')
+
+ bpm 'fetch', '--package'
+ wait
+ end
+
+ it "should remove dependency from package.json" do
+ File.read(home('coffee-1.0.1.pre', 'package.json')).should include('jquery')
+ bpm 'remove', 'jquery', '--package'
+ puts stdout.read
+ File.read(home('coffee-1.0.1.pre', 'package.json')).should_not include('jquery')
+ end
+end
@@ -0,0 +1,9 @@
+require "spec_helper"
+
+describe "BPM::PackageProject class" do
+ it "should accept packages as project root" do
+ BPM::PackageProject.is_project_root?(fixtures('packages', 'backbone')).should be_true
+ BPM::PackageProject.is_project_root?(fixtures('projects', 'hello_world')).should be_false
+ BPM::PackageProject.is_project_root?(fixtures('packages', 'non_existent')).should be_false
+ end
+end

0 comments on commit 5291f07

Please sign in to comment.