typescript-node 1.0.0 → 1.1.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/.travis.yml +3 -13
- data/CHANGES.md +5 -0
- data/README.md +2 -3
- data/lib/typescript-node.rb +22 -15
- data/lib/typescript-node/version.rb +1 -1
- data/test/data/es5.ts +19 -0
- data/test/test_typescript-node.rb +15 -0
- data/typescript-node.gemspec +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce6af8b1e3c9570a286f6f1f314e5555f12750d4
|
|
4
|
+
data.tar.gz: cd729825096bd4721f6321313a10378532716219
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc8a3325a12473151713c1517c9a970f639221ccbc62043079fe981f3c9d6256d854e5c13c3359fd9fa97d5e20d2a241e54a2b277df22b53019b8dd3a262c3ad
|
|
7
|
+
data.tar.gz: 46e6209b9086ca589f14d83f342790167cc6e51f20749d95cacdefbf0b2727cd7ac0d7d1b26dc10c9ea2941143845c3c750255f9b158367c82c7a24232983b9b
|
data/.travis.yml
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
language: ruby
|
|
2
2
|
rvm:
|
|
3
|
-
- 1.8.7
|
|
4
3
|
- 1.9.3
|
|
5
|
-
- 1.9.2
|
|
6
4
|
- 2.0.0
|
|
7
|
-
- 2.1.
|
|
8
|
-
- rbx-2
|
|
9
|
-
- jruby-18mode
|
|
5
|
+
- 2.1.1
|
|
6
|
+
- rbx-2
|
|
10
7
|
- jruby-19mode
|
|
11
|
-
|
|
12
|
-
script: bundle exec rspec
|
|
13
|
-
matrix:
|
|
14
|
-
allow_failures:
|
|
15
|
-
- rvm: 1.8.7
|
|
16
|
-
- rvm: jruby-18mode
|
|
17
|
-
- rvm: jruby-19mode
|
|
18
|
-
- rvm: ree
|
|
8
|
+
script: bundle exec rake test
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
|
@@ -25,17 +25,16 @@ require 'typescript-node'
|
|
|
25
25
|
TypeScript::Node.check_node
|
|
26
26
|
|
|
27
27
|
# compiles a TypeScript source file and returns TypeScript::Node::CompileResult
|
|
28
|
-
result = TypeScript::Node.compile_file(file)
|
|
28
|
+
result = TypeScript::Node.compile_file(file, '--target', 'ES5')
|
|
29
29
|
result.success? # => true if succeeded
|
|
30
30
|
result.js # => output JavaScript source code
|
|
31
31
|
result.stdout # => what tsc(1) shows to stdout
|
|
32
32
|
result.stderr # => what tsc(1) shows to stderr
|
|
33
33
|
|
|
34
34
|
# compiles a TypeScript source code string and returns String
|
|
35
|
-
js_source = TypeScript::Node.compile_file(ts_source)
|
|
35
|
+
js_source = TypeScript::Node.compile_file(ts_source, '--target', 'ES5')
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
|
|
39
38
|
## Contributing
|
|
40
39
|
|
|
41
40
|
1. Fork it
|
data/lib/typescript-node.rb
CHANGED
|
@@ -13,35 +13,42 @@ module TypeScript
|
|
|
13
13
|
TypeScript::Src.version
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
def tsc(*args)
|
|
18
|
+
cmd = [node, Src.tsc_path.to_s, *args]
|
|
19
|
+
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
|
|
20
|
+
stdin.close
|
|
21
|
+
[wait_thr.value, stdout.read, stderr.read]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
16
25
|
# Compile TypeScript source file.
|
|
17
26
|
# @param [String] source_file TypeScript source file
|
|
18
27
|
# @return [TypeScript::Node::CompileResult] compile result
|
|
19
|
-
def compile_file(source_file)
|
|
28
|
+
def compile_file(source_file, *tsc_options)
|
|
20
29
|
Dir.mktmpdir do |output_dir|
|
|
21
30
|
output_file = File.join(output_dir, "out.js")
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
)
|
|
32
|
-
end
|
|
31
|
+
exit_status, stdout, stderr = tsc(*tsc_options, '--out', output_file, source_file)
|
|
32
|
+
|
|
33
|
+
output_js = File.exists?(output_file) ? File.read(output_file) : nil
|
|
34
|
+
CompileResult.new(
|
|
35
|
+
output_js,
|
|
36
|
+
exit_status,
|
|
37
|
+
stdout,
|
|
38
|
+
stderr,
|
|
39
|
+
)
|
|
33
40
|
end
|
|
34
41
|
end
|
|
35
42
|
|
|
36
43
|
# Compile TypeScript to JavaScript.
|
|
37
44
|
# @param [String] source TypeScript to be compiled
|
|
38
45
|
# @return [String] Resulted JavaScript
|
|
39
|
-
def compile(source)
|
|
46
|
+
def compile(source, *tsc_options)
|
|
40
47
|
js_file = Tempfile.new(["typescript-node", ".ts"])
|
|
41
48
|
begin
|
|
42
49
|
js_file.write(source)
|
|
43
50
|
js_file.close
|
|
44
|
-
result = compile_file(js_file.path)
|
|
51
|
+
result = compile_file(js_file.path, *tsc_options)
|
|
45
52
|
if result.success?
|
|
46
53
|
result.js
|
|
47
54
|
else
|
|
@@ -77,7 +84,7 @@ module TypeScript
|
|
|
77
84
|
def check_node
|
|
78
85
|
unless locate_executable(node)
|
|
79
86
|
raise "typescript-node requires node command, but it's not found. Please install it. " +
|
|
80
|
-
|
|
87
|
+
"Set TS_NODE environmental variable If you want to use node command in non-standard path."
|
|
81
88
|
end
|
|
82
89
|
end
|
|
83
90
|
end
|
data/test/data/es5.ts
ADDED
|
@@ -32,10 +32,25 @@ class TestTypeScriptNode < Test::Unit::TestCase
|
|
|
32
32
|
assert { subject.stderr != '' }
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
def test_compile_file_with_es5
|
|
36
|
+
file = File.expand_path('data/es5.ts', File.dirname(__FILE__))
|
|
37
|
+
subject = TypeScript::Node.compile_file(file, '--target', 'ES5')
|
|
38
|
+
|
|
39
|
+
assert { subject.success? }
|
|
40
|
+
end
|
|
41
|
+
|
|
35
42
|
def test_compile
|
|
36
43
|
subject = TypeScript::Node.compile('class T { say() { console.log("Hello, world!") } }')
|
|
37
44
|
|
|
38
45
|
assert { subject != '' }
|
|
39
46
|
assert { subject != nil }
|
|
40
47
|
end
|
|
48
|
+
|
|
49
|
+
def test_compile_with_es5
|
|
50
|
+
subject = TypeScript::Node.compile('class T { get name() { return "foo" } }', '--target', 'ES5')
|
|
51
|
+
|
|
52
|
+
assert { subject != '' }
|
|
53
|
+
assert { subject != nil }
|
|
54
|
+
end
|
|
55
|
+
|
|
41
56
|
end
|
data/typescript-node.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: typescript-node
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- KAWACHI Takashi
|
|
@@ -56,6 +56,7 @@ files:
|
|
|
56
56
|
- lib/typescript-node/compile_result.rb
|
|
57
57
|
- lib/typescript-node/version.rb
|
|
58
58
|
- test/data/bad.ts
|
|
59
|
+
- test/data/es5.ts
|
|
59
60
|
- test/data/hello.ts
|
|
60
61
|
- test/test_typescript-node.rb
|
|
61
62
|
- typescript-node.gemspec
|
|
@@ -70,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
70
71
|
requirements:
|
|
71
72
|
- - ">="
|
|
72
73
|
- !ruby/object:Gem::Version
|
|
73
|
-
version:
|
|
74
|
+
version: 1.9.3
|
|
74
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
76
|
requirements:
|
|
76
77
|
- - ">="
|
|
@@ -84,5 +85,6 @@ specification_version: 4
|
|
|
84
85
|
summary: TypeScript ruby interface using Node.js
|
|
85
86
|
test_files:
|
|
86
87
|
- test/data/bad.ts
|
|
88
|
+
- test/data/es5.ts
|
|
87
89
|
- test/data/hello.ts
|
|
88
90
|
- test/test_typescript-node.rb
|