ruby-dart2js 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/dart2js.rb +65 -22
- data/lib/dart2js_exceptions.rb +34 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8975f5f12c70378910a52d911d2ed746c684af68
|
4
|
+
data.tar.gz: a943e00afd8467cee2885bded0b32b597d9d41fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cb646a3b2b75f61f9477c6d76703ea1100bd0cb576053b4434929e1759fd1d469568539b0aed9389a514533b54f07e03e1a9296bd57ab590bf0df697476e2be
|
7
|
+
data.tar.gz: ae9137727ed687af98990ac5c0e8f549022333e1c9842e13adfbe46e4ec6dfbcb45ae6acc137fd4aff05d629d4b20191fd4b8626f9117ebe0b1766f7d6f5a742
|
data/README.md
CHANGED
data/lib/dart2js.rb
CHANGED
@@ -2,6 +2,8 @@ require 'tempfile'
|
|
2
2
|
require 'dart2js_exceptions'
|
3
3
|
|
4
4
|
class Dart2Js
|
5
|
+
include Dart2JsExceptions
|
6
|
+
|
5
7
|
class << self
|
6
8
|
attr_writer :dart2js_binary
|
7
9
|
|
@@ -11,7 +13,7 @@ class Dart2Js
|
|
11
13
|
|
12
14
|
private
|
13
15
|
def find_dart2js_in_path
|
14
|
-
system('dart2js
|
16
|
+
system('dart2js --version') ? 'dart2js' : false
|
15
17
|
end
|
16
18
|
|
17
19
|
def find_dart2js_in_sdk
|
@@ -22,49 +24,90 @@ class Dart2Js
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
attr_reader :data, :
|
26
|
-
attr_accessor :out_file, :out_dir, :dart2js_binary
|
27
|
+
attr_reader :data, :in_file, :result
|
28
|
+
attr_accessor :pwd, :out_file, :out_dir, :dart2js_binary
|
27
29
|
|
28
30
|
def initialize(file_or_data, options = {})
|
29
31
|
@dart2js_binary = options[:dart2js_binary] || self.class.dart2js_binary
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
|
33
|
+
if options[:out_file].is_a?(File)
|
34
|
+
@out_file = options[:out_file]
|
35
|
+
elsif options[:out_file]
|
36
|
+
@out_file = File.new(options[:out_file])
|
37
|
+
end
|
38
|
+
|
39
|
+
if options[:out_dir]
|
40
|
+
@out_dir = options[:out_dir]
|
41
|
+
@out_file ||= File.join(@out_dir, uniqe_tmpfile_name)
|
42
|
+
else
|
43
|
+
@out_file ||= Tempfile.open('dart2js_output')
|
44
|
+
end
|
45
|
+
|
46
|
+
if file_or_data.is_a?(File)
|
47
|
+
@in_file = file_or_data
|
48
|
+
elsif File.exist?(file_or_data)
|
49
|
+
@in_file = File.new(file_or_data)
|
38
50
|
else
|
39
51
|
@data = file_or_data
|
52
|
+
@pwd = options[:pwd]
|
40
53
|
end
|
41
54
|
end
|
42
55
|
|
43
|
-
def compile
|
56
|
+
def compile(minify = true)
|
57
|
+
prepare_input
|
58
|
+
prepare_output
|
44
59
|
cmd = [ @dart2js_binary,
|
45
|
-
minify ? ' -m '
|
46
|
-
%Q{-o"#{
|
47
|
-
|
60
|
+
minify ? ' -m ': nil,
|
61
|
+
%Q{-o"#{output_path}"},
|
62
|
+
input_path ].join(' ')
|
48
63
|
process = IO.popen(cmd, 'r')
|
49
64
|
@result = process.read
|
50
65
|
process.close
|
51
66
|
return_code = $?.to_i
|
52
|
-
return_code
|
67
|
+
if return_code != 0
|
68
|
+
raise CompilationException.new(self, cmd)
|
69
|
+
else
|
70
|
+
get_js_content
|
71
|
+
end
|
53
72
|
end
|
54
73
|
|
55
74
|
def get_js_content
|
56
75
|
File.read(@out_file)
|
57
76
|
end
|
58
77
|
|
78
|
+
def close
|
79
|
+
[@in_file, @out_file].each do |f|
|
80
|
+
f.close! if f.respond_to?(:close!)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
59
84
|
private
|
85
|
+
def input_path
|
86
|
+
@in_file.path
|
87
|
+
end
|
88
|
+
|
89
|
+
def output_path
|
90
|
+
@out_file.path
|
91
|
+
end
|
92
|
+
|
60
93
|
def prepare_input
|
61
94
|
if data
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
tmp_file
|
66
|
-
else
|
67
|
-
@input_file
|
95
|
+
@in_file = Tempfile.open('dart2js_input', @pwd)
|
96
|
+
@in_file.write data
|
97
|
+
@in_file.close
|
68
98
|
end
|
99
|
+
unless File.exists?(input_path)
|
100
|
+
raise PrepareInputException.new(self, "prepare_input ran but 'in_file' does not exist!")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def prepare_output
|
105
|
+
if !@out_file.is_a?(Tempfile) && File.exists?(output_path)
|
106
|
+
raise PrepareOutputException.new(self, "Won't overwrite existing file that is not a 'Tempfile''")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def uniqe_tmpfile_name(ext = 'js')
|
111
|
+
"dart2js_#{self.object_id}_#{Time.now.usec}.#{ext}"
|
69
112
|
end
|
70
113
|
end
|
data/lib/dart2js_exceptions.rb
CHANGED
@@ -1,12 +1,40 @@
|
|
1
1
|
module Dart2JsExceptions
|
2
|
-
class
|
3
|
-
|
2
|
+
class Dart2JsException < Exception
|
3
|
+
def initialize(compiler)
|
4
|
+
@instance = compiler
|
5
|
+
end
|
6
|
+
end
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
+
class CompilationException < Dart2JsException
|
9
|
+
def initialize(compiler, cmd)
|
10
|
+
super(compiler)
|
8
11
|
@cmd = cmd;
|
9
|
-
|
12
|
+
end
|
13
|
+
|
14
|
+
def message
|
15
|
+
"dart2js compilation '#{@cmd}' failed:\n #{@instance.result}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
class PrepareInputException < Dart2JsException
|
20
|
+
def initialize(compiler, reason)
|
21
|
+
super(compiler)
|
22
|
+
@reason = reason
|
23
|
+
end
|
24
|
+
|
25
|
+
def message
|
26
|
+
"dart2js prepare_input failed\n in_file: #{@instance.in_file}\n input_path: #{@instance.input_path}\n reason: #{@reason}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class PrepareOutputException < Dart2JsException
|
31
|
+
def initialize(compiler, reason)
|
32
|
+
super(compiler)
|
33
|
+
@reason = reason
|
34
|
+
end
|
35
|
+
|
36
|
+
def message
|
37
|
+
"dart2js prepare_output failed\n out_file: #{@instance.out_file}\n output_path: #{@instance.output_path}\n reason: #{@reason}"
|
10
38
|
end
|
11
39
|
end
|
12
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-dart2js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcel Sackermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email:
|
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
42
|
version: '0'
|
43
43
|
requirements: []
|
44
44
|
rubyforge_project:
|
45
|
-
rubygems_version: 2.
|
45
|
+
rubygems_version: 2.4.8
|
46
46
|
signing_key:
|
47
47
|
specification_version: 4
|
48
48
|
summary: Provides dart2js compiling for compatibility.
|