bpm 0.1.4 → 1.0.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (341) hide show
  1. data/CHANGELOG.md +20 -0
  2. data/README.md +1 -1
  3. data/TODO.md +90 -2
  4. data/bpm.gemspec +3 -3
  5. data/lib/bpm/cli/base.rb +103 -52
  6. data/lib/bpm/errors.rb +51 -0
  7. data/lib/bpm/init_generator.rb +1 -8
  8. data/lib/bpm/libgems_ext/libgems.rb +9 -0
  9. data/lib/bpm/local.rb +6 -11
  10. data/lib/bpm/package.rb +272 -178
  11. data/lib/bpm/pipeline/generated_asset.rb +88 -28
  12. data/lib/bpm/pipeline/plugin_asset.rb +8 -2
  13. data/lib/bpm/pipeline/source_url_processor.rb +16 -0
  14. data/lib/bpm/pipeline/transport_processor.rb +5 -3
  15. data/lib/bpm/pipeline.rb +33 -23
  16. data/lib/bpm/project.rb +492 -167
  17. data/lib/bpm/project_generator.rb +14 -1
  18. data/lib/bpm/remote.rb +6 -4
  19. data/lib/bpm/server.rb +4 -15
  20. data/lib/bpm/version.rb +2 -1
  21. data/lib/bpm.rb +2 -0
  22. data/man/bpm-add.1.ronn +22 -0
  23. data/man/bpm-build.1.ronn +22 -0
  24. data/man/bpm-compile.1.ronn +23 -0
  25. data/man/bpm-config.7.ronn +21 -0
  26. data/man/bpm-fetch.1.ronn +22 -0
  27. data/man/bpm-fetched.1.ronn +22 -0
  28. data/man/bpm-init.1.ronn +22 -0
  29. data/man/bpm-list.1.ronn +22 -0
  30. data/man/bpm-login.1.ronn +22 -0
  31. data/man/bpm-new.1.ronn +22 -0
  32. data/man/bpm-owner.1.ronn +22 -0
  33. data/man/bpm-preview.1.ronn +22 -0
  34. data/man/bpm-push.1.ronn +22 -0
  35. data/man/bpm-remove.1.ronn +22 -0
  36. data/man/bpm-unpack.1.ronn +22 -0
  37. data/man/bpm-yank.1.ronn +22 -0
  38. data/man/bpm.1.ronn +31 -0
  39. data/spec/cli/add_spec.rb +26 -7
  40. data/spec/cli/fetch_spec.rb +15 -6
  41. data/spec/cli/init_spec.rb +165 -25
  42. data/spec/cli/{build_spec.rb → pack_spec.rb} +9 -10
  43. data/spec/cli/push_spec.rb +4 -4
  44. data/spec/cli/rebuild_spec.rb +181 -0
  45. data/spec/cli/remove_spec.rb +3 -4
  46. data/spec/cli/unpack_spec.rb +6 -6
  47. data/spec/fixtures/gems/core-test-0.4.9.bpkg +0 -0
  48. data/spec/fixtures/{core-test-0.4.9.bpkg → gems/uglify-js-1.0.4.bpkg} +0 -0
  49. data/spec/fixtures/packages/core-test/extras/extra_file.html +3 -0
  50. data/spec/fixtures/packages/core-test/index.html +3 -0
  51. data/spec/fixtures/{core-test → packages/core-test}/package.json +9 -3
  52. data/spec/fixtures/packages/invalid_json/package.json +3 -0
  53. data/spec/fixtures/packages/uglify-js/README.html +825 -0
  54. data/spec/fixtures/packages/uglify-js/README.org +431 -0
  55. data/spec/fixtures/packages/uglify-js/bin/uglifyjs +305 -0
  56. data/spec/fixtures/packages/uglify-js/docstyle.css +75 -0
  57. data/spec/fixtures/packages/uglify-js/lib/parse-js.js +1 -0
  58. data/spec/fixtures/packages/uglify-js/lib/process.js +1 -0
  59. data/spec/fixtures/packages/uglify-js/lib/squeeze-more.js +1 -0
  60. data/spec/fixtures/packages/uglify-js/package.json +27 -0
  61. data/spec/fixtures/packages/uglify-js/plugins/minifier.js +6 -0
  62. data/spec/fixtures/packages/uglify-js/uglify-js.js +17 -0
  63. data/spec/fixtures/projects/hello2/README.md +21 -0
  64. data/{templates/init → spec/fixtures/projects/hello2}/assets/bpm_packages.js +6 -1
  65. data/{templates/init → spec/fixtures/projects/hello2}/assets/bpm_styles.css +1 -1
  66. data/spec/fixtures/projects/hello2/hello2.json +16 -0
  67. data/spec/fixtures/projects/hello2/index.html +13 -0
  68. data/spec/fixtures/projects/hello2/packages/a/lib/main.js +2 -0
  69. data/spec/fixtures/projects/hello2/packages/a/package.json +17 -0
  70. data/spec/fixtures/projects/hello2/packages/b/lib/main.js +2 -0
  71. data/spec/fixtures/projects/hello2/packages/b/package.json +17 -0
  72. data/spec/fixtures/projects/hello2/packages/c/lib/main.js +2 -0
  73. data/spec/fixtures/projects/hello2/packages/c/package.json +16 -0
  74. data/spec/fixtures/projects/hello_dev/LICENSE +19 -0
  75. data/spec/fixtures/projects/hello_dev/README.md +21 -0
  76. data/spec/fixtures/projects/hello_dev/app/main.js +6 -0
  77. data/spec/fixtures/projects/hello_dev/assets/bpm_libs.js +5 -0
  78. data/spec/fixtures/projects/hello_dev/assets/bpm_styles.css +6 -0
  79. data/spec/fixtures/projects/hello_dev/css/main.css +1 -0
  80. data/spec/fixtures/projects/hello_dev/hello_dev.json +25 -0
  81. data/spec/fixtures/projects/hello_dev/index.html +14 -0
  82. data/spec/fixtures/projects/hello_dev/packages/style_package/css/some_style.css +3 -0
  83. data/spec/fixtures/{minitest/minitest.json → projects/hello_dev/packages/style_package/package.json} +5 -9
  84. data/spec/fixtures/projects/hello_world/LICENSE +19 -0
  85. data/spec/fixtures/projects/hello_world/assets/bpm_packages.js +1 -0
  86. data/spec/fixtures/projects/hello_world/assets/bpm_styles.css +1 -0
  87. data/spec/fixtures/projects/hello_world/custom_dir/custom.js +1 -0
  88. data/spec/fixtures/projects/hello_world/hello_world.json +41 -0
  89. data/spec/fixtures/projects/hello_world/lib/another.js +1 -0
  90. data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/package.json +5 -2
  91. data/spec/fixtures/projects/hello_world/vendor/lib/something.js +1 -0
  92. data/spec/fixtures/projects/init_app/assets/bpm_libs.js +6 -0
  93. data/spec/fixtures/projects/init_app/assets/bpm_styles.css +5 -0
  94. data/spec/fixtures/projects/init_app/assets/new_project/bpm_libs.js +6 -0
  95. data/spec/fixtures/projects/init_app/assets/new_project/bpm_styles.css +5 -0
  96. data/spec/fixtures/projects/init_app/new_project.json +27 -0
  97. data/spec/fixtures/projects/init_default/assets/bpm_libs.js +6 -0
  98. data/spec/fixtures/projects/init_default/assets/bpm_styles.css +5 -0
  99. data/spec/fixtures/projects/init_default/new_project.json +15 -0
  100. data/spec/fixtures/projects/minitest/minitest.json +26 -0
  101. data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/package.json +1 -1
  102. data/spec/fixtures/projects/needs_rake/needs_rake.json +7 -0
  103. data/spec/fixtures/{transporter → projects/transporter}/packages/transport/package.json +1 -1
  104. data/spec/package_spec.rb +343 -315
  105. data/spec/pipeline_spec.rb +89 -71
  106. data/spec/plugins/minifier_spec.rb +25 -16
  107. data/spec/plugins/transport_spec.rb +1 -1
  108. data/spec/project_spec.rb +97 -34
  109. data/spec/spec_helper.rb +41 -0
  110. data/spec/support/fake_gem_server.rb +8 -4
  111. data/spec/support/path.rb +8 -0
  112. data/spec/support/project.rb +50 -17
  113. data/templates/init/project.json +12 -14
  114. data/templates/project/LICENSE +1 -1
  115. data/templates/project/app/main.js +6 -0
  116. data/templates/project/css/main.css +1 -0
  117. data/templates/project/index.html +4 -3
  118. data/vendor/sprockets/.travis.yml +3 -2
  119. data/vendor/sprockets/Gemfile +0 -6
  120. data/vendor/sprockets/lib/sprockets/asset.rb +7 -12
  121. data/vendor/sprockets/lib/sprockets/asset_attributes.rb +70 -53
  122. data/vendor/sprockets/lib/sprockets/base.rb +1 -14
  123. data/vendor/sprockets/lib/sprockets/bundled_asset.rb +72 -45
  124. data/vendor/sprockets/lib/sprockets/caching.rb +28 -23
  125. data/vendor/sprockets/lib/sprockets/context.rb +56 -26
  126. data/vendor/sprockets/lib/sprockets/directive_processor.rb +21 -4
  127. data/vendor/sprockets/lib/sprockets/eco_template.rb +3 -4
  128. data/vendor/sprockets/lib/sprockets/ejs_template.rb +3 -4
  129. data/vendor/sprockets/lib/sprockets/engines.rb +26 -1
  130. data/vendor/sprockets/lib/sprockets/environment.rb +2 -1
  131. data/vendor/sprockets/lib/sprockets/index.rb +1 -0
  132. data/vendor/sprockets/lib/sprockets/mime.rb +38 -0
  133. data/vendor/sprockets/lib/sprockets/processing.rb +4 -45
  134. data/vendor/sprockets/lib/sprockets/static_asset.rb +5 -6
  135. data/vendor/sprockets/lib/sprockets/static_compilation.rb +4 -12
  136. data/vendor/sprockets/lib/sprockets/trail.rb +2 -1
  137. data/vendor/sprockets/test/fixtures/default/blank.gif +0 -0
  138. data/vendor/sprockets/test/fixtures/default/with_data_uri.css.erb +3 -0
  139. data/vendor/sprockets/test/test_asset.rb +121 -15
  140. data/vendor/sprockets/test/test_asset_attributes.rb +85 -21
  141. data/vendor/sprockets/test/test_environment.rb +13 -36
  142. metadata +564 -444
  143. data/spec/cli/new_spec.rb +0 -118
  144. data/spec/fixtures/hello_world/assets/bpm_packages.js +0 -13
  145. data/spec/fixtures/hello_world/assets/bpm_styles.css +0 -14
  146. data/spec/fixtures/hello_world/hello_world.json +0 -20
  147. /data/spec/fixtures/{badrake-0.8.7.bpkg → gems/badrake-0.8.7.bpkg} +0 -0
  148. /data/spec/fixtures/{builder-3.0.0.bpkg → gems/builder-3.0.0.bpkg} +0 -0
  149. /data/spec/fixtures/{bundler-1.1.pre.bpkg → gems/bundler-1.1.pre.bpkg} +0 -0
  150. /data/spec/fixtures/{coffee-1.0.1.pre.bpkg → gems/coffee-1.0.1.pre.bpkg} +0 -0
  151. /data/spec/fixtures/{custom_generator-1.0.bpkg → gems/custom_generator-1.0.bpkg} +0 -0
  152. /data/spec/fixtures/{highline-1.6.1.bpkg → gems/highline-1.6.1.bpkg} +0 -0
  153. /data/spec/fixtures/{ivory-0.0.1.bpkg → gems/ivory-0.0.1.bpkg} +0 -0
  154. /data/spec/fixtures/{jquery-1.4.3.bpkg → gems/jquery-1.4.3.bpkg} +0 -0
  155. /data/spec/fixtures/{optparse-1.0.1.bpkg → gems/optparse-1.0.1.bpkg} +0 -0
  156. /data/spec/fixtures/{rake-0.8.6.bpkg → gems/rake-0.8.6.bpkg} +0 -0
  157. /data/spec/fixtures/{rake-0.8.7.bpkg → gems/rake-0.8.7.bpkg} +0 -0
  158. /data/spec/fixtures/{spade-0.5.0.bpkg → gems/spade-0.5.0.bpkg} +0 -0
  159. /data/spec/fixtures/{src → packages}/README.txt +0 -0
  160. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/.gitignore +0 -0
  161. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/CHANGELOG.md +0 -0
  162. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/ISSUES.md +0 -0
  163. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/LICENSE +0 -0
  164. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/README.md +0 -0
  165. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/UPGRADING.md +0 -0
  166. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/bin/bundle +0 -0
  167. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/definition.js +0 -0
  168. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/dependency.js +0 -0
  169. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/dsl.js +0 -0
  170. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/ui.js +0 -0
  171. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler.js +0 -0
  172. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-config.ronn +0 -0
  173. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-exec.ronn +0 -0
  174. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-install.ronn +0 -0
  175. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-package.ronn +0 -0
  176. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-update.ronn +0 -0
  177. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle.ronn +0 -0
  178. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/gemfile.5.ronn +0 -0
  179. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/index.txt +0 -0
  180. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/package.json +0 -0
  181. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/bin/cake +0 -0
  182. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/bin/coffee +0 -0
  183. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee/base.js +0 -0
  184. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee/mocha/chai.js +0 -0
  185. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee.js +0 -0
  186. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/package.json +0 -0
  187. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/qunit/coffee/test.js +0 -0
  188. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/qunit/test.js +0 -0
  189. /data/spec/fixtures/{core-test → packages/core-test}/bin/cot +0 -0
  190. /data/spec/fixtures/{core-test → packages/core-test}/lib/main.js +0 -0
  191. /data/spec/fixtures/{core-test → packages/core-test}/resources/runner.css +0 -0
  192. /data/spec/fixtures/{core-test → packages/core-test}/tests/test.js +0 -0
  193. /data/spec/fixtures/{custom_generator → packages/custom_generator}/lib/main.js +0 -0
  194. /data/spec/fixtures/{custom_generator → packages/custom_generator}/package.json +0 -0
  195. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/init/project.json +0 -0
  196. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project/app.js +0 -0
  197. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project/lib/main.js +0 -0
  198. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project_generator.rb +0 -0
  199. /data/spec/fixtures/{src → packages}/jquery/lib/main.js +0 -0
  200. /data/spec/fixtures/{src → packages}/jquery/package.json +0 -0
  201. /data/spec/fixtures/{src → packages}/rake-0.8.6/CHANGES +0 -0
  202. /data/spec/fixtures/{src → packages}/rake-0.8.6/MIT-LICENSE +0 -0
  203. /data/spec/fixtures/{src → packages}/rake-0.8.6/README +0 -0
  204. /data/spec/fixtures/{src → packages}/rake-0.8.6/Rakefile +0 -0
  205. /data/spec/fixtures/{src → packages}/rake-0.8.6/TODO +0 -0
  206. /data/spec/fixtures/{src → packages}/rake-0.8.6/bin/rake +0 -0
  207. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/command_line_usage.rdoc +0 -0
  208. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/Rakefile1 +0 -0
  209. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/Rakefile2 +0 -0
  210. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/a.c +0 -0
  211. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/b.c +0 -0
  212. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/main.c +0 -0
  213. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/glossary.rdoc +0 -0
  214. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/jamis.rb +0 -0
  215. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/proto_rake.rdoc +0 -0
  216. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rake.1.gz +0 -0
  217. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rakefile.rdoc +0 -0
  218. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rational.rdoc +0 -0
  219. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.4.14.rdoc +0 -0
  220. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.4.15.rdoc +0 -0
  221. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.0.rdoc +0 -0
  222. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.3.rdoc +0 -0
  223. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.4.rdoc +0 -0
  224. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.6.0.rdoc +0 -0
  225. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.0.rdoc +0 -0
  226. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.1.rdoc +0 -0
  227. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.2.rdoc +0 -0
  228. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.3.rdoc +0 -0
  229. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.0.rdoc +0 -0
  230. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.2.rdoc +0 -0
  231. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.3.rdoc +0 -0
  232. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.4.rdoc +0 -0
  233. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.5.rdoc +0 -0
  234. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.6.rdoc +0 -0
  235. /data/spec/fixtures/{src → packages}/rake-0.8.6/install.rb +0 -0
  236. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/alt_system.rb +0 -0
  237. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/classic_namespace.rb +0 -0
  238. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/clean.rb +0 -0
  239. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/compositepublisher.rb +0 -0
  240. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/ftptools.rb +0 -0
  241. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/publisher.rb +0 -0
  242. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/rubyforgepublisher.rb +0 -0
  243. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/sshpublisher.rb +0 -0
  244. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/sys.rb +0 -0
  245. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/gempackagetask.rb +0 -0
  246. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/loaders/makefile.rb +0 -0
  247. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/packagetask.rb +0 -0
  248. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/rake_test_loader.rb +0 -0
  249. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/rdoctask.rb +0 -0
  250. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/ruby182_test_unit_fix.rb +0 -0
  251. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/runtest.rb +0 -0
  252. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/tasklib.rb +0 -0
  253. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/testtask.rb +0 -0
  254. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/win32.rb +0 -0
  255. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake.rb +0 -0
  256. /data/spec/fixtures/{src → packages}/rake-0.8.6/package.json +0 -0
  257. /data/spec/fixtures/{src → packages}/rake-0.8.6/test/capture_stdout.rb +0 -0
  258. /data/spec/fixtures/{src → packages}/rake-0.8.7/CHANGES +0 -0
  259. /data/spec/fixtures/{src → packages}/rake-0.8.7/MIT-LICENSE +0 -0
  260. /data/spec/fixtures/{src → packages}/rake-0.8.7/README +0 -0
  261. /data/spec/fixtures/{src → packages}/rake-0.8.7/Rakefile +0 -0
  262. /data/spec/fixtures/{src → packages}/rake-0.8.7/TODO +0 -0
  263. /data/spec/fixtures/{src → packages}/rake-0.8.7/bin/rake +0 -0
  264. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/command_line_usage.rdoc +0 -0
  265. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/Rakefile1 +0 -0
  266. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/Rakefile2 +0 -0
  267. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/a.c +0 -0
  268. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/b.c +0 -0
  269. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/main.c +0 -0
  270. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/glossary.rdoc +0 -0
  271. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/jamis.rb +0 -0
  272. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/proto_rake.rdoc +0 -0
  273. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rake.1.gz +0 -0
  274. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rakefile.rdoc +0 -0
  275. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rational.rdoc +0 -0
  276. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.4.14.rdoc +0 -0
  277. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.4.15.rdoc +0 -0
  278. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.0.rdoc +0 -0
  279. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.3.rdoc +0 -0
  280. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.4.rdoc +0 -0
  281. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.6.0.rdoc +0 -0
  282. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.0.rdoc +0 -0
  283. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.1.rdoc +0 -0
  284. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.2.rdoc +0 -0
  285. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.3.rdoc +0 -0
  286. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.0.rdoc +0 -0
  287. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.2.rdoc +0 -0
  288. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.3.rdoc +0 -0
  289. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.4.rdoc +0 -0
  290. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.5.rdoc +0 -0
  291. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.6.rdoc +0 -0
  292. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.7.rdoc +0 -0
  293. /data/spec/fixtures/{src → packages}/rake-0.8.7/install.rb +0 -0
  294. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/alt_system.rb +0 -0
  295. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/classic_namespace.rb +0 -0
  296. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/clean.rb +0 -0
  297. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/compositepublisher.rb +0 -0
  298. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/ftptools.rb +0 -0
  299. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/publisher.rb +0 -0
  300. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/rubyforgepublisher.rb +0 -0
  301. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/sshpublisher.rb +0 -0
  302. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/sys.rb +0 -0
  303. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/gempackagetask.rb +0 -0
  304. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/loaders/makefile.rb +0 -0
  305. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/packagetask.rb +0 -0
  306. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/rake_test_loader.rb +0 -0
  307. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/rdoctask.rb +0 -0
  308. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/ruby182_test_unit_fix.rb +0 -0
  309. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/runtest.rb +0 -0
  310. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/tasklib.rb +0 -0
  311. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/testtask.rb +0 -0
  312. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/win32.rb +0 -0
  313. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake.rb +0 -0
  314. /data/spec/fixtures/{src → packages}/rake-0.8.7/package.json +0 -0
  315. /data/spec/fixtures/{src → packages}/rake-0.8.7/test/capture_stdout.rb +0 -0
  316. /data/spec/fixtures/{src → packages}/spade/lib/main.js +0 -0
  317. /data/spec/fixtures/{src → packages}/spade/package.json +0 -0
  318. /data/spec/fixtures/{custom_name → projects/custom_name}/MyProject.json +0 -0
  319. /data/spec/fixtures/{hello_world → projects/hello2}/LICENSE +0 -0
  320. /data/{templates/project → spec/fixtures/projects/hello2}/app.js +0 -0
  321. /data/spec/fixtures/{hello_world → projects/hello_world}/README.md +0 -0
  322. /data/spec/fixtures/{hello_world → projects/hello_world}/assets/papa-smurf.jpg +0 -0
  323. /data/spec/fixtures/{hello_world → projects/hello_world}/css/dummy.css +0 -0
  324. /data/spec/fixtures/{hello_world → projects/hello_world}/lib/main.js +0 -0
  325. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/assets/dummy.txt +0 -0
  326. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/css/sample_styles.css +0 -0
  327. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/custom_dir/basic-module.js +0 -0
  328. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/lib/main.js +0 -0
  329. /data/spec/fixtures/{hello_world → projects/hello_world}/tests/main-test.js +0 -0
  330. /data/spec/fixtures/{minitest → projects/minitest}/assets/bpm_packages.js +0 -0
  331. /data/spec/fixtures/{minitest → projects/minitest}/assets/bpm_styles.css +0 -0
  332. /data/spec/fixtures/{minitest → projects/minitest}/assets/minitest/app_package.js +0 -0
  333. /data/spec/fixtures/{minitest → projects/minitest}/lib/main.js +0 -0
  334. /data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/lib/main.js +0 -0
  335. /data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/minifier/main.js +0 -0
  336. /data/spec/fixtures/{simple_hello/assets/bpm_packages.js → projects/simple_hello/assets/bpm_libs.js} +0 -0
  337. /data/spec/fixtures/{simple_hello → projects/simple_hello}/lib/main.js +0 -0
  338. /data/spec/fixtures/{transporter → projects/transporter}/lib/main.js +0 -0
  339. /data/spec/fixtures/{transporter → projects/transporter}/packages/transport/lib/main.js +0 -0
  340. /data/spec/fixtures/{transporter → projects/transporter}/packages/transport/transports/wrapper.js +0 -0
  341. /data/spec/fixtures/{transporter → projects/transporter}/transporter.json +0 -0
data/lib/bpm/package.rb CHANGED
@@ -2,63 +2,116 @@ require 'json'
2
2
 
3
3
  module BPM
4
4
  class Package
5
- EXT = "bpkg"
6
- METADATA = %w[keywords licenses engines main bin directories]
7
- FIELDS = %w[name version description author homepage summary]
8
- attr_accessor :metadata, :lib_path, :tests_path, :errors, :json_path, :attributes, :directories, :dependencies, :root_path
9
- attr_accessor *FIELDS
5
+ EXT = "bpkg"
6
+
7
+ # All JSON fields
8
+ FIELDS = {
9
+ "keywords" => :array,
10
+ "licenses" => :array,
11
+ "engines" => :array,
12
+ "main" => :string,
13
+ "bin" => :hash,
14
+ "directories" => :hash,
15
+ "pipeline" => :hash,
16
+ "name" => :string,
17
+ "version" => :string,
18
+ "description" => :string,
19
+ "author" => :string,
20
+ "homepage" => :string,
21
+ "summary" => :string,
22
+ "dependencies" => :hash,
23
+ "dependencies:development" => :hash,
24
+ "bpm:build" => :hash,
25
+ "bpm:formats" => :hash,
26
+ "bpm:transport" => :string,
27
+ "bpm:use:transport" => :string,
28
+ "bpm:minifier" => :string
29
+ }
30
+
31
+ PLUGIN_FIELDS = %w[bpm:formats bpm:minifier bpm:transport bpm:use:transport]
32
+
33
+ # Fields that can be loaded straight into the gemspec
34
+ SPEC_FIELDS = %w[name email homepage summary description]
35
+
36
+ # Fields that should be bundled up into JSON in the gemspec
37
+ METADATA_FIELDS = %w[keywords licenses engines main bin directories pipeline bpm:build bpm:formats bpm:transport]
38
+
39
+ REQUIRED_FIELDS = %w[name description summary homepage author version directories]
40
+
41
+ attr_accessor *FIELDS.keys.map{|f| f.gsub(':', '_') }
42
+
43
+ attr_accessor :json_path, :email
44
+ attr_reader :root_path, :errors
10
45
 
11
46
  def self.from_spec(spec)
12
47
  pkg = new(spec.full_gem_path)
13
- pkg.bpkg = spec
48
+ pkg.fill_from_gemspec(spec)
14
49
  pkg
15
50
  end
16
51
 
17
52
  def initialize(root_path=nil, email = "")
18
- @root_path = root_path || Dir.pwd
19
- @json_path = File.join @root_path, 'package.json'
20
- @email = email
21
- @attributes = {}
22
- @dependencies = {}
23
- @directories = {}
24
- @metadata = {}
25
- end
26
-
27
- def bpkg=(spec)
28
- unless spec.is_a?(LibGems::Specification)
29
- spec = LibGems::Format.from_file_by_path(spec.to_s).spec
53
+ @root_path = root_path || Dir.pwd
54
+ @json_path = File.join @root_path, 'bpm_package.json'
55
+ unless File.exists? @json_path
56
+ @json_path = File.join @root_path, 'package.json'
30
57
  end
31
- fill_from_gemspec(spec)
58
+
59
+ @email = email
60
+ @errors = []
61
+ # Set defaults
62
+ FIELDS.keys.each{|f| send("#{c2u(f)}=", fd(f))}
32
63
  end
33
64
 
34
65
  def to_spec
35
66
  return unless valid?
36
67
  LibGems::Specification.new do |spec|
37
- spec.name = name
38
- spec.version = version
39
- spec.authors = [author]
40
- spec.email = @email
41
- spec.homepage = homepage
42
- spec.summary = summary
43
- spec.description = description
44
- spec.requirements = [metadata.to_json]
45
- spec.files = directory_files + template_files + transport_files + ["package.json"]
46
- spec.test_files = glob_files(tests_path)
47
- spec.bindir = bin_path
48
- spec.executables = bin_files.map{|p| File.basename(p) } if bin_path
49
- # TODO: IS this right?
68
+ SPEC_FIELDS.each{|f| spec.send("#{f}=", send(f)) }
69
+ spec.version = version
70
+ spec.authors = [author]
71
+ spec.files = directory_files + ["package.json"]
72
+ spec.test_files = glob_files(tests_path)
73
+ spec.bindir = bin_path
74
+ spec.licenses = licenses.map{|l| l["type"]}
75
+ spec.executables = bin_files.map{|p| File.basename(p) } if bin_path
76
+
77
+ metadata = Hash[METADATA_FIELDS.map{|f| [f, send(c2u(f)) ] }]
78
+ spec.requirements = [metadata.to_json]
79
+
80
+ # TODO: Is this right?
50
81
  spec.rubyforge_project = "bpm"
82
+
51
83
  def spec.file_name
52
84
  "#{full_name}.#{EXT}"
53
85
  end
54
- dependencies.each{|d,v| spec.add_dependency(d, v) } if dependencies
86
+
87
+ dependencies.each{|d,v| spec.add_dependency(d,v) }
88
+ dependencies_development.each{|d,v| spec.add_development_dependency(d,v) }
55
89
  end
56
90
  end
57
91
 
58
- def as_json(options = {})
59
- json = self.metadata.clone
60
- FIELDS.each{|key| json[key] = send(key)}
61
- json["dependencies"] = self.dependencies
92
+ def as_json
93
+
94
+ seen_keys = @read_keys || []
95
+ json = {}
96
+
97
+ # keep order of keys read in
98
+ seen_keys.each do |key|
99
+ if FIELDS.include?(key)
100
+ val = send(c2u(key == 'build' ? 'pipeline' : key))
101
+ else
102
+ val = @attributes[key]
103
+ end
104
+
105
+ json[key] = val if val && !val.empty?
106
+ end
107
+
108
+ FIELDS.keys.each do |key|
109
+ next if seen_keys.include?(key)
110
+ val = send(c2u(key))
111
+ key = 'build' if key == 'pipeline'
112
+ json[key] = val if val && !val.empty?
113
+ end
114
+
62
115
  json
63
116
  end
64
117
 
@@ -66,14 +119,93 @@ module BPM
66
119
  as_json.to_json
67
120
  end
68
121
 
69
- def to_full_name
122
+ def full_name
70
123
  "#{name}-#{version}"
71
124
  end
72
125
 
73
- def to_ext
74
- "#{self.to_full_name}.#{EXT}"
126
+ def file_name
127
+ "#{full_name}.#{EXT}"
128
+ end
129
+
130
+ def directory_files
131
+ dir_names = directories.reject { |k,_| k == 'tests' }.values
132
+ build_names = bpm_build.values.map do |hash|
133
+ hash['directories'] || hash['assets']
134
+ end
135
+
136
+ build_names += PLUGIN_FIELDS.map do |field_name|
137
+ val = self.send(c2u(field_name))
138
+ val = val && val =~ /^#{name}\// ? val[name.size+1..-1]+'.js' : nil
139
+ puts "FIELD: #{field_name} #{self.send(c2u(field_name))} val=#{val}"
140
+ val
141
+ end
142
+
143
+ (dir_names+build_names).flatten.compact.uniq.map do |dir|
144
+ glob_files(dir)
145
+ end.flatten
146
+ end
147
+
148
+ def bin_files
149
+ bin && bin.values
150
+ end
151
+
152
+ def bin_path
153
+ directories["bin"] || "bin"
154
+ end
155
+
156
+ def lib_path
157
+ directories["lib"] || "lib"
158
+ end
159
+
160
+ def tests_path
161
+ directories["tests"] || "tests"
75
162
  end
76
163
 
164
+ def find_transport_plugins(project)
165
+ dependencies.keys.map do |pkg_name|
166
+ dep = project.local_deps.find do |pkg|
167
+ pkg.load_json
168
+ pkg.name == pkg_name
169
+ end
170
+ raise "Could not find dependency: #{pkg_name}" unless dep
171
+ dep.bpm_transport
172
+ end.compact
173
+ end
174
+
175
+ def pipeline_libs
176
+ (pipeline && pipeline['libs']) || ['lib']
177
+ end
178
+
179
+ def pipeline_css
180
+ (pipeline && pipeline['css']) || ['css']
181
+ end
182
+
183
+ def pipeline_assets
184
+ (pipeline && pipeline['assets']) || ['assets', 'resources']
185
+ end
186
+
187
+ def pipeline_tests
188
+ (pipeline && pipeline['tests']) || ['tests']
189
+ end
190
+
191
+ # Returns a hash of dependencies inferred from the build settings.
192
+ def dependencies_build
193
+ ret = {}
194
+
195
+ bpm_build.each do |target_name, opts|
196
+ next unless opts.is_a?(Hash)
197
+
198
+ minifier = opts['minifier']
199
+ case minifier
200
+ when String
201
+ ret[minifier] = '>= 0'
202
+ when Hash
203
+ ret.merge! minifier
204
+ end
205
+ end
206
+ ret
207
+ end
208
+
77
209
  def template_path(name)
78
210
  path = File.join(root_path, 'templates', name.to_s)
79
211
  File.exist?(path) ? path : nil
@@ -88,10 +220,6 @@ module BPM
88
220
  generator
89
221
  end
90
222
 
91
- def errors
92
- @errors ||= []
93
- end
94
-
95
223
  def validate
96
224
  validate_fields && validate_version && validate_paths
97
225
  end
@@ -104,10 +232,60 @@ module BPM
104
232
  File.exist?(json_path)
105
233
  end
106
234
 
235
+ def validate_name_and_path
236
+ filename = File.basename(root_path)
237
+ unless filename==name || filename=="#{name}-#{version}"
238
+ raise BPM::InvalidPackageNameError.new self
239
+ end
240
+ end
241
+
107
242
  def load_json
108
- read && parse
243
+ begin
244
+ json = JSON.parse(File.read(@json_path))
245
+ rescue JSON::ParserError, Errno::EACCES, Errno::ENOENT => ex
246
+ raise BPM::InvalidPackageError.new self, ex.message
247
+ end
248
+
249
+ @read_keys = json.keys.dup # to retain order on save
250
+ @attributes = json # save for saving
251
+
252
+ FIELDS.keys.each do |field|
253
+ if field == 'pipeline'
254
+ self.pipeline = json['build'] || fd(field)
255
+ else
256
+ send("#{c2u(field)}=", json[field] || fd(field))
257
+ end
258
+ end
259
+
260
+ validate_name_and_path
261
+
262
+ true
263
+ end
264
+
265
+ def fill_from_gemspec(spec)
266
+ unless spec.is_a?(LibGems::Specification)
267
+ spec = LibGems::Format.from_file_by_path(spec.to_s).spec
268
+ end
269
+
270
+ SPEC_FIELDS.each{|f| send("#{f}=", spec.send(f) || fd(field)) }
271
+
272
+ self.author = spec.authors.first
273
+ self.version = spec.version.to_s
274
+
275
+ metadata = spec.requirements.first
276
+ if metadata
277
+ metadata = JSON.parse(metadata)
278
+ METADATA_FIELDS.each{|f| send("#{c2u(f)}=", metadata[f] || fd(f))}
279
+ end
280
+
281
+ self.dependencies = Hash[spec.dependencies.map{|d| [d.name, d.requirement.to_s ]}]
282
+ self.dependencies_development = Hash[spec.development_dependencies.map{|d| [d.name, d.requirement.to_s ]}]
109
283
  end
110
284
 
285
+ # Collects an expanded list of all dependencies this package depends on
286
+ # directly or indirectly. This assume the project has already resolved
287
+ # any needed dependencies and therefore will raise an exception if a
288
+ # dependency cannot be found locally in the project.
111
289
  def expanded_deps(project)
112
290
  ret = []
113
291
  seen = []
@@ -122,14 +300,13 @@ module BPM
122
300
  todo << found
123
301
  ret << found
124
302
  else
125
- puts "COULD NOT FIND DEP: #{dep_name}"
303
+ raise "Required local dependency not found #{dep_name}"
126
304
  end
127
305
  end
128
-
129
306
  end
130
307
  ret
131
308
  end
132
-
309
+
133
310
  # TODO: Make better errors
134
311
  # TODO: This might not work well with conflicting versions
135
312
  def local_deps(search_path=nil)
@@ -153,157 +330,74 @@ module BPM
153
330
  end
154
331
  end
155
332
 
156
- def directory_files
157
- directories.reject{|k,_| k == 'tests' }.values.map{|dir| glob_files(dir) }.flatten
158
- end
333
+ private
159
334
 
160
- def bin_files
161
- if @attributes["bin"]
162
- @attributes["bin"].values
163
- else
164
- []
335
+ # colon to underscore
336
+ def c2u(key)
337
+ key.gsub(':', '_')
165
338
  end
166
- end
167
-
168
- def template_files
169
- glob_files("templates")
170
- end
171
-
172
- def transport_files
173
- glob_files("transports")
174
- end
175
-
176
- def bin_path
177
- @directories["bin"] || "bin"
178
- end
179
-
180
- def lib_path
181
- @directories["lib"] || "lib"
182
- end
183
-
184
- def tests_path
185
- @directories["tests"] || "tests"
186
- end
187
339
 
188
- def transport_plugins(project)
189
- plugin_modules('plugin:transport', project, false)
190
- end
191
-
192
- def minifier_plugins(project)
193
- [@attributes['plugin:minifier']].compact
194
- end
195
-
196
- def plugin_modules(key_name, project, own=true)
197
- return [@attributes[key_name]] if own && @attributes[key_name]
198
- dependencies.keys.map do |pkg_name|
199
- dep = project.local_deps.find do |pkg|
200
- pkg.load_json
201
- pkg.name == pkg_name
340
+ # field default
341
+ def fd(key)
342
+ case FIELDS[key]
343
+ when :array then []
344
+ when :hash then {}
202
345
  end
203
-
204
- if dep
205
- dep.attributes[key_name]
206
- else
207
- puts "COULD NOT FIND DEP: #{pkg_name}"
208
- end
209
-
210
- end.compact
211
- end
212
-
213
- # named directories that are expected to contain code. These will be
214
- # searched for supported modules
215
- def pipeline_libs
216
- (@attributes['pipeline'] && @attributes['pipeline']['libs']) || ['lib']
217
- end
218
-
219
- def pipeline_css
220
- (@attributes['pipeline'] && @attributes['pipeline']['css']) || ['css']
221
- end
222
-
223
- def pipeline_assets
224
- (@attributes['pipeline'] && @attributes['pipeline']['assets']) || ['assets', 'resources']
225
- end
226
-
227
- private
228
-
229
- def parse
230
- FIELDS.each do |field|
231
- send("#{field}=", @attributes[field])
232
346
  end
233
347
 
234
- self.dependencies = @attributes["dependencies"] || {}
235
- self.directories = @attributes["directories"] || {}
236
- self.metadata = Hash[*@attributes.select { |k, v| METADATA.include?(k) }.flatten(1)]
237
- end
238
-
239
- def read
240
- @attributes = JSON.parse(File.read(@json_path))
241
- rescue *[JSON::ParserError, Errno::EACCES, Errno::ENOENT] => ex
242
- add_error "There was a problem parsing #{File.basename(@json_path)}: #{ex.message}"
243
- end
244
-
245
- def validate_paths
246
- success = true
348
+ def validate_paths
349
+ success = true
247
350
 
248
- if paths = [*lib_path]
249
- non_dirs = paths.reject{|p| File.directory?(File.join(@root_path, p))}
351
+ paths = [*lib_path]
250
352
  if paths.empty?
251
353
  add_error "A lib directory is required"
252
354
  success = false
253
- elsif !non_dirs.empty?
254
- add_error "#{non_dirs.map{|p| "'#{p}'" }.join(", ")}, specified for lib directory, is not a directory"
355
+ else
356
+ non_dirs = paths.reject{|p| File.directory?(File.join(root_path, p))}
357
+ unless non_dirs.empty?
358
+ add_error "#{non_dirs.map{|p| "'#{p}'" }.join(", ")}, specified for lib directory, is not a directory"
359
+ success = false
360
+ end
361
+ end
362
+
363
+ # look for actual 'tests' in directories hash since simply having no
364
+ # tests dir is allowed as well.
365
+ unless directories['tests'].nil? || File.directory?(File.join(@root_path, tests_path))
366
+ add_error "'#{tests_path}', specified for tests directory, is not a directory"
255
367
  success = false
256
368
  end
257
- end
258
369
 
259
- # look for actual 'tests' in directories hash since simply having no
260
- # tests dir is allowed as well.
261
- unless @directories['tests'].nil? || File.directory?(File.join(@root_path, tests_path))
262
- add_error "'#{tests_path}', specified for tests directory, is not a directory"
263
- success = false
370
+ success
264
371
  end
265
372
 
266
- success
267
- end
268
-
269
- def validate_version
270
- LibGems::Version.new(version)
271
- true
272
- rescue ArgumentError => ex
273
- add_error ex.to_s
274
- end
373
+ def validate_version
374
+ LibGems::Version.new(version)
375
+ true
376
+ rescue ArgumentError => ex
377
+ add_error ex.to_s
378
+ false
379
+ end
275
380
 
276
- def validate_fields
277
- %w[name description summary homepage author version directories].all? do |field|
278
- value = send(field)
279
- if value.nil? || value.size.zero?
280
- add_error "Package requires a '#{field}' field"
281
- else
282
- true
381
+ def validate_fields
382
+ REQUIRED_FIELDS.all? do |field|
383
+ value = send(field)
384
+ if value.nil? || value.empty?
385
+ add_error "Package requires a '#{field}' field"
386
+ false
387
+ else
388
+ true
389
+ end
283
390
  end
284
391
  end
285
- end
286
392
 
287
- def add_error(message)
288
- self.errors << message
289
- false
290
- end
291
-
292
- def glob_files(path)
293
- Dir[File.join(path, "**", "*")].reject{|f| File.directory?(f) }
294
- end
295
-
296
- def fill_from_gemspec(spec)
297
- FIELDS.each{|field| send("#{field}=", spec.send(field).to_s) }
298
-
299
- self.dependencies = {}
300
- spec.dependencies.each{|d| self.dependencies[d.name] = d.requirement.to_s }
393
+ def add_error(message)
394
+ self.errors << message
395
+ end
301
396
 
302
- if spec.requirements && spec.requirements.size>0
303
- self.metadata = JSON.parse(spec.requirements.first)
397
+ def glob_files(path)
398
+ return path if File.exists?(path) && !File.directory?(path)
399
+ Dir[File.join(path, "**", "*")].reject{|f| File.directory?(f) }
304
400
  end
305
- end
306
401
 
307
402
  end
308
403
  end
309
-
@@ -21,30 +21,86 @@ module BPM
21
21
  minify super
22
22
  end
23
23
 
24
- def minify(body)
25
- project = environment.project
26
- minifier_name = project.minifier_name
27
- if minifier_name && content_type == 'application/javascript'
28
- pkg = project.package_from_name minifier_name
29
- minifier_plugin_name = pkg.minifier_plugins(project).first
30
- plugin_ctx = environment.plugin_context_for minifier_plugin_name
31
-
32
- V8::C::Locker() do
33
- plugin_ctx["PACKAGE_INFO"] = pkg.attributes
34
- plugin_ctx["DATA"] = body
35
- body = plugin_ctx.eval("BPM_PLUGIN.minify(DATA, PACKAGE_INFO)")
24
+ def minify(hash)
25
+ return hash if environment.mode == :debug
26
+
27
+ hash = environment.cache_hash("#{pathname}:minify", id) do
28
+ project = environment.project
29
+ minifier_name = project.minifier_name asset_name
30
+ minifier_name = minifier_name.keys.first if minifier_name
31
+
32
+ if minifier_name && content_type == 'application/javascript'
33
+ pkg = project.package_from_name minifier_name
34
+ if pkg.nil?
35
+ raise MinifierNotFoundError.new(minifier_name)
36
+ end
37
+
38
+ minifier_plugin_name = pkg.bpm_minifier
39
+ if minifier_plugin_name.nil?
40
+ raise MinifierNotFoundError.new(minifier_name)
41
+ end
42
+
43
+ plugin_ctx = environment.plugin_context_for minifier_plugin_name
44
+
45
+ # slice out the header at the top - we don't want the minifier to
46
+ # touch it.
47
+ data = hash['source']
48
+ header = data.match /^(\/\* ====.+====\*\/)$/m
49
+ if header
50
+ header = header[0] + "\n"
51
+ data = data[header.size..-1]
52
+ end
53
+
54
+ V8::C::Locker() do
55
+ plugin_ctx["PACKAGE_INFO"] = pkg.as_json
56
+ plugin_ctx["DATA"] = data
57
+ data = plugin_ctx.eval("BPM_PLUGIN.minify(DATA, PACKAGE_INFO)")
58
+ end
59
+
60
+ data = header+data if header
61
+
62
+ { 'length' => Rack::Utils.bytesize(data),
63
+ 'digest' => environment.digest.update(data).hexdigest,
64
+ 'source' => data }
65
+ else
66
+ hash
36
67
  end
37
68
  end
38
-
39
- body
69
+
70
+ hash['length'] = Integer(hash['length']) if hash['length'].is_a?(String)
71
+
72
+ @length = hash['length']
73
+ @digest = hash['digest']
74
+ @source = hash['source']
75
+
76
+ hash
77
+ end
78
+
79
+ def asset_name
80
+ project = environment.project
81
+ if pathname.to_s.include?(project.assets_root)
82
+ pathname.relative_path_from(Pathname.new(project.assets_root)).to_s
83
+ elsif pathname.to_s.include?(project.preview_root)
84
+ pathname.relative_path_from(Pathname.new(project.preview_root)).to_s
85
+ end
40
86
  end
41
87
 
42
88
  def build_dependency_context_and_body
43
89
 
44
- project = environment.project
45
- pkgs = pathname.to_s =~ /app_/ ? [project] : project.local_deps
90
+ project = environment.project
91
+ settings = project.build_settings(environment.mode)[asset_name]
92
+ pkgs = settings.keys.map do |pkg_name|
93
+ next if pkg_name == 'bpm:minifier'
94
+ if pkg_name == project.name
95
+ project
96
+ else
97
+ project.local_deps.find { |dep| dep.name == pkg_name }
98
+ end
99
+ end.compact
100
+
46
101
  if pkgs.size > 0
47
- manifest = pkgs.map do |x|
102
+ manifest = pkgs.sort { |a,b| a.name <=> b.name }
103
+ manifest = manifest.map do |x|
48
104
  "#{x.name} (#{x.version})"
49
105
  end.join " "
50
106
  else
@@ -54,10 +110,9 @@ module BPM
54
110
  # Add in the generated header
55
111
  body = <<EOF
56
112
  /* ===========================================================================
57
- BPM Static Dependencies
113
+ BPM Combined Asset File
58
114
  MANIFEST: #{manifest}
59
115
  This file is generated automatically by the bpm (http://www.bpmjs.org)
60
- To use this file, load this file in your HTML head.
61
116
  =========================================================================*/
62
117
 
63
118
  EOF
@@ -69,17 +124,22 @@ EOF
69
124
  context = blank_context
70
125
  context.require_asset(pathname) # start with self
71
126
 
72
- dir_name, dir_method = FORMAT_METHODS[content_type] || ['lib', 'pipeline_libs']
127
+ if pathname.to_s =~ /_tests\.js$/
128
+ dir_name, dir_method = ['tests', 'pipeline_tests']
129
+ else
130
+ dir_name, dir_method = FORMAT_METHODS[content_type] || ['lib', 'pipeline_libs']
131
+ end
73
132
 
74
133
  pkgs.map do |pkg|
75
- pkg.load_json
76
- pkg.send(dir_method).each do |dir|
77
- dir_name = pkg.directories[dir] || dir
78
- search_path = File.expand_path File.join(pkg.root_path, dir_name)
79
-
80
- Dir[File.join(search_path, '**', '*')].sort.each do |fn|
81
- context.depend_on File.dirname(fn)
82
- context.require_asset(fn) if context.asset_requirable? fn
134
+ settings[pkg.name].each do |dir|
135
+ dir_names = Array(pkg.directories[dir] || dir)
136
+ dir_names.each do |dir_name|
137
+ search_path = File.expand_path File.join(pkg.root_path, dir_name)
138
+
139
+ Dir[File.join(search_path, '**', '*')].sort.each do |fn|
140
+ context.depend_on File.dirname(fn)
141
+ context.require_asset(fn) if context.asset_requirable? fn
142
+ end
83
143
  end
84
144
  end
85
145
  end