jsg 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/jsg +40 -10
- data/jsg.rb +6 -1
- data/lib/jsg/version.rb +1 -1
- metadata +3 -4
- data/template/serve.sh +0 -1
- /data/template/{.gitignore → gitignore} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e678932e88c5f4332664d8f94c855c6cf5c37eccb4c0ff55779061d20ee7a8f
|
4
|
+
data.tar.gz: eded22db06e19449e076d82332e9aa00db620fff95fd6c69d1b3a6710815eb2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7f34af3bdec9dd82ed50497bbe141bfd95c2bfc8dd0417fa9312a2893ce1547ddeb438d806070f151693aef6695bfd8fd79571fc010edcdf66dd72b84a8b742
|
7
|
+
data.tar.gz: 1cb61dbdeb8b53b6697e3521b86ef0db32e3050d66ac69fc658a7a22601cc3a6c62fe08c402e205a7378546f9f8761cfdd6914063b93881f3c45204badab815c
|
data/exe/jsg
CHANGED
@@ -12,16 +12,14 @@ module JSG
|
|
12
12
|
destination = File.join(Dir.pwd, project_name)
|
13
13
|
|
14
14
|
if Dir.exist?(destination)
|
15
|
-
|
16
|
-
return
|
15
|
+
raise "Sorry #{destination} already exists, please choose other name or delete the folder"
|
17
16
|
end
|
18
17
|
FileUtils.mkdir_p(destination)
|
19
18
|
|
20
19
|
Dir.glob("#{base_path}/**/*").each do |file_path|
|
21
20
|
next if File.directory?(file_path)
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
|
25
23
|
content = File.read(file_path)
|
26
24
|
result = if file_path.end_with?(".erb")
|
27
25
|
template = ERB.new(content)
|
@@ -32,6 +30,10 @@ module JSG
|
|
32
30
|
|
33
31
|
relative_path = file_path.sub("#{base_path}/", "").gsub(/\.erb$/, "")
|
34
32
|
new_file_path = File.join(destination, relative_path)
|
33
|
+
|
34
|
+
p new_file_path
|
35
|
+
|
36
|
+
new_file_path.gsub!("gitignore", ".gitignore")
|
35
37
|
FileUtils.mkdir_p(File.dirname(new_file_path))
|
36
38
|
File.write(new_file_path, result)
|
37
39
|
end
|
@@ -39,8 +41,26 @@ module JSG
|
|
39
41
|
|
40
42
|
def self.build
|
41
43
|
system("bundle install")
|
42
|
-
|
43
|
-
|
44
|
+
system("rbwasm build -o assets/ruby-app.wasm")
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.server
|
48
|
+
require 'webrick'
|
49
|
+
|
50
|
+
port = 8080
|
51
|
+
|
52
|
+
loop do
|
53
|
+
begin
|
54
|
+
server = WEBrick::HTTPServer.new(BindAddres: '0.0.0.0', :Port => port, :DocumentRoot => Dir.pwd)
|
55
|
+
trap('INT') { server.shutdown }
|
56
|
+
puts "Serving at port http://0.0.0.0.:#{port}"
|
57
|
+
server.start
|
58
|
+
break
|
59
|
+
rescue Errno::EADDRINUSE
|
60
|
+
port += 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
44
64
|
end
|
45
65
|
end
|
46
66
|
|
@@ -52,17 +72,27 @@ when "new"
|
|
52
72
|
project_name = ARGV.shift # Next argument should be the project name
|
53
73
|
|
54
74
|
if project_name
|
55
|
-
|
56
|
-
|
75
|
+
begin
|
76
|
+
JSG.create_project(project_name)
|
77
|
+
# check if we have an internet connection or think about caching this somewhere.
|
78
|
+
Dir.chdir(project_name) do
|
79
|
+
JSG.build
|
80
|
+
end
|
81
|
+
rescue StandardError => e
|
82
|
+
end
|
57
83
|
else
|
58
84
|
puts "Error: Project name is required."
|
59
|
-
puts "For help, run: jsg new --help"
|
85
|
+
#puts "For help, run: jsg new --help"
|
60
86
|
exit 1
|
61
87
|
end
|
62
88
|
when "build"
|
63
89
|
JSG.build
|
90
|
+
when "serve", "server"
|
91
|
+
JSG.server
|
64
92
|
else
|
65
93
|
puts "Unknown command: #{command}"
|
66
|
-
puts "Use 'jsg new
|
94
|
+
puts "Use 'jsg new projectname' for creating new projects."
|
95
|
+
puts "Use 'jsg build to build the .wasm file of the project."
|
96
|
+
puts "Use 'jsg server to start a server."
|
67
97
|
exit 1
|
68
98
|
end
|
data/jsg.rb
CHANGED
@@ -154,6 +154,7 @@ end
|
|
154
154
|
# Applying the JSG module to JS::Object to patch existing methods and add new ones
|
155
155
|
class JS::Object
|
156
156
|
include JSGPatch
|
157
|
+
|
157
158
|
end
|
158
159
|
|
159
160
|
# Extending the JS module to include new class methods
|
@@ -163,6 +164,8 @@ module JS
|
|
163
164
|
end
|
164
165
|
|
165
166
|
module JSG
|
167
|
+
class Error < StandardError; end
|
168
|
+
|
166
169
|
def self.window(*args)
|
167
170
|
JS.send(:global, *args)
|
168
171
|
end
|
@@ -179,6 +182,8 @@ module JSG
|
|
179
182
|
singleton_class.alias_method :d, :document
|
180
183
|
singleton_class.alias_method :q, :querySelectorAll
|
181
184
|
|
185
|
+
|
186
|
+
|
182
187
|
def self.method_missing(method, *args, &block)
|
183
188
|
if JS.respond_to?(method)
|
184
189
|
JS.send(method, *args, &block)
|
@@ -190,4 +195,4 @@ module JSG
|
|
190
195
|
def self.respond_to_missing?(method, include_private = false)
|
191
196
|
JS.respond_to?(method, include_private) || super
|
192
197
|
end
|
193
|
-
end
|
198
|
+
end
|
data/lib/jsg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erb
|
@@ -61,11 +61,10 @@ files:
|
|
61
61
|
- jsg.rb
|
62
62
|
- lib/jsg/version.rb
|
63
63
|
- sig/jsg.rbs
|
64
|
-
- template/.gitignore
|
65
64
|
- template/Gemfile
|
66
65
|
- template/assets/browser.script.iife.js
|
66
|
+
- template/gitignore
|
67
67
|
- template/index.html.erb
|
68
|
-
- template/serve.sh
|
69
68
|
- template/src/main.rb
|
70
69
|
homepage: https://github.com/largo/jsg
|
71
70
|
licenses:
|
data/template/serve.sh
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby -run -e httpd . -p 8080
|
File without changes
|