tsc-ruby 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tsc-ruby.rb +11 -9
- data/lib/tsc-ruby/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d301484bc34fd67282b5e6129557d4e762a72d
|
4
|
+
data.tar.gz: 848471b0a2d0098e57b90285f47dbba303381952
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d2926b4e0e6279a11bc757745c83fa7d67fe5e88f8248549463fd7a33c23dafcbd870e1f50eaeb5562a4fd73f186b71031f922778d940dd52c9ab3d6eda8880
|
7
|
+
data.tar.gz: 4a915aeb1e6e898c78fae5cdcb351ef2ad44f35f5a1c8617af02a423cc6025533102e4787409472b30364aceb3f3dced4f3d54a5111fc506c724de38bf67fcd7
|
data/lib/tsc-ruby.rb
CHANGED
@@ -29,18 +29,18 @@ module TypeScript
|
|
29
29
|
# @return [String] compiled JavaScript
|
30
30
|
def compile(script, *tsc_options)
|
31
31
|
script = script.read if script.respond_to?(:read)
|
32
|
-
|
32
|
+
input_file = Tempfile.new(%w(tsc-ruby .ts))
|
33
33
|
begin
|
34
|
-
|
35
|
-
|
36
|
-
result = compile_file(
|
34
|
+
input_file.write(script)
|
35
|
+
input_file.close
|
36
|
+
result = compile_file(input_file.path, *tsc_options)
|
37
37
|
if result.success?
|
38
38
|
result.js
|
39
39
|
else
|
40
40
|
raise result.stderr + result.stdout
|
41
41
|
end
|
42
42
|
ensure
|
43
|
-
|
43
|
+
input_file.unlink
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -50,11 +50,13 @@ module TypeScript
|
|
50
50
|
#
|
51
51
|
# @param [String] TypeScript script file
|
52
52
|
# @return [TypeScript::Ruby::CompileResult] compile result
|
53
|
-
def compile_file(
|
53
|
+
def compile_file(input_file_path, *tsc_options)
|
54
54
|
Dir.mktmpdir do |output_dir|
|
55
|
-
stdout, stderr, exit_status = tsc(*tsc_options, '--outDir', output_dir,
|
56
|
-
|
57
|
-
|
55
|
+
stdout, stderr, exit_status = tsc(*tsc_options, '--outDir', output_dir, input_file_path)
|
56
|
+
# now input file is in output_dir but with a .js extension
|
57
|
+
output_file_path = File.join(output_dir, File.basename(input_file_path, '.ts')) + '.js'
|
58
|
+
raise "Compiled JS file not found: #{output_file_path}" unless File.exist? output_file_path
|
59
|
+
output_js = File.read(output_file_path)
|
58
60
|
CompileResult.new(output_js, exit_status, stdout, stderr)
|
59
61
|
end
|
60
62
|
end
|
data/lib/tsc-ruby/version.rb
CHANGED