dragonruby-egg 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dbdcd93f1ddb45e46dda6c8ea2cb44eeace67558a04a417367fd6c7cc50d1e93
4
+ data.tar.gz: f3d41e967e4b7c6001b3b050a0329a23940db9ac574c285551f0107473176163
5
+ SHA512:
6
+ metadata.gz: 283be22db3317bf2de5cfea3c914e19c78b53599f21d91f8e28371a3f86f041caf19cd9a159d5e84f51471c40713eaa6ef616b97bfca8f1ef6ff5ae497068da0
7
+ data.tar.gz: 831e2537cccd96361543fd1e2b6700d5381fab124af774befe6aee210ca9363b16761e3a0fdd6605ca94eb87dcef54c1b21ddf8a99676f9dbeeaa89b28166f73
data/app/arguments.rb ADDED
@@ -0,0 +1,60 @@
1
+ module Dre
2
+ @options = {
3
+ is_docs: false,
4
+ is_egg: false,
5
+ root_path: nil,
6
+ path: nil,
7
+ install: nil,
8
+ new: nil
9
+ }
10
+ @options[:path] = OptionParser.last_arg if Dir.exist?(OptionParser.last_arg)
11
+
12
+ OptionParser.parse do |parser|
13
+ parser.banner(
14
+ "#{DragonrubyEgg::Constants::APP_FULL_NAME} is a tool for managing DragonRuby.\n" +
15
+ "Usage: #{APP_NAME} [options] [path]\n" +
16
+ "\nOptions:"
17
+ )
18
+ parser.on( "new NAME", "", "They will create a new game project.") do |name|
19
+ @options[:new] = name
20
+ end
21
+ parser.on( "install MODULE", "", "Installs the module in the working folder.\n" +
22
+ "(Example: install dr-core-rb,\n" +
23
+ "install filipvrba.dr-core-rb)\n" ) do |repo_module|
24
+ @options[:install] = repo_module
25
+ end
26
+ parser.on( "-e", "--egg", "This opens a page in the main browser\n" +
27
+ "that lists all the modules that can be\n"+
28
+ "installed in the game project." ) do
29
+ @options[:is_egg] = true
30
+ end
31
+ parser.on( "-d", "--docs", "Opens the documentation for DragonRuby\n" +
32
+ "in the main browser." ) do
33
+ @options[:is_docs] = true
34
+ end
35
+ parser.on( "-sr PATH", "--set-root PATH",
36
+ "This command sets the root\n" +
37
+ "path to DragonRuby.\n" +
38
+ "(Default: '#{@configuration.parse(:root_path)}')"
39
+ ) do |path|
40
+ @options[:root_path] = path
41
+ end
42
+ parser.on( "-h", "--help", "Show help" ) do
43
+ puts parser
44
+ exit
45
+ end
46
+ parser.on( "-v", "--version", "Show version" ) do
47
+ DragonrubyEgg::Event.print('VERSION', DragonrubyEgg::VERSION)
48
+ exit
49
+ end
50
+ end
51
+
52
+ def self.options_empty?
53
+ @options.each do |k, v|
54
+ if k != :path and v
55
+ return false
56
+ end
57
+ end
58
+ return true
59
+ end
60
+ end
@@ -0,0 +1,36 @@
1
+ module Dre
2
+ module_function
3
+
4
+ @configuration = JsonParser.new File.join(ROOT, 'config/default.json')
5
+ h_root_path = lambda { |_| @configuration.parse(:root_path) }
6
+ DragonrubyEgg::Event.add(:root_path, h_root_path)
7
+
8
+ def configuration_on
9
+ @configuration.on_handler(:root_path,
10
+ lambda do
11
+ r_path = DragonrubyEgg::Executable.find_root_path
12
+ unless r_path
13
+ DragonrubyEgg::Event.print('ROOT-PATH',
14
+ "No DragonRuby root path has been found."
15
+ )
16
+ DragonrubyEgg::Event.print('WARNING',
17
+ "Please set the root path using the -sr " +
18
+ "or --set-root argument."
19
+ )
20
+ end
21
+ return r_path
22
+ end
23
+ ) do |is_end, r_path|
24
+ unless is_end
25
+ DragonrubyEgg::Event.print('ROOT-PATH',
26
+ "The root path has not been set and so the analysis " +
27
+ "of the root path is performed."
28
+ )
29
+ else
30
+ DragonrubyEgg::Event.print('SET', "root_path: #{r_path}")
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ Dre.configuration_on()
data/app/inputs.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Dre
2
+ h_correct = lambda do |d|
3
+ print "Install this '#{d[0]}.#{d[1]}' module? (y/N): "
4
+ input = STDIN.gets.chomp
5
+ result = false
6
+
7
+ if input.downcase.index("y")
8
+ result = true
9
+ end
10
+ return result
11
+ end
12
+
13
+ DragonrubyEgg::Event.add(:input_correct, h_correct)
14
+ end
data/app/main.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'dragonruby_egg'
2
+ require 'option_parser'
3
+ require 'json_parser'
4
+
5
+ require_relative './configuration'
6
+ require_relative './arguments'
7
+ require_relative './inputs'
8
+
9
+ module Dre
10
+ module_function
11
+
12
+ def root_path_state
13
+ sym = :root_path
14
+ root_path = @options[sym]
15
+ if root_path
16
+ if root_path == ''
17
+ DragonrubyEgg::Event.print('WARNING', "An empty string for" +
18
+ "the root path is not acceptable.")
19
+ @configuration.delete(sym)
20
+ configuration_on()
21
+ else
22
+ @configuration.parse(sym, root_path)
23
+ DragonrubyEgg::Event.print('SET', "#{sym.to_s}: #{root_path.to_s}")
24
+ end
25
+ end
26
+ end
27
+
28
+ def main_state
29
+ if options_empty?
30
+ DragonrubyEgg::Executable.dragonruby(@options[:path])
31
+ elsif @options[:is_docs]
32
+ DragonrubyEgg::Executable.docs()
33
+ elsif @options[:is_egg]
34
+ DragonrubyEgg::Executable.egg()
35
+ elsif @options[:install]
36
+ if @options[:path]
37
+ DragonrubyEgg::Executable.install(@options[:install], @options[:path])
38
+ else
39
+ DragonrubyEgg::Event.print('WARNING', "A working path must " +
40
+ "be defined to install the module.")
41
+ end
42
+ elsif @options[:new]
43
+ DragonrubyEgg::Executable.new_project(@options[:new], @options[:path])
44
+ end
45
+ end
46
+ end
47
+
48
+ Dre.root_path_state()
49
+ Dre.main_state()
data/bin/dre ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_NAME = File.basename($0)
4
+ ROOT = File.expand_path("..", __dir__)
5
+ $: << File.join(ROOT, 'lib')
6
+ require_relative "../app/main"
@@ -0,0 +1,13 @@
1
+ module DragonrubyEgg
2
+ VERSION = "1.0.0"
3
+ module Constants
4
+ APP_FULL_NAME = 'DragonRuby-Egg'
5
+ DR_EXES = {
6
+ dr: 'dragonruby',
7
+ drh: 'dragonruby-httpd',
8
+ drp: 'dragonruby-publish'
9
+ }
10
+ DR_DOCS = 'docs/docs.html'
11
+ DRE_URL = 'https://dragonruby-egg-ui-rjs.vercel.app/'
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module DragonrubyEgg
5
+ module Database
6
+ GUARD_MODULES = "Ku3biL772AhmQndV"
7
+ DB_NAME = 1
8
+
9
+ module_function
10
+
11
+ def get_modules
12
+ rest_data = RestClient.get('https://bef.fly.dev/api/v1/guard', {
13
+ params: {
14
+ token: GUARD_MODULES,
15
+ database: DB_NAME
16
+ }
17
+ })
18
+ return JSON.parse(rest_data)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ module DragonrubyEgg
2
+ module Event
3
+ HANDLERS = {}
4
+ @is_print_active = true
5
+
6
+ module_function
7
+
8
+ def set_print_active(bool)
9
+ @is_print_active = bool
10
+ end
11
+
12
+ def print(event, message = "")
13
+ unless @is_print_active
14
+ return
15
+ end
16
+
17
+ puts("#{Time.now.strftime("%l:%M:%S %p").lstrip} [#{APP_NAME}] #{event} | #{message}")
18
+ end
19
+
20
+ def add(symbol, handler)
21
+ HANDLERS[symbol] = handler
22
+ end
23
+
24
+ def emit(symbol, *args)
25
+ HANDLERS[symbol].call(args)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,81 @@
1
+ module DragonrubyEgg
2
+ module Executable
3
+ module_function
4
+
5
+ def root_path? path
6
+ exes = Constants::DR_EXES.map { |_,v| File.join(path, v) }
7
+ exes.each do |exe|
8
+ is_existing = File.exist?(exe) && File.executable?(exe)
9
+ unless is_existing
10
+ return false
11
+ end
12
+ end
13
+
14
+ return true
15
+ end
16
+
17
+ def find_root_path(root = '/')
18
+ paths = Dir.glob(
19
+ "#{root}/**/#{Constants::DR_EXES[:dr]}",
20
+ File::FNM_DOTMATCH
21
+ )
22
+ paths.each do |path|
23
+ if File.exist?(path)
24
+ r_path = File.dirname(path)
25
+ if root_path?(r_path)
26
+ return r_path
27
+ end
28
+ end
29
+ end
30
+
31
+ return nil
32
+ end
33
+
34
+ def web_brower
35
+ %x(xdg-settings get default-web-browser)
36
+ .sub(/\..*$/, '').rstrip
37
+ end
38
+
39
+ def dragonruby arg
40
+ root_path = Event::emit(:root_path)
41
+ path = File.join(root_path, Constants::DR_EXES[:dr])
42
+ system("#{path} #{arg}")
43
+ end
44
+
45
+ def docs
46
+ root_path = Event::emit(:root_path)
47
+ doc_file = File.join(root_path, Constants::DR_DOCS)
48
+ system("#{web_brower} #{doc_file} &")
49
+ end
50
+
51
+ def egg
52
+ root_path = Event::emit(:root_path)
53
+ system("#{web_brower} #{Constants::DRE_URL} &")
54
+ end
55
+
56
+ def install repo_module, path
57
+ module_url = Modules.get_module_url(repo_module)
58
+ unless module_url
59
+ return
60
+ end
61
+ module_path = "#{path}/modules/#{repo_module}"
62
+
63
+ is_install = system("git clone --recurse-submodules #{module_url}.git '#{module_path}'")
64
+ if is_install
65
+ Event.print('INSTALL', "The '#{repo_module}' module " +
66
+ "has been installed in this '.#{module_path.sub(path, '')}' folder.")
67
+ end
68
+ end
69
+
70
+ def new_project name, path
71
+ root_path = Event::emit(:root_path)
72
+ unless path
73
+ path = Dir.pwd
74
+ end
75
+ is_copy = system("cp -r '#{root_path}/mygame' '#{path}/#{name}'")
76
+ if is_copy
77
+ Event.print('NEW', "The '#{name}' project has been created.")
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,24 @@
1
+ module DragonrubyEgg
2
+ module Modules
3
+ module_function
4
+
5
+ def get_module_url(repo_module)
6
+ modules = Database.get_modules()
7
+
8
+ modules.each do |_module|
9
+ author = _module["author"]
10
+ name = _module["name"]
11
+ url = _module["github_url"]
12
+
13
+ if repo_module.index(/^(#{author}.)?#{name}$/)
14
+ is_correct = Event.emit(:input_correct, author, name)
15
+ if is_correct
16
+ return url
17
+ end
18
+ end
19
+ end # modules each
20
+
21
+ return nil
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ require 'dragonruby_egg/constants'
2
+ require 'dragonruby_egg/event'
3
+ require 'dragonruby_egg/database'
4
+ require 'dragonruby_egg/modules'
5
+ require 'dragonruby_egg/executable'
6
+
7
+ module DragonrubyEgg
8
+ end
@@ -0,0 +1,107 @@
1
+ require "json"
2
+ require 'fileutils'
3
+
4
+ class JsonParser
5
+ attr_reader :path, :db
6
+
7
+ def initialize path, auto_write = true
8
+ @path = path
9
+ @db = open @path
10
+ @auto_write = auto_write
11
+ end
12
+
13
+ def on symbol, value
14
+ unless @db.include?(symbol.to_s)
15
+ parse symbol, value
16
+ end
17
+ end
18
+
19
+ def on_handler symbol, handler, &block
20
+ unless @db.include?(symbol.to_s)
21
+ block.call(false) if block
22
+ value = handler.call()
23
+ if value
24
+ parse symbol, value
25
+ block.call(true, value) if block
26
+ end
27
+ end
28
+ end
29
+
30
+ def parse symbols, value = nil, delete = nil
31
+ symbols_join = ""
32
+ if symbols.class.name == "Array"
33
+ symbols_join = symbols.join("\"][\"")
34
+ else
35
+ symbols_join = symbols.to_s
36
+ end
37
+ symbols_join = "[\"#{symbols_join}\"]"
38
+
39
+ unless delete
40
+ unless value
41
+ eval "@db#{ symbols_join }"
42
+ else
43
+ eval "@db#{ symbols_join } = value"
44
+
45
+ if @auto_write
46
+ write @path, @db
47
+ end
48
+ end
49
+ else
50
+ if symbols
51
+ eval "@db#{ symbols_join }.delete('#{delete}')"
52
+ else
53
+ eval "@db.delete('#{delete}')"
54
+ end
55
+
56
+ if @auto_write
57
+ write @path, @db
58
+ end
59
+ end
60
+ end
61
+
62
+ def exist?
63
+ @db.empty?
64
+ end
65
+
66
+ def delete key, symbols = nil
67
+ parse(symbols, nil, key)
68
+ end
69
+
70
+ private
71
+ def open path
72
+ begin
73
+ result = String.new
74
+ File.open path do |f|
75
+ result = JSON.parse f.read
76
+ end
77
+
78
+ return result
79
+ rescue
80
+ return Hash.new
81
+ end
82
+ end
83
+
84
+ def write path, db
85
+ begin
86
+ create_dir path do
87
+
88
+ f = File.new path, "w"
89
+ f.write JSON.pretty_generate db
90
+ f.close
91
+ end
92
+ end
93
+ end
94
+
95
+ def create_dir path, &callback
96
+ begin
97
+ dir_path = File.dirname path
98
+ unless Dir.exist? dir_path
99
+ FileUtils.mkpath dir_path
100
+ end
101
+
102
+ callback.call
103
+ rescue
104
+
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,91 @@
1
+ class OptionParser
2
+
3
+ LEFT = 2
4
+ MIDDLE = 33
5
+
6
+ attr_reader :args
7
+
8
+ def self.parse(args = ARGV)
9
+ parser = OptionParser.new
10
+ yield parser
11
+ parser.process args
12
+ parser
13
+ end
14
+
15
+ def self.last_arg(args = ARGV)
16
+ args.length >= 1 ? args[args.length - 1] : ''
17
+ end
18
+
19
+ def initialize(args = ARGV)
20
+ @args = args
21
+ @banner = nil
22
+ @flags = Array.new
23
+ end
24
+
25
+ def banner(banner)
26
+ @banner = banner
27
+ end
28
+
29
+ def on(short_flag, long_flag, description, &block)
30
+ @flags << { short_flag: short_flag || '', long_flag: long_flag || '',
31
+ description: description || '', block: block }
32
+ end
33
+
34
+ def process( args = ARGV )
35
+ unless args.length == 0
36
+ args.each_with_index do |arg, i|
37
+ @flags.each do |flag|
38
+ name = -> (type_flag) do
39
+ flag[type_flag].gsub( /[a-z -]/, '' )
40
+ end
41
+
42
+ flag_strip = -> (type_flag) do
43
+ flag[type_flag].sub( name.(type_flag), '' ).strip()
44
+ end
45
+ has_flag = -> (type_flag) { arg == flag_strip.(type_flag) }
46
+
47
+ if has_flag.(:short_flag) or
48
+ has_flag.(:long_flag)
49
+
50
+ has_name = -> (type_flag) do
51
+ name.(type_flag) != ""
52
+ end
53
+ value = nil
54
+
55
+ if has_name.(:short_flag) or
56
+ has_name.(:long_flag)
57
+ value = args[i + 1]
58
+ end
59
+
60
+ flag[:block].call( value )
61
+ end
62
+ end
63
+ end
64
+ else
65
+ flag = @flags[0]
66
+ flag[:block].call
67
+ end
68
+ end
69
+
70
+ def self.get_empty_spaces
71
+ " " * (MIDDLE + LEFT)
72
+ end
73
+
74
+ def to_s()
75
+ io = Array.new
76
+ if banner = @banner
77
+ io << banner
78
+ io << "\n"
79
+ end
80
+
81
+ @flags.each do |flag|
82
+ l_flag = !flag[:long_flag].empty? ? ", #{flag[:long_flag]}" : ""
83
+ flags = "#{flag[:short_flag]}#{l_flag}".ljust(MIDDLE)
84
+ desc = flag[:description].gsub("\n", "\n#{OptionParser.get_empty_spaces}")
85
+ io << "".ljust(LEFT) + flags + desc
86
+ io << "\n"
87
+ end
88
+
89
+ io.join
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dragonruby-egg
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Filip Vrba
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-04-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: With the tool, you can create new projects, install modules into a game
14
+ project and open documentation using a command. There are many more functions and
15
+ they are started with the 'dre' command.
16
+ email: filipvrbaxi@gmail.com
17
+ executables:
18
+ - dre
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - app/arguments.rb
23
+ - app/configuration.rb
24
+ - app/inputs.rb
25
+ - app/main.rb
26
+ - bin/dre
27
+ - lib/dragonruby_egg.rb
28
+ - lib/dragonruby_egg/constants.rb
29
+ - lib/dragonruby_egg/database.rb
30
+ - lib/dragonruby_egg/event.rb
31
+ - lib/dragonruby_egg/executable.rb
32
+ - lib/dragonruby_egg/modules.rb
33
+ - lib/json_parser.rb
34
+ - lib/option_parser.rb
35
+ homepage: https://dragonruby-egg-ui-rjs.vercel.app/
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ source_code_uri: https://github.com/filipvrba/dragonruby-egg-rb
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.4.10
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: DragonRuby-Egg is a tool for managing DragonRuby.
59
+ test_files: []