coffee_without_nodejs 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/coff +7 -8
- data/lib/coffee_without_nodejs.rb +2 -2
- data/lib/coffee_without_nodejs/compiler.rb +32 -19
- data/lib/coffee_without_nodejs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61de08829c462bf882db9eff690eb2c6beb92b82
|
4
|
+
data.tar.gz: 6575e27221ed2c3a518d01979fc817a34db62e7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00275f2bf31c659e3f94ae43c575004d06d7d153484f29cfaf661cc64af3f81a440117363fa20fb560a042fbfdc5848d811f854aa893bab045d5a8c5b6d70656
|
7
|
+
data.tar.gz: 0a5b166a5028434dd1ee0b1165d0f893c671f6bb2788753592ac944c26282822d25cfd5ae08a081d0c5a5c887e2277b4cd6c79398deae658a8e6639f4cc3c74d
|
data/bin/coff
CHANGED
@@ -2,25 +2,24 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
4
|
require 'coffee_without_nodejs'
|
5
|
+
require 'coderay'
|
5
6
|
|
6
7
|
if ARGV.first == '-e'
|
7
8
|
ARGV.shift
|
8
|
-
content = CoffeeWithoutNodejs.compile(ARGV.first)
|
9
|
-
|
9
|
+
content = CoffeeWithoutNodejs.compile(ARGV.first).to_s
|
10
|
+
print CodeRay.scan(content, :js).terminal unless content.empty?
|
10
11
|
else
|
11
12
|
if ARGV.empty?
|
12
13
|
`notify-send 'Starting coffee compiler.' -t 1000` if system 'which notify-send &>/dev/null'
|
13
14
|
CoffeeWithoutNodejs.watch!
|
15
|
+
elsif test 'd', ARGV.first
|
16
|
+
Dir.chdir(ARGV.first) { CoffeeWithoutNodejs.watch! }
|
14
17
|
else
|
15
18
|
ARGV.each do |file|
|
16
19
|
fail "`#{file}' is not valid filename." unless File.exist? file
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
else
|
21
|
-
js_file = CoffeeWithoutNodejs.compile(file).to_s
|
22
|
-
system "coderay -js \"#{js_file}\"" unless js_file.empty?
|
23
|
-
end
|
21
|
+
content = CoffeeWithoutNodejs.compile(file).to_s
|
22
|
+
print CodeRay.scan(content, :js).terminal unless content.empty?
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
@@ -5,9 +5,9 @@ require 'coffee_without_nodejs/compiler'
|
|
5
5
|
require 'coffee_without_nodejs/watcher'
|
6
6
|
|
7
7
|
module CoffeeWithoutNodejs
|
8
|
-
def self.compile(coffee, bare=true)
|
8
|
+
def self.compile(coffee, bare=true, create_target_jsfile=false)
|
9
9
|
if File.file?(coffee)
|
10
|
-
CoffeeCompiler.compile_file(coffee, bare)
|
10
|
+
CoffeeCompiler.compile_file(coffee, bare, create_target_jsfile)
|
11
11
|
else
|
12
12
|
CoffeeCompiler.compile(coffee, bare)
|
13
13
|
end
|
@@ -14,7 +14,7 @@ module CoffeeWithoutNodejs
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def wrapper
|
17
|
-
|
17
|
+
<<-WRAPPER
|
18
18
|
(function(script, options) {
|
19
19
|
try {
|
20
20
|
return CoffeeScript.compile(script, options);
|
@@ -35,33 +35,41 @@ WRAPPER
|
|
35
35
|
|
36
36
|
def compile(script, bare=true)
|
37
37
|
compiler.call(wrapper, script, bare: bare)
|
38
|
+
rescue ExecJS::RuntimeError
|
39
|
+
puts $!.message
|
38
40
|
end
|
39
41
|
|
40
|
-
def compile_file(file, bare=true)
|
42
|
+
def compile_file(file, bare=true, create_target_jsfile=false)
|
41
43
|
root_dir = Pathname(Dir.pwd)
|
42
44
|
file_path = Pathname(File.expand_path(file))
|
43
45
|
source_code = file_path.read
|
44
46
|
|
45
|
-
|
47
|
+
target_js_content = compiler.call(wrapper, source_code, bare: bare)
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
if create_target_jsfile
|
50
|
+
js_path, map_path = create_js_path_from(file_path)
|
51
|
+
source_files = file_path.relative_path_from(js_path.dirname).to_s
|
52
|
+
generated_file = js_path.relative_path_from(js_path.dirname).to_s
|
53
|
+
relative_map_path = map_path.relative_path_from(js_path.dirname).to_s
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
File.open(map_path, 'wb') do |f|
|
56
|
-
f.print compiler.call(wrapper, source_code,
|
57
|
-
sourceMap: true,
|
58
|
-
sourceFiles: [source_files],
|
59
|
-
generatedFile: generated_file)["v3SourceMap"]
|
60
|
-
end
|
55
|
+
File.open(js_path, 'wb') do |f|
|
56
|
+
f.print "#{ENV['JS_SHEBANG']}\n\n" if ENV['JS_SHEBANG']
|
57
|
+
f.print target_js_content, "\n//# sourceMappingURL=#{relative_map_path}"
|
58
|
+
end
|
61
59
|
|
62
|
-
|
60
|
+
File.open(map_path, 'wb') do |f|
|
61
|
+
f.print compiler.call(wrapper, source_code,
|
62
|
+
sourceMap: true,
|
63
|
+
sourceFiles: [source_files],
|
64
|
+
generatedFile: generated_file)['v3SourceMap']
|
65
|
+
end
|
63
66
|
|
64
|
-
|
67
|
+
puts "[1m[32m==>[0m #{js_path.relative_path_from(root_dir)}"
|
68
|
+
js_path
|
69
|
+
else
|
70
|
+
puts "[1m[32m==>[0m #{file_path}"
|
71
|
+
target_js_content
|
72
|
+
end
|
65
73
|
rescue ExecJS::RuntimeError
|
66
74
|
error_msg = "[#{file_path.relative_path_from(root_dir)}]: #{$!.message}"
|
67
75
|
`notify-send "#{error_msg}" -t 5000` if system 'which notify-send &>/dev/null'
|
@@ -87,7 +95,12 @@ WRAPPER
|
|
87
95
|
# if not in coffee directory, rename it.
|
88
96
|
js_path = path.sub(/\.js\.coffee$|\.coffee$/, '.js')
|
89
97
|
map_path = js_path.sub_ext('.js.map').sub(/\/([^\/]+)$/, '/.\1')
|
90
|
-
|
98
|
+
|
99
|
+
if path == js_path
|
100
|
+
warn 'filename extension is .coffee or .js.coffee?'
|
101
|
+
exit
|
102
|
+
end
|
103
|
+
[js_path, map_path]
|
91
104
|
end
|
92
105
|
end
|
93
106
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee_without_nodejs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Billy.Zheng(zw963)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|