bpm 1.0.0.beta.13 → 1.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +35 -1
- data/README.md +1 -1
- data/bin/bpm +18 -1
- data/bpm.gemspec +3 -3
- data/lib/bpm.rb +34 -1
- data/lib/bpm/cli/base.rb +32 -44
- data/lib/bpm/errors.rb +15 -3
- data/lib/bpm/execjs_ext.rb +99 -0
- data/lib/bpm/local.rb +1 -1
- data/lib/bpm/package.rb +53 -51
- data/lib/bpm/pipeline.rb +21 -14
- data/lib/bpm/pipeline/directive_processor.rb +9 -0
- data/lib/bpm/pipeline/generated_asset.rb +59 -13
- data/lib/bpm/pipeline/package_pipeline.rb +2 -2
- data/lib/bpm/pipeline/plugin_asset.rb +1 -1
- data/lib/bpm/pipeline/plugin_context.rb +12 -2
- data/lib/bpm/pipeline/plugin_processor.rb +27 -4
- data/lib/bpm/project.rb +171 -139
- data/lib/bpm/server.rb +14 -9
- data/lib/bpm/version.rb +1 -1
- data/man/{bpm-compile.1.ronn → bpm-rebuild.1.ronn} +0 -0
- data/man/bpm.1.ronn +112 -9
- data/spec/cli/add_spec.rb +15 -6
- data/spec/cli/init_spec.rb +7 -7
- data/spec/cli/pack_spec.rb +13 -8
- data/spec/cli/preview_spec.rb +10 -0
- data/spec/cli/rebuild_spec.rb +5 -5
- data/spec/cli/remove_spec.rb +1 -1
- data/spec/fixtures/gems/core-test-0.4.9.bpkg +0 -0
- data/spec/fixtures/packages/backbone/package.json +2 -2
- data/spec/fixtures/packages/core-test/package.json +1 -1
- data/spec/fixtures/projects/coffee/coffee.json +4 -4
- data/spec/fixtures/projects/coffee/{packages → vendor}/coffee-script/compiler.js +0 -0
- data/spec/fixtures/projects/coffee/{packages → vendor}/coffee-script/lib/main.js +0 -0
- data/spec/fixtures/projects/coffee/{packages → vendor}/coffee-script/package.json +0 -0
- data/spec/fixtures/projects/coffee/{packages/handlebars → vendor/handlebars-format}/format.js +0 -0
- data/spec/fixtures/projects/coffee/{packages/handlebars → vendor/handlebars-format}/lib/main.js +0 -0
- data/spec/fixtures/projects/coffee/{packages/handlebars → vendor/handlebars-format}/package.json +2 -2
- data/spec/fixtures/projects/coffee/vendor/handlebars/package.json +15 -0
- data/spec/fixtures/projects/coffee/vendor/spade-coffee/package.json +15 -0
- data/spec/fixtures/projects/coffee/vendor/spade-handlebars/package.json +15 -0
- data/spec/fixtures/projects/coffee/vendor/spade/lib/main.js +1 -0
- data/spec/fixtures/projects/coffee/{packages → vendor}/spade/package.json +0 -0
- data/spec/fixtures/projects/coffee/{packages → vendor}/spade/transport.js +0 -0
- data/spec/fixtures/projects/hello2/{packages → vendor}/a/lib/main.js +0 -0
- data/spec/fixtures/projects/hello2/{packages → vendor}/a/package.json +0 -0
- data/spec/fixtures/projects/hello2/{packages → vendor}/b/lib/main.js +0 -0
- data/spec/fixtures/projects/hello2/{packages → vendor}/b/package.json +0 -0
- data/spec/fixtures/projects/hello2/{packages → vendor}/c/lib/main.js +0 -0
- data/spec/fixtures/projects/hello2/{packages → vendor}/c/package.json +0 -0
- data/spec/fixtures/projects/hello_dev/{packages → vendor}/style_package/css/some_style.css +0 -0
- data/spec/fixtures/projects/hello_dev/{packages → vendor}/style_package/package.json +0 -0
- data/spec/fixtures/projects/hello_world/another/one.js +1 -0
- data/spec/fixtures/projects/hello_world/another/two.js +1 -0
- data/spec/fixtures/projects/hello_world/hello_world.json +6 -5
- data/spec/fixtures/projects/hello_world/lib2/something.js +1 -0
- data/spec/fixtures/projects/hello_world/{packages → vendor}/custom_package/assets/dummy.txt +0 -0
- data/spec/fixtures/projects/hello_world/{packages → vendor}/custom_package/css/sample_styles.css +0 -0
- data/spec/fixtures/projects/hello_world/{packages → vendor}/custom_package/custom_dir/basic-module.js +0 -0
- data/spec/fixtures/projects/hello_world/{packages → vendor}/custom_package/lib/main.js +0 -0
- data/spec/fixtures/projects/hello_world/{packages → vendor}/custom_package/package.json +1 -1
- data/spec/fixtures/projects/hello_world/vendor/prerelease_package/package.json +4 -0
- data/spec/fixtures/projects/init_app/new_project.json +3 -3
- data/spec/fixtures/projects/init_default/new_project.json +2 -2
- data/spec/fixtures/projects/minitest/minitest.json +1 -1
- data/spec/fixtures/projects/minitest/{packages → vendor}/uglyduck/lib/main.js +0 -0
- data/spec/fixtures/projects/minitest/{packages → vendor}/uglyduck/minifier/main.js +0 -0
- data/spec/fixtures/projects/minitest/{packages → vendor}/uglyduck/package.json +0 -0
- data/spec/fixtures/projects/minitrans/minitrans.json +1 -1
- data/spec/fixtures/projects/minitrans/{packages → vendor}/transport/lib/main.js +0 -0
- data/spec/fixtures/projects/minitrans/{packages → vendor}/transport/package.json +0 -0
- data/spec/fixtures/projects/minitrans/{packages → vendor}/transport/transports/wrapper.js +0 -0
- data/spec/fixtures/projects/minitrans/{packages → vendor}/uglyduck/lib/main.js +0 -0
- data/spec/fixtures/projects/minitrans/{packages → vendor}/uglyduck/minifier/main.js +0 -0
- data/spec/fixtures/projects/minitrans/{packages → vendor}/uglyduck/package.json +0 -0
- data/spec/fixtures/projects/transporter/{packages → vendor}/transport/lib/main.js +0 -0
- data/spec/fixtures/projects/transporter/{packages → vendor}/transport/package.json +0 -0
- data/spec/fixtures/projects/transporter/{packages → vendor}/transport/transports/wrapper.js +0 -0
- data/spec/package_pipeline_spec.rb +8 -5
- data/spec/package_spec.rb +31 -26
- data/spec/pipeline_spec.rb +72 -64
- data/spec/plugins/format_spec.rb +7 -7
- data/spec/project_spec.rb +6 -5
- data/spec/spec_helper.rb +5 -4
- data/spec/support/cli.rb +9 -7
- data/spec/support/env.rb +7 -4
- data/spec/support/path.rb +1 -0
- data/support/es5-shim.js +935 -0
- data/templates/init/project.json +2 -3
- metadata +112 -97
- data/lib/bpm/pipeline/transport_processor.rb +0 -34
- data/spec/fixtures/projects/coffee/packages/spade/lib/main.js +0 -1
- data/spec/fixtures/projects/hello_world/vendor/lib/something.js +0 -1
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
# 1.0.0.beta.14
|
2
|
+
|
3
|
+
* Switched from therubyracer to execjs, should provide Windows support
|
4
|
+
* Don't blow up when encountering invalid vendored packages
|
5
|
+
* Better error handling for CLI
|
6
|
+
* Added flag for easier debugging
|
7
|
+
* Allow packages to be put in vendor directory - Fixes #14
|
8
|
+
* Cleanup Package fields
|
9
|
+
* Allow packages to be developed in directories without matching names
|
10
|
+
* Fix prerelease flag for local packages - Fixes #16
|
11
|
+
* Bpm Init no longer changes folder name - Fixes #13
|
12
|
+
* Patched Sprockets directive bug
|
13
|
+
|
14
|
+
# 1.0.0.beta.13
|
15
|
+
|
16
|
+
* Updated to latest LibGems with bug fixes
|
17
|
+
* Improved error messages
|
18
|
+
|
19
|
+
# 1.0.0.beta.12
|
20
|
+
|
21
|
+
* Updated to Rack 1.3.2
|
22
|
+
* Removed old references to bpm:formats
|
23
|
+
* Added wiki link
|
24
|
+
|
25
|
+
# 1.0.0.beta.11
|
26
|
+
|
27
|
+
* Moved JSON transport and minifiers into bpm:provides
|
28
|
+
* Documentation updates and fixes - Fixes #3
|
29
|
+
* Updated options and fixed tests
|
30
|
+
|
31
|
+
# 1.0.0.beta.10
|
32
|
+
|
33
|
+
* Updated documentation
|
34
|
+
* Switched to GetBPM.org
|
1
35
|
|
2
36
|
# 1.0.0.beta.9
|
3
37
|
|
@@ -68,4 +102,4 @@ New format for defining a format or transport plugin:
|
|
68
102
|
# 1.0.0.beta.3.pre
|
69
103
|
|
70
104
|
* started changelog
|
71
|
-
|
105
|
+
|
data/README.md
CHANGED
data/bin/bpm
CHANGED
@@ -4,5 +4,22 @@ $:.unshift(lib) if File.exists?(lib)
|
|
4
4
|
|
5
5
|
require 'bpm'
|
6
6
|
|
7
|
-
|
7
|
+
begin
|
8
|
+
BPM::CLI::Base.start
|
9
|
+
rescue BPM::Error => e
|
10
|
+
raise e if ENV['DEBUG']
|
11
|
+
warn e.message
|
12
|
+
exit false
|
13
|
+
rescue Interrupt => e
|
14
|
+
raise e if ENV['DEBUG']
|
15
|
+
puts "\nQuitting..."
|
16
|
+
exit false
|
17
|
+
rescue SystemExit => e
|
18
|
+
exit e.status
|
19
|
+
rescue Exception => e
|
20
|
+
warn "Unfortunately, a fatal error has occurred. " +
|
21
|
+
"Please report this error to the BPM issue tracker at " +
|
22
|
+
"https://github.com/bpm/bpm/issues so that we can fix it. Thanks!"
|
23
|
+
raise e
|
24
|
+
end
|
8
25
|
|
data/bpm.gemspec
CHANGED
@@ -16,13 +16,13 @@ Gem::Specification.new do |s|
|
|
16
16
|
mswin = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
|
17
17
|
mri = !mswin && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby")
|
18
18
|
|
19
|
-
s.add_dependency "libgems", "~> 0.1.
|
19
|
+
s.add_dependency "libgems", "~> 0.1.3"
|
20
20
|
s.add_dependency "gemcutter", "~> 0.6.1"
|
21
21
|
s.add_dependency "highline", "~> 1.6.1"
|
22
22
|
s.add_dependency "json_pure", "~> 1.4.6"
|
23
23
|
s.add_dependency "thor", "~> 0.14.3"
|
24
|
-
s.add_dependency "
|
25
|
-
s.add_dependency "sprockets", "~> 2.0.0
|
24
|
+
s.add_dependency "execjs", "~> 1.2.4"
|
25
|
+
s.add_dependency "sprockets", "~> 2.0.0"
|
26
26
|
|
27
27
|
s.add_development_dependency "rspec"
|
28
28
|
s.add_development_dependency "rack", "~> 1.3.2"
|
data/lib/bpm.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
Encoding.default_external = 'UTF-8'
|
2
|
+
|
1
3
|
module BPM
|
2
4
|
BPM_DIR = ".bpm"
|
3
5
|
TEMPLATES_DIR = File.expand_path("../../templates", __FILE__)
|
6
|
+
ES5_SHIM_PATH = File.expand_path("../../support/es5-shim.js", __FILE__)
|
4
7
|
|
5
8
|
autoload :CLI, 'bpm/cli'
|
6
9
|
autoload :Credentials, 'bpm/credentials'
|
@@ -18,7 +21,37 @@ module BPM
|
|
18
21
|
autoload :PluginContext, 'bpm/pipeline/plugin_context'
|
19
22
|
autoload :PackagePipeline, 'bpm/pipeline/package_pipeline'
|
20
23
|
autoload :FormatProcessor, 'bpm/pipeline/format_processor'
|
21
|
-
autoload :PluginProcessor,
|
24
|
+
autoload :PluginProcessor, 'bpm/pipeline/plugin_processor'
|
25
|
+
|
26
|
+
def self.compile_js(data)
|
27
|
+
require 'bpm/execjs_ext'
|
28
|
+
@es5_shim ||= File.read(ES5_SHIM_PATH)
|
29
|
+
ExecJS.compile(@es5_shim+"\n"+data)
|
30
|
+
end
|
31
|
+
|
32
|
+
@@show_deprecations = false
|
33
|
+
@@deprecation_count = 0
|
34
|
+
|
35
|
+
def self.show_deprecations
|
36
|
+
@@show_deprecations
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.show_deprecations=(val)
|
40
|
+
@@show_deprecations = val
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.deprecation_count
|
44
|
+
@@deprecation_count
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.deprecation_warning(message)
|
48
|
+
if show_deprecations
|
49
|
+
warn "[DEPRECATION] #{message}"
|
50
|
+
else
|
51
|
+
@@deprecation_count += 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
22
55
|
end
|
23
56
|
|
24
57
|
# The BPM constants need to be defined first
|
data/lib/bpm/cli/base.rb
CHANGED
@@ -16,7 +16,19 @@ module BPM
|
|
16
16
|
shell.say "\nbpm (v#{BPM::VERSION}) - the browser package manager\n\n"
|
17
17
|
super shell, subcommand
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
|
+
def self.start(given_args=ARGV, config={})
|
21
|
+
if given_args.include?('--verbose') || given_args.include?('-V')
|
22
|
+
BPM.show_deprecations = true
|
23
|
+
end
|
24
|
+
|
25
|
+
super
|
26
|
+
|
27
|
+
if BPM.deprecation_count > 0
|
28
|
+
puts "[WARN] #{BPM.deprecation_count} deprecation warnings were hidden. Run with --verbose to see them."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
20
32
|
desc "owner", "Manage users for a package"
|
21
33
|
subcommand "owner", BPM::CLI::Owner
|
22
34
|
|
@@ -44,11 +56,11 @@ module BPM
|
|
44
56
|
end
|
45
57
|
end
|
46
58
|
rescue LibGems::InstallError => e
|
47
|
-
|
59
|
+
raise BPM::Error.new("Fetch error: #{e}")
|
48
60
|
rescue LibGems::GemNotFoundException => e
|
49
61
|
abort "Can't find package #{e.name} #{e.version} available for fetch"
|
50
62
|
rescue Errno::EACCES, LibGems::FilePermissionError => e
|
51
|
-
|
63
|
+
raise BPM::Error.new(e.message)
|
52
64
|
end
|
53
65
|
end
|
54
66
|
end
|
@@ -78,7 +90,7 @@ module BPM
|
|
78
90
|
|
79
91
|
deps = {}
|
80
92
|
package_names.each do |name|
|
81
|
-
vers = options[:version] || (options[:prerelease] ? '>= 0
|
93
|
+
vers = options[:version] || (options[:prerelease] ? '>= 0.pre' : '>= 0')
|
82
94
|
if name =~ /^(.+?)(-(\d[\w\.]*))?\.bpkg$/
|
83
95
|
name = $1
|
84
96
|
vers = $3 if $3
|
@@ -90,12 +102,8 @@ module BPM
|
|
90
102
|
# find project
|
91
103
|
project = find_project
|
92
104
|
|
93
|
-
|
94
|
-
|
95
|
-
project.build options[:mode], true
|
96
|
-
rescue BPM::Error => e
|
97
|
-
abort e.message
|
98
|
-
end
|
105
|
+
project.add_dependencies deps, options[:development], true
|
106
|
+
project.build options[:mode], true
|
99
107
|
end
|
100
108
|
|
101
109
|
desc "remove [PACKAGE]", "Remove one or more packages from a bpm project"
|
@@ -108,14 +116,10 @@ module BPM
|
|
108
116
|
abort "You must specify at least one package"
|
109
117
|
end
|
110
118
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
project.build options[:mode], true
|
116
|
-
rescue BPM::Error => e
|
117
|
-
abort e.message
|
118
|
-
end
|
119
|
+
project = find_project
|
120
|
+
project.unbuild options[:verbose]
|
121
|
+
project.remove_dependencies package_names, true
|
122
|
+
project.build options[:mode], true
|
119
123
|
end
|
120
124
|
|
121
125
|
desc "preview", "Preview server that will autocompile assets as you request them. Useful for hacking"
|
@@ -127,7 +131,7 @@ module BPM
|
|
127
131
|
project.verify_and_repair options[:mode], options[:verbose]
|
128
132
|
BPM::Server.start project, :Port => options[:port], :mode => options[:mode].to_sym
|
129
133
|
end
|
130
|
-
|
134
|
+
|
131
135
|
desc "rebuild", "Rebuilds bpm assets, does not update versions"
|
132
136
|
method_option :mode, :type => :string, :default => :production, :aliases => ['-m'], :desc => 'Build mode for compile'
|
133
137
|
method_option :project, :type => :string, :default => nil, :aliases => ['-p'], :desc => 'Specify project location other than working directory'
|
@@ -135,10 +139,8 @@ module BPM
|
|
135
139
|
def rebuild
|
136
140
|
find_project.fetch_dependencies(true) if options[:update]
|
137
141
|
find_project.build options[:mode].to_sym, true
|
138
|
-
rescue BPM::Error => e
|
139
|
-
abort e.message
|
140
142
|
end
|
141
|
-
|
143
|
+
|
142
144
|
desc "login", "Log in with your BPM credentials"
|
143
145
|
method_option :username, :type => :string, :default => nil, :aliases => ['-u'], :desc => 'Specify the username to login as'
|
144
146
|
method_option :password, :type => :string, :default => nil, :aliases => ['-p'], :desc => 'Specify the login password'
|
@@ -224,7 +226,7 @@ module BPM
|
|
224
226
|
packages = nil if packages.size == 0
|
225
227
|
project = find_project
|
226
228
|
project.verify_and_repair
|
227
|
-
|
229
|
+
|
228
230
|
deps = options[:development] ? project.sorted_development_deps : project.sorted_runtime_deps
|
229
231
|
deps.each do |dep|
|
230
232
|
next if packages && !packages.include?(dep.name)
|
@@ -249,11 +251,11 @@ module BPM
|
|
249
251
|
paths.each do |path|
|
250
252
|
name = options[:name] || File.basename(path)
|
251
253
|
|
252
|
-
# if someone specified both a name and path assume they meant
|
253
|
-
# exactly what they said
|
254
|
+
# if someone specified both a name and path assume they meant
|
255
|
+
# exactly what they said
|
254
256
|
if name == File.basename(path)
|
255
|
-
|
256
|
-
path =
|
257
|
+
new_path = File.join(File.dirname(path), File.basename(path))
|
258
|
+
path = new_path if !File.directory?(path)
|
257
259
|
end
|
258
260
|
|
259
261
|
if File.directory?(path)
|
@@ -266,11 +268,7 @@ module BPM
|
|
266
268
|
success = generator.new(self, name, path, template_path, package).run
|
267
269
|
run_init(name, true, path, package) if success
|
268
270
|
end
|
269
|
-
|
270
271
|
end
|
271
|
-
|
272
|
-
rescue BPM::Error => e
|
273
|
-
abort e.message
|
274
272
|
end
|
275
273
|
|
276
274
|
desc "pack [PACKAGE]", "Build a bpm package from a package.json"
|
@@ -289,8 +287,6 @@ module BPM
|
|
289
287
|
end
|
290
288
|
abort failure_message
|
291
289
|
end
|
292
|
-
rescue BPM::Error => e
|
293
|
-
abort e.message
|
294
290
|
end
|
295
291
|
|
296
292
|
desc "unpack [PACKAGE]", "Extract files from a bpm package"
|
@@ -334,7 +330,7 @@ module BPM
|
|
334
330
|
|
335
331
|
def run_init(name, include_app, path, package=nil)
|
336
332
|
|
337
|
-
# we only need to create a new project.json if one does not
|
333
|
+
# we only need to create a new project.json if one does not
|
338
334
|
# already exist.
|
339
335
|
unless BPM::Project.is_project_root? path
|
340
336
|
template_path = package ? package.template_path(:init) : nil
|
@@ -379,10 +375,10 @@ module BPM
|
|
379
375
|
abort "You do not appear to be inside of a bpm project"
|
380
376
|
end
|
381
377
|
end
|
382
|
-
|
378
|
+
|
383
379
|
project
|
384
380
|
end
|
385
|
-
|
381
|
+
|
386
382
|
def print_specs(names, index)
|
387
383
|
packages = {}
|
388
384
|
|
@@ -414,14 +410,6 @@ module BPM
|
|
414
410
|
BPM::Package.from_spec(spec)
|
415
411
|
end
|
416
412
|
|
417
|
-
def underscore(str)
|
418
|
-
str.gsub(/::/, '/').
|
419
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
420
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
421
|
-
tr("-", "_").
|
422
|
-
downcase
|
423
|
-
end
|
424
|
-
|
425
413
|
end
|
426
414
|
end
|
427
415
|
end
|
data/lib/bpm/errors.rb
CHANGED
@@ -14,11 +14,16 @@ module BPM
|
|
14
14
|
class InvalidPackageError < BPM::Error
|
15
15
|
def format_message(package, msg=nil)
|
16
16
|
msg = msg.nil? ? '' : ": #{msg}"
|
17
|
-
|
17
|
+
path = begin
|
18
|
+
Pathname.new(package.json_path).relative_path_from(Pathname.new(Dir.pwd))
|
19
|
+
rescue
|
20
|
+
package.json_path
|
21
|
+
end
|
22
|
+
"There was a problem parsing #{path}#{msg}"
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
|
-
class
|
26
|
+
class InvalidPackagePathError < BPM::InvalidPackageError
|
22
27
|
def format_message(package)
|
23
28
|
"Package at #{package.root_path} name and directory do not match. (name: #{package.name}). Change the directory or package.json name to match."
|
24
29
|
end
|
@@ -55,5 +60,12 @@ module BPM
|
|
55
60
|
EOF
|
56
61
|
end
|
57
62
|
end
|
58
|
-
|
63
|
+
|
64
|
+
class CircularDependencyError < BPM::Error
|
65
|
+
def initialize(original)
|
66
|
+
set_backtrace(original.backtrace)
|
67
|
+
super(original.message)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
59
71
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'execjs'
|
2
|
+
|
3
|
+
# The following is backported from ExecJS master (post 1.2.4)
|
4
|
+
# Once 1.2.5 is released, we can remove this
|
5
|
+
|
6
|
+
module ExecJS
|
7
|
+
class ExternalRuntime
|
8
|
+
def initialize(options)
|
9
|
+
@name = options[:name]
|
10
|
+
@command = options[:command]
|
11
|
+
@runner_path = options[:runner_path]
|
12
|
+
@test_args = options[:test_args]
|
13
|
+
@test_match = options[:test_match]
|
14
|
+
@encoding = options[:encoding]
|
15
|
+
@binary = locate_binary
|
16
|
+
end
|
17
|
+
|
18
|
+
def exec_runtime(filename)
|
19
|
+
output = sh("#{@binary} #{filename} 2>&1")
|
20
|
+
if $?.success?
|
21
|
+
output
|
22
|
+
else
|
23
|
+
raise RuntimeError, output
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def which(command)
|
30
|
+
Array(command).each do |name|
|
31
|
+
name, args = name.split(/\s+/, 2)
|
32
|
+
result = if ExecJS.windows?
|
33
|
+
`"#{ExecJS.root}/support/which.bat" #{name}`
|
34
|
+
else
|
35
|
+
`command -v #{name} 2>/dev/null`
|
36
|
+
end
|
37
|
+
|
38
|
+
if path = result.strip.split("\n").first
|
39
|
+
return args ? "#{path} #{args}" : path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
if "".respond_to?(:force_encoding)
|
46
|
+
def sh(command)
|
47
|
+
output, options = nil, {}
|
48
|
+
options[:internal_encoding] = 'UTF-8'
|
49
|
+
options[:external_encoding] = @encoding if @encoding
|
50
|
+
IO.popen(command, options) { |f| output = f.read }
|
51
|
+
output
|
52
|
+
end
|
53
|
+
else
|
54
|
+
require "iconv"
|
55
|
+
|
56
|
+
def sh(command)
|
57
|
+
output = nil
|
58
|
+
IO.popen(command) { |f| output = f.read }
|
59
|
+
|
60
|
+
if @encoding
|
61
|
+
Iconv.new('UTF-8', @encoding).iconv(output)
|
62
|
+
else
|
63
|
+
output
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module Runtimes
|
70
|
+
remove_const :JavaScriptCore
|
71
|
+
JavaScriptCore = ExternalRuntime.new(
|
72
|
+
:name => "JavaScriptCore",
|
73
|
+
:command => ["/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc", "jsc"],
|
74
|
+
:runner_path => ExecJS.root + "/support/jsc_runner.js"
|
75
|
+
)
|
76
|
+
|
77
|
+
remove_const :JScript
|
78
|
+
JScript = ExternalRuntime.new(
|
79
|
+
:name => "JScript",
|
80
|
+
:command => "cscript //E:jscript //Nologo //U",
|
81
|
+
:runner_path => ExecJS.root + "/support/jscript_runner.js",
|
82
|
+
:encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
|
83
|
+
)
|
84
|
+
|
85
|
+
instance_variable_set(:@runtimes, [
|
86
|
+
RubyRacer,
|
87
|
+
RubyRhino,
|
88
|
+
Johnson,
|
89
|
+
Mustang,
|
90
|
+
Node,
|
91
|
+
JavaScriptCore,
|
92
|
+
SpiderMonkey,
|
93
|
+
JScript
|
94
|
+
])
|
95
|
+
end
|
96
|
+
|
97
|
+
self.runtime = Runtimes.autodetect
|
98
|
+
|
99
|
+
end
|