middleman-typescript 0.0.4 → 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.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/middleman-typescript/extension.rb +70 -5
- data/lib/middleman-typescript/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: 156eea0b6b9dededb79ec53dcd15aa4829c2acc3
|
4
|
+
data.tar.gz: 8f1ea93322438bd4cb72ac6036b20961517ebc41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ac568b6e704b6fbe78bcc53a9c5a69e74ceabf59c6594fe18fe7c36539514de4ad852fdeb97a1161920d75fbf52446dd6f4935a682b8ac3efae98b7aa386ee9
|
7
|
+
data.tar.gz: 24988884d16facabf3e4cf7cb7bc4df39407b3b225293bd06e5af82e921c80eea4c8d5c7bf532181ee722bdd6379175db1ca47af3c90f8574099addac348a080
|
data/README.md
CHANGED
@@ -18,8 +18,20 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Configuration
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
activate :typescript,
|
22
|
+
typescript_dir: 'ts', # default: 'typescripts'
|
23
|
+
js_lib_dir: 'vendor', # default: 'lib'
|
24
|
+
target: 'ES3', # default: 'ES5'
|
25
|
+
no_implicit_any: false # default: true
|
26
|
+
configure :development do
|
27
|
+
ignore '.idea/*' # for Intellij idea user
|
28
|
+
ignore 'source/typescripts/*' # *.ts ignore LiveReload
|
29
|
+
activate :livereload
|
30
|
+
end
|
31
|
+
|
32
|
+
configure :build do
|
33
|
+
ignore 'typescripts/*' # ignore copy *.ts to build dir
|
34
|
+
end
|
23
35
|
|
24
36
|
Create typescripts directory under source directory.
|
25
37
|
## Contributing
|
@@ -5,28 +5,30 @@ module Middleman
|
|
5
5
|
option :typescript_dir, 'typescripts', 'Set TypeScript dir.'
|
6
6
|
option :target, 'ES5', 'Target version.(Default ES5)'
|
7
7
|
option :no_implicit_any, true, 'Use --noImplicitAny option.(Default true)'
|
8
|
+
option :js_lib_dir, 'lib', 'Set JavaScript library dir.'
|
8
9
|
def initialize(app, options_hash={}, &block)
|
9
10
|
super
|
10
|
-
return unless app.environment == :development
|
11
11
|
|
12
12
|
app.set :typescript_dir, options.typescript_dir
|
13
13
|
compile_options = ['--target', options.target]
|
14
14
|
compile_options << '--noImplicitAny' if options.no_implicit_any
|
15
15
|
app.set :typescript_compile_options, compile_options
|
16
|
+
app.set :typescript_js_lib_dir, options.js_lib_dir
|
16
17
|
|
17
18
|
app.ready do
|
18
19
|
files.changed do |file|
|
19
20
|
next if File.extname(file) != '.ts'
|
20
21
|
|
21
22
|
file_path = "#{Dir.pwd}/#{file}"
|
23
|
+
# Cannot call compile_to_js method...
|
24
|
+
# compile_to_js(file_path)
|
22
25
|
result = TypeScript::Node.compile_file(file_path, *app.typescript_compile_options)
|
23
26
|
if result.success?
|
24
|
-
file_name = File.basename(file_path).gsub(/\.ts/, '.js')
|
25
27
|
export_dir = source_dir + File.dirname(file_path).sub(source_dir, '').sub(app.typescript_dir, app.js_dir)
|
26
|
-
|
27
|
-
export_path = "#{export_dir}/#{file_name}"
|
28
|
+
FileUtils.mkdir_p export_dir unless Dir.exist? export_dir
|
28
29
|
|
29
|
-
File.
|
30
|
+
file_name = File.basename(file_path).gsub(/\.ts/, '.js')
|
31
|
+
File.open "#{export_dir}/#{file_name}", "w" do |f|
|
30
32
|
f.write result.js
|
31
33
|
end
|
32
34
|
else
|
@@ -44,5 +46,68 @@ module Middleman
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
49
|
+
|
50
|
+
def after_configuration
|
51
|
+
remove_javascripts_without_library
|
52
|
+
compile_typescripts
|
53
|
+
end
|
54
|
+
|
55
|
+
def after_build
|
56
|
+
remove_typescripts_from_build_path
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def remove_javascripts_without_library
|
61
|
+
app.logger.info "TypeScript: Removing JavaScript files..."
|
62
|
+
Dir.glob("#{app.source_dir}/#{app.js_dir}/*") do |js_file_path|
|
63
|
+
unless js_file_path.split('/').include? app.typescript_js_lib_dir
|
64
|
+
unlink_recursive(js_file_path)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def compile_typescripts
|
70
|
+
app.logger.info "TypeScript: Compiling TypeScript files..."
|
71
|
+
Dir.glob("#{app.source_dir}/#{app.typescript_dir}/**/*") do |file_path|
|
72
|
+
next if File.directory?(file_path) || File.extname(file_path) != '.ts'
|
73
|
+
compile_to_js file_path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def remove_typescripts_from_build_path
|
78
|
+
typescript_build_path = "#{Dir.pwd}/#{app.build_dir}/#{app.typescript_dir}"
|
79
|
+
if Dir.exist? typescript_build_path
|
80
|
+
app.logger.info "TypeScript: Removing #{app.build_dir}/#{app.typescript_dir}/"
|
81
|
+
unlink_recursive typescript_build_path
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def unlink_recursive(file_path, &block)
|
86
|
+
if File.directory?(file_path)
|
87
|
+
Dir.glob("#{file_path}/*") do |f|
|
88
|
+
unlink_recursive f, &block
|
89
|
+
end
|
90
|
+
Dir.rmdir(file_path)
|
91
|
+
else
|
92
|
+
File.unlink file_path
|
93
|
+
end
|
94
|
+
block.call(file_path) if block
|
95
|
+
end
|
96
|
+
|
97
|
+
def compile_to_js(file_path)
|
98
|
+
result = TypeScript::Node.compile_file(file_path, *app.typescript_compile_options)
|
99
|
+
if result.success?
|
100
|
+
file_name = File.basename(file_path).gsub(/\.ts/, '.js')
|
101
|
+
export_dir = app.source_dir + File.dirname(file_path).sub(app.source_dir, '').sub(app.typescript_dir, app.js_dir)
|
102
|
+
FileUtils.mkdir_p export_dir unless Dir.exist? export_dir
|
103
|
+
export_path = "#{export_dir}/#{file_name}"
|
104
|
+
|
105
|
+
File.open export_path, "w" do |f|
|
106
|
+
f.write result.js
|
107
|
+
end
|
108
|
+
else
|
109
|
+
app.logger.info "TypeScript: #{result.stderr}"
|
110
|
+
end
|
111
|
+
end
|
47
112
|
end
|
48
113
|
end
|