|
1 | 1 | require 'bundler'
|
2 | 2 | Bundler.require
|
3 | 3 |
|
4 |
| - |
5 |
| -desc "Build opal/opal/rspec/rspec.js" |
6 |
| -task :dist do |
7 |
| - File.open('opal/opal/rspec/rspec.js', 'w+') do |out| |
8 |
| - out << build_rspec |
9 |
| - end |
10 |
| -end |
11 |
| - |
12 |
| - |
13 | 4 | Bundler::GemHelper.install_tasks
|
14 |
| -task :build => :dist |
15 |
| - |
16 | 5 |
|
17 | 6 | require 'opal/rspec/rake_task'
|
18 | 7 | Opal::RSpec::RakeTask.new(:default)
|
19 |
| -task :default => :dist |
20 |
| - |
21 |
| - |
22 |
| -desc "Show dev/min sizes" |
23 |
| -task :sizes do |
24 |
| - code = build_rspec |
25 |
| - min = uglify code |
26 |
| - |
27 |
| - puts "\ndevelopment: #{code.size}, minified: #{min.size}" |
28 |
| -end |
29 |
| - |
30 |
| - |
31 |
| - |
32 |
| - |
33 |
| -def build_rspec |
34 |
| - Opal::Processor.dynamic_require_severity = :warning |
35 |
| - |
36 |
| - code = [] |
37 |
| - gems = %w(rspec rspec-core rspec-support rspec-expectations rspec-mocks) |
38 |
| - |
39 |
| - gems.each do |gem_name| |
40 |
| - spec = Gem::Specification.find_by_name gem_name |
41 |
| - gem_dir = File.join spec.gem_dir, 'lib' |
42 |
| - prefix = gem_dir + '/' |
43 |
| - |
44 |
| - Dir.glob(File.join(gem_dir, '**/*.rb')).each do |source| |
45 |
| - requirable = source.sub(prefix, '').sub(/\.rb$/, '') |
46 |
| - |
47 |
| - compiler = Opal::Compiler.new File.read(source), |
48 |
| - requirable: true, file: requirable, dynamic_require_severity: :warning |
49 |
| - |
50 |
| - code << compiler.compile |
51 |
| - end |
52 |
| - end |
53 |
| - |
54 |
| - stubs = %w(shellwords fileutils optparse) |
55 |
| - |
56 |
| - stubs.each do |stub| |
57 |
| - compiler = Opal::Compiler.new '', requirable: true, file: stub |
58 |
| - code << compiler.compile |
59 |
| - end |
60 |
| - |
61 |
| - code.join "\n" |
62 |
| -end |
63 |
| - |
64 |
| -def uglify(str) |
65 |
| - IO.popen('uglifyjs', 'r+') do |i| |
66 |
| - i.puts str |
67 |
| - i.close_write |
68 |
| - return i.read |
69 |
| - end |
70 |
| -rescue Errno::ENOENT |
71 |
| - $stderr.puts '"uglifyjs" command not found (install with: "npm install -g uglify-js")' |
72 |
| - nil |
73 |
| -end |
0 commit comments