rubyjs-vite 1.1.3 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,43 @@
1
+ module RJSV
2
+ module Plugins
3
+ module Scaffold
4
+ module CLI
5
+ module Arguments
6
+ @options = {
7
+ create_web: nil,
8
+ element: nil,
9
+ }
10
+
11
+ module_function
12
+
13
+ def init(scaffold)
14
+ OptionParser.parse do |parser|
15
+ parser.banner(
16
+ "#{scaffold.description()}\n\n" +
17
+ "Usage: #{APP_NAME} #{scaffold.name()} [options]\n" +
18
+ "\nOptions:"
19
+ )
20
+
21
+ parser.on( "web NAME", "", "Creates a new web project with\n" +
22
+ "a basic code architecture." ) do |name|
23
+ @options[:create_web] = name
24
+ end
25
+ parser.on( "element NAME", "", "Creates scaffolding for the new element.\n" ) do |name|
26
+ @options[:element] = name
27
+ end
28
+
29
+ parser.on( "-h", "--help", "Show help" ) do
30
+ puts parser
31
+ exit
32
+ end
33
+ end
34
+ end
35
+
36
+ def options
37
+ @options
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,64 @@
1
+ module RJSV
2
+ module Plugins
3
+ module Scaffold
4
+ module Create
5
+ module_function
6
+
7
+ def web path_output
8
+ path_scaffold = File.expand_path('./share/scaffold/web', ROOT)
9
+
10
+ puts "Scaffolding project in #{path_output}..."
11
+ RJSV::Core::Files.copy(path_scaffold, path_output)
12
+
13
+ json_package = JsonParser.new File.join(path_output, "package.json")
14
+ json_package.parse :name, File.basename(path_output).downcase
15
+ end
16
+
17
+ def element(name, &block)
18
+ name_class = name.split(/[_-]/).map(&:capitalize).join
19
+ name_file = name.gsub('-', '_')
20
+ name_element = name.gsub('_', '-')
21
+
22
+ path_scaffold = File.expand_path('./share/scaffold/element', ROOT)
23
+ path_scaffold_element = File.join(path_scaffold, 'element.js.rb')
24
+ path_scaffold_init = File.join(path_scaffold, 'init.js.rb')
25
+
26
+ content_element = RJSV::Core::Files.open(path_scaffold_element)
27
+ .sub('NAME_CLASS', name_class)
28
+ content_init = RJSV::Core::Files.open(path_scaffold_init)
29
+ .gsub('NAME_CLASS', name_class)
30
+ .sub('NAME_FILE', name_file)
31
+ .sub('NAME_ELEMENT', name_element)
32
+
33
+ path_output_element = File.join(
34
+ Dir.pwd, 'src', 'rb', 'elements', "elm_#{name_file}.js.rb"
35
+ )
36
+ path_output_init = File.join(
37
+ Dir.pwd, 'src', 'rb', 'elements.js.rb'
38
+ )
39
+
40
+ files = [
41
+ {
42
+ path: path_output_element,
43
+ content: content_element,
44
+ mode: 'w+'
45
+ },
46
+ {
47
+ path: path_output_init,
48
+ content: content_init,
49
+ mode: 'a+'
50
+ }
51
+ ]
52
+
53
+ files.each do |file|
54
+ RJSV::Core::Files.write_with_dir(
55
+ file[:content], file[:path], file[:mode]
56
+ )
57
+ block.call("Modified '.#{file[:path].sub(Dir.pwd, '')}'") if block
58
+ end
59
+ block.call("Element 'elm-#{name_element}'") if block
60
+ end
61
+ end#Create
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,40 @@
1
+ module RJSV
2
+ module Plugins
3
+ module Scaffold
4
+ module States
5
+ module_function
6
+
7
+ def create_web_state(options)
8
+ project = options[:create_web]
9
+ if project
10
+ path_output = File.join(Dir.pwd, project)
11
+ Create.web(path_output)
12
+ is_installed = Vite.install(path_output)
13
+
14
+ if is_installed
15
+ puts "\nDone. Now run:\n\n cd #{project}\n bin/server\n\n"
16
+ else
17
+ wspaces = ' '*2
18
+ puts "\nThe Vite library installation encountered an issue.\n" +
19
+ "NodeJS is probably not installed on your machine.\n" +
20
+ "Please rerun the Vite installation after installing NodeJS.\n" +
21
+ "Use these instructions:\n\n" +
22
+ "#{wspaces}cd #{project}\n" +
23
+ "#{wspaces}npm install\n" +
24
+ "#{wspaces}bin/server"
25
+ end
26
+ end
27
+ end
28
+
29
+ def create_element_state(options)
30
+ name = options[:element]
31
+ if name
32
+ Create.element(name) do |message|
33
+ RJSV::Core::Event.print('scaffold', message)
34
+ end
35
+ end
36
+ end
37
+ end#States
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ module RJSV
2
+ module Plugins
3
+ module Scaffold
4
+ module Vite
5
+ module_function
6
+
7
+ def install(path_output)
8
+ system("cd #{path_output} && npm install")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ export default class ElmNAME_CLASS < HTMLElement
2
+ def initialize
3
+ super
4
+
5
+ init_elm()
6
+ end
7
+
8
+ def connected_callback()
9
+ end
10
+
11
+ def disconnected_callback()
12
+ end
13
+
14
+ def init_elm()
15
+ template = """
16
+ """
17
+
18
+ self.innerHTML = template
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+
2
+ import 'ElmNAME_CLASS', './elements/elm_NAME_FILE'
3
+ window.custom_elements.define('elm-NAME_ELEMENT', ElmNAME_CLASS)
@@ -22,3 +22,5 @@ dist-ssr
22
22
  *.njsproj
23
23
  *.sln
24
24
  *.sw?
25
+
26
+ .env
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
- APP_NAME -c -w -s src/rjs -o src/.js &
3
+ rjsv -t -w -s src/rb -o src/js &
4
4
  npm run dev
5
5
 
6
6
  trap - SIGINT
@@ -0,0 +1,10 @@
1
+ # Readme: https://www.ruby2js.com/docs/options
2
+
3
+ preset
4
+
5
+ filter :functions
6
+ filter :camelCase
7
+
8
+ eslevel 2021
9
+
10
+ include_method :class
@@ -8,6 +8,6 @@
8
8
  </head>
9
9
  <body>
10
10
  <div id="app"></div>
11
- <script type="module" src="/src/.js/main.js"></script>
11
+ <script type="module" src="/src/js/main.js"></script>
12
12
  </body>
13
13
  </html>
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "dsdsds",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build --base=./",
9
+ "preview": "vite preview"
10
+ },
11
+ "devDependencies": {
12
+ "vite": "^4.3.9"
13
+ }
14
+ }
@@ -0,0 +1 @@
1
+ export const ENV = import.meta.env
@@ -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
@@ -0,0 +1,12 @@
1
+ export default class Net
2
+ def self.curl(url, &callback)
3
+ fetch(url)
4
+ .then(lambda do |response|
5
+ response.text()
6
+ end)
7
+ .then(lambda do |text|
8
+ callback(text) if callback
9
+ end)
10
+ end
11
+ end
12
+ window.Net = Net
@@ -0,0 +1,2 @@
1
+ import './core/events'
2
+ import './core/net'
@@ -1,3 +1,5 @@
1
1
  import '../css/style.css'
2
2
 
3
+ import './core'
4
+
3
5
  document.querySelector('#app').innerHTML = "<h1>Hello RubyJS</h1>"
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.1.3
4
+ version: 2.0.1
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: 2023-06-02 00:00:00.000000000 Z
11
+ date: 2024-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2js
@@ -16,66 +16,80 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '5.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '5.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: listen
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.7'
33
+ version: '3.8'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.7'
41
- description: Using this translation tool, you can run Vite server and write code in
42
- Ruby syntax using JS API. See GitHub for further information. |> https://github.com/filipvrba/ruby-js
40
+ version: '3.8'
41
+ description: This is a tool that behaves like a CLI application. The tool can track
42
+ RB files in real time and transpile them into JS files. RubyJS-Vite has its own
43
+ ecosystem and various plugins can be added. This tool can also communicate with
44
+ Vite tool for easier web development. Read the documentation for more information.
43
45
  email: filipvrbaxi@gmail.com
44
46
  executables:
45
47
  - rjsv
46
48
  extensions: []
47
49
  extra_rdoc_files: []
48
50
  files:
49
- - app/arguments.rb
50
- - app/config.rb
51
- - app/main.rb
52
- - app/signals.rb
53
51
  - bin/rjsv
54
- - lib/description.rb
55
52
  - lib/json_parser.rb
56
53
  - lib/option_parser.rb
57
- - lib/ruby_js.rb
58
- - lib/ruby_js/code_join.rb
59
- - lib/ruby_js/constants.rb
60
- - lib/ruby_js/helper.rb
61
- - lib/ruby_js/scaffold.rb
62
- - lib/ruby_js/version.rb
63
- - share/template/.codejoin
64
- - share/template/.gitignore
65
- - share/template/bin/generate
66
- - share/template/bin/server
67
- - share/template/bin/watch
68
- - share/template/index.html
69
- - share/template/package.json
70
- - share/template/public/vite.svg
71
- - share/template/src/css/style.css
72
- - share/template/src/rjs/main.rjs
54
+ - lib/rjsv.rb
55
+ - lib/rjsv/cli/arguments.rb
56
+ - lib/rjsv/cli/plugins.rb
57
+ - lib/rjsv/cli/signals.rb
58
+ - lib/rjsv/cli/states.rb
59
+ - lib/rjsv/constants.rb
60
+ - lib/rjsv/core/constants.rb
61
+ - lib/rjsv/core/event.rb
62
+ - lib/rjsv/core/files.rb
63
+ - lib/rjsv/plugin.rb
64
+ - lib/rjsv/translate.rb
65
+ - lib/rjsv/version.rb
66
+ - lib/rjsv/watch.rb
67
+ - plugins/scaffold/lib/init.rb
68
+ - plugins/scaffold/lib/scaffold/cli/arguments.rb
69
+ - plugins/scaffold/lib/scaffold/create.rb
70
+ - plugins/scaffold/lib/scaffold/states.rb
71
+ - plugins/scaffold/lib/scaffold/vite.rb
72
+ - share/scaffold/element/element.js.rb
73
+ - share/scaffold/element/init.js.rb
74
+ - share/scaffold/web/.gitignore
75
+ - share/scaffold/web/bin/server
76
+ - share/scaffold/web/config/ruby2js.rb
77
+ - share/scaffold/web/index.html
78
+ - share/scaffold/web/package.json
79
+ - share/scaffold/web/public/vite.svg
80
+ - share/scaffold/web/src/css/style.css
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
85
+ - share/scaffold/web/src/rb/main.js.rb
73
86
  homepage: https://rubygems.org/gems/rubyjs-vite
74
87
  licenses:
75
88
  - MIT
76
89
  metadata:
77
90
  source_code_uri: https://github.com/filipvrba/ruby-js
78
- post_install_message:
91
+ documentation_uri: https://filipvrba.github.io/ruby-js/
92
+ post_install_message:
79
93
  rdoc_options: []
80
94
  require_paths:
81
95
  - lib
@@ -90,8 +104,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
104
  - !ruby/object:Gem::Version
91
105
  version: '0'
92
106
  requirements: []
93
- rubygems_version: 3.4.10
94
- signing_key:
107
+ rubygems_version: 3.5.3
108
+ signing_key:
95
109
  specification_version: 4
96
- summary: Converts the syntax of ruby into javascript.
110
+ summary: CLI application with RB file transpilation that communicates with the Vite
111
+ tool.
97
112
  test_files: []
data/app/arguments.rb DELETED
@@ -1,67 +0,0 @@
1
- require "option_parser"
2
-
3
- @options = {
4
- compile: false,
5
- generate: nil,
6
- watch: false,
7
- output: Dir.pwd,
8
- output_type: RubyJS::Constants::FILE_TYPE_O,
9
- source: Dir.pwd,
10
- eslevel: Config::get_eslevel,
11
- pid: nil,
12
- }
13
-
14
- OptionParser.parse do |parser|
15
- parser.banner(
16
- "Converts the syntax of ruby into javascript.\n" +
17
- "Usage: #{RubyJS::Constants::APP_NAME} [options]\n" +
18
- "\nOptions:"
19
- )
20
- parser.on( "-h", "--help", "Show help" ) do
21
- puts parser
22
- exit
23
- end
24
- parser.on( "-v", "--version", "Show version" ) do
25
- puts "Version is #{RubyJS::VERSION}"
26
- exit
27
- end
28
- parser.on( "-w", "--watch", "Watch scripts for changes and rerun commands." ) do
29
- @options[:watch] = true
30
- end
31
- parser.on( "-c", "--compile", "Compile to JavaScript and save as .#{@options[:output_type]} files." ) do
32
- @options[:compile] = true
33
- end
34
- parser.on( "-g PATH", "--generate PATH", "Copies every rjs file into a single rjs file." ) do |path|
35
- if File.directory?(path)
36
- @options[:generate] = path
37
- else
38
- @options[:generate] = ""
39
- end
40
- end
41
- parser.on("-o DIR", "--output DIR", "Set the output path or path/filename\n" +
42
- "for compiled JavaScript." ) do |dir|
43
- @options[:output] = dir
44
- end
45
- parser.on("-ot TYPE", "--output-type TYPE", "Set the output type.\n" +
46
- "The default: #{@options[:output_type]}" ) do |type|
47
- @options[:output_type] = type
48
- end
49
- parser.on("-s DIR", "--source DIR", "Set the source path or path/filename\n" +
50
- "for RubyJS." ) do |dir|
51
- @options[:source] = dir
52
- end
53
- parser.on("-es LEVEL", "--eslevel LEVEL", "ECMAScript versions for compilation.\n" +
54
- "The default: #{@options[:eslevel]}\n" +
55
- "(Accepted level ranges 2015...2022.)") do |level|
56
-
57
- @options[:eslevel] = level.to_i
58
- end
59
- parser.on("--pid PROCESS", "", "When the pid is set, the SIGUSR1\n" +
60
- "signal is triggered." ) do |pid|
61
- @options[:pid] = pid.to_i
62
- end
63
- parser.on("--create PROJECT", nil, "Creates a new project using scaffolding." ) do |project|
64
- RubyJS::Scaffold.create project
65
- exit
66
- end
67
- end
data/app/config.rb DELETED
@@ -1,11 +0,0 @@
1
- module Config
2
- module_function
3
-
4
- @default = JsonParser.new File.join(ROOT, 'config/default.json')
5
- # If eslevel doesn't already exist, the default value is used to initialize it.
6
- @default.on :eslevel, "2021"
7
-
8
- def get_eslevel
9
- @default.parse(:eslevel).to_i
10
- end
11
- end
data/app/main.rb DELETED
@@ -1,75 +0,0 @@
1
- require "ruby_js"
2
- require_relative "config"
3
- require_relative "arguments"
4
- require_relative "signals"
5
-
6
- def compile_fun path_f
7
- RubyJS.compile path_f, {
8
- eslevel: @options[:eslevel],
9
- path_s: @options[:source],
10
- path_o: @options[:output],
11
- type_o: @options[:output_type],
12
- }
13
- end
14
-
15
- def compile path_f
16
- if @options[:compile]
17
- compile_fun(path_f)
18
- else
19
- puts RubyJS::Helper.event_p("warning", "This '#{path_f}' file was edited, " +
20
- "but it wasn't made into a js file.")
21
- end
22
- end
23
-
24
- def generate
25
- if @options[:generate]
26
- code_j = RubyJS.generate_cj @options[:source], @options[:generate]
27
- return code_j.get_ignore_r
28
- end
29
-
30
- return RubyJS::CodeJoin::TEST_N
31
- end
32
- ignore_cjfs = generate()
33
-
34
- if @options[:compile]
35
- RubyJS.get_files(@options[:source]).each do |path_f|
36
- compile_fun(path_f)
37
- end
38
- end
39
-
40
- if @options[:watch]
41
- h_sigusr = lambda do
42
- pid = @options[:pid]
43
- if pid
44
- Process.kill("USR1", pid)
45
- end
46
- end
47
-
48
- puts RubyJS::Helper.event_p("message", "There is now a watch for edited files.")
49
- h_sigusr.call()
50
-
51
- path_s = @options[:source]
52
-
53
- RubyJS::Helper.create_dir(path_s)
54
- RubyJS.watch path_s, ignore_cjfs do |modified, added, removed|
55
- generate()
56
-
57
- unless added.empty?
58
- compile(added.last)
59
- end
60
-
61
- unless modified.empty?
62
- compile(modified.last)
63
- end
64
-
65
- unless removed.empty?
66
- RubyJS.free removed.last, {
67
- path_s: @options[:source],
68
- path_o: @options[:output],
69
- type_o: @options[:output_type],
70
- }
71
- end
72
-
73
- h_sigusr.call()
74
- end
75
- end
data/app/signals.rb DELETED
@@ -1,4 +0,0 @@
1
- Signal.trap("INT") do
2
- puts "\n" + RubyJS::Helper.event_p("exiting")
3
- exit
4
- end
data/lib/description.rb DELETED
@@ -1,10 +0,0 @@
1
- module Description
2
- module_function
3
-
4
- def get_readme(parag_count)
5
- path_ra = File.expand_path("..", __dir__)
6
- path_fa = File.join(path_ra, 'README.md')
7
- content = File.open(path_fa).read.split("\n")[1..parag_count + 1]
8
- content.join("\n")
9
- end
10
- end