jsg 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17be1d2e6749531713121d32c6a693369be433ad4b089b3a24680432c5fa7b58
4
- data.tar.gz: 5cf7794b2fdcf5bbfa66776bf5295059a5a535b1f191a632f024a859bf72e384
3
+ metadata.gz: 3e678932e88c5f4332664d8f94c855c6cf5c37eccb4c0ff55779061d20ee7a8f
4
+ data.tar.gz: eded22db06e19449e076d82332e9aa00db620fff95fd6c69d1b3a6710815eb2c
5
5
  SHA512:
6
- metadata.gz: eea66cabb0155161fdf1b0e7dd25d239b9f3a54750fc8bd33e9528c50ec305e6b0644afed29e9d9560476c5b8a73e0d279d30fedee40154a151ff5cbdabebbce
7
- data.tar.gz: b1213c76694bea4ace6b52339a75b879ecfecfa792227e6025e3f91f69b14f2e20752944ecedda3c89cbbbc4b391a813c306a1fc0b64139d2335f30d11f34be6
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
- puts "Sorry #{destination} already exists, please choose other name or delete the folder"
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
- p file_path
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
- # rbwasm --log-level debug build --ruby-version 3.3 --target wasm32-unknown-wasip1 --build-profile full
43
- system("bundle exec rbwasm build -o assets/ruby-app.wasm")
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
- JSG.create_project(project_name)
56
- JSG.build
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 --help' for creating new projects."
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSG
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
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.0
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-14 00:00:00.000000000 Z
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