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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59d4390234fd961b3a2e5b21b30e802131cb73df824872946a01b0a4f64a8cc6
4
- data.tar.gz: 349b7074debec95163e688a5557b345487744fce06dafc62691b51f7ade053e2
3
+ metadata.gz: d0560bc80d78dbd09066e90e798256b9f292c5da42da3acbdba71b07c91798b8
4
+ data.tar.gz: ffe9e04e44c9dc857de936cf69995ac880936a4943202e9bc928066317f40299
5
5
  SHA512:
6
- metadata.gz: 4be03971e338d21e56556e82ce22e0abdc3decf8e944cbe90f9b71465d20b725536571bd1969fa64f788dd7d4a8ce10c115c3ddbc3a5e86cbd9ddc3e4000d320
7
- data.tar.gz: c02374559aa1f1aa8be0bfe8ad7cbc5fd0dc8cba3b465d55daca0e184d504abbdb6ad4c03ae60435b085db2c305b6f37585271a206b99487fc1cec33affb936b
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
- OpalWebpackCompileServer::Exe.run
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 = './.owl_cache/load_paths.json'
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 Exe
53
- def self.run
54
- exit(1) if File.exist?(OWCS_SOCKET_PATH) # OWCS already running
55
- if File.exist?(OWL_LP_CACHE)
56
- Opal.append_paths(*(Oj.load(File.read(OWL_LP_CACHE))['opal_load_paths']))
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
- EventMachine.run do
61
- EventMachine.start_unix_domain_server(OWCS_SOCKET_PATH, OpalWebpackCompileServer::Compiler)
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
+ # }
@@ -1,3 +1,3 @@
1
1
  module OpalWebpackCompileServer
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
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.2
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-21 00:00:00.000000000 Z
11
+ date: 2018-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine