rubyjs-vite 2.0.0 → 2.0.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 +4 -4
- data/lib/rjsv/cli/arguments.rb +9 -7
- data/lib/rjsv/cli/plugins.rb +2 -1
- data/lib/rjsv/cli/states.rb +69 -0
- data/lib/rjsv/constants.rb +2 -1
- data/lib/rjsv/core/files.rb +25 -8
- data/lib/rjsv/version.rb +1 -1
- data/lib/rjsv/watch.rb +11 -11
- data/lib/rjsv.rb +6 -58
- data/plugins/scaffold/lib/scaffold/states.rb +1 -1
- data/share/scaffold/element/element.js.rb +2 -2
- data/share/scaffold/element/init.js.rb +1 -1
- data/share/scaffold/web/package.json +1 -1
- data/share/scaffold/web/src/rb/core/events.js.rb +20 -0
- data/share/scaffold/web/src/rb/core/net.js.rb +12 -0
- data/share/scaffold/web/src/rb/core.js.rb +2 -0
- data/share/scaffold/web/src/rb/main.js.rb +2 -0
- metadata +10 -7
- data/share/scaffold/web/.env +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3baf7c830c6ab5d908f949113abc8a4ad9fe322b01e452f152387dc4045dfbb
|
4
|
+
data.tar.gz: b99b607fc01cfb132b2db97c19a8f4f69e6ec1594531f6c08949e43b240e4677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c51615a4a21a4ed84b73eaba45ef9dec248a9cea20c1ec6bef66fb7d4c43018897e2173a8dc2eb0c5f58eb628495a24e5d8e051d425a4b34a723d19818addff5
|
7
|
+
data.tar.gz: 4621c5d09324f795801cc902f54039225cab4f6c70b538a4c02cef350671ff73a66012b30938ab33d5da1cb5b0aeaae015fe941628f1cb3cbf6610ec6895255a
|
data/lib/rjsv/cli/arguments.rb
CHANGED
@@ -32,17 +32,19 @@ module RJSV
|
|
32
32
|
end
|
33
33
|
parser.on( "-t", "--translate", "It translates all loaded RB files\n" +
|
34
34
|
"into JavaScript code and stores them\n" +
|
35
|
-
"in certain type files
|
35
|
+
"in certain type files.\n" ) do
|
36
36
|
@options[:translate] = true
|
37
37
|
end
|
38
|
-
parser.on("-s DIR", "--source DIR", "The path of the source folder
|
39
|
-
"all RB files are found
|
40
|
-
"ending
|
38
|
+
parser.on("-s DIR", "--source DIR", "The path or paths of the source folder(s)\n" +
|
39
|
+
"where all RB files are found\n" +
|
40
|
+
"(e.g., files ending in *.js.#{RJSV::Constants::SUFFIX_RB}).") do |dir|
|
41
|
+
|
41
42
|
@options[:source] = dir
|
42
43
|
end
|
43
|
-
parser.on("-o DIR", "--output DIR", "The path of the output folder
|
44
|
-
"all Ruby
|
45
|
-
"JavaScript with the prepared file type
|
44
|
+
parser.on("-o DIR", "--output DIR", "The path or paths of the output folder(s)\n" +
|
45
|
+
"where all Ruby code will be translated into\n" +
|
46
|
+
"JavaScript with the prepared file type.\n" ) do |dir|
|
47
|
+
|
46
48
|
@options[:output] = dir
|
47
49
|
end
|
48
50
|
|
data/lib/rjsv/cli/plugins.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
module RJSV
|
2
|
+
module CLI
|
3
|
+
##
|
4
|
+
# Here are the code blocks that are activated when
|
5
|
+
# the main function is triggered.
|
6
|
+
# Functions communicate using arguments passed via
|
7
|
+
# the command line, which are passed as options_cli.
|
8
|
+
# These functions include translate and watch,
|
9
|
+
# which can be reused when creating custom plugins.
|
10
|
+
|
11
|
+
module States
|
12
|
+
module_function
|
13
|
+
|
14
|
+
##
|
15
|
+
# Block of code that handles the transpilation of script.
|
16
|
+
# This is opening a Ruby script container file,
|
17
|
+
# which is then converted into a JavaScript file.
|
18
|
+
# The file is saved to the output path.
|
19
|
+
|
20
|
+
def translate_state(path, options_cli)
|
21
|
+
if options_cli[:translate]
|
22
|
+
content_ruby = Core::Files.open(path)
|
23
|
+
if content_ruby && path
|
24
|
+
path_output = Core::Files.change_path_to_output(path, options_cli)
|
25
|
+
RJSV::Translate.ruby_to_js_with_write(content_ruby, path_output) do |err|
|
26
|
+
Core::Event.print('error', "#{path.sub(File.join(Dir.pwd, ''), '')} #{err}")
|
27
|
+
return
|
28
|
+
end
|
29
|
+
Core::Event.print('translated', path_output)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Block of code that tracks files under the input paths.
|
36
|
+
# If a file has been logged, several events are performed,
|
37
|
+
# such as adding, modifying, and removing logged files.
|
38
|
+
# These events then trigger procedural methods to process the requests.
|
39
|
+
|
40
|
+
def watch_state(options_cli)
|
41
|
+
if options_cli[:watch]
|
42
|
+
Core::Event.print('message', 'There is now a watch for edited files.')
|
43
|
+
paths = options_cli[:source].split(RJSV::Constants::PATH_SPLIT)
|
44
|
+
RJSV::Watch.modified_files(*paths) do |modified, added, removed|
|
45
|
+
unless added.empty?
|
46
|
+
added.each do |path|
|
47
|
+
translate_state(path, options_cli)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
unless modified.empty?
|
52
|
+
modified.each do |path|
|
53
|
+
translate_state(path, options_cli)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
unless removed.empty?
|
58
|
+
removed.each do |path|
|
59
|
+
path_output = Core::Files.change_path_to_output(path, options_cli)
|
60
|
+
Core::Files.remove(path_output)
|
61
|
+
Core::Event.print('deleted', path_output)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end#watch_state
|
67
|
+
end#States
|
68
|
+
end
|
69
|
+
end
|
data/lib/rjsv/constants.rb
CHANGED
data/lib/rjsv/core/files.rb
CHANGED
@@ -61,19 +61,36 @@ module RJSV
|
|
61
61
|
# path for the output path.
|
62
62
|
|
63
63
|
def change_path_to_output(path, options_cli)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
find_output_path = lambda do
|
65
|
+
index_s_path = options_cli[:source].split(RJSV::Constants::PATH_SPLIT)
|
66
|
+
.index {|e| path.index(e) != nil }
|
67
|
+
s_path = options_cli[:source].split(RJSV::Constants::PATH_SPLIT)[index_s_path]
|
68
|
+
mo_path = options_cli[:output].split(RJSV::Constants::PATH_SPLIT)[index_s_path]
|
69
|
+
|
70
|
+
unless mo_path
|
71
|
+
mo_path = options_cli[:output].split(RJSV::Constants::PATH_SPLIT)[0]
|
72
|
+
Core::Event.print('warning', "Output path not found for '#{s_path}'.")
|
73
|
+
end
|
74
|
+
|
75
|
+
return path.sub(s_path, mo_path)
|
76
|
+
end
|
77
|
+
|
78
|
+
find_output_path.call()
|
79
|
+
.sub(/\.#{RJSV::Constants::SUFFIX_RB}$/, '')
|
80
|
+
.sub(File.join(Dir.pwd(), ''), '')
|
68
81
|
end
|
69
82
|
|
70
83
|
##
|
71
84
|
# Finds all files with the extension '.*.rb'
|
72
|
-
# from the defined
|
85
|
+
# from the defined paths.
|
86
|
+
|
87
|
+
def find_all(paths)
|
88
|
+
path_all = []
|
89
|
+
paths.split(RJSV::Constants::PATH_SPLIT).each do |path|
|
90
|
+
path_all << File.join(path, '**', '*') + ".*.#{RJSV::Constants::SUFFIX_RB}"
|
91
|
+
end
|
73
92
|
|
74
|
-
|
75
|
-
path_all = File.join(path, '**', '*')
|
76
|
-
Dir.glob("#{path_all}.*.#{RJSV::Constants::SUFFIX_RB}")
|
93
|
+
Dir.glob(path_all)
|
77
94
|
end
|
78
95
|
|
79
96
|
##
|
data/lib/rjsv/version.rb
CHANGED
data/lib/rjsv/watch.rb
CHANGED
@@ -11,18 +11,18 @@ module RJSV
|
|
11
11
|
module_function
|
12
12
|
|
13
13
|
##
|
14
|
-
# Tracks modified files in the
|
15
|
-
# defined as the source
|
16
|
-
# function is called, the event listener is
|
17
|
-
# for events such as modified, added,
|
18
|
-
# file events. Therefore, the method
|
19
|
-
# the application to sleep and silently
|
20
|
-
# the event process. It watches all
|
21
|
-
# extension '.*.rb',
|
22
|
-
# any sub
|
14
|
+
# Tracks modified files in the paths that are
|
15
|
+
# defined as the source directories. When this
|
16
|
+
# function is called, the event listener is
|
17
|
+
# triggered for events such as modified, added,
|
18
|
+
# and deleted file events. Therefore, the method
|
19
|
+
# can put the application to sleep and silently
|
20
|
+
# monitor the event process. It watches all
|
21
|
+
# files with the extension '.*.rb', where
|
22
|
+
# the asterisk means any sub-extension such as '.js'.
|
23
23
|
|
24
|
-
def modified_files(
|
25
|
-
listener = Listen.to(
|
24
|
+
def modified_files(*paths, &block)
|
25
|
+
listener = Listen.to(*paths,
|
26
26
|
only: /\..*\.#{Constants::SUFFIX_RB}$/
|
27
27
|
) do |m, a, r|
|
28
28
|
|
data/lib/rjsv.rb
CHANGED
@@ -9,13 +9,14 @@ require 'rjsv/core/event'
|
|
9
9
|
require 'rjsv/core/files'
|
10
10
|
require 'rjsv/core/constants'
|
11
11
|
|
12
|
+
require 'rjsv/translate'
|
13
|
+
require 'rjsv/watch'
|
14
|
+
|
15
|
+
require 'rjsv/cli/states'
|
12
16
|
require 'rjsv/cli/signals'
|
13
17
|
require 'rjsv/cli/plugins'
|
14
18
|
require 'rjsv/cli/arguments'
|
15
19
|
|
16
|
-
require 'rjsv/translate'
|
17
|
-
require 'rjsv/watch'
|
18
|
-
|
19
20
|
##
|
20
21
|
# This is the main initialization module of
|
21
22
|
# all modules that are needed for the functionality
|
@@ -28,59 +29,6 @@ module RJSV
|
|
28
29
|
|
29
30
|
module_function
|
30
31
|
|
31
|
-
##
|
32
|
-
# Block of code that handles the transpilation of script.
|
33
|
-
# This is opening a Ruby script container file,
|
34
|
-
# which is then converted into a JavaScript file.
|
35
|
-
# The file is saved to the output path.
|
36
|
-
|
37
|
-
def translate_state(path)
|
38
|
-
if @options_cli[:translate]
|
39
|
-
content_ruby = Core::Files.open(path)
|
40
|
-
if content_ruby && path
|
41
|
-
path_output = Core::Files.change_path_to_output(path, @options_cli)
|
42
|
-
Translate.ruby_to_js_with_write(content_ruby, path_output) do |err|
|
43
|
-
Core::Event.print('error', "#{path.sub(File.join(Dir.pwd, ''), '')} #{err}")
|
44
|
-
return
|
45
|
-
end
|
46
|
-
Core::Event.print('translated', path_output)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
##
|
52
|
-
# Block of code that tracks files under the input path.
|
53
|
-
# If a file has been logged, several events are performed
|
54
|
-
# such as to add, modify and remove logged files.
|
55
|
-
# These then trigger procedural methods to process the requests.
|
56
|
-
|
57
|
-
def watch_state()
|
58
|
-
if @options_cli[:watch]
|
59
|
-
Core::Event.print('message', 'There is now a watch for edited files.')
|
60
|
-
Watch.modified_files(@options_cli[:source]) do |modified, added, removed|
|
61
|
-
unless added.empty?
|
62
|
-
added.each do |path|
|
63
|
-
translate_state(path)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
unless modified.empty?
|
68
|
-
modified.each do |path|
|
69
|
-
translate_state(path)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
unless removed.empty?
|
74
|
-
removed.each do |path|
|
75
|
-
path_output = Core::Files.change_path_to_output(path, @options_cli)
|
76
|
-
Core::Files.remove(path_output)
|
77
|
-
Core::Event.print('deleted', path_output)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end#watch_state
|
83
|
-
|
84
32
|
##
|
85
33
|
# This is the main function to run the desired
|
86
34
|
# block function scenarios. In order to arm itself
|
@@ -95,11 +43,11 @@ module RJSV
|
|
95
43
|
if @options_cli[:translate]
|
96
44
|
files_rb = Core::Files.find_all(@options_cli[:source])
|
97
45
|
files_rb.each do |path|
|
98
|
-
translate_state(path)
|
46
|
+
CLI::States.translate_state(path, @options_cli)
|
99
47
|
end
|
100
48
|
end
|
101
49
|
|
102
|
-
watch_state()
|
50
|
+
CLI::States.watch_state(@options_cli)
|
103
51
|
end
|
104
52
|
end#main
|
105
53
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export default class Events
|
2
|
+
def self.emit(dom, event, values = nil)
|
3
|
+
custom_event = new CustomEvent(event, {
|
4
|
+
detail: {
|
5
|
+
value: values
|
6
|
+
}
|
7
|
+
})
|
8
|
+
|
9
|
+
document.query_selector(dom).dispatch_event(custom_event)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.connect(dom, event, &callback)
|
13
|
+
document.query_selector(dom).add_event_listener(event, callback) if callback
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.disconnect(dom, event, &callback)
|
17
|
+
document.query_selector(dom).remove_event_listener(event, callback) if callback
|
18
|
+
end
|
19
|
+
end
|
20
|
+
window.Events = Events
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyjs-vite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filip Vrba
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby2js
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/rjsv/cli/arguments.rb
|
56
56
|
- lib/rjsv/cli/plugins.rb
|
57
57
|
- lib/rjsv/cli/signals.rb
|
58
|
+
- lib/rjsv/cli/states.rb
|
58
59
|
- lib/rjsv/constants.rb
|
59
60
|
- lib/rjsv/core/constants.rb
|
60
61
|
- lib/rjsv/core/event.rb
|
@@ -70,7 +71,6 @@ files:
|
|
70
71
|
- plugins/scaffold/lib/scaffold/vite.rb
|
71
72
|
- share/scaffold/element/element.js.rb
|
72
73
|
- share/scaffold/element/init.js.rb
|
73
|
-
- share/scaffold/web/.env
|
74
74
|
- share/scaffold/web/.gitignore
|
75
75
|
- share/scaffold/web/bin/server
|
76
76
|
- share/scaffold/web/config/ruby2js.rb
|
@@ -79,6 +79,9 @@ files:
|
|
79
79
|
- share/scaffold/web/public/vite.svg
|
80
80
|
- share/scaffold/web/src/css/style.css
|
81
81
|
- share/scaffold/web/src/js/env.js
|
82
|
+
- share/scaffold/web/src/rb/core.js.rb
|
83
|
+
- share/scaffold/web/src/rb/core/events.js.rb
|
84
|
+
- share/scaffold/web/src/rb/core/net.js.rb
|
82
85
|
- share/scaffold/web/src/rb/main.js.rb
|
83
86
|
homepage: https://rubygems.org/gems/rubyjs-vite
|
84
87
|
licenses:
|
@@ -86,7 +89,7 @@ licenses:
|
|
86
89
|
metadata:
|
87
90
|
source_code_uri: https://github.com/filipvrba/ruby-js
|
88
91
|
documentation_uri: https://filipvrba.github.io/ruby-js/
|
89
|
-
post_install_message:
|
92
|
+
post_install_message:
|
90
93
|
rdoc_options: []
|
91
94
|
require_paths:
|
92
95
|
- lib
|
@@ -101,8 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
104
|
- !ruby/object:Gem::Version
|
102
105
|
version: '0'
|
103
106
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
105
|
-
signing_key:
|
107
|
+
rubygems_version: 3.5.16
|
108
|
+
signing_key:
|
106
109
|
specification_version: 4
|
107
110
|
summary: CLI application with RB file transpilation that communicates with the Vite
|
108
111
|
tool.
|
data/share/scaffold/web/.env
DELETED
File without changes
|