bpm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. data/.gitignore +4 -0
  2. data/.gitmodules +0 -0
  3. data/Gemfile +16 -0
  4. data/README.md +55 -0
  5. data/TODO.md +3 -0
  6. data/bin/bpm +8 -0
  7. data/bpm.gemspec +41 -0
  8. data/lib/bpm.rb +18 -0
  9. data/lib/bpm/cli.rb +6 -0
  10. data/lib/bpm/cli/base.rb +358 -0
  11. data/lib/bpm/cli/owner.rb +46 -0
  12. data/lib/bpm/credentials.rb +36 -0
  13. data/lib/bpm/default.json +9 -0
  14. data/lib/bpm/generator.rb +69 -0
  15. data/lib/bpm/init_generator.rb +43 -0
  16. data/lib/bpm/libgems_ext.rb +11 -0
  17. data/lib/bpm/libgems_ext/config_file.rb +33 -0
  18. data/lib/bpm/libgems_ext/dependency_installer.rb +150 -0
  19. data/lib/bpm/libgems_ext/installer.rb +39 -0
  20. data/lib/bpm/libgems_ext/libgems.rb +39 -0
  21. data/lib/bpm/libgems_ext/spec_fetcher.rb +11 -0
  22. data/lib/bpm/local.rb +76 -0
  23. data/lib/bpm/package.rb +277 -0
  24. data/lib/bpm/pipeline.rb +100 -0
  25. data/lib/bpm/pipeline/directive_processor.rb +47 -0
  26. data/lib/bpm/pipeline/generated_asset.rb +68 -0
  27. data/lib/bpm/pipeline/transport_processor.rb +32 -0
  28. data/lib/bpm/project.rb +427 -0
  29. data/lib/bpm/project_generator.rb +34 -0
  30. data/lib/bpm/remote.rb +104 -0
  31. data/lib/bpm/repository.rb +18 -0
  32. data/lib/bpm/server.rb +44 -0
  33. data/lib/bpm/version.rb +3 -0
  34. data/spec/cli/add_spec.rb +159 -0
  35. data/spec/cli/build_spec.rb +87 -0
  36. data/spec/cli/fetch_spec.rb +135 -0
  37. data/spec/cli/fetched_spec.rb +52 -0
  38. data/spec/cli/init_spec.rb +50 -0
  39. data/spec/cli/list_spec.rb +74 -0
  40. data/spec/cli/login_spec.rb +110 -0
  41. data/spec/cli/new_spec.rb +92 -0
  42. data/spec/cli/owner_spec.rb +114 -0
  43. data/spec/cli/push_spec.rb +73 -0
  44. data/spec/cli/remove_spec.rb +84 -0
  45. data/spec/cli/unpack_spec.rb +72 -0
  46. data/spec/cli/unyank_spec.rb +73 -0
  47. data/spec/cli/yank_spec.rb +73 -0
  48. data/spec/credentials_spec.rb +23 -0
  49. data/spec/fixtures/badrake-0.8.7.spd +0 -0
  50. data/spec/fixtures/builder-3.0.0.spd +0 -0
  51. data/spec/fixtures/bundler-1.1.pre.spd +0 -0
  52. data/spec/fixtures/coffee-1.0.1.pre.spd +0 -0
  53. data/spec/fixtures/core-test-0.4.9.spd +0 -0
  54. data/spec/fixtures/core-test/bin/cot +3 -0
  55. data/spec/fixtures/core-test/lib/main.js +1 -0
  56. data/spec/fixtures/core-test/package.json +46 -0
  57. data/spec/fixtures/core-test/resources/runner.css +1 -0
  58. data/spec/fixtures/core-test/tests/test.js +1 -0
  59. data/spec/fixtures/custom_generator-1.0.spd +0 -0
  60. data/spec/fixtures/custom_generator/lib/main.js +1 -0
  61. data/spec/fixtures/custom_generator/package.json +12 -0
  62. data/spec/fixtures/custom_generator/templates/init/project.json +19 -0
  63. data/spec/fixtures/custom_generator/templates/project/app.js +1 -0
  64. data/spec/fixtures/custom_generator/templates/project/lib/main.js +0 -0
  65. data/spec/fixtures/custom_generator/templates/project_generator.rb +20 -0
  66. data/spec/fixtures/hello_world/LICENSE +19 -0
  67. data/spec/fixtures/hello_world/README.md +21 -0
  68. data/spec/fixtures/hello_world/assets/bpm_packages.js +13 -0
  69. data/spec/fixtures/hello_world/assets/bpm_styles.css +14 -0
  70. data/spec/fixtures/hello_world/assets/papa-smurf.jpg +0 -0
  71. data/spec/fixtures/hello_world/hello_world.json +20 -0
  72. data/spec/fixtures/hello_world/lib/main.js +9 -0
  73. data/spec/fixtures/hello_world/packages/custom_package/assets/dummy.txt +1 -0
  74. data/spec/fixtures/hello_world/packages/custom_package/css/sample_styles.css +3 -0
  75. data/spec/fixtures/hello_world/packages/custom_package/custom_dir/basic-module.js +1 -0
  76. data/spec/fixtures/hello_world/packages/custom_package/lib/main.js +1 -0
  77. data/spec/fixtures/hello_world/packages/custom_package/package.json +22 -0
  78. data/spec/fixtures/hello_world/tests/main-test.js +8 -0
  79. data/spec/fixtures/highline-1.6.1.spd +0 -0
  80. data/spec/fixtures/ivory-0.0.1.spd +0 -0
  81. data/spec/fixtures/jquery-1.4.3.spd +0 -0
  82. data/spec/fixtures/optparse-1.0.1.spd +0 -0
  83. data/spec/fixtures/rake-0.8.6.spd +0 -0
  84. data/spec/fixtures/rake-0.8.7.spd +0 -0
  85. data/spec/fixtures/simple_hello/assets/bpm_packages.js +1 -0
  86. data/spec/fixtures/simple_hello/lib/main.js +1 -0
  87. data/spec/fixtures/spade-0.5.0.spd +0 -0
  88. data/spec/fixtures/src/README.txt +1 -0
  89. data/spec/fixtures/src/bundler-1.1.pre/.gitignore +22 -0
  90. data/spec/fixtures/src/bundler-1.1.pre/CHANGELOG.md +646 -0
  91. data/spec/fixtures/src/bundler-1.1.pre/ISSUES.md +47 -0
  92. data/spec/fixtures/src/bundler-1.1.pre/LICENSE +21 -0
  93. data/spec/fixtures/src/bundler-1.1.pre/README.md +29 -0
  94. data/spec/fixtures/src/bundler-1.1.pre/UPGRADING.md +103 -0
  95. data/spec/fixtures/src/bundler-1.1.pre/bin/bundle +20 -0
  96. data/spec/fixtures/src/bundler-1.1.pre/lib/bundler.js +23 -0
  97. data/spec/fixtures/src/bundler-1.1.pre/lib/bundler/definition.js +14 -0
  98. data/spec/fixtures/src/bundler-1.1.pre/lib/bundler/dependency.js +15 -0
  99. data/spec/fixtures/src/bundler-1.1.pre/lib/bundler/dsl.js +9 -0
  100. data/spec/fixtures/src/bundler-1.1.pre/lib/bundler/ui.js +6 -0
  101. data/spec/fixtures/src/bundler-1.1.pre/man/bundle-config.ronn +90 -0
  102. data/spec/fixtures/src/bundler-1.1.pre/man/bundle-exec.ronn +111 -0
  103. data/spec/fixtures/src/bundler-1.1.pre/man/bundle-install.ronn +314 -0
  104. data/spec/fixtures/src/bundler-1.1.pre/man/bundle-package.ronn +59 -0
  105. data/spec/fixtures/src/bundler-1.1.pre/man/bundle-update.ronn +176 -0
  106. data/spec/fixtures/src/bundler-1.1.pre/man/bundle.ronn +80 -0
  107. data/spec/fixtures/src/bundler-1.1.pre/man/gemfile.5.ronn +279 -0
  108. data/spec/fixtures/src/bundler-1.1.pre/man/index.txt +6 -0
  109. data/spec/fixtures/src/bundler-1.1.pre/package.json +19 -0
  110. data/spec/fixtures/src/coffee-1.0.1.pre/bin/cake +0 -0
  111. data/spec/fixtures/src/coffee-1.0.1.pre/bin/coffee +0 -0
  112. data/spec/fixtures/src/coffee-1.0.1.pre/lib/coffee.js +0 -0
  113. data/spec/fixtures/src/coffee-1.0.1.pre/lib/coffee/base.js +0 -0
  114. data/spec/fixtures/src/coffee-1.0.1.pre/lib/coffee/mocha/chai.js +0 -0
  115. data/spec/fixtures/src/coffee-1.0.1.pre/package.json +19 -0
  116. data/spec/fixtures/src/coffee-1.0.1.pre/qunit/coffee/test.js +0 -0
  117. data/spec/fixtures/src/coffee-1.0.1.pre/qunit/test.js +0 -0
  118. data/spec/fixtures/src/jquery/lib/main.js +7179 -0
  119. data/spec/fixtures/src/jquery/package.json +15 -0
  120. data/spec/fixtures/src/rake-0.8.6/CHANGES +436 -0
  121. data/spec/fixtures/src/rake-0.8.6/MIT-LICENSE +21 -0
  122. data/spec/fixtures/src/rake-0.8.6/README +196 -0
  123. data/spec/fixtures/src/rake-0.8.6/Rakefile +430 -0
  124. data/spec/fixtures/src/rake-0.8.6/TODO +20 -0
  125. data/spec/fixtures/src/rake-0.8.6/bin/rake +31 -0
  126. data/spec/fixtures/src/rake-0.8.6/doc/command_line_usage.rdoc +102 -0
  127. data/spec/fixtures/src/rake-0.8.6/doc/example/Rakefile1 +38 -0
  128. data/spec/fixtures/src/rake-0.8.6/doc/example/Rakefile2 +35 -0
  129. data/spec/fixtures/src/rake-0.8.6/doc/example/a.c +6 -0
  130. data/spec/fixtures/src/rake-0.8.6/doc/example/b.c +6 -0
  131. data/spec/fixtures/src/rake-0.8.6/doc/example/main.c +11 -0
  132. data/spec/fixtures/src/rake-0.8.6/doc/glossary.rdoc +51 -0
  133. data/spec/fixtures/src/rake-0.8.6/doc/jamis.rb +591 -0
  134. data/spec/fixtures/src/rake-0.8.6/doc/proto_rake.rdoc +127 -0
  135. data/spec/fixtures/src/rake-0.8.6/doc/rake.1.gz +0 -0
  136. data/spec/fixtures/src/rake-0.8.6/doc/rakefile.rdoc +534 -0
  137. data/spec/fixtures/src/rake-0.8.6/doc/rational.rdoc +151 -0
  138. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.4.14.rdoc +23 -0
  139. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.4.15.rdoc +35 -0
  140. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.5.0.rdoc +53 -0
  141. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.5.3.rdoc +78 -0
  142. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.5.4.rdoc +46 -0
  143. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.6.0.rdoc +141 -0
  144. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.7.0.rdoc +119 -0
  145. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.7.1.rdoc +59 -0
  146. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.7.2.rdoc +121 -0
  147. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.7.3.rdoc +47 -0
  148. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.8.0.rdoc +114 -0
  149. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.8.2.rdoc +165 -0
  150. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.8.3.rdoc +112 -0
  151. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.8.4.rdoc +147 -0
  152. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.8.5.rdoc +53 -0
  153. data/spec/fixtures/src/rake-0.8.6/doc/release_notes/rake-0.8.6.rdoc +55 -0
  154. data/spec/fixtures/src/rake-0.8.6/install.rb +88 -0
  155. data/spec/fixtures/src/rake-0.8.6/lib/rake.rb +2502 -0
  156. data/spec/fixtures/src/rake-0.8.6/lib/rake/alt_system.rb +108 -0
  157. data/spec/fixtures/src/rake-0.8.6/lib/rake/classic_namespace.rb +8 -0
  158. data/spec/fixtures/src/rake-0.8.6/lib/rake/clean.rb +33 -0
  159. data/spec/fixtures/src/rake-0.8.6/lib/rake/contrib/compositepublisher.rb +24 -0
  160. data/spec/fixtures/src/rake-0.8.6/lib/rake/contrib/ftptools.rb +153 -0
  161. data/spec/fixtures/src/rake-0.8.6/lib/rake/contrib/publisher.rb +75 -0
  162. data/spec/fixtures/src/rake-0.8.6/lib/rake/contrib/rubyforgepublisher.rb +18 -0
  163. data/spec/fixtures/src/rake-0.8.6/lib/rake/contrib/sshpublisher.rb +47 -0
  164. data/spec/fixtures/src/rake-0.8.6/lib/rake/contrib/sys.rb +209 -0
  165. data/spec/fixtures/src/rake-0.8.6/lib/rake/gempackagetask.rb +97 -0
  166. data/spec/fixtures/src/rake-0.8.6/lib/rake/loaders/makefile.rb +42 -0
  167. data/spec/fixtures/src/rake-0.8.6/lib/rake/packagetask.rb +184 -0
  168. data/spec/fixtures/src/rake-0.8.6/lib/rake/rake_test_loader.rb +5 -0
  169. data/spec/fixtures/src/rake-0.8.6/lib/rake/rdoctask.rb +209 -0
  170. data/spec/fixtures/src/rake-0.8.6/lib/rake/ruby182_test_unit_fix.rb +23 -0
  171. data/spec/fixtures/src/rake-0.8.6/lib/rake/runtest.rb +23 -0
  172. data/spec/fixtures/src/rake-0.8.6/lib/rake/tasklib.rb +23 -0
  173. data/spec/fixtures/src/rake-0.8.6/lib/rake/testtask.rb +161 -0
  174. data/spec/fixtures/src/rake-0.8.6/lib/rake/win32.rb +55 -0
  175. data/spec/fixtures/src/rake-0.8.6/package.json +18 -0
  176. data/spec/fixtures/src/rake-0.8.6/test/capture_stdout.rb +26 -0
  177. data/spec/fixtures/src/rake-0.8.7/CHANGES +440 -0
  178. data/spec/fixtures/src/rake-0.8.7/MIT-LICENSE +21 -0
  179. data/spec/fixtures/src/rake-0.8.7/README +196 -0
  180. data/spec/fixtures/src/rake-0.8.7/Rakefile +430 -0
  181. data/spec/fixtures/src/rake-0.8.7/TODO +20 -0
  182. data/spec/fixtures/src/rake-0.8.7/bin/rake +31 -0
  183. data/spec/fixtures/src/rake-0.8.7/doc/command_line_usage.rdoc +102 -0
  184. data/spec/fixtures/src/rake-0.8.7/doc/example/Rakefile1 +38 -0
  185. data/spec/fixtures/src/rake-0.8.7/doc/example/Rakefile2 +35 -0
  186. data/spec/fixtures/src/rake-0.8.7/doc/example/a.c +6 -0
  187. data/spec/fixtures/src/rake-0.8.7/doc/example/b.c +6 -0
  188. data/spec/fixtures/src/rake-0.8.7/doc/example/main.c +11 -0
  189. data/spec/fixtures/src/rake-0.8.7/doc/glossary.rdoc +51 -0
  190. data/spec/fixtures/src/rake-0.8.7/doc/jamis.rb +591 -0
  191. data/spec/fixtures/src/rake-0.8.7/doc/proto_rake.rdoc +127 -0
  192. data/spec/fixtures/src/rake-0.8.7/doc/rake.1.gz +0 -0
  193. data/spec/fixtures/src/rake-0.8.7/doc/rakefile.rdoc +534 -0
  194. data/spec/fixtures/src/rake-0.8.7/doc/rational.rdoc +151 -0
  195. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.4.14.rdoc +23 -0
  196. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.4.15.rdoc +35 -0
  197. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.5.0.rdoc +53 -0
  198. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.5.3.rdoc +78 -0
  199. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.5.4.rdoc +46 -0
  200. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.6.0.rdoc +141 -0
  201. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.7.0.rdoc +119 -0
  202. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.7.1.rdoc +59 -0
  203. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.7.2.rdoc +121 -0
  204. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.7.3.rdoc +47 -0
  205. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.8.0.rdoc +114 -0
  206. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.8.2.rdoc +165 -0
  207. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.8.3.rdoc +112 -0
  208. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.8.4.rdoc +147 -0
  209. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.8.5.rdoc +53 -0
  210. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.8.6.rdoc +55 -0
  211. data/spec/fixtures/src/rake-0.8.7/doc/release_notes/rake-0.8.7.rdoc +55 -0
  212. data/spec/fixtures/src/rake-0.8.7/install.rb +88 -0
  213. data/spec/fixtures/src/rake-0.8.7/lib/rake.rb +2506 -0
  214. data/spec/fixtures/src/rake-0.8.7/lib/rake/alt_system.rb +108 -0
  215. data/spec/fixtures/src/rake-0.8.7/lib/rake/classic_namespace.rb +8 -0
  216. data/spec/fixtures/src/rake-0.8.7/lib/rake/clean.rb +33 -0
  217. data/spec/fixtures/src/rake-0.8.7/lib/rake/contrib/compositepublisher.rb +24 -0
  218. data/spec/fixtures/src/rake-0.8.7/lib/rake/contrib/ftptools.rb +153 -0
  219. data/spec/fixtures/src/rake-0.8.7/lib/rake/contrib/publisher.rb +75 -0
  220. data/spec/fixtures/src/rake-0.8.7/lib/rake/contrib/rubyforgepublisher.rb +18 -0
  221. data/spec/fixtures/src/rake-0.8.7/lib/rake/contrib/sshpublisher.rb +47 -0
  222. data/spec/fixtures/src/rake-0.8.7/lib/rake/contrib/sys.rb +209 -0
  223. data/spec/fixtures/src/rake-0.8.7/lib/rake/gempackagetask.rb +97 -0
  224. data/spec/fixtures/src/rake-0.8.7/lib/rake/loaders/makefile.rb +42 -0
  225. data/spec/fixtures/src/rake-0.8.7/lib/rake/packagetask.rb +184 -0
  226. data/spec/fixtures/src/rake-0.8.7/lib/rake/rake_test_loader.rb +5 -0
  227. data/spec/fixtures/src/rake-0.8.7/lib/rake/rdoctask.rb +209 -0
  228. data/spec/fixtures/src/rake-0.8.7/lib/rake/ruby182_test_unit_fix.rb +23 -0
  229. data/spec/fixtures/src/rake-0.8.7/lib/rake/runtest.rb +23 -0
  230. data/spec/fixtures/src/rake-0.8.7/lib/rake/tasklib.rb +23 -0
  231. data/spec/fixtures/src/rake-0.8.7/lib/rake/testtask.rb +161 -0
  232. data/spec/fixtures/src/rake-0.8.7/lib/rake/win32.rb +55 -0
  233. data/spec/fixtures/src/rake-0.8.7/package.json +18 -0
  234. data/spec/fixtures/src/rake-0.8.7/test/capture_stdout.rb +26 -0
  235. data/spec/fixtures/src/spade/lib/main.js +1 -0
  236. data/spec/fixtures/src/spade/package.json +15 -0
  237. data/spec/fixtures/transporter/lib/main.js +3 -0
  238. data/spec/fixtures/transporter/packages/transport/lib/wrapper.js +5 -0
  239. data/spec/fixtures/transporter/packages/transport/package.json +21 -0
  240. data/spec/fixtures/transporter/transporter.json +18 -0
  241. data/spec/gauntlet_spec.rb +33 -0
  242. data/spec/package_spec.rb +319 -0
  243. data/spec/pipeline_spec.rb +213 -0
  244. data/spec/project_spec.rb +130 -0
  245. data/spec/spec_helper.rb +42 -0
  246. data/spec/support/cli.rb +93 -0
  247. data/spec/support/env.rb +18 -0
  248. data/spec/support/fake.rb +53 -0
  249. data/spec/support/fake_gem_server.rb +72 -0
  250. data/spec/support/fake_gemcutter.rb +50 -0
  251. data/spec/support/matchers.rb +32 -0
  252. data/spec/support/path.rb +63 -0
  253. data/spec/support/project.rb +43 -0
  254. data/templates/init/assets/bpm_packages.js +7 -0
  255. data/templates/init/assets/bpm_styles.css +7 -0
  256. data/templates/init/project.json +16 -0
  257. data/templates/project/LICENSE +19 -0
  258. data/templates/project/README.md +21 -0
  259. data/templates/project/app.js +1 -0
  260. data/templates/project/index.html +13 -0
  261. metadata +627 -0
@@ -0,0 +1,39 @@
1
+ require 'libgems'
2
+
3
+ module LibGems
4
+ def self.default_sources
5
+ %w[https://sproutcutter.heroku.com/]
6
+ end
7
+
8
+ def self.host
9
+ @host ||= "https://sproutcutter.heroku.com"
10
+ end
11
+
12
+ def self.default_dir
13
+ File.join LibGems.user_home, BPM::BPM_DIR
14
+ end
15
+
16
+ def self.user_dir
17
+ File.join LibGems.user_home, BPM::BPM_DIR
18
+ end
19
+
20
+ def self.config_file
21
+ File.join LibGems.user_home, '.bpmrc'
22
+ end
23
+
24
+ def self.path
25
+ @gem_path ||= nil
26
+
27
+ unless @gem_path then
28
+ paths = [ENV['BPM_PATH'] || LibGems.configuration.path || default_path]
29
+ set_paths paths.compact.join(File::PATH_SEPARATOR)
30
+ end
31
+
32
+ @gem_path
33
+ end
34
+
35
+ def self.dir
36
+ set_home(ENV['BPM_HOME'] || LibGems.configuration.home || default_dir) unless @gem_home
37
+ @gem_home
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ require 'libgems/spec_fetcher'
2
+
3
+ module LibGems
4
+ class SpecFetcher
5
+ alias :orig_initialize :initialize
6
+ def initialize(*args)
7
+ orig_initialize(*args)
8
+ @dir = File.join LibGems.dir, 'specs'
9
+ end
10
+ end
11
+ end
data/lib/bpm/local.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'libgems/uninstaller'
2
+
3
+ module BPM
4
+ class Local < Repository
5
+ def uninstall(package)
6
+ LibGems::Uninstaller.new(package).uninstall
7
+ true
8
+ rescue LibGems::InstallError
9
+ false
10
+ end
11
+
12
+ def pack(path, email=nil)
13
+ package_path = File.dirname(File.expand_path path)
14
+ cur_pwd = Dir.pwd
15
+
16
+ FileUtils.cd package_path if package_path != cur_pwd
17
+ package = BPM::Package.new(nil, email || creds.email)
18
+ package.json_path = File.basename path
19
+
20
+
21
+ if package.valid?
22
+ silence do
23
+ LibGems::Builder.new(package.to_spec).build
24
+ end
25
+ end
26
+
27
+ FileUtils.cd cur_pwd if package_path != cur_pwd
28
+ package
29
+ end
30
+
31
+ def unpack(path, target)
32
+ package = BPM::Package.new
33
+ package.bpkg = path
34
+ unpack_dir = File.expand_path(File.join(Dir.pwd, target, package.to_full_name))
35
+ LibGems::Installer.new(path, :unpack => true).unpack unpack_dir
36
+ package
37
+ end
38
+
39
+ def installed(packages)
40
+ specs = LibGems.source_index.search dependency_for(packages)
41
+
42
+ specs.map do |spec|
43
+ [spec.name, spec.version, spec.original_platform]
44
+ end
45
+ end
46
+
47
+ def preferred_version(package, vers, prerelease)
48
+ dep = LibGems::Dependency.new package, vers
49
+ specs = LibGems.source_index.search dep
50
+ specs.last.version.to_s
51
+ end
52
+
53
+ def source_root(package, vers, prerelease)
54
+ dep = LibGems::Dependency.new package, vers
55
+ specs = LibGems.source_index.search dep
56
+
57
+ dep2 = LibGems::Dependency.new package, '>= 0'
58
+ specs2 = LibGems.source_index.search dep2
59
+
60
+ spec = specs.last
61
+ spec &&
62
+ File.join(spec.installation_path, 'gems', "#{spec.name}-#{spec.version}")
63
+ end
64
+
65
+ private
66
+
67
+ def silence
68
+ original_verbose = LibGems.configuration.verbose
69
+ LibGems.configuration.verbose = false
70
+ yield
71
+ ensure
72
+ LibGems.configuration.verbose = original_verbose
73
+ end
74
+ end
75
+ end
76
+
@@ -0,0 +1,277 @@
1
+ require 'json'
2
+
3
+ module BPM
4
+ class Package
5
+ EXT = "spd"
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
10
+
11
+ def self.from_spec(spec)
12
+ pkg = new(spec.full_gem_path)
13
+ pkg.bpkg = spec
14
+ pkg
15
+ end
16
+
17
+ 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 bpm
28
+ @bpm || BPM::VERSION
29
+ end
30
+
31
+ def bpkg=(spec)
32
+ unless spec.is_a?(LibGems::Specification)
33
+ spec = LibGems::Format.from_file_by_path(spec.to_s).spec
34
+ end
35
+ fill_from_gemspec(spec)
36
+ end
37
+
38
+ def to_spec
39
+ return unless valid?
40
+ LibGems::Specification.new do |spec|
41
+ spec.name = name
42
+ spec.version = version
43
+ spec.authors = [author]
44
+ spec.email = @email
45
+ spec.homepage = homepage
46
+ spec.summary = summary
47
+ spec.description = description
48
+ spec.requirements = [metadata.to_json]
49
+ spec.files = directory_files + template_files + ["package.json"]
50
+ spec.test_files = glob_files(tests_path)
51
+ spec.bindir = bin_path
52
+ spec.executables = bin_files.map{|p| File.basename(p) } if bin_path
53
+ # TODO: IS this right?
54
+ spec.rubyforge_project = "bpm"
55
+ def spec.file_name
56
+ "#{full_name}.#{EXT}"
57
+ end
58
+ dependencies.each{|d,v| spec.add_dependency(d, v) } if dependencies
59
+ end
60
+ end
61
+
62
+ def as_json(options = {})
63
+ json = self.metadata.clone
64
+ FIELDS.each{|key| json[key] = send(key)}
65
+ json["dependencies"] = self.dependencies
66
+ json
67
+ end
68
+
69
+ def to_json
70
+ as_json.to_json
71
+ end
72
+
73
+ def to_full_name
74
+ "#{name}-#{version}"
75
+ end
76
+
77
+ def to_ext
78
+ "#{self.to_full_name}.#{EXT}"
79
+ end
80
+
81
+ def template_path(name)
82
+ path = File.join(root_path, 'templates', name.to_s)
83
+ File.exist?(path) ? path : nil
84
+ end
85
+
86
+ def generator_for(type)
87
+ unless generator = BPM.generator_for(name, type, false)
88
+ path = File.join(root_path, 'templates', "#{type}_generator.rb")
89
+ load path if File.exist?(path)
90
+ generator = BPM.generator_for(name, type)
91
+ end
92
+ generator
93
+ end
94
+
95
+ def errors
96
+ @errors ||= []
97
+ end
98
+
99
+ def validate
100
+ validate_fields && validate_version && validate_paths
101
+ end
102
+
103
+ def valid?
104
+ load_json && validate
105
+ end
106
+
107
+ def has_json?
108
+ File.exist?(json_path)
109
+ end
110
+
111
+ def load_json
112
+ read && parse
113
+ end
114
+
115
+ # TODO: Make better errors
116
+ # TODO: This might not work well with conflicting versions
117
+ def local_deps(search_path=nil)
118
+ search_path ||= File.join(root_path, "packages")
119
+
120
+ dependencies.inject([]) do |list, (name, version)|
121
+ package = Package.new(File.join(search_path, name))
122
+ requirement = LibGems::Requirement.new(version)
123
+ if package.has_json?
124
+ package.load_json
125
+ else
126
+ raise "Can't find package #{name} required in #{self.name}"
127
+ end
128
+ unless requirement.satisfied_by?(LibGems::Version.new(package.version))
129
+ raise "#{name} (#{package.version}) doesn't match #{version} required in #{self.name}"
130
+ end
131
+ (package.local_deps(search_path) << package).each do |dep|
132
+ list << dep unless list.any?{|d| d.name == dep.name }
133
+ end
134
+ list
135
+ end
136
+ end
137
+
138
+ def directory_files
139
+ directories.reject{|k,_| k == 'tests' }.values.map{|dir| glob_files(dir) }.flatten
140
+ end
141
+
142
+ def bin_files
143
+ if @attributes["bin"]
144
+ @attributes["bin"].values
145
+ else
146
+ []
147
+ end
148
+ end
149
+
150
+ def template_files
151
+ glob_files("templates")
152
+ end
153
+
154
+ def bin_path
155
+ @directories["bin"] || "bin"
156
+ end
157
+
158
+ def lib_path
159
+ @directories["lib"] || "lib"
160
+ end
161
+
162
+ def tests_path
163
+ @directories["tests"] || "tests"
164
+ end
165
+
166
+ def transport_plugins(project)
167
+ plugin_modules('plugin:transport', project)
168
+ end
169
+
170
+ def plugin_modules(key_name, project)
171
+ return [@attributes[key_name]] if @attributes[key_name]
172
+ dependencies.keys.map do |pkg_name|
173
+ dep = project.local_deps.find do |pkg|
174
+ pkg.load_json
175
+ pkg.name == pkg_name
176
+ end
177
+ dep.attributes[key_name]
178
+ end.compact
179
+ end
180
+
181
+ # named directories that are expected to contain code. These will be
182
+ # searched for supported modules
183
+ def pipeline_libs
184
+ (@attributes['pipeline'] && @attributes['pipeline']['libs']) || ['lib']
185
+ end
186
+
187
+ def pipeline_css
188
+ (@attributes['pipeline'] && @attributes['pipeline']['css']) || ['css']
189
+ end
190
+
191
+ def pipeline_assets
192
+ (@attributes['pipeline'] && @attributes['pipeline']['assets']) || ['assets', 'resources']
193
+ end
194
+
195
+ private
196
+
197
+ def parse
198
+ FIELDS.each do |field|
199
+ send("#{field}=", @attributes[field])
200
+ end
201
+
202
+ self.dependencies = @attributes["dependencies"] || {}
203
+ self.directories = @attributes["directories"] || {}
204
+ self.metadata = Hash[*@attributes.select { |k, v| METADATA.include?(k) }.flatten(1)]
205
+ end
206
+
207
+ def read
208
+ @attributes = JSON.parse(File.read(@json_path))
209
+ rescue *[JSON::ParserError, Errno::EACCES, Errno::ENOENT] => ex
210
+ add_error "There was a problem parsing #{File.basename(@json_path)}: #{ex.message}"
211
+ end
212
+
213
+ def validate_paths
214
+ success = true
215
+
216
+ if paths = [*lib_path]
217
+ non_dirs = paths.reject{|p| File.directory?(File.join(@root_path, p))}
218
+ if paths.empty?
219
+ add_error "A lib directory is required"
220
+ success = false
221
+ elsif !non_dirs.empty?
222
+ add_error "#{non_dirs.map{|p| "'#{p}'" }.join(", ")}, specified for lib directory, is not a directory"
223
+ success = false
224
+ end
225
+ end
226
+
227
+ # look for actual 'tests' in directories hash since simply having no
228
+ # tests dir is allowed as well.
229
+ unless @directories['tests'].nil? || File.directory?(File.join(@root_path, tests_path))
230
+ add_error "'#{tests_path}', specified for tests directory, is not a directory"
231
+ success = false
232
+ end
233
+
234
+ success
235
+ end
236
+
237
+ def validate_version
238
+ LibGems::Version.new(version)
239
+ true
240
+ rescue ArgumentError => ex
241
+ add_error ex.to_s
242
+ end
243
+
244
+ def validate_fields
245
+ %w[name description summary homepage author version directories].all? do |field|
246
+ value = send(field)
247
+ if value.nil? || value.size.zero?
248
+ add_error "Package requires a '#{field}' field"
249
+ else
250
+ true
251
+ end
252
+ end
253
+ end
254
+
255
+ def add_error(message)
256
+ self.errors << message
257
+ false
258
+ end
259
+
260
+ def glob_files(path)
261
+ Dir[File.join(path, "**", "*")].reject{|f| File.directory?(f) }
262
+ end
263
+
264
+ def fill_from_gemspec(spec)
265
+ FIELDS.each{|field| send("#{field}=", spec.send(field).to_s) }
266
+
267
+ self.dependencies = {}
268
+ spec.dependencies.each{|d| self.dependencies[d.name] = d.requirement.to_s }
269
+
270
+ if spec.requirements && spec.requirements.size>0
271
+ self.metadata = JSON.parse(spec.requirements.first)
272
+ end
273
+ end
274
+
275
+ end
276
+ end
277
+
@@ -0,0 +1,100 @@
1
+ require 'sprockets'
2
+
3
+ module BPM
4
+
5
+ autoload :DirectiveProcessor, 'bpm/pipeline/directive_processor'
6
+ autoload :GeneratedAsset, 'bpm/pipeline/generated_asset'
7
+ autoload :TransportProcessor, 'bpm/pipeline/transport_processor'
8
+
9
+ # A BPM package-aware asset pipeline. Asset lookup respects package.json
10
+ # directory configurations as well as loading preprocessors, formats, and
11
+ # postprocessors from the package config.
12
+ #
13
+ class Pipeline < Sprockets::Environment
14
+
15
+ attr_reader :project
16
+
17
+ # Pass in the project you want the pipeline to manage.
18
+ def initialize(project)
19
+ @project = project
20
+ project_path = project.root_path
21
+
22
+ super project_path
23
+
24
+ # use custom directive processor
25
+ %w(text/css application/javascript).each do |kind|
26
+ unregister_processor kind, Sprockets::DirectiveProcessor
27
+ register_processor kind, BPM::DirectiveProcessor
28
+ end
29
+
30
+ register_postprocessor 'application/javascript', BPM::TransportProcessor
31
+
32
+
33
+ # configure search paths
34
+ append_path File.join project_path, '.bpm', 'packages'
35
+ append_path File.dirname project_path
36
+ append_path File.join project_path, 'assets'
37
+ end
38
+
39
+ # Loads the passed JavaScript file and evals it. Used for loading
40
+ # transport and other plugins.
41
+ def js_context_for(path)
42
+ @js_contexts ||= {}
43
+ @js_contexts[path] ||= build_js_context(path)
44
+ end
45
+
46
+ # Returns an array of all the buildable assets in the current directory.
47
+ # These are the assets that will be built when you compile the project.
48
+ def buildable_assets
49
+
50
+ # make sure the logical_path can be used to simply build into the
51
+ # assets directory when we are done
52
+ ret = ['bpm_packages.js', 'bpm_styles.css']
53
+
54
+ project.local_deps.each do |pkg|
55
+ pkg.load_json
56
+ pkg.pipeline_assets.each do |dir|
57
+ dir_name = pkg.directories[dir] || dir
58
+ dir_name.sub! /^\.?\//, ''
59
+ pkg_root = File.join(pkg.root_path, dir_name)
60
+ Dir[File.join(pkg_root, '**', '*')].each do |fn|
61
+ fn.sub! /^#{Regexp.escape pkg_root}\//, ''
62
+ ret << File.join(pkg.name, dir_name, fn)
63
+ end
64
+ end
65
+ end
66
+
67
+ ret.sort.map { |x| find_asset x }.compact
68
+ end
69
+
70
+ # Detect whenever we are asked to build some of the magic files and swap
71
+ # in a custom asset type that can generate the contents.
72
+ def build_asset(logical_path, pathname, options)
73
+ magic_paths = %w(bpm_packages.js bpm_styles.css).map do |filename|
74
+ File.join project.root_path, 'assets', filename
75
+ end
76
+
77
+ if magic_paths.include? pathname.to_s
78
+ BPM::GeneratedAsset.new(self, logical_path, pathname, options)
79
+ else
80
+ super logical_path, pathname, options
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def build_js_context(path)
87
+ require 'v8'
88
+
89
+ ctx = V8::Context.new do |ctx|
90
+ ctx['exports'] = {}
91
+ ctx.eval "(function(exports) { #{File.read path} })(exports);"
92
+ end
93
+
94
+ @js_contexts[path] = ctx
95
+ end
96
+
97
+
98
+ end
99
+
100
+ end