drakkon 0.0.7 → 0.0.8

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: 22dc052674cbdeb00139240538434c5098c27f5b4daa59ecc35ba3fd30fc6219
4
- data.tar.gz: e705e6edc55b2b979761da02ad021d4d0ae427b6b03144fc8d20835f3a89f496
3
+ metadata.gz: 7d96f5b298a5a1e72de4af63cc4586b919d087944132ff010e9a764ed1c6efee
4
+ data.tar.gz: 60245722e0177e6228bc4c4f99b89c25e394c4474ff4ce314316ac0251bab21b
5
5
  SHA512:
6
- metadata.gz: f02cc623e83d177b61e9043d4852571b5be61c9ac3fea8aa73009e2469fe90636c2da8976829209342cbbd8c6358033586f1c1994bf2a3814157ebb0b19cbfe7
7
- data.tar.gz: 582b9944ca4aeec1d5963fd92190f4330b97cdbcc1f99892f725dbe3629290c523bc3926e4f89ac111f96b874422a6503b2a40bde396fe606a393237cbe69033
6
+ metadata.gz: 6f01268dbb5324527bbd69d4dbb5bd6a4c5c9ab33866782a47fc4b264b1bc6e41f332b668d71ca288340684d0b666863baef5327b78780cfd3c677a6ee90fec8
7
+ data.tar.gz: 324e6d67efb2a03400dc0a474525d5f8676e323a6bc6b9f4a9a9ff92a91bc31c967332d3f45706534b00018bc9c446c6c51700e49541496c36b000f5b94cf2e5
data/lib/drakkon/build.rb CHANGED
@@ -90,6 +90,10 @@ module Drakkon
90
90
  args.include?('images')
91
91
  end
92
92
 
93
+ def self.force_fonts?
94
+ args.include?('fonts')
95
+ end
96
+
93
97
  def self.force_manifest?
94
98
  args.include?('manifest')
95
99
  end
@@ -3,7 +3,8 @@ module Drakkon
3
3
  # Run Command for CLI
4
4
  module Bundle
5
5
  def self.build!(args, context)
6
- return if Settings.gems.empty?
6
+ # Gems are not required
7
+ # return if Settings.gems.empty?
7
8
 
8
9
  @context = context
9
10
 
@@ -16,14 +17,63 @@ module Drakkon
16
17
 
17
18
  idx = collect
18
19
 
19
- do_the_bundle(idx)
20
+ if Settings.bundle_compile?
21
+ LogBot.info('Gems Bundle', 'Compile')
22
+ compiled_bundle(idx)
23
+ else
24
+ LogBot.info('Gems Bundle', 'Expand')
25
+ expand_bundle(idx)
26
+ end
20
27
 
21
28
  Settings.update(:bundle_digest, digest)
22
29
  rescue TTY::Reader::InputInterrupt
23
30
  exit 0
24
31
  end
25
32
 
26
- def self.do_the_bundle(idx)
33
+ # Including files without merging them
34
+ def self.expand_bundle(idx)
35
+ # Make Directory `app/drakkon` if it doesn't exist
36
+ FileUtils.mkdir_p('app/drakkon') unless File.directory?('app/drakkon')
37
+
38
+ # Create Sub Directory to make switching to compile / eaiser
39
+ # Always clear to ensure fresh directory
40
+ FileUtils.rm_rf(unbundle_dir) if File.directory?(unbundle_dir)
41
+ FileUtils.mkdir_p(unbundle_dir)
42
+
43
+ # Touch the file if it doesn't exist
44
+ FileUtils.touch(bundle_file) unless File.exist?(bundle_file)
45
+
46
+ File.open(bundle_file, 'w') do |f|
47
+ idx.keys.sort.reverse.each do |i|
48
+ idx[i].each do |file_data|
49
+ file = file_data[:path]
50
+ unless File.exist?(file)
51
+ LogBot.fatal('Bundle', "File not found #{file.pastel(:red)}")
52
+ next
53
+ end
54
+
55
+ file_path = "#{unbundle_dir}/#{File.basename(file_data[:safe_name])}.rb"
56
+
57
+ FileUtils.cp(file, file_path)
58
+ f << "require '#{file_path}'\n"
59
+ end
60
+ end
61
+
62
+ # Include other files
63
+ f << "require 'app/drakkon/image_index.rb' \n" if Settings.image_index?
64
+ f << "require 'app/drakkon/manifest.rb' \n" if Settings.manifest?
65
+ f << "require 'app/drakkon/font_index.rb' \n" if Settings.font_index?
66
+
67
+ # File Close
68
+ end
69
+
70
+ # FileUtils.cp(bundle_file, "#{drakkon_dir}/bundle/#{Time.now.to_i}.rb")
71
+ end
72
+
73
+ def self.compiled_bundle(idx)
74
+ # Always clear to ensure fresh directory
75
+ FileUtils.rm_rf(unbundle_dir) if File.directory?(unbundle_dir)
76
+
27
77
  # Make Directory `app/drakkon` if it doesn't exist
28
78
  FileUtils.mkdir_p('app/drakkon') unless File.directory?('app/drakkon')
29
79
 
@@ -33,7 +83,9 @@ module Drakkon
33
83
  File.open(bundle_file, 'w') do |f|
34
84
  # Index Writer
35
85
  idx.keys.sort.reverse.each do |i|
36
- idx[i].each do |file|
86
+ idx[i].each do |file_data|
87
+ file = file_data[:path]
88
+
37
89
  unless File.exist?(file)
38
90
  LogBot.fatal('Bundle', "File not found #{file.pastel(:red)}")
39
91
  next
@@ -46,6 +98,7 @@ module Drakkon
46
98
  # Include other files
47
99
  f << "require 'app/drakkon/image_index.rb' \n" if Settings.image_index?
48
100
  f << "require 'app/drakkon/manifest.rb' \n" if Settings.manifest?
101
+ f << "require 'app/drakkon/font_index.rb' \n" if Settings.font_index?
49
102
 
50
103
  # File Close
51
104
  end
@@ -53,7 +106,8 @@ module Drakkon
53
106
 
54
107
  def self.collect
55
108
  idx = {}
56
- Settings.gems.each_value do |gem|
109
+ Settings.gems.each do |gem_name, gem|
110
+ gem[:name] = gem_name.to_s.downcase
57
111
  case gem[:source].to_sym
58
112
  when :local then collect_local_source(idx, gem)
59
113
  else
@@ -78,7 +132,10 @@ module Drakkon
78
132
  next
79
133
  end
80
134
 
81
- idx[mod.weight].push file_name
135
+ # Convert full file path into single string / relative naming (no directories)
136
+ safe_name = "#{gem.name}_#{file.gsub('/', '_')}"
137
+
138
+ idx[mod.weight].push(path: file_name, name: file, safe_name: safe_name)
82
139
  end
83
140
  end
84
141
 
@@ -86,7 +143,10 @@ module Drakkon
86
143
  if gem[:data].key?(:files)
87
144
  gem[:data][:files].each_value do |f|
88
145
  idx[f.weight] ||= []
89
- idx[f.weight].push "#{path}/#{f.file}"
146
+ # idx[f.weight].push "#{path}/#{f.file}"
147
+ safe_name = "#{gem.name}_#{f.file.gsub('/', '_')}"
148
+
149
+ idx[f.weight].push(path: "#{path}/#{f.file}", name: f.file, safe_name: safe_name)
90
150
  end
91
151
 
92
152
  end
@@ -105,6 +165,11 @@ module Drakkon
105
165
  "#{@context}/app/drakkon"
106
166
  end
107
167
 
168
+ # Directory for uncompiled files / Relative
169
+ def self.unbundle_dir
170
+ 'app/drakkon/unbundle'
171
+ end
172
+
108
173
  def self.prompt
109
174
  TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
110
175
  end
data/lib/drakkon/init.rb CHANGED
@@ -49,7 +49,9 @@ module Drakkon
49
49
  platforms: [],
50
50
  version: Hub.version_latest,
51
51
  image_index: true,
52
+ font_index: true,
52
53
  manifest: true,
54
+ bundle_compile: true,
53
55
  gems: {}
54
56
  }
55
57
 
@@ -68,7 +68,7 @@ module Drakkon
68
68
 
69
69
  def self.config
70
70
  # Write Default
71
- File.write(config_file, Oj.dump({})) unless File.exist?(config_file)
71
+ File.write(config_file, JSON.pretty_generate({})) unless File.exist?(config_file)
72
72
 
73
73
  @config ||= JSON.parse(File.read(config_file), { symbolize_names: true })
74
74
 
@@ -92,7 +92,7 @@ module Drakkon
92
92
 
93
93
  def self.write
94
94
  # LogBot.debug('Hub', "Writing Config: #{config_file}")
95
- File.write(config_file, Oj.dump(config))
95
+ File.write(config_file, JSON.pretty_generate(config))
96
96
  end
97
97
 
98
98
  def self.log_file
@@ -0,0 +1,88 @@
1
+ module Drakkon
2
+ module Fonts
3
+ # General Font Index Helper
4
+ module Index
5
+ def self.index
6
+ @index ||= {}
7
+
8
+ @index
9
+ end
10
+
11
+ def self.context
12
+ @context ||= Dir.pwd
13
+
14
+ @context
15
+ end
16
+
17
+ def self.digest
18
+ list = Dir["#{fonts_directory}/*"]
19
+ Digest::MD5.hexdigest(list.map { |x| Digest::MD5.file(x).hexdigest }.join)
20
+ end
21
+
22
+ def self.fonts_directory
23
+ "#{context}/fonts/"
24
+ end
25
+
26
+ def self.run!(force: false, dir: nil)
27
+ @context = dir || Dir.pwd
28
+
29
+ # Create Directory if sprites directory is missing
30
+ FileUtils.mkdir_p(fonts_directory)
31
+
32
+ if Settings.config[:font_digest] == digest
33
+ LogBot.info('Fonts Index', 'Nothing New')
34
+ return unless force
35
+ end
36
+
37
+ build_index
38
+
39
+ Settings.update(:font_digest, digest)
40
+
41
+ File.write("#{context}/app/drakkon/font_index.rb", result)
42
+ end
43
+
44
+ def self.build_index
45
+ check fonts_directory
46
+ end
47
+
48
+ def self.result
49
+ <<~RB
50
+ module Drakkon
51
+ module Fonts
52
+ def self.index
53
+ #{index.inspect}
54
+ end
55
+ end
56
+ end
57
+ RB
58
+ end
59
+
60
+ # Recursively Go through
61
+ def self.check(dir = nil)
62
+ LogBot.info('Font Index', "Check: #{dir}")
63
+
64
+ # Collect Fonts
65
+ list = Dir["#{dir}/*"]
66
+
67
+ # Ignore Empties
68
+ return if list.empty?
69
+
70
+ # Do other things
71
+ Dir["#{dir}/*"].each do |file|
72
+ next if File.directory?(file)
73
+
74
+ process(file)
75
+ end
76
+
77
+ :done
78
+ end
79
+
80
+ def self.process(file = nil)
81
+ name = File.basename(file, File.extname(file))
82
+ index[name] = file.gsub(fonts_directory, '')[1..]
83
+ end
84
+ # =========================================================
85
+ end
86
+ # =========================================================
87
+ end
88
+ end
@@ -50,7 +50,7 @@ module Drakkon
50
50
 
51
51
  puts
52
52
 
53
- exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)}"
53
+ exit unless prompt.yes? 'Are you sure?'.pastel(:bright_yellow).to_s
54
54
 
55
55
  generate(font: font, text: text, size: size, color: color, file: file)
56
56
  rescue TTY::Reader::InputInterrupt
@@ -12,7 +12,7 @@ module Drakkon
12
12
 
13
13
  # Helper to exit if project isn't ready for drakkon usage
14
14
  def self.ready?
15
- return if init?
15
+ return false if init?
16
16
 
17
17
  LogBot.warn('Setup', "Drakkon not configured. Run #{'init'.pastel(:green)} first")
18
18
 
@@ -51,6 +51,14 @@ module Drakkon
51
51
  config[:image_index]
52
52
  end
53
53
 
54
+ def self.font_index?
55
+ config[:font_index]
56
+ end
57
+
58
+ def self.bundle_compile?
59
+ config[:bundle_compile]
60
+ end
61
+
54
62
  def self.manifest?
55
63
  config[:manifest]
56
64
  end
@@ -63,8 +71,10 @@ module Drakkon
63
71
  # Defaults
64
72
  @config[:platforms] ||= []
65
73
  @config[:version] ||= Hub.version_latest
66
- @config[:image_index] ||= true
67
- @config[:manifest] ||= true
74
+ @config[:image_index] = true if @config[:image_index].nil?
75
+ @config[:manifest] = true if @config[:manifest].nil?
76
+ @config[:bundle_compile] = true if @config[:bundle_compile].nil?
77
+ @config[:font_index] = true if @config[:font_index].nil?
68
78
  @config[:gems] ||= {}
69
79
  end
70
80
 
@@ -74,7 +84,6 @@ module Drakkon
74
84
 
75
85
  if @config.nil?
76
86
  @config ||= JSON.parse(File.read(config_file), { symbolize_names: true })
77
- # @config ||= Oj.load File.read(config_file)
78
87
  config_defaults
79
88
  end
80
89
 
@@ -94,7 +103,6 @@ module Drakkon
94
103
  def self.write
95
104
  # LogBot.debug('Settings', "Writing Config: #{config_file}")
96
105
  File.write(config_file, JSON.pretty_generate(config))
97
- # File.write(config_file, Oj.dump(config))
98
106
  end
99
107
 
100
108
  def self.menu
@@ -102,7 +110,9 @@ module Drakkon
102
110
  menu.choice name: 'platforms', value: :platforms
103
111
  menu.choice name: 'version', value: :version
104
112
  menu.choice name: 'image_index', value: :image_index
113
+ menu.choice name: 'font_index', value: :font_index
105
114
  menu.choice name: 'manifest', value: :manifest
115
+ menu.choice name: 'bundle_compile', value: :bundle_compile
106
116
  menu.choice name: 'exit', value: :exit
107
117
  end
108
118
  rescue TTY::Reader::InputInterrupt
@@ -119,6 +129,11 @@ module Drakkon
119
129
  Settings.update(:image_index, prompt.yes?("Index Images? (Enabled: #{image_index?})"))
120
130
  when :manifest
121
131
  Settings.update(:image_index, prompt.yes?("Write Manifest? (Enabled: #{manifest?})"))
132
+ when :bundle_compile
133
+ Settings.update(:bundle_compile,
134
+ prompt.yes?("Create Bundle / Compile Gems? (Enabled: #{config[:bundle_compile]})"))
135
+ when :font_index
136
+ Settings.update(:font_index, prompt.yes?("Index Fonts? (Enabled: #{config[:font_index]})"))
122
137
  when :exit
123
138
  exit 0
124
139
  end
@@ -1,3 +1,3 @@
1
1
  module Drakkon
2
- VERSION = '0.0.7'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
@@ -50,6 +50,10 @@ module Drakkon
50
50
  args.include?('manifest')
51
51
  end
52
52
 
53
+ def self.force_fonts?
54
+ args.include?('fonts')
55
+ end
56
+
53
57
  def self.prompt
54
58
  TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
55
59
  end
@@ -7,7 +7,7 @@ module Drakkon
7
7
 
8
8
  cmd = @list.shift
9
9
  if index.include? cmd
10
- Commands.send("cmd_#{cmd}".to_sym, @list)
10
+ Commands.send(:"cmd_#{cmd}", @list)
11
11
  else
12
12
  puts "Unknown Command: '#{cmd.pastel(:red)}'"
13
13
  puts
data/lib/drakkon/run.rb CHANGED
@@ -49,7 +49,7 @@ module Drakkon
49
49
  # Watch for Updates
50
50
  # ======================================
51
51
  # Force the bundle
52
- files = Gems::Bundle.collect.values.flatten
52
+ files = Gems::Bundle.collect.values.flatten.map(&:path)
53
53
  files.push "#{Run.context}/sprites/" if Settings.image_index?
54
54
 
55
55
  Filewatcher.new(files, every: true).watch do |changes|
@@ -62,6 +62,7 @@ module Drakkon
62
62
  def self.run_setup
63
63
  Images::Index.run!(force: force_images?) if Settings.image_index?
64
64
  Manifest.run!(force: force_manifest?) if Settings.manifest?
65
+ Fonts::Index.run!(force: force_fonts?) if Settings.font_index?
65
66
  Gems::Bundle.build!(args, @context)
66
67
  end
67
68
 
data/lib/drakkon/web.rb CHANGED
@@ -29,40 +29,3 @@ module Drakkon
29
29
  end
30
30
  # ==========================================================================
31
31
  end
32
-
33
- # set :port, 4567
34
- # set :bind, '0.0.0.0'
35
- # set :server, :puma
36
- # set :show_exceptions, false
37
- # disable :logging # Duplicate Log Entries
38
- # set :dump_errors, false # Duplicate Eception Dumping
39
-
40
- # use Rack::CommonLogger
41
-
42
- module Drakkon
43
- module Web
44
- # WebApp
45
- class Runny < Sinatra::Base
46
- configure do
47
- set :public_folder, Dir.pwd
48
- end
49
-
50
- # I hate you Cors
51
- enable :cross_origin
52
- before do
53
- response.headers['Access-Control-Allow-Origin'] = '*'
54
- response.headers['Access-Control-Allow-Headers'] = '*'
55
- response.headers['Access-Control-Allow-Methods'] = 'GET,PUT,POST,PATCH,DELETE,OPTIONS'
56
-
57
- response.headers['Cross-Origin-Opener-Policy'] = 'same-origin'
58
- response.headers['Cross-Origin-Embedder-Policy'] = 'require-corp'
59
- end
60
-
61
- get '/' do
62
- File.read(File.join(settings.public_folder, 'index.html'))
63
- end
64
- # ========================================================================
65
- end
66
- # ==========================================================================
67
- end
68
- end
data/lib/drakkon.rb CHANGED
@@ -13,8 +13,8 @@ require 'tty-pager'
13
13
  # Templates
14
14
  require 'erb'
15
15
 
16
- # Parsing
17
- require 'oj'
16
+ # Parsing || Move to vanilla JSON for simplification
17
+ # require 'oj'
18
18
 
19
19
  # Image Handling
20
20
  require 'mini_magick'
@@ -34,9 +34,6 @@ require 'sinatra/base'
34
34
  # Load All Sub Directories / Order Matters
35
35
  require_all "#{File.dirname(__FILE__)}/drakkon"
36
36
 
37
- # Oj Settings
38
- Oj.default_options = { symbol_keys: true, mode: :compat }
39
-
40
37
  # HashDot Instead of Struct
41
38
  require 'hash_dot'
42
39
  Hash.use_dot_syntax = true
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drakkon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davin Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-15 00:00:00.000000000 Z
11
+ date: 2024-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: faker
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: filewatcher
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +52,6 @@ dependencies:
66
52
  - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: oj
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: pry
85
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +94,6 @@ dependencies:
122
94
  - - ">="
123
95
  - !ruby/object:Gem::Version
124
96
  version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: sinatra
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
97
  - !ruby/object:Gem::Dependency
140
98
  name: tty-option
141
99
  requirement: !ruby/object:Gem::Requirement
@@ -238,6 +196,7 @@ files:
238
196
  - lib/drakkon/lib/images/cli.rb
239
197
  - lib/drakkon/lib/images/desaturate.rb
240
198
  - lib/drakkon/lib/images/flip_flop.rb
199
+ - lib/drakkon/lib/images/fonts.rb
241
200
  - lib/drakkon/lib/images/gif.rb
242
201
  - lib/drakkon/lib/images/index.rb
243
202
  - lib/drakkon/lib/images/list.rb