rubyjs-vite 1.1.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +71 -0
- data/lib/rjsv/cli/signals.rb +15 -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 +96 -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 +105 -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/{template → scaffold/web}/package.json +6 -3
- data/share/scaffold/web/src/css/style.css +0 -0
- data/share/scaffold/web/src/js/env.js +1 -0
- metadata +42 -30
- 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/src/css/style.css → scaffold/web/.env} +0 -0
- /data/share/{template → scaffold/web}/public/vite.svg +0 -0
- /data/share/{template/src/rjs/main.rjs → scaffold/web/src/rb/main.js.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be5d3678617c35c3ed3a02eb1e9822bb725055fed392f18742262757f0ce9064
|
4
|
+
data.tar.gz: 3e0e450c8464c82f8b4795e39c85ee92a3f5c25316ee1a0d63dd3703061e3e1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa91c0766b29943444a4c872f59306c527b4b27f60fdc4c17793469a6e2ae9cf404a76c9d0a503b150002664279810516befc50bafa13277d567d4a5aee5bbf8
|
7
|
+
data.tar.gz: d88354c19f850192b3b77cf6fa80dcafe2401795bc2eeabc9c34bb3cdfbbbd16f6c43ea70f2559032fdaa717a210f292288cf853faf6bec6a5d2beea3a882582
|
data/bin/rjsv
CHANGED
data/lib/option_parser.rb
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
module RJSV
|
2
|
+
module CLI
|
3
|
+
##
|
4
|
+
# Module for all arguments to the CLI application.
|
5
|
+
# The argument initializes the OptionParser,
|
6
|
+
# which defines the arguments in detail.
|
7
|
+
# It is also nested with a function that adds
|
8
|
+
# all arguments from modules.
|
9
|
+
|
10
|
+
module Arguments
|
11
|
+
@options = {
|
12
|
+
translate: false,
|
13
|
+
watch: false,
|
14
|
+
source: Dir.pwd,
|
15
|
+
output: Dir.pwd,
|
16
|
+
}
|
17
|
+
|
18
|
+
OptionParser.parse do |parser|
|
19
|
+
parser.banner(
|
20
|
+
"A transpiler tool that translates code\n" +
|
21
|
+
"from Ruby to JS language and transforms it into\n" +
|
22
|
+
"files that are readable by browsers.\n\n" +
|
23
|
+
"Usage: #{APP_NAME} [options]\n" +
|
24
|
+
"\nOptions:"
|
25
|
+
)
|
26
|
+
|
27
|
+
Plugins.add_arguments(parser)
|
28
|
+
|
29
|
+
parser.on( "-w", "--watch", "Monitors all RB files in real time\n" +
|
30
|
+
"to see if they have been modified." ) do
|
31
|
+
@options[:watch] = true
|
32
|
+
end
|
33
|
+
parser.on( "-t", "--translate", "It translates all loaded RB files\n" +
|
34
|
+
"into JavaScript code and stores them\n" +
|
35
|
+
"in certain type files." ) do
|
36
|
+
@options[:translate] = true
|
37
|
+
end
|
38
|
+
parser.on("-s DIR", "--source DIR", "The path of the source folder where\n" +
|
39
|
+
"all RB files are found (example of\n" +
|
40
|
+
"ending file type *.js.#{RJSV::Constants::SUFFIX_RB}).\n") do |dir|
|
41
|
+
@options[:source] = dir
|
42
|
+
end
|
43
|
+
parser.on("-o DIR", "--output DIR", "The path of the output folder where\n" +
|
44
|
+
"all Ruby codes will be translated into\n" +
|
45
|
+
"JavaScript with the prepared file type." ) do |dir|
|
46
|
+
@options[:output] = dir
|
47
|
+
end
|
48
|
+
|
49
|
+
parser.on( "-h", "--help", "Show help" ) do
|
50
|
+
puts parser
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
parser.on( "-v", "--version", "Show version" ) do
|
54
|
+
puts "Version is #{RJSV::VERSION}"
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Options is a get method and gets
|
61
|
+
# all options from arguments.
|
62
|
+
|
63
|
+
def self.options
|
64
|
+
@options
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# It finds out if the plugin is written in the argument.
|
69
|
+
|
70
|
+
def self.active_plugin?
|
71
|
+
unless ARGV.empty?
|
72
|
+
return ARGV[0].index(/^-/) == nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end#Arguments
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module RJSV
|
2
|
+
module CLI
|
3
|
+
##
|
4
|
+
# This is the module that handles plugins so
|
5
|
+
# that they are found, imported and inizialized.
|
6
|
+
|
7
|
+
module Plugins
|
8
|
+
PLUGIN_INFO = "(this is a plugin)"
|
9
|
+
|
10
|
+
module_function
|
11
|
+
|
12
|
+
##
|
13
|
+
# Finds all init.rb files in the plugins folder.
|
14
|
+
# Otherwise, the absolute path is determined
|
15
|
+
# by the Dir.pwd() method.
|
16
|
+
|
17
|
+
def find_all_init(path = Dir.pwd)
|
18
|
+
l_path = lambda { |p| File.join(p, 'plugins', '**', 'init.rb') }
|
19
|
+
Dir.glob [
|
20
|
+
l_path.call(path),
|
21
|
+
l_path.call(ROOT)
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Imports all found init.rb files into Ruby script.
|
27
|
+
#
|
28
|
+
# Returns the classes that are imported,
|
29
|
+
# otherwise returns an empty array.
|
30
|
+
|
31
|
+
def require_all_init()
|
32
|
+
find_all_init().each do |plugin_index_path|
|
33
|
+
require plugin_index_path
|
34
|
+
end
|
35
|
+
|
36
|
+
if defined?(RJSV::Plugins)
|
37
|
+
return Core::Constants.get_classes(RJSV::Plugins)
|
38
|
+
end
|
39
|
+
|
40
|
+
return []
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Adds a plugin argument and initializes its nested arguments.
|
45
|
+
#
|
46
|
+
# It chooses the name and description of the argument
|
47
|
+
# to be the one written on behalf of the plugin,
|
48
|
+
# which is found from the RJSV::Plugin class.
|
49
|
+
|
50
|
+
def add_arguments(parser)
|
51
|
+
@classes.each_with_index do |plugin_class, i|
|
52
|
+
begin
|
53
|
+
if plugin_class
|
54
|
+
plugin = plugin_class.new
|
55
|
+
parser.on(plugin.name, "", "#{plugin.description}\n" +
|
56
|
+
"#{PLUGIN_INFO}#{"\n" if @classes.length == i+1}" ) do
|
57
|
+
plugin.arguments()
|
58
|
+
plugin.init()
|
59
|
+
end
|
60
|
+
end
|
61
|
+
rescue => exception
|
62
|
+
Core::Event.print('class', "The program found the '#{plugin_class.name}' class, " +
|
63
|
+
"but its arguments cannot be created.\n\n")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end#add_arguments
|
67
|
+
|
68
|
+
@classes = require_all_init()
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RJSV
|
2
|
+
module Core
|
3
|
+
##
|
4
|
+
# The module is reserved for handling classes and modules.
|
5
|
+
# Thus, it is a manipulation of constant keywords.
|
6
|
+
|
7
|
+
module Constants
|
8
|
+
module_function
|
9
|
+
|
10
|
+
##
|
11
|
+
# This method tries to find already initialized
|
12
|
+
# classes from the mod (module) using the abstract
|
13
|
+
# class RJSV::Plugin. It returns an array of classes.
|
14
|
+
|
15
|
+
def get_classes(mod)
|
16
|
+
mod.constants.map do |c|
|
17
|
+
const = mod.const_get(c)
|
18
|
+
|
19
|
+
if const.is_a?(Class) &&
|
20
|
+
const.superclass.name == 'RJSV::Plugin'
|
21
|
+
const
|
22
|
+
elsif const.is_a? Module
|
23
|
+
get_classes(const)
|
24
|
+
else
|
25
|
+
next
|
26
|
+
end
|
27
|
+
end.flatten.compact
|
28
|
+
end#get_classes
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RJSV
|
2
|
+
module Core
|
3
|
+
##
|
4
|
+
# Event module for handling fifo events. This is
|
5
|
+
# so far a module for just the basic event
|
6
|
+
# printing element.
|
7
|
+
|
8
|
+
module Event
|
9
|
+
module_function
|
10
|
+
|
11
|
+
##
|
12
|
+
# Prints an event type using the puts() method
|
13
|
+
# that shows the time, cli application name,
|
14
|
+
# event and event message.
|
15
|
+
|
16
|
+
def print(event, message = "")
|
17
|
+
supplement = message.empty? ? message : " | #{message}"
|
18
|
+
|
19
|
+
puts "#{Time.now.strftime("%l:%M:%S %p").lstrip} " +
|
20
|
+
"[#{APP_NAME}] #{event.upcase}#{supplement}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module RJSV
|
2
|
+
module Core
|
3
|
+
##
|
4
|
+
# The file module ensures safe handling of files.
|
5
|
+
# It always checks if a file really exists on
|
6
|
+
# the input path or if a certain folder exists
|
7
|
+
# on the output path. It can also change
|
8
|
+
# the absolute path or find all necessary files
|
9
|
+
# for further manipulation.
|
10
|
+
|
11
|
+
module Files
|
12
|
+
require 'fileutils'
|
13
|
+
|
14
|
+
module_function
|
15
|
+
|
16
|
+
##
|
17
|
+
# Opens the file securely and returns the content
|
18
|
+
# from the file. If the file does not exist,
|
19
|
+
# it returns nil.
|
20
|
+
|
21
|
+
def open(path)
|
22
|
+
if File.exist? path
|
23
|
+
File.open path do |f|
|
24
|
+
return f.read
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Stores the file with the assigned container
|
33
|
+
# by safely discovering its folder and, if necessary,
|
34
|
+
# creating it when it does not exist in the path.
|
35
|
+
# It can also be assigned a file write mode.
|
36
|
+
|
37
|
+
def write_with_dir(content, path, mode = 'w+')
|
38
|
+
unless Dir.exist? File.dirname(path)
|
39
|
+
FileUtils.mkdir_p File.dirname(path)
|
40
|
+
end
|
41
|
+
|
42
|
+
File.open path, mode do |f|
|
43
|
+
f.write(content)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Safely removes the file from the path.
|
49
|
+
# If the file is the last one in the folder,
|
50
|
+
# the folder is also deleted with the file.
|
51
|
+
|
52
|
+
def remove(path)
|
53
|
+
File.delete(path) if File.exist?(path)
|
54
|
+
path_dir = File.dirname(path)
|
55
|
+
Dir.delete(path_dir) if Dir.empty?(path_dir)
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# The method is special in that it examines arguments
|
60
|
+
# from the CLI and modifies the definition
|
61
|
+
# path for the output path.
|
62
|
+
|
63
|
+
def change_path_to_output(path, options_cli)
|
64
|
+
path.sub(File.join(Dir.pwd, ''), '')
|
65
|
+
.sub(options_cli[:source], '')
|
66
|
+
.sub(/\.#{RJSV::Constants::SUFFIX_RB}$/, '')
|
67
|
+
.prepend(options_cli[:output])
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Finds all files with the extension '.*.rb'
|
72
|
+
# from the defined path.
|
73
|
+
|
74
|
+
def find_all(path)
|
75
|
+
path_all = File.join(path, '**', '*')
|
76
|
+
Dir.glob("#{path_all}.*.#{RJSV::Constants::SUFFIX_RB}")
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Copies all files from the input path to the
|
81
|
+
# output path. This is a method that copies all
|
82
|
+
# files even those that are invisible to the
|
83
|
+
# UNIX system (dot file).
|
84
|
+
|
85
|
+
def copy(path_input, path_output)
|
86
|
+
files = Dir.glob("#{path_input}/**/*", File::FNM_DOTMATCH)
|
87
|
+
.select { |f| File.file?(f) }
|
88
|
+
files.each do |path_file|
|
89
|
+
path_cp = path_file.sub(path_input, path_output)
|
90
|
+
FileUtils.mkdir_p File.dirname(path_cp)
|
91
|
+
FileUtils.cp(path_file, path_cp)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/rjsv/plugin.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module RJSV
|
2
|
+
##
|
3
|
+
# Abstract 'class' for creating initialization plagins.
|
4
|
+
# They are teachable for defining basic information
|
5
|
+
# and is the starting point for triggering functions
|
6
|
+
# using the init() function. If we are creating
|
7
|
+
# a custom plugin, we need to inherit this 'class'
|
8
|
+
# into its own 'class'.
|
9
|
+
|
10
|
+
class Plugin
|
11
|
+
##
|
12
|
+
# Description of the plugin that is printed to the CLI during help.
|
13
|
+
|
14
|
+
def description
|
15
|
+
abstract_error('description()')
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# This function is not mandatory and automatically
|
20
|
+
# defines the 'module' name according to
|
21
|
+
# the plugin 'module'.
|
22
|
+
|
23
|
+
def name
|
24
|
+
self.class.name.split('::')[-2].downcase
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# The method should pass an initialization
|
29
|
+
# method for all arguments of this plugin.
|
30
|
+
|
31
|
+
def arguments
|
32
|
+
abstract_error('arguments()')
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# The method that is the main initialization
|
37
|
+
# block for the code that the plugin
|
38
|
+
# should execute.
|
39
|
+
|
40
|
+
def init
|
41
|
+
abstract_error('init()')
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
##
|
46
|
+
# A private method that raises an error
|
47
|
+
# message about an abstract class with
|
48
|
+
# a function name.
|
49
|
+
|
50
|
+
def abstract_error(fn_name)
|
51
|
+
raise "The '#{fn_name}' method is abstract, " +
|
52
|
+
"it needs to be implemented in a nested '#{self.class.name}' class."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module RJSV
|
2
|
+
##
|
3
|
+
# Here we can load everything necessary for
|
4
|
+
# the transpilation process of Ruby script into JavaScript.
|
5
|
+
# The transpilation process uses the Ruby2JS library.
|
6
|
+
# The transpilation is safe and catches error messages
|
7
|
+
# if the Ruby script has been written incorrectly.
|
8
|
+
|
9
|
+
module Translate
|
10
|
+
require 'ruby2js'
|
11
|
+
|
12
|
+
module_function
|
13
|
+
|
14
|
+
##
|
15
|
+
# Converts Ruby script to JavaScript using Ruby2JS library.
|
16
|
+
# If an error occurs during transpilation, the error
|
17
|
+
# message is raised in the next nested code block.
|
18
|
+
|
19
|
+
def ruby_to_js(content_ruby, &block)
|
20
|
+
begin
|
21
|
+
return Ruby2JS.convert(content_ruby)
|
22
|
+
rescue => exception
|
23
|
+
block.call(exception) if block
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Converts Ruby script to JavaScript using Ruby2JS library.
|
30
|
+
# The final transpilation is followed by saving it to
|
31
|
+
# a file with a predefined path.
|
32
|
+
|
33
|
+
def ruby_to_js_with_write(content_ruby, path, &block)
|
34
|
+
content_js = ruby_to_js(content_ruby) do |err|
|
35
|
+
block.call(err) if block
|
36
|
+
end
|
37
|
+
Core::Files.write_with_dir(content_js, path) if content_js
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/rjsv/version.rb
ADDED
data/lib/rjsv/watch.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module RJSV
|
2
|
+
##
|
3
|
+
# Module for real-time monitoring of files on
|
4
|
+
# the local disk. It uses the 'listen' library
|
5
|
+
# for this function. There is only one method
|
6
|
+
# that can be loaded here which triggers everything.
|
7
|
+
|
8
|
+
module Watch
|
9
|
+
require "listen"
|
10
|
+
|
11
|
+
module_function
|
12
|
+
|
13
|
+
##
|
14
|
+
# Tracks modified files in the path that is
|
15
|
+
# defined as the source directory. When this
|
16
|
+
# function is called, the event listener is triggered
|
17
|
+
# for events such as modified, added, and deleted
|
18
|
+
# file events. Therefore, the method can put
|
19
|
+
# the application to sleep and silently monitor
|
20
|
+
# the event process. It watches all files with
|
21
|
+
# extension '.*.rb', which asterisk means
|
22
|
+
# any sub extension such as '.js'.
|
23
|
+
|
24
|
+
def modified_files(path, &block)
|
25
|
+
listener = Listen.to(path,
|
26
|
+
only: /\..*\.#{Constants::SUFFIX_RB}$/
|
27
|
+
) do |m, a, r|
|
28
|
+
|
29
|
+
block.call(m, a, r) if block
|
30
|
+
end
|
31
|
+
listener.start
|
32
|
+
sleep
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rjsv.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'option_parser'
|
2
|
+
require 'json_parser'
|
3
|
+
|
4
|
+
require 'rjsv/version'
|
5
|
+
require 'rjsv/constants'
|
6
|
+
require 'rjsv/plugin'
|
7
|
+
|
8
|
+
require 'rjsv/core/event'
|
9
|
+
require 'rjsv/core/files'
|
10
|
+
require 'rjsv/core/constants'
|
11
|
+
|
12
|
+
require 'rjsv/cli/signals'
|
13
|
+
require 'rjsv/cli/plugins'
|
14
|
+
require 'rjsv/cli/arguments'
|
15
|
+
|
16
|
+
require 'rjsv/translate'
|
17
|
+
require 'rjsv/watch'
|
18
|
+
|
19
|
+
##
|
20
|
+
# This is the main initialization module of
|
21
|
+
# all modules that are needed for the functionality
|
22
|
+
# of this RubyJS-Vite transpiler. The methods that
|
23
|
+
# shape the direction of the application are
|
24
|
+
# also written here.
|
25
|
+
|
26
|
+
module RJSV
|
27
|
+
@options_cli = CLI::Arguments.options
|
28
|
+
|
29
|
+
module_function
|
30
|
+
|
31
|
+
##
|
32
|
+
# Block of code that handles the transpilation of script.
|
33
|
+
# This is opening a Ruby script container file,
|
34
|
+
# which is then converted into a JavaScript file.
|
35
|
+
# The file is saved to the output path.
|
36
|
+
|
37
|
+
def translate_state(path)
|
38
|
+
if @options_cli[:translate]
|
39
|
+
content_ruby = Core::Files.open(path)
|
40
|
+
if content_ruby && path
|
41
|
+
path_output = Core::Files.change_path_to_output(path, @options_cli)
|
42
|
+
Translate.ruby_to_js_with_write(content_ruby, path_output) do |err|
|
43
|
+
Core::Event.print('error', "#{path.sub(File.join(Dir.pwd, ''), '')} #{err}")
|
44
|
+
return
|
45
|
+
end
|
46
|
+
Core::Event.print('translated', path_output)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Block of code that tracks files under the input path.
|
53
|
+
# If a file has been logged, several events are performed
|
54
|
+
# such as to add, modify and remove logged files.
|
55
|
+
# These then trigger procedural methods to process the requests.
|
56
|
+
|
57
|
+
def watch_state()
|
58
|
+
if @options_cli[:watch]
|
59
|
+
Core::Event.print('message', 'There is now a watch for edited files.')
|
60
|
+
Watch.modified_files(@options_cli[:source]) do |modified, added, removed|
|
61
|
+
unless added.empty?
|
62
|
+
added.each do |path|
|
63
|
+
translate_state(path)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
unless modified.empty?
|
68
|
+
modified.each do |path|
|
69
|
+
translate_state(path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
unless removed.empty?
|
74
|
+
removed.each do |path|
|
75
|
+
path_output = Core::Files.change_path_to_output(path, @options_cli)
|
76
|
+
Core::Files.remove(path_output)
|
77
|
+
Core::Event.print('deleted', path_output)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end#watch_state
|
83
|
+
|
84
|
+
##
|
85
|
+
# This is the main function to run the desired
|
86
|
+
# block function scenarios. In order to arm itself
|
87
|
+
# regarding plugins and directly Arguments,
|
88
|
+
# this method checks the accessibility of the plugin
|
89
|
+
# by checking if it is active or attached in
|
90
|
+
# the argument given by the confirmed command
|
91
|
+
# from the terminal.
|
92
|
+
|
93
|
+
def main()
|
94
|
+
unless CLI::Arguments.active_plugin?
|
95
|
+
if @options_cli[:translate]
|
96
|
+
files_rb = Core::Files.find_all(@options_cli[:source])
|
97
|
+
files_rb.each do |path|
|
98
|
+
translate_state(path)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
watch_state()
|
103
|
+
end
|
104
|
+
end#main
|
105
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RJSV
|
2
|
+
module Plugins
|
3
|
+
module Scaffold
|
4
|
+
require_relative './scaffold/cli/arguments'
|
5
|
+
|
6
|
+
require_relative './scaffold/vite'
|
7
|
+
require_relative './scaffold/states'
|
8
|
+
require_relative './scaffold/create'
|
9
|
+
|
10
|
+
class Init < RJSV::Plugin
|
11
|
+
def initialize
|
12
|
+
@arguments_cli = RJSV::Plugins::Scaffold::CLI::Arguments
|
13
|
+
end
|
14
|
+
|
15
|
+
def description
|
16
|
+
"Scaffolding can create new\n" +
|
17
|
+
"projects or create new elements."
|
18
|
+
end
|
19
|
+
|
20
|
+
def arguments
|
21
|
+
@arguments_cli.init(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def init()
|
25
|
+
Scaffold::States.create_web_state(@arguments_cli.options)
|
26
|
+
Scaffold::States.create_element_state(@arguments_cli.options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -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
|