rubyjs-vite 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/arguments.rb +6 -2
- data/app/main.rb +17 -3
- data/lib/ruby_js/code_join.rb +117 -0
- data/lib/ruby_js/scaffold.rb +3 -0
- data/lib/ruby_js/version.rb +1 -1
- data/lib/ruby_js.rb +27 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a31e0e75faaeba2ed338cacc961aa931983d8c5d0b05952dcc11da4db3845ffb
|
4
|
+
data.tar.gz: a78a09246f00a73615405922aca8b6bdcecb6b51e72485fe87fef8e2c15c3a71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4283995ad07250069d1641ea613206df45d7b5ded6a4cfb1e5847abf3d5aff2bc48194edf7f4c00f1cddacb584da47de0e21158403e15ca776b8db0be03c24dd
|
7
|
+
data.tar.gz: 7490c439c8e2626708ea9ad8808787ca31b1e88c760fce91609b35e34fc14ba50a178e496bb4f7780d5790a46a29f19a817ce00efce21d900a1aad0b7dd0bad5
|
data/app/arguments.rb
CHANGED
@@ -2,6 +2,7 @@ require "option_parser"
|
|
2
2
|
|
3
3
|
@options = {
|
4
4
|
compile: false,
|
5
|
+
generate: false,
|
5
6
|
watch: false,
|
6
7
|
output: Dir.pwd,
|
7
8
|
source: Dir.pwd,
|
@@ -22,11 +23,14 @@ OptionParser.parse do |parser|
|
|
22
23
|
puts "Version is #{RubyJS::VERSION}"
|
23
24
|
exit
|
24
25
|
end
|
26
|
+
parser.on( "-w", "--watch", "Watch scripts for changes and rerun commands." ) do
|
27
|
+
@options[:watch] = true
|
28
|
+
end
|
25
29
|
parser.on( "-c", "--compile", "Compile to JavaScript and save as .js files." ) do
|
26
30
|
@options[:compile] = true
|
27
31
|
end
|
28
|
-
parser.on( "-
|
29
|
-
@options[:
|
32
|
+
parser.on( "-g", "--generate", "Copies every rjs file into a single rjs file." ) do
|
33
|
+
@options[:generate] = true
|
30
34
|
end
|
31
35
|
parser.on("-o DIR", "--output DIR", "Set the output path or path/filename\n" +
|
32
36
|
"for compiled JavaScript." ) do |dir|
|
data/app/main.rb
CHANGED
@@ -15,10 +15,22 @@ def compile path_f
|
|
15
15
|
if @options[:compile]
|
16
16
|
compile_fun(path_f)
|
17
17
|
else
|
18
|
-
puts "This '#{path_f}' file was edited,
|
18
|
+
puts RubyJS::Helper.event_p("warning", "This '#{path_f}' file was edited, " +
|
19
|
+
"but it wasn't made into a js file.")
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
23
|
+
def generate
|
24
|
+
if @options[:generate]
|
25
|
+
path_s = @options[:source]
|
26
|
+
code_j = RubyJS.generate_cj path_s
|
27
|
+
return code_j.get_ignore_r
|
28
|
+
end
|
29
|
+
|
30
|
+
return RubyJS::CodeJoin::TEST_N
|
31
|
+
end
|
32
|
+
ignore_cjfs = generate()
|
33
|
+
|
22
34
|
if @options[:compile]
|
23
35
|
RubyJS.get_files(@options[:source]).each do |path_f|
|
24
36
|
compile_fun(path_f)
|
@@ -26,11 +38,13 @@ if @options[:compile]
|
|
26
38
|
end
|
27
39
|
|
28
40
|
if @options[:watch]
|
29
|
-
puts "There is now a watch for edited files."
|
41
|
+
puts RubyJS::Helper.event_p("message", "There is now a watch for edited files.")
|
30
42
|
path_s = @options[:source]
|
31
43
|
|
32
44
|
RubyJS::Helper.create_dir(path_s)
|
33
|
-
RubyJS.watch path_s do |modified, added, removed|
|
45
|
+
RubyJS.watch path_s, ignore_cjfs do |modified, added, removed|
|
46
|
+
generate()
|
47
|
+
|
34
48
|
unless added.empty?
|
35
49
|
compile(added.last)
|
36
50
|
end
|
@@ -0,0 +1,117 @@
|
|
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]
|
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 = []
|
70
|
+
fa_arr = []
|
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
|
+
fe_arr_u = fe_arr.group_by{|x|x[1]}.values.map(&:last).reverse
|
95
|
+
return fa_arr.clone.concat(fe_arr_u).to_s.gsub(/[\[\]\"]/, '').split(', ')
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_s
|
99
|
+
result = ""
|
100
|
+
# " * Module Description" +
|
101
|
+
# " *" +
|
102
|
+
# " * @version #{}" +
|
103
|
+
# " * @date #{}" +
|
104
|
+
# " * @author #{}" +
|
105
|
+
# " * @remarks #{}" +
|
106
|
+
# " * @github #{}" +
|
107
|
+
# " */"
|
108
|
+
|
109
|
+
get_pos_class.each do |f_s|
|
110
|
+
content_e = f_s.content.gsub(/import.*\n/, '').gsub('export ', '').gsub('default ', '')
|
111
|
+
content_en = content_e[content_e.length - 1] == "\n" ? content_e : content_e.concat("\n")
|
112
|
+
result << content_en
|
113
|
+
end
|
114
|
+
return result
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/ruby_js/scaffold.rb
CHANGED
@@ -12,6 +12,9 @@ module RubyJS
|
|
12
12
|
json_oc = JsonParser.new File.join(path_ao, "package.json")
|
13
13
|
json_oc.parse :name, project.downcase
|
14
14
|
|
15
|
+
json_cj = JsonParser.new File.join(path_ao, ".codejoin")
|
16
|
+
json_cj.parse :name, project.downcase
|
17
|
+
|
15
18
|
change_watch_f(path_ao)
|
16
19
|
install_vite(project, path_ao)
|
17
20
|
end
|
data/lib/ruby_js/version.rb
CHANGED
data/lib/ruby_js.rb
CHANGED
@@ -8,9 +8,10 @@ module RubyJS
|
|
8
8
|
require "ruby_js/helper"
|
9
9
|
require "ruby_js/constants"
|
10
10
|
require "ruby_js/scaffold"
|
11
|
+
require "ruby_js/code_join"
|
11
12
|
|
12
|
-
def self.watch path
|
13
|
-
listener = Listen.to(path, only: /\.#{Constants::FILE_TYPE}
|
13
|
+
def self.watch path, ignore = ""
|
14
|
+
listener = Listen.to(path, only: /\.#{Constants::FILE_TYPE}$/, ignore: /#{ignore}/) do |modified, added, removed|
|
14
15
|
yield modified, added, removed
|
15
16
|
end
|
16
17
|
listener.start
|
@@ -32,6 +33,30 @@ module RubyJS
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
36
|
+
def self.generate_cj path_s
|
37
|
+
path_hfd = path_s
|
38
|
+
unless File.exist?(File.join(path_s, CodeJoin::FILE_HN))
|
39
|
+
path_hfd = ROOT
|
40
|
+
end
|
41
|
+
|
42
|
+
code_join = CodeJoin.new path_hfd
|
43
|
+
get_files(path_s).each do |path_f|
|
44
|
+
unless path_f.index(/#{code_join.get_ignore_r}/)
|
45
|
+
code_join.add_file(path_f)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
content_join = code_join.to_s
|
50
|
+
|
51
|
+
name_f = "#{code_join.json_cj.parse(:name).downcase.gsub(' ', '_')}_" +
|
52
|
+
"#{Time.now.strftime("%ya%m%d")}.#{Constants::FILE_TYPE}"
|
53
|
+
path_f = File.join(path_s, name_f)
|
54
|
+
RubyJS::Helper.write(path_f, content_join)
|
55
|
+
puts Helper.event_p("generated", path_f)
|
56
|
+
|
57
|
+
return code_join
|
58
|
+
end
|
59
|
+
|
35
60
|
def self.free path_f, options
|
36
61
|
path_o = Helper.absolute_path path_f, options
|
37
62
|
Helper.free path_o
|
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: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filip Vrba
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-27 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/json_parser.rb
|
56
56
|
- lib/option_parser.rb
|
57
57
|
- lib/ruby_js.rb
|
58
|
+
- lib/ruby_js/code_join.rb
|
58
59
|
- lib/ruby_js/constants.rb
|
59
60
|
- lib/ruby_js/helper.rb
|
60
61
|
- lib/ruby_js/scaffold.rb
|