ruby-typescript 0.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.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +13 -0
  3. data/lib/ruby-typescript.rb +75 -0
  4. metadata +90 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Payton Yao
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ Ruby TypeScript
2
+ =================
3
+
4
+ This is a wrapper that uses the [TypeScript](https://github.com/Microsoft/TypeScript) developed by Microsoft.
5
+
6
+ That is, it runs TypeScript as a separate process to compile things.
7
+
8
+ ## Dependencies
9
+
10
+ You must have TypeScript installed (i.e. you can run the command `tsc`).
11
+
12
+ Alternatively, you can set the `TYPESCRIPT_SOURCE_PATH` environment variable to the location
13
+ of the tsc script (e.g. `~/.npm/typescript/1.1.0-1/package/bin/tsc`) and it'll use that through node.
@@ -0,0 +1,75 @@
1
+ require "open3"
2
+
3
+ module TypeScript
4
+ VERSION = '0.1.0'
5
+
6
+ class Error < StandardError
7
+ end
8
+
9
+ class << self
10
+ def typescript_path
11
+ ENV['TYPESCRIPT_SOURCE_PATH']
12
+ end
13
+
14
+ def node_compile(*args)
15
+ if typescript_path
16
+ cmd = ['node', typescript_path] + args
17
+ else
18
+ cmd = ['tsc'] + args
19
+ end
20
+ cmd = cmd.join(' ')
21
+ stdin, stdout, stderr, wait_thr = Open3.popen3(cmd)
22
+ stdin.close
23
+ [stdout.read, stderr.read, wait_thr]
24
+ end
25
+
26
+ def flatten_options(options)
27
+ args = []
28
+ if options[:output]
29
+ args << '--out' << options[:output]
30
+ end
31
+
32
+ if options[:source_map]
33
+ args << '--sourceMap'
34
+ end
35
+ return args
36
+ end
37
+
38
+
39
+ # Compiles a TypeScript file to JavaScript.
40
+ #
41
+ # @param [String] filepath the path to the TypeScript file
42
+ # @param [Hash] options the options for the execution
43
+ # @option options [String] :output the output path
44
+ # @option options [Boolean] :source_map create the source map or not
45
+ def compile_file(filepath, options={})
46
+ options = options.clone
47
+ if not options[:output]
48
+ options[:output] = filepath.gsub(/\.ts$/, '.js')
49
+ end
50
+ output_filename = options[:output]
51
+ args = [filepath] + flatten_options(options)
52
+ stdout, stderr, wait_thr = node_compile(*args)
53
+
54
+ if wait_thr.nil?
55
+ success = stdout.empty? and stderr.empty?
56
+ else
57
+ success = wait_thr.value == 0
58
+ end
59
+
60
+ if success
61
+ result = {
62
+ :js => output_filename,
63
+ :stdout => stdout,
64
+ }
65
+ if options[:source_map]
66
+ result[:source_map] = output_filename + '.map'
67
+ end
68
+ return result
69
+ else
70
+ raise TypeScript::Error, ( stderr.empty? ? stdout : stderr )
71
+ end
72
+ end
73
+
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-typescript
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Payton Yao
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2014-10-12 00:00:00 +08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ description: Ruby TypeScript is a wrapper for the JavaScript TypeScript compiler.
45
+ email:
46
+ - payton.yao@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - lib/ruby-typescript.rb
55
+ - LICENSE
56
+ - README.md
57
+ has_rdoc: true
58
+ homepage: http://github.com/jabbawookiees/ruby-typescript
59
+ licenses:
60
+ - MIT
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 1
79
+ - 3
80
+ - 6
81
+ version: 1.3.6
82
+ requirements: []
83
+
84
+ rubyforge_project: ruby-typescript
85
+ rubygems_version: 1.3.6
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Ruby TypeScript Compiler
89
+ test_files: []
90
+