typescript-node 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/typescript-node.rb +39 -1
- data/lib/typescript-node/version.rb +1 -1
- metadata +3 -3
data/lib/typescript-node.rb
CHANGED
@@ -8,10 +8,14 @@ module TypeScript
|
|
8
8
|
module Node
|
9
9
|
|
10
10
|
class << self
|
11
|
+
|
12
|
+
# Compile TypeScript source file.
|
13
|
+
# @param [String] source_file TypeScript source file
|
14
|
+
# @return [TypeScript::Node::CompileResult] compile result
|
11
15
|
def compile_file(source_file)
|
12
16
|
Dir.mktmpdir do |output_dir|
|
13
17
|
output_file = File.join(output_dir, "out.js")
|
14
|
-
cmd = [
|
18
|
+
cmd = [node, Src.tsc_path, "--out", output_file, source_file]
|
15
19
|
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
|
16
20
|
exit_status = wait_thr.value
|
17
21
|
output_js = File.exists?(output_file) ? File.read(output_file) : nil
|
@@ -25,6 +29,9 @@ module TypeScript
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
32
|
+
# Compile TypeScript to JavaScript.
|
33
|
+
# @param [String] source TypeScript to be compiled
|
34
|
+
# @return [String] Resulted JavaScript
|
28
35
|
def compile(source)
|
29
36
|
js_file = Tempfile.new(["typescript-node", ".ts"])
|
30
37
|
begin
|
@@ -40,6 +47,37 @@ module TypeScript
|
|
40
47
|
js_file.unlink
|
41
48
|
end
|
42
49
|
end
|
50
|
+
|
51
|
+
# node command
|
52
|
+
# TS_NODE environmental variable is used when it is set.
|
53
|
+
def node
|
54
|
+
ENV["TS_NODE"] || "node"
|
55
|
+
end
|
56
|
+
|
57
|
+
def locate_executable(cmd)
|
58
|
+
if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ && File.extname(cmd) == ""
|
59
|
+
cmd << ".exe"
|
60
|
+
end
|
61
|
+
|
62
|
+
if File.executable? cmd
|
63
|
+
cmd
|
64
|
+
else
|
65
|
+
path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p|
|
66
|
+
full_path = File.join(p, cmd)
|
67
|
+
File.executable?(full_path) && File.file?(full_path)
|
68
|
+
}
|
69
|
+
path && File.expand_path(cmd, path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def check_node
|
74
|
+
unless locate_executable(self.node)
|
75
|
+
raise "typescript-node requires node command, but it's not found. Please install it. " +
|
76
|
+
"Set TS_NODE environmental variable If you want to use node command in non-standard path."
|
77
|
+
end
|
78
|
+
end
|
43
79
|
end
|
44
80
|
end
|
45
81
|
end
|
82
|
+
|
83
|
+
TypeScript::Node.check_node
|
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: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -60,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version: '0'
|
61
61
|
segments:
|
62
62
|
- 0
|
63
|
-
hash:
|
63
|
+
hash: 3347903559548868122
|
64
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
segments:
|
71
71
|
- 0
|
72
|
-
hash:
|
72
|
+
hash: 3347903559548868122
|
73
73
|
requirements: []
|
74
74
|
rubyforge_project:
|
75
75
|
rubygems_version: 1.8.24
|