typescript-node 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
19
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem "rake"
5
+ gem "rspec"
6
+ end
7
+
8
+ # Specify your gem's dependencies in typescript-node-ruby.gemspec
9
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 KAWACHI Takashi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Typescript::Node::Ruby
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'typescript-node-ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install typescript-node-ruby
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,45 @@
1
+ require "tmpdir"
2
+ require "tempfile"
3
+ require "typescript-src"
4
+ require "typescript-node/version"
5
+ require "typescript-node/compile_result"
6
+
7
+ module TypeScript
8
+ module Node
9
+
10
+ class << self
11
+ def compile_file(source_file)
12
+ Dir.mktmpdir do |output_dir|
13
+ output_file = File.join(output_dir, "out.js")
14
+ cmd = ["node", Src.tsc_path, "--out", output_file, source_file]
15
+ Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
16
+ exit_status = wait_thr.value
17
+ output_js = File.exists?(output_file) ? File.read(output_file) : nil
18
+ CompileResult.new(
19
+ output_js,
20
+ exit_status,
21
+ stdout.read,
22
+ stderr.read
23
+ )
24
+ end
25
+ end
26
+ end
27
+
28
+ def compile(source)
29
+ js_file = Tempfile.new(["typescript-node", ".ts"])
30
+ begin
31
+ js_file.write(source)
32
+ js_file.close
33
+ result = compile_file(js_file.path)
34
+ if result.success?
35
+ result.js
36
+ else
37
+ raise result.stderr
38
+ end
39
+ ensure
40
+ js_file.unlink
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ module TypeScript
4
+ module Node
5
+ class CompileResult
6
+
7
+ # Constructor
8
+ #
9
+ # @param [String] js compiled JavaScript
10
+ # @param [Fixnum] exit_status return code of tsc command
11
+ # @param [String] stdout Standard out
12
+ # @return [String] stderr Standard err
13
+ def initialize(js, exit_status, stdout, stderr)
14
+ @js = js
15
+ @exit_status = exit_status
16
+ @stdout = stdout
17
+ @stderr = stderr
18
+ end
19
+
20
+ attr_reader :js, :source_map, :exit_status, :stdout, :stderr
21
+
22
+ def success?
23
+ @exit_status == 0
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,5 @@
1
+ module TypeScript
2
+ module Node
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ console.log("Hello TypeScript")
@@ -0,0 +1,18 @@
1
+ require "typescript-node"
2
+
3
+ module TypeScript
4
+ module Node
5
+ describe "#compile_file" do
6
+ subject do
7
+ hello_ts = File.expand_path("data/hello.ts", File.dirname(__FILE__))
8
+ Node.compile_file(hello_ts)
9
+ end
10
+
11
+ its(:exit_status) { should == 0 }
12
+ it { should be_success }
13
+ its(:js) { should == "console.log(\"Hello TypeScript\");\r\n" }
14
+ its(:stdout) { should == "" }
15
+ its(:stderr) { should == "" }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/typescript-node/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["KAWACHI Takashi"]
6
+ gem.email = ["tkawachi@gmail.com"]
7
+ gem.description = %q{TypeScript ruby interface using Node.js}
8
+ gem.summary = %q{TypeScript ruby interface using Node.js}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "typescript-node"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = TypeScript::Node::VERSION
17
+
18
+ gem.add_dependency 'typescript-src', '0.8.1.1'
19
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typescript-node
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - KAWACHI Takashi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: typescript-src
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.1.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.1.1
30
+ description: TypeScript ruby interface using Node.js
31
+ email:
32
+ - tkawachi@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - lib/typescript-node.rb
43
+ - lib/typescript-node/compile_result.rb
44
+ - lib/typescript-node/version.rb
45
+ - spec/data/hello.ts
46
+ - spec/typescript-node_spec.rb
47
+ - typescript-node.gemspec
48
+ homepage: ''
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ segments:
61
+ - 0
62
+ hash: 1120283378456098797
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ segments:
70
+ - 0
71
+ hash: 1120283378456098797
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.24
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: TypeScript ruby interface using Node.js
78
+ test_files:
79
+ - spec/data/hello.ts
80
+ - spec/typescript-node_spec.rb