opal-webpack-compile-server 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/opal-webpack-compile-server +7 -1
- data/lib/opal-webpack-compile-server/exe.rb +114 -11
- data/lib/opal-webpack-compile-server/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0560bc80d78dbd09066e90e798256b9f292c5da42da3acbdba71b07c91798b8
|
4
|
+
data.tar.gz: ffe9e04e44c9dc857de936cf69995ac880936a4943202e9bc928066317f40299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 643f8484a8b0a7633328b26b7603f0cc8d1d3a1b13fd2b40b979b0e687d4a02852e439f8aedf9283f481d6aa75a312a85fbb7272bec3e27d2e85f64f49df16c2
|
7
|
+
data.tar.gz: 79684975da3264865093971bae2926e8e948fd516182667b775ad9db44030f552e85e748e1e814d164e487378f3c96ce3c5b6023e8dc70ea1139401d4c5f513b
|
@@ -2,4 +2,10 @@
|
|
2
2
|
require 'opal-webpack-compile-server/exe'
|
3
3
|
require 'opal-webpack-compile-server/version'
|
4
4
|
|
5
|
-
|
5
|
+
if ARGV[0] == 'kill'
|
6
|
+
puts "Killing OWL Compile Server"
|
7
|
+
OpalWebpackCompileServer::Exe.kill
|
8
|
+
else
|
9
|
+
puts "Starting OWL Compile Server"
|
10
|
+
OpalWebpackCompileServer::Exe.run
|
11
|
+
end
|
@@ -4,15 +4,15 @@ require 'opal/paths'
|
|
4
4
|
require 'opal/source_map'
|
5
5
|
require 'source_map'
|
6
6
|
require 'opal/compiler'
|
7
|
+
require 'socket'
|
7
8
|
|
8
9
|
at_exit do
|
9
|
-
File.unlink(OpalWebpackCompileServer::OWCS_SOCKET_PATH)
|
10
|
+
File.unlink(OpalWebpackCompileServer::OWCS_SOCKET_PATH) if OpalWebpackCompileServer::Exe.unlink_socket?
|
10
11
|
end
|
11
12
|
|
12
13
|
module OpalWebpackCompileServer
|
13
|
-
|
14
14
|
OWL_CACHE_DIR = './.owl_cache/'
|
15
|
-
OWL_LP_CACHE = '
|
15
|
+
OWL_LP_CACHE = OWL_CACHE_DIR + 'load_paths.json'
|
16
16
|
OWCS_SOCKET_PATH = OWL_CACHE_DIR + 'owcs_socket'
|
17
17
|
|
18
18
|
class Compiler < EventMachine::Connection
|
@@ -49,17 +49,120 @@ module OpalWebpackCompileServer
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
class
|
53
|
-
def self.
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
class LoadPathManager
|
53
|
+
def self.get_load_path_entries(path)
|
54
|
+
path_entries = []
|
55
|
+
dir_entries = Dir.entries(path)
|
56
|
+
dir_entries.each do |entry|
|
57
|
+
next if entry == '.'
|
58
|
+
next if entry == '..'
|
59
|
+
absolute_path = File.join(path, entry)
|
60
|
+
if File.directory?(absolute_path)
|
61
|
+
more_path_entries = get_load_path_entries(absolute_path)
|
62
|
+
path_entries.push(*more_path_entries) if more_path_entries.size > 0
|
63
|
+
elsif (absolute_path.end_with?('.rb') || absolute_path.end_with?('.js')) && File.file?(absolute_path)
|
64
|
+
path_entries.push(absolute_path)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
path_entries
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.get_load_paths
|
71
|
+
load_paths = %x{
|
72
|
+
bundle exec rails runner "puts (Rails.configuration.respond_to?(:assets) ? (Rails.configuration.assets.paths + Opal.paths).uniq : Opal.paths)"
|
73
|
+
}
|
74
|
+
if $? == 0
|
75
|
+
load_path_lines = load_paths.split("\n")
|
76
|
+
load_path_lines.pop if load_path_lines.last == ''
|
77
|
+
|
78
|
+
load_path_entries = []
|
79
|
+
|
80
|
+
load_path_lines.each do |path|
|
81
|
+
more_path_entries = get_load_path_entries(path)
|
82
|
+
load_path_entries.push(*more_path_entries) if more_path_entries.size > 0
|
83
|
+
end
|
84
|
+
cache_obj = { 'opal_load_paths' => load_path_lines, 'opal_load_path_entries' => load_path_entries }
|
85
|
+
Dir.mkdir(OpalWebpackCompileServer::OWL_CACHE_DIR) unless Dir.exist?(OpalWebpackCompileServer::OWL_CACHE_DIR)
|
86
|
+
File.write(OpalWebpackCompileServer::OWL_LP_CACHE, Oj.dump(cache_obj))
|
57
87
|
else
|
88
|
+
puts 'Error getting load paths!'
|
58
89
|
exit(2)
|
59
90
|
end
|
60
|
-
|
61
|
-
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class Exe
|
95
|
+
def self.unlink_socket?
|
96
|
+
@unlink
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.unlink_on_exit
|
100
|
+
@unlink = true
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.dont_unlink_on_exit
|
104
|
+
@unlink = false
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.kill
|
108
|
+
if File.exist?(OWCS_SOCKET_PATH)
|
109
|
+
dont_unlink_on_exit
|
110
|
+
s = UNIXSocket.new(OWCS_SOCKET_PATH)
|
111
|
+
s.send("command:kill\n", 0)
|
112
|
+
s.close
|
113
|
+
exit(0)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.run
|
118
|
+
if File.exist?(OWCS_SOCKET_PATH) # OWCS already running
|
119
|
+
puts "Another Compile Server already running, exiting"
|
120
|
+
dont_unlink_on_exit
|
121
|
+
exit(1)
|
122
|
+
else
|
123
|
+
unlink_on_exit
|
124
|
+
load_paths = OpalWebpackCompileServer::LoadPathManager.get_load_paths
|
125
|
+
if load_paths
|
126
|
+
Opal.append_paths(*load_paths)
|
127
|
+
Process.daemon(true)
|
128
|
+
EventMachine.run do
|
129
|
+
EventMachine.start_unix_domain_server(OWCS_SOCKET_PATH, OpalWebpackCompileServer::Compiler)
|
130
|
+
end
|
131
|
+
end
|
62
132
|
end
|
63
133
|
end
|
64
134
|
end
|
65
|
-
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# js
|
138
|
+
#
|
139
|
+
# get_load_paths() {
|
140
|
+
# var load_paths;
|
141
|
+
# if (fs.existsSync('bin/rails')) {
|
142
|
+
# load_paths = child_process.execSync('bundle exec rails runner ' +
|
143
|
+
# '"puts (Rails.configuration.respond_to?(:assets) ? ' +
|
144
|
+
# '(Rails.configuration.assets.paths + Opal.paths).uniq : ' +
|
145
|
+
# 'Opal.paths); exit 0"');
|
146
|
+
# } else {
|
147
|
+
# load_paths = child_process.execSync('bundle exec ruby -e "Bundler.require; puts Opal.paths; exit 0"');
|
148
|
+
# }
|
149
|
+
# var load_path_lines = load_paths.toString().split('\n');
|
150
|
+
# var lp_length = load_path_lines.length;
|
151
|
+
# if (load_path_lines[lp_length-1] === '' || load_path_lines[lp_length-1] == null) {
|
152
|
+
# load_path_lines.pop();
|
153
|
+
# }
|
154
|
+
# return load_path_lines;
|
155
|
+
# }
|
156
|
+
#
|
157
|
+
# get_load_path_entries(load_paths) {
|
158
|
+
# var load_path_entries = [];
|
159
|
+
# var lp_length = load_paths.length;
|
160
|
+
# for (var i = 0; i < lp_length; i++) {
|
161
|
+
# var dir_entries = this.get_directory_entries(load_paths[i], false);
|
162
|
+
# var d_length = dir_entries.length;
|
163
|
+
# for (var k = 0; k < d_length; k++) {
|
164
|
+
# load_path_entries.push(dir_entries[k]);
|
165
|
+
# }
|
166
|
+
# }
|
167
|
+
# return load_path_entries;
|
168
|
+
# }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-webpack-compile-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|