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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rjsv +6 -2
  3. data/lib/option_parser.rb +6 -2
  4. data/lib/rjsv/cli/arguments.rb +77 -0
  5. data/lib/rjsv/cli/plugins.rb +72 -0
  6. data/lib/rjsv/cli/signals.rb +15 -0
  7. data/lib/rjsv/cli/states.rb +68 -0
  8. data/lib/rjsv/constants.rb +8 -0
  9. data/lib/rjsv/core/constants.rb +31 -0
  10. data/lib/rjsv/core/event.rb +24 -0
  11. data/lib/rjsv/core/files.rb +95 -0
  12. data/lib/rjsv/plugin.rb +55 -0
  13. data/lib/rjsv/translate.rb +40 -0
  14. data/lib/rjsv/version.rb +3 -0
  15. data/lib/rjsv/watch.rb +35 -0
  16. data/lib/rjsv.rb +53 -0
  17. data/plugins/scaffold/lib/init.rb +31 -0
  18. data/plugins/scaffold/lib/scaffold/cli/arguments.rb +43 -0
  19. data/plugins/scaffold/lib/scaffold/create.rb +64 -0
  20. data/plugins/scaffold/lib/scaffold/states.rb +40 -0
  21. data/plugins/scaffold/lib/scaffold/vite.rb +13 -0
  22. data/share/scaffold/element/element.js.rb +20 -0
  23. data/share/scaffold/element/init.js.rb +3 -0
  24. data/share/{template → scaffold/web}/.gitignore +2 -0
  25. data/share/{template → scaffold/web}/bin/server +1 -1
  26. data/share/scaffold/web/config/ruby2js.rb +10 -0
  27. data/share/{template → scaffold/web}/index.html +1 -1
  28. data/share/scaffold/web/package.json +14 -0
  29. data/share/scaffold/web/src/js/env.js +1 -0
  30. data/share/scaffold/web/src/rb/core/events.js.rb +20 -0
  31. data/share/scaffold/web/src/rb/core/net.js.rb +12 -0
  32. data/share/scaffold/web/src/rb/core.js.rb +2 -0
  33. data/share/{template/src/rjs/main.rjs → scaffold/web/src/rb/main.js.rb} +2 -0
  34. metadata +49 -34
  35. data/app/arguments.rb +0 -67
  36. data/app/config.rb +0 -11
  37. data/app/main.rb +0 -75
  38. data/app/signals.rb +0 -4
  39. data/lib/description.rb +0 -10
  40. data/lib/ruby_js/code_join.rb +0 -153
  41. data/lib/ruby_js/constants.rb +0 -7
  42. data/lib/ruby_js/helper.rb +0 -50
  43. data/lib/ruby_js/scaffold.rb +0 -52
  44. data/lib/ruby_js/version.rb +0 -3
  45. data/lib/ruby_js.rb +0 -74
  46. data/share/template/.codejoin +0 -8
  47. data/share/template/bin/generate +0 -3
  48. data/share/template/bin/watch +0 -3
  49. data/share/template/package.json +0 -11
  50. /data/share/{template → scaffold/web}/public/vite.svg +0 -0
  51. /data/share/{template → scaffold/web}/src/css/style.css +0 -0
@@ -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
@@ -1,7 +0,0 @@
1
- module RubyJS
2
- module Constants
3
- FILE_TYPE = 'rjs'
4
- FILE_TYPE_O = 'js'
5
- APP_NAME = 'rjsv'
6
- end
7
- end
@@ -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
@@ -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
@@ -1,3 +0,0 @@
1
- module RubyJS
2
- VERSION = "1.1.3"
3
- end
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
@@ -1,8 +0,0 @@
1
- {
2
- "name": "project",
3
- "ignore": [
4
- "FILE_N_.*.rjs",
5
- "test.rjs",
6
- "main.rjs"
7
- ]
8
- }
@@ -1,3 +0,0 @@
1
- #!/bin/bash
2
-
3
- APP_NAME -g -s src/rjs -o src/.js
@@ -1,3 +0,0 @@
1
- #!/bin/bash
2
-
3
- APP_NAME -c -w -s src/rjs -o src/.js
@@ -1,11 +0,0 @@
1
- {
2
- "name": "template",
3
- "private": true,
4
- "version": "0.0.0",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "vite build",
9
- "preview": "vite preview"
10
- }
11
- }
File without changes
File without changes