lib/bpm/project.rb in bpm-1.0.0.beta.4 vs lib/bpm/project.rb in bpm-1.0.0.beta.5

- old
+ new

@@ -42,14 +42,16 @@ if !name # If no name, try to find project json and get name from it project_file = self.class.project_file_path(root_path) name = File.basename(project_file, '.json') if project_file + else + project_file = File.join root_path, "#{name}.json" end @name = name || File.basename(root_path) - @json_path = File.join(root_path, "#{@name}.json") + @json_path = project_file load_json && validate end def bpm @@ -76,10 +78,14 @@ def local_package_root(package_name=nil) File.join([@root_path, 'packages', package_name].compact) end + def vendor_root(*paths) + File.join @root_path, 'vendor', *paths + end + def internal_package_root(package_name=nil) File.join([@root_path, BPM_DIR, 'packages', package_name].compact) end def assets_root(*paths) @@ -89,35 +95,37 @@ def preview_root(*paths) File.join @root_path, '.bpm', 'preview', *paths end def build_app? - !!(bpm_build && bpm_build["#{name}/bpm_libs.js"]) + !!(bpm_build && bpm_build["bpm_libs.js"] && + bpm_build["bpm_libs.js"]["directories"] && + bpm_build["bpm_libs.js"]["directories"].size>0) end def build_app=(value) - bpm_libs = "#{name}/bpm_libs.js" - bpm_styles = "#{name}/bpm_styles.css" + bpm_libs = "bpm_libs.js" + bpm_styles = "bpm_styles.css" if value - if bpm_build[bpm_libs].nil? - bpm_build[bpm_libs] = { - "directories" => ["app"], - "minifier" => "uglify-js" - } - end + bpm_build[bpm_libs] ||= {} + hash = bpm_build[bpm_libs] + hash['directories'] ||= [] + hash['directories'] << 'lib' if hash['directories'].size==0 + hash['minifier'] ||= 'uglify-js' - if bpm_build[bpm_styles].nil? - bpm_build[bpm_styles] = { - "directories" => ["css"] - } - end - + bpm_build[bpm_styles] ||= {} + hash = bpm_build[bpm_styles] + hash['directories'] ||= [] + hash['directories'] << 'css' if hash['directories'].size==0 + + directories ||= {} + directories['lib'] ||= ['app'] else - bpm_build.delete bpm_libs - bpm_build.delete bpm_styles + bpm_build[bpm_libs]['directories'] = [] + bpm_build[bpm_styles]['directories'] = [] end value end # returns array of all assets that should be generated for this project @@ -133,13 +141,13 @@ rebuild_dependency_list nil, verbose rebuild_preview verbose end def rebuild_preview(verbose=false) - + needs_rebuild = true - + if File.directory?(preview_root) cur_previews = Dir[preview_root('**', '*')].sort.reject { |x| File.directory?(x) } exp_filenames = buildable_asset_filenames(:debug) exp_previews = exp_filenames.map { |x| preview_root(x) }.sort needs_rebuild = cur_previews != exp_previews @@ -157,26 +165,26 @@ end # Add a new dependency # # Adds to the project json and installs dependency - + def add_dependencies(new_deps, development=false, verbose=false) old_deps = build_local_dependency_list(false) || [] hard_deps = (development ? dependencies_development : dependencies).merge(new_deps) all_hard_deps = all_dependencies.merge(new_deps) - exp_deps = find_non_local_dependencies(hard_deps, true) - + exp_deps = find_non_local_dependencies(all_hard_deps, true) + puts "Fetching packages from remote..." if verbose core_fetch_dependencies(exp_deps, verbose) - + if development self.dependencies_development = hard_deps else self.dependencies = hard_deps end - + rebuild_dependency_list(all_hard_deps, verbose) local_deps.each do |dep| next if old_deps.find { |pkg| (pkg.name == dep.name) && (pkg.version == dep.version) } puts "Added #{development ? "development " : ""}package '#{dep.name}' (#{dep.version})" @@ -261,11 +269,11 @@ FileUtils.cp asset.pathname, dst_path else $stdout << "~ Building #{asset.logical_path}..." if verbose File.open(dst_path, 'w+') { |fd| fd << asset.to_s } if verbose - gzip_size = `gzip -c #{dst_path}`.size + gzip_size = `gzip -c #{dst_path}`.bytesize gzip_size = gzip_size < 1024 ? "#{gzip_size} bytes" : "#{gzip_size / 1024} Kb" $stdout << " (gzipped size: #{gzip_size})\n" end end end @@ -504,12 +512,12 @@ until search_list.empty? name, version = search_list.shift next if seen.include?(name) seen << name - package_root = local_package_root(name) - if File.exists?(package_root) + package_root = locate_local_package(name) + if package_root pkg = BPM::Package.new(package_root) pkg.load_json unless satisfied_by?(version, pkg.version) raise LocalPackageConflictError.new(pkg.name, version, pkg.version) @@ -588,11 +596,11 @@ end # Tell if package is vendored def has_local_package?(package_name) - File.directory?(local_package_root(package_name)) + !!locate_local_package(package_name) end # Tell if given version is satisfied by the passed version @@ -638,21 +646,30 @@ ret end + def locate_local_package(package_name) + src_path = local_package_root package_name + unless File.directory?(src_path) + src_path = Dir[vendor_root('*','packages','*')].find do |path| + File.basename(path)==package_name && File.directory?(path) + end + end + src_path + end + # Find package locally or in global cache def locate_package(package_name, vers, verbose) local = has_local_package?(package_name) # It's true that we don't have a prerelase check here, but the # previous one we had didn't do anything, so it's better to have # none than one that doesn't work vers = ">= 0" if vers == ">= 0-pre" - src_path = local ? - local_package_root(package_name) : - BPM::Local.new.source_root(package_name, vers) + src_path = local ? locate_local_package(package_name) : + BPM::Local.new.source_root(package_name, vers) return nil unless src_path pkg = BPM::Package.new(src_path) pkg.load_json # throws exception if json invalid