rubyjs-vite 1.0.3 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23e29f893a32c27dccaecfb2e4a1ca9f58b4dbf2a293bf083e2d18f91856de5f
4
- data.tar.gz: b34cd11ca9673abb54cf10b24e555dcfa6003787fb6634f968793fae7e631291
3
+ metadata.gz: c39af5daef081c5bc9c342f12d60d2638d5ee4d4da919248b8141f4d597dc60c
4
+ data.tar.gz: 9976bce372c776e1017f2803a5668bd18884c267ad267b121a1560381a298c05
5
5
  SHA512:
6
- metadata.gz: b0d3b0c745905aa0bb5ff214bbcc35586e9423e33805f8e3bdce47ad9c1481880db2d4cbebafeb2d9d949f8e65a35f40520380347d637ff5f3a4c8fbad91ed67
7
- data.tar.gz: 52f8b3751a57ecd83a4137dcafa157ac875ae57f48a8f5b40f214789af41fd331ffd55cbe2edb274e8d0d33cad2bfc16e7fa3ea05c53ee67b1f1c696a80a4099
6
+ metadata.gz: 8eea646c8f3a31ba4c855d5bbed5dbea5cf93f6bd37c63c814636faecf3757c776fbcff4b8f849fe1d814953ddba69b3458fee64d56a4fdb9df3fe6bf175dc8f
7
+ data.tar.gz: 4a0cb39723484ca3cbbf110f3d1722f647bbd4ed741b8f2b5c65bfbd63d34234c61ce07db82a67954c25020a757bd4afd9bafaeab5e818fb1906205ea7fffa12
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( "-w", "--watch", "Watch scripts for changes and rerun commands." ) do
29
- @options[:watch] = true
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, but it wasn't made into a js file."
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
@@ -12,15 +12,20 @@ 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
- change_watch_f(path_ao)
15
+ json_cj = JsonParser.new File.join(path_ao, ".codejoin")
16
+ json_cj.parse :name, project.downcase
17
+
18
+ change_name_f(path_ao)
16
19
  install_vite(project, path_ao)
17
20
  end
18
21
 
19
- def self.change_watch_f path_ao
20
- path_bin_ao = "#{path_ao}/bin/watch"
21
- content = Helper.open(path_bin_ao)
22
- content_ch = content.sub("APP_NAME", Constants::APP_NAME)
23
- Helper.write(path_bin_ao, content_ch)
22
+ def self.change_name_f path_ao
23
+ paths_bin_ao = ["#{path_ao}/bin/watch", "#{path_ao}/bin/generate"]
24
+ paths_bin_ao.each do |p|
25
+ content = Helper.open(p)
26
+ content_ch = content.sub("APP_NAME", Constants::APP_NAME)
27
+ Helper.write(p, content_ch)
28
+ end
24
29
  end
25
30
 
26
31
  def self.install_vite project, path_ao
@@ -1,3 +1,3 @@
1
1
  module RubyJS
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.5"
3
3
  end
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}$/) do |modified, added, removed|
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
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ APP_NAME -g -s src/rjs -o src/.js
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.3
4
+ version: 1.0.5
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-22 00:00:00.000000000 Z
11
+ date: 2022-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2js
@@ -55,10 +55,12 @@ 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
61
62
  - lib/ruby_js/version.rb
63
+ - share/template/bin/generate
62
64
  - share/template/bin/server
63
65
  - share/template/bin/watch
64
66
  - share/template/index.html