rubyjs-vite 1.1.3 → 2.0.1
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/bin/rjsv +6 -2
- data/lib/option_parser.rb +6 -2
- data/lib/rjsv/cli/arguments.rb +77 -0
- data/lib/rjsv/cli/plugins.rb +72 -0
- data/lib/rjsv/cli/signals.rb +15 -0
- data/lib/rjsv/cli/states.rb +68 -0
- data/lib/rjsv/constants.rb +8 -0
- data/lib/rjsv/core/constants.rb +31 -0
- data/lib/rjsv/core/event.rb +24 -0
- data/lib/rjsv/core/files.rb +95 -0
- data/lib/rjsv/plugin.rb +55 -0
- data/lib/rjsv/translate.rb +40 -0
- data/lib/rjsv/version.rb +3 -0
- data/lib/rjsv/watch.rb +35 -0
- data/lib/rjsv.rb +53 -0
- data/plugins/scaffold/lib/init.rb +31 -0
- data/plugins/scaffold/lib/scaffold/cli/arguments.rb +43 -0
- data/plugins/scaffold/lib/scaffold/create.rb +64 -0
- data/plugins/scaffold/lib/scaffold/states.rb +40 -0
- data/plugins/scaffold/lib/scaffold/vite.rb +13 -0
- data/share/scaffold/element/element.js.rb +20 -0
- data/share/scaffold/element/init.js.rb +3 -0
- data/share/{template → scaffold/web}/.gitignore +2 -0
- data/share/{template → scaffold/web}/bin/server +1 -1
- data/share/scaffold/web/config/ruby2js.rb +10 -0
- data/share/{template → scaffold/web}/index.html +1 -1
- data/share/scaffold/web/package.json +14 -0
- data/share/scaffold/web/src/js/env.js +1 -0
- 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/{template/src/rjs/main.rjs → scaffold/web/src/rb/main.js.rb} +2 -0
- metadata +49 -34
- data/app/arguments.rb +0 -67
- data/app/config.rb +0 -11
- data/app/main.rb +0 -75
- data/app/signals.rb +0 -4
- data/lib/description.rb +0 -10
- data/lib/ruby_js/code_join.rb +0 -153
- data/lib/ruby_js/constants.rb +0 -7
- data/lib/ruby_js/helper.rb +0 -50
- data/lib/ruby_js/scaffold.rb +0 -52
- data/lib/ruby_js/version.rb +0 -3
- data/lib/ruby_js.rb +0 -74
- data/share/template/.codejoin +0 -8
- data/share/template/bin/generate +0 -3
- data/share/template/bin/watch +0 -3
- data/share/template/package.json +0 -11
- /data/share/{template → scaffold/web}/public/vite.svg +0 -0
- /data/share/{template → scaffold/web}/src/css/style.css +0 -0
data/lib/ruby_js/code_join.rb
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
require "json_parser"
|
2
|
-
|
3
|
-
module RubyJS
|
4
|
-
FileS = Struct.new :path, :content, :class_rid
|
5
|
-
|
6
|
-
class CodeJoin
|
7
|
-
FILE_N = "FILE_N"
|
8
|
-
TEST_N = "test.rjs"
|
9
|
-
FILE_HN = ".codejoin"
|
10
|
-
|
11
|
-
attr_reader :json_cj
|
12
|
-
|
13
|
-
def initialize path_s
|
14
|
-
@files = []
|
15
|
-
|
16
|
-
@json_cj = JsonParser.new File.join(path_s, FILE_HN)
|
17
|
-
@json_cj.on :name, "project"
|
18
|
-
@json_cj.on :ignore, ["#{FILE_N}_.*.rjs", TEST_N, "main.rjs"]
|
19
|
-
end
|
20
|
-
|
21
|
-
def add_file path_f
|
22
|
-
content = File.open(path_f).read
|
23
|
-
i_c = content.index /class/
|
24
|
-
i_n = content.index(/\n/, i_c) if i_c
|
25
|
-
@files << FileS.new(path_f, content, [i_c, i_n])
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_ignore_r
|
29
|
-
result = ""
|
30
|
-
@json_cj.parse(:ignore).each do |i|
|
31
|
-
result << i.sub(/#{FILE_N}/, @json_cj.parse(:name).downcase.gsub(' ', '_')).concat("$|")
|
32
|
-
end
|
33
|
-
return result.sub(/\|$/, '')
|
34
|
-
end
|
35
|
-
|
36
|
-
def get_pos_class
|
37
|
-
files_ch = {}
|
38
|
-
files_nc = []
|
39
|
-
@files.each do |f|
|
40
|
-
if f.class_rid[0]
|
41
|
-
r_class = f.content[f.class_rid[0], f.class_rid[1] - f.class_rid[0]]
|
42
|
-
r_class_s = r_class.split(' ')
|
43
|
-
_class = r_class_s[1]
|
44
|
-
_super = r_class_s[3]
|
45
|
-
|
46
|
-
files_ch[_class] = _super
|
47
|
-
else
|
48
|
-
files_nc << f
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
files_c = []
|
53
|
-
extends_pos_class(files_ch).each do |c|
|
54
|
-
@files.each do |f|
|
55
|
-
if f.class_rid[0]
|
56
|
-
r_class = f.content[f.class_rid[0], f.class_rid[1] - f.class_rid[0]]
|
57
|
-
if r_class.index("class #{c}")
|
58
|
-
files_c << f
|
59
|
-
break
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
return files_c + files_nc
|
66
|
-
end
|
67
|
-
|
68
|
-
def extends_pos_class hash
|
69
|
-
fe_arr = [] # Extend class
|
70
|
-
fa_arr = [] # No extend class
|
71
|
-
hash.each do |c, e|
|
72
|
-
if e
|
73
|
-
arr_c = [c, e]
|
74
|
-
def e_loop hash, key
|
75
|
-
k = hash.dig(key)
|
76
|
-
if k
|
77
|
-
yield k
|
78
|
-
e_loop(hash, k) do |kk|
|
79
|
-
yield kk
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
e_loop(hash, e) do |k|
|
84
|
-
arr_c << k
|
85
|
-
end
|
86
|
-
|
87
|
-
arr_c.pop
|
88
|
-
fe_arr << arr_c.reverse
|
89
|
-
else
|
90
|
-
fa_arr << c
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
last_class = check_last_extend_class(fe_arr)
|
95
|
-
|
96
|
-
fe_arr_ue = []
|
97
|
-
fe_arr.each do |cs|
|
98
|
-
cs.each do |c|
|
99
|
-
fe_arr_ue << c
|
100
|
-
end
|
101
|
-
end
|
102
|
-
fe_arr_uniq = change_extend_class_position(last_class, fe_arr_ue.uniq)
|
103
|
-
|
104
|
-
return fa_arr.clone.concat(fe_arr_uniq)
|
105
|
-
end
|
106
|
-
|
107
|
-
def change_extend_class_position last_class, fe_arr_uniq
|
108
|
-
last_class.each do |c|
|
109
|
-
i_c = fe_arr_uniq.delete c
|
110
|
-
fe_arr_uniq.push c
|
111
|
-
end
|
112
|
-
return fe_arr_uniq
|
113
|
-
end
|
114
|
-
|
115
|
-
def check_last_extend_class fe_arr
|
116
|
-
last_class = []
|
117
|
-
fe_arr.each do |cs|
|
118
|
-
unless last_class.empty?
|
119
|
-
last_class.each do |c|
|
120
|
-
is_exist = cs.find_index(c)
|
121
|
-
if is_exist
|
122
|
-
last_class.delete(c)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
if cs.length == 1
|
128
|
-
last_class << cs[0]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
return last_class
|
132
|
-
end
|
133
|
-
|
134
|
-
def to_s
|
135
|
-
result = ""
|
136
|
-
# " * Module Description" +
|
137
|
-
# " *" +
|
138
|
-
# " * @version #{}" +
|
139
|
-
# " * @date #{}" +
|
140
|
-
# " * @author #{}" +
|
141
|
-
# " * @remarks #{}" +
|
142
|
-
# " * @github #{}" +
|
143
|
-
# " */"
|
144
|
-
|
145
|
-
get_pos_class.each do |f_s|
|
146
|
-
content_e = f_s.content.gsub(/import.*\n/, '').gsub('export ', '').gsub('default ', '')
|
147
|
-
content_en = content_e[content_e.length - 1] == "\n" ? content_e : content_e.concat("\n")
|
148
|
-
result << content_en
|
149
|
-
end
|
150
|
-
return result
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
data/lib/ruby_js/constants.rb
DELETED
data/lib/ruby_js/helper.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module RubyJS
|
2
|
-
module Helper
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
def self.open path
|
6
|
-
result = ""
|
7
|
-
|
8
|
-
if File.exist? path
|
9
|
-
File.open path do |f|
|
10
|
-
result = f.read
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
result
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.write path_o, content
|
18
|
-
path_od = File.dirname(path_o)
|
19
|
-
create_dir(path_od)
|
20
|
-
|
21
|
-
file = File.new(path_o, "w+")
|
22
|
-
file.write content
|
23
|
-
file.close
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.free path_fro
|
27
|
-
# File
|
28
|
-
File.delete(path_fro) if File.exist? path_fro
|
29
|
-
# Dir
|
30
|
-
path_dro = File.dirname(path_fro)
|
31
|
-
Dir.delete(path_dro) if Dir.empty? path_dro
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.event_p event, path_f = ""
|
35
|
-
"#{Time.now.strftime("%l:%M:%S %p").lstrip} [#{Constants::APP_NAME}] #{event} #{path_f}"
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.absolute_path path_f, path_options, prefix
|
39
|
-
path_ffr = path_f.sub("#{Dir.pwd}/", '').sub(path_options[:path_s], '').sub(Constants::FILE_TYPE, prefix)
|
40
|
-
path_ffa = File.join(path_options[:path_o], path_ffr)
|
41
|
-
path_ffa
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.create_dir path
|
45
|
-
unless Dir.exist? path
|
46
|
-
FileUtils.mkdir_p path
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/lib/ruby_js/scaffold.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
module RubyJS
|
2
|
-
module Scaffold
|
3
|
-
require "json_parser"
|
4
|
-
|
5
|
-
def self.create project
|
6
|
-
path_as = File.expand_path("./share/template", ROOT)
|
7
|
-
path_ao = File.join(Dir.pwd, project)
|
8
|
-
|
9
|
-
puts "Scaffolding project in #{path_ao}..."
|
10
|
-
files = Dir.glob("#{path_as}/**/*", File::FNM_DOTMATCH).select { |f| File.file?(f) }
|
11
|
-
files.each do |pas|
|
12
|
-
pao = pas.sub(path_as, path_ao)
|
13
|
-
FileUtils.mkdir_p(File.dirname(pao))
|
14
|
-
FileUtils.cp(pas, pao)
|
15
|
-
end
|
16
|
-
|
17
|
-
json_oc = JsonParser.new File.join(path_ao, "package.json")
|
18
|
-
json_oc.parse :name, project.downcase
|
19
|
-
|
20
|
-
json_cj = JsonParser.new File.join(path_ao, ".codejoin")
|
21
|
-
json_cj.parse :name, project.downcase
|
22
|
-
|
23
|
-
change_name_f(path_ao)
|
24
|
-
install_vite(project, path_ao)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.change_name_f path_ao
|
28
|
-
paths_bin_ao = Dir.glob("#{path_ao}/bin/*")
|
29
|
-
paths_bin_ao.each do |p|
|
30
|
-
content = Helper.open(p)
|
31
|
-
content_ch = content.sub("APP_NAME", Constants::APP_NAME)
|
32
|
-
Helper.write(p, content_ch)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.install_vite project, path_ao
|
37
|
-
is_done = system("cd #{path_ao} && npm install -D vite")
|
38
|
-
if is_done
|
39
|
-
puts "\nDone. Now run:\n\n cd #{project}\n bin/server\n\n"
|
40
|
-
else
|
41
|
-
wspaces = ' '*2
|
42
|
-
puts "\nThe Vite library installation encountered an issue.\n" +
|
43
|
-
"NodeJS is probably not installed on your machine.\n" +
|
44
|
-
"Please rerun the Vite installation after installing NodeJS.\n" +
|
45
|
-
"Use these instructions:\n\n" +
|
46
|
-
"#{wspaces}cd #{project}\n" +
|
47
|
-
"#{wspaces}npm install -D vite\n" +
|
48
|
-
"#{wspaces}bin/server"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/lib/ruby_js/version.rb
DELETED
data/lib/ruby_js.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'ruby2js'
|
2
|
-
require "ruby2js/filter/esm"
|
3
|
-
require "listen"
|
4
|
-
require "option_parser"
|
5
|
-
|
6
|
-
module RubyJS
|
7
|
-
require "ruby_js/version"
|
8
|
-
require "ruby_js/helper"
|
9
|
-
require "ruby_js/constants"
|
10
|
-
require "ruby_js/scaffold"
|
11
|
-
require "ruby_js/code_join"
|
12
|
-
|
13
|
-
def self.watch path, ignore = ""
|
14
|
-
listener = Listen.to(path, only: /\.#{Constants::FILE_TYPE}$/, ignore: /#{ignore}/) do |modified, added, removed|
|
15
|
-
yield modified, added, removed
|
16
|
-
end
|
17
|
-
listener.start
|
18
|
-
sleep
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.compile path_f, options
|
22
|
-
path_o = Helper.absolute_path(path_f,
|
23
|
-
{ path_s: options[:path_s], path_o: options[:path_o] }, options[:type_o])
|
24
|
-
|
25
|
-
begin
|
26
|
-
content_rb = Helper.open(path_f)
|
27
|
-
content_js = Ruby2JS.convert(content_rb, eslevel: options[:eslevel]
|
28
|
-
) unless content_rb.empty?
|
29
|
-
|
30
|
-
path_write = Helper.write(path_o, content_js)
|
31
|
-
puts Helper.event_p("compiled", path_o)
|
32
|
-
rescue => exception
|
33
|
-
# p exception.inspect
|
34
|
-
puts Helper.event_p("error", "#{path_o} #{exception}")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.generate_cj path_s, path_g
|
39
|
-
path_hfd = path_s
|
40
|
-
unless File.exist?(File.join(path_s, CodeJoin::FILE_HN))
|
41
|
-
path_hfd = Dir.pwd
|
42
|
-
end
|
43
|
-
|
44
|
-
code_join = CodeJoin.new path_hfd
|
45
|
-
get_files(path_s).each do |path_f|
|
46
|
-
unless path_f.index(/#{code_join.get_ignore_r}/)
|
47
|
-
code_join.add_file(path_f)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
content_join = code_join.to_s
|
52
|
-
|
53
|
-
name_f = "#{code_join.json_cj.parse(:name).downcase.gsub(' ', '_')}_" +
|
54
|
-
"#{Time.now.strftime("%ya%m%d")}.#{Constants::FILE_TYPE}"
|
55
|
-
path_w = path_g.empty? ? path_s : path_g
|
56
|
-
path_f = File.join(path_w, name_f)
|
57
|
-
RubyJS::Helper.write(path_f, content_join)
|
58
|
-
puts Helper.event_p("generated", path_f)
|
59
|
-
|
60
|
-
return code_join
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.free path_f, options
|
64
|
-
path_o = Helper.absolute_path path_f, options, options[:type_o]
|
65
|
-
Helper.free path_o
|
66
|
-
|
67
|
-
puts Helper.event_p("deleted", path_o)
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.get_files(path_s)
|
71
|
-
path = "#{path_s}/**/*.#{Constants::FILE_TYPE}"
|
72
|
-
Dir.glob(path)
|
73
|
-
end
|
74
|
-
end
|
data/share/template/.codejoin
DELETED
data/share/template/bin/generate
DELETED
data/share/template/bin/watch
DELETED
data/share/template/package.json
DELETED
File without changes
|
File without changes
|