Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy loading code generation #14

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions generators/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def run_generator(&block)

print '⌛ Creating icon components...'
yield block
puts "\r🎉 Icon components created successfully!"
puts "\e[2K\r🎉 Icon components created successfully!"

make_components_lazy_loadable(ICONS_PACK_PATH)
run_rubocop(ICONS_PACK_PATH)
delete_repo(REPO_NAME)
end
Expand All @@ -29,14 +30,14 @@ def clone_repo(repo_url, repo_name)
print "⌛ Cloning '#{repo_name}' repo..."

if Dir.exist?("generators/#{repo_name}")
puts "\r✅ '#{repo_name}' repo already exists"
puts "\e[2K\r✅ '#{repo_name}' repo already exists"

return
end

system!("git clone #{repo_url} generators/#{repo_name}")

puts "\r🎉 '#{repo_name}' repo cloned successfully!"
puts "\e[2K\r🎉 '#{repo_name}' repo cloned successfully!"
end

def prepare_phlex_icons_pack_directory(icons_pack_path)
Expand All @@ -50,13 +51,13 @@ def prepare_phlex_icons_pack_directory(icons_pack_path)
File.delete(file)
end

puts "\r🎉 '#{icons_pack_path}' directory prepared successfully!"
puts "\e[2K\r🎉 '#{icons_pack_path}' directory prepared successfully!"
end

def component_file_name(icon_file_name, replacements = nil)
replacements ||= {}

icon_name = File.basename(icon_file_name, '.svg')
icon_name = File.basename(icon_file_name, File.extname(icon_file_name))

replacements.each do |key, value|
icon_name = icon_name.gsub(key, value) if icon_name.start_with?(key)
Expand All @@ -68,13 +69,32 @@ def component_file_name(icon_file_name, replacements = nil)
def component_class_name(icon_file_name, replacements = nil)
replacements ||= {}

icon_name = File.basename(icon_file_name, '.svg')
icon_name = File.basename(icon_file_name, File.extname(icon_file_name))

replacements.each do |key, value|
icon_name = icon_name.gsub(key, value) if icon_name.start_with?(key)
end

icon_name.gsub('-', ' ').split.map(&:capitalize).join
icon_name.gsub(/[-_]/, ' ').split.map(&:capitalize).join
end

def make_components_lazy_loadable(path)
print '⌛ Making components lazy-loadable...'

autoload_lines = Dir.glob("#{path}/*.rb").map do |file|
next if ['base.rb', 'configuration.rb'].include?(File.basename(file))

" autoload :#{component_class_name(file)}, '#{file.chomp(File.extname(file))}'"
end.compact.join("\n")

new_content = File.read("#{path}.rb").gsub(
/# auto-generated autoload: start.*# auto-generated autoload: end/m,
"# auto-generated autoload: start\n#{autoload_lines}\n # auto-generated autoload: end"
)

File.write("#{path}.rb", new_content)

puts "\e[2K\r🎉 Components are lazy-loadable!"
end

def run_rubocop(path)
Expand All @@ -86,15 +106,15 @@ def run_rubocop(path)
File.write(file, File.read(file).gsub('rubocop:enable ,', 'rubocop:enable '))
end

puts "\r🎉 RuboCop ran successfully!"
puts "\e[2K\r🎉 RuboCop ran successfully!"
end

def delete_repo(repo_name)
print "⌛ Deleting '#{repo_name}' repo..."

FileUtils.rm_rf("generators/#{repo_name}")

puts "\r🎉 '#{repo_name}' repo deleted successfully!"
puts "\e[2K\r🎉 '#{repo_name}' repo deleted successfully!"
end

def system!(command)
Expand Down
2,059 changes: 2,053 additions & 6 deletions lib/phlex/icons/bootstrap.rb

Large diffs are not rendered by default.

279 changes: 273 additions & 6 deletions lib/phlex/icons/flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,285 @@

module Phlex
module Icons
module Flag
module Flag # rubocop:disable Metrics/ModuleLength
extend Phlex::Icons::Helper
extend Phlex::Kit

require_relative 'flag/base'
require_relative 'flag/configuration'

Dir[File.join(__dir__, 'flag', '*.rb')].each do |file|
next if ['base.rb', 'configuration.rb'].include?(File.basename(file))

autoload class_name_from_file_path(file), file
end
# auto-generated autoload: start
autoload :Ad, 'lib/phlex/icons/flag/ad'
autoload :Ae, 'lib/phlex/icons/flag/ae'
autoload :Af, 'lib/phlex/icons/flag/af'
autoload :Ag, 'lib/phlex/icons/flag/ag'
autoload :Ai, 'lib/phlex/icons/flag/ai'
autoload :Al, 'lib/phlex/icons/flag/al'
autoload :Am, 'lib/phlex/icons/flag/am'
autoload :Ao, 'lib/phlex/icons/flag/ao'
autoload :Aq, 'lib/phlex/icons/flag/aq'
autoload :Ar, 'lib/phlex/icons/flag/ar'
autoload :Arab, 'lib/phlex/icons/flag/arab'
autoload :As, 'lib/phlex/icons/flag/as'
autoload :At, 'lib/phlex/icons/flag/at'
autoload :Au, 'lib/phlex/icons/flag/au'
autoload :Aw, 'lib/phlex/icons/flag/aw'
autoload :Ax, 'lib/phlex/icons/flag/ax'
autoload :Az, 'lib/phlex/icons/flag/az'
autoload :Ba, 'lib/phlex/icons/flag/ba'
autoload :Bb, 'lib/phlex/icons/flag/bb'
autoload :Bd, 'lib/phlex/icons/flag/bd'
autoload :Be, 'lib/phlex/icons/flag/be'
autoload :Bf, 'lib/phlex/icons/flag/bf'
autoload :Bg, 'lib/phlex/icons/flag/bg'
autoload :Bh, 'lib/phlex/icons/flag/bh'
autoload :Bi, 'lib/phlex/icons/flag/bi'
autoload :Bj, 'lib/phlex/icons/flag/bj'
autoload :Bl, 'lib/phlex/icons/flag/bl'
autoload :Bm, 'lib/phlex/icons/flag/bm'
autoload :Bn, 'lib/phlex/icons/flag/bn'
autoload :Bo, 'lib/phlex/icons/flag/bo'
autoload :Bq, 'lib/phlex/icons/flag/bq'
autoload :Br, 'lib/phlex/icons/flag/br'
autoload :Bs, 'lib/phlex/icons/flag/bs'
autoload :Bt, 'lib/phlex/icons/flag/bt'
autoload :Bv, 'lib/phlex/icons/flag/bv'
autoload :Bw, 'lib/phlex/icons/flag/bw'
autoload :By, 'lib/phlex/icons/flag/by'
autoload :Bz, 'lib/phlex/icons/flag/bz'
autoload :Ca, 'lib/phlex/icons/flag/ca'
autoload :Cc, 'lib/phlex/icons/flag/cc'
autoload :Cd, 'lib/phlex/icons/flag/cd'
autoload :Cefta, 'lib/phlex/icons/flag/cefta'
autoload :Cf, 'lib/phlex/icons/flag/cf'
autoload :Cg, 'lib/phlex/icons/flag/cg'
autoload :Ch, 'lib/phlex/icons/flag/ch'
autoload :Ci, 'lib/phlex/icons/flag/ci'
autoload :Ck, 'lib/phlex/icons/flag/ck'
autoload :Cl, 'lib/phlex/icons/flag/cl'
autoload :Cm, 'lib/phlex/icons/flag/cm'
autoload :Cn, 'lib/phlex/icons/flag/cn'
autoload :Co, 'lib/phlex/icons/flag/co'
autoload :Cp, 'lib/phlex/icons/flag/cp'
autoload :Cr, 'lib/phlex/icons/flag/cr'
autoload :Cu, 'lib/phlex/icons/flag/cu'
autoload :Cv, 'lib/phlex/icons/flag/cv'
autoload :Cw, 'lib/phlex/icons/flag/cw'
autoload :Cx, 'lib/phlex/icons/flag/cx'
autoload :Cy, 'lib/phlex/icons/flag/cy'
autoload :Cz, 'lib/phlex/icons/flag/cz'
autoload :De, 'lib/phlex/icons/flag/de'
autoload :Dg, 'lib/phlex/icons/flag/dg'
autoload :Dj, 'lib/phlex/icons/flag/dj'
autoload :Dk, 'lib/phlex/icons/flag/dk'
autoload :Dm, 'lib/phlex/icons/flag/dm'
autoload :Do, 'lib/phlex/icons/flag/do'
autoload :Dz, 'lib/phlex/icons/flag/dz'
autoload :Eac, 'lib/phlex/icons/flag/eac'
autoload :Ec, 'lib/phlex/icons/flag/ec'
autoload :Ee, 'lib/phlex/icons/flag/ee'
autoload :Eg, 'lib/phlex/icons/flag/eg'
autoload :Eh, 'lib/phlex/icons/flag/eh'
autoload :Er, 'lib/phlex/icons/flag/er'
autoload :Es, 'lib/phlex/icons/flag/es'
autoload :EsCt, 'lib/phlex/icons/flag/es_ct'
autoload :EsGa, 'lib/phlex/icons/flag/es_ga'
autoload :EsPv, 'lib/phlex/icons/flag/es_pv'
autoload :Et, 'lib/phlex/icons/flag/et'
autoload :Eu, 'lib/phlex/icons/flag/eu'
autoload :Fi, 'lib/phlex/icons/flag/fi'
autoload :Fj, 'lib/phlex/icons/flag/fj'
autoload :Fk, 'lib/phlex/icons/flag/fk'
autoload :Fm, 'lib/phlex/icons/flag/fm'
autoload :Fo, 'lib/phlex/icons/flag/fo'
autoload :Fr, 'lib/phlex/icons/flag/fr'
autoload :Ga, 'lib/phlex/icons/flag/ga'
autoload :Gb, 'lib/phlex/icons/flag/gb'
autoload :GbEng, 'lib/phlex/icons/flag/gb_eng'
autoload :GbNir, 'lib/phlex/icons/flag/gb_nir'
autoload :GbSct, 'lib/phlex/icons/flag/gb_sct'
autoload :GbWls, 'lib/phlex/icons/flag/gb_wls'
autoload :Gd, 'lib/phlex/icons/flag/gd'
autoload :Ge, 'lib/phlex/icons/flag/ge'
autoload :Gf, 'lib/phlex/icons/flag/gf'
autoload :Gg, 'lib/phlex/icons/flag/gg'
autoload :Gh, 'lib/phlex/icons/flag/gh'
autoload :Gi, 'lib/phlex/icons/flag/gi'
autoload :Gl, 'lib/phlex/icons/flag/gl'
autoload :Gm, 'lib/phlex/icons/flag/gm'
autoload :Gn, 'lib/phlex/icons/flag/gn'
autoload :Gp, 'lib/phlex/icons/flag/gp'
autoload :Gq, 'lib/phlex/icons/flag/gq'
autoload :Gr, 'lib/phlex/icons/flag/gr'
autoload :Gs, 'lib/phlex/icons/flag/gs'
autoload :Gt, 'lib/phlex/icons/flag/gt'
autoload :Gu, 'lib/phlex/icons/flag/gu'
autoload :Gw, 'lib/phlex/icons/flag/gw'
autoload :Gy, 'lib/phlex/icons/flag/gy'
autoload :Hk, 'lib/phlex/icons/flag/hk'
autoload :Hm, 'lib/phlex/icons/flag/hm'
autoload :Hn, 'lib/phlex/icons/flag/hn'
autoload :Hr, 'lib/phlex/icons/flag/hr'
autoload :Ht, 'lib/phlex/icons/flag/ht'
autoload :Hu, 'lib/phlex/icons/flag/hu'
autoload :Ic, 'lib/phlex/icons/flag/ic'
autoload :Id, 'lib/phlex/icons/flag/id'
autoload :Ie, 'lib/phlex/icons/flag/ie'
autoload :Il, 'lib/phlex/icons/flag/il'
autoload :Im, 'lib/phlex/icons/flag/im'
autoload :In, 'lib/phlex/icons/flag/in'
autoload :Io, 'lib/phlex/icons/flag/io'
autoload :Iq, 'lib/phlex/icons/flag/iq'
autoload :Ir, 'lib/phlex/icons/flag/ir'
autoload :Is, 'lib/phlex/icons/flag/is'
autoload :It, 'lib/phlex/icons/flag/it'
autoload :Je, 'lib/phlex/icons/flag/je'
autoload :Jm, 'lib/phlex/icons/flag/jm'
autoload :Jo, 'lib/phlex/icons/flag/jo'
autoload :Jp, 'lib/phlex/icons/flag/jp'
autoload :Ke, 'lib/phlex/icons/flag/ke'
autoload :Kg, 'lib/phlex/icons/flag/kg'
autoload :Kh, 'lib/phlex/icons/flag/kh'
autoload :Ki, 'lib/phlex/icons/flag/ki'
autoload :Km, 'lib/phlex/icons/flag/km'
autoload :Kn, 'lib/phlex/icons/flag/kn'
autoload :Kp, 'lib/phlex/icons/flag/kp'
autoload :Kr, 'lib/phlex/icons/flag/kr'
autoload :Kw, 'lib/phlex/icons/flag/kw'
autoload :Ky, 'lib/phlex/icons/flag/ky'
autoload :Kz, 'lib/phlex/icons/flag/kz'
autoload :La, 'lib/phlex/icons/flag/la'
autoload :Lb, 'lib/phlex/icons/flag/lb'
autoload :Lc, 'lib/phlex/icons/flag/lc'
autoload :Li, 'lib/phlex/icons/flag/li'
autoload :Lk, 'lib/phlex/icons/flag/lk'
autoload :Lr, 'lib/phlex/icons/flag/lr'
autoload :Ls, 'lib/phlex/icons/flag/ls'
autoload :Lt, 'lib/phlex/icons/flag/lt'
autoload :Lu, 'lib/phlex/icons/flag/lu'
autoload :Lv, 'lib/phlex/icons/flag/lv'
autoload :Ly, 'lib/phlex/icons/flag/ly'
autoload :Ma, 'lib/phlex/icons/flag/ma'
autoload :Mc, 'lib/phlex/icons/flag/mc'
autoload :Md, 'lib/phlex/icons/flag/md'
autoload :Me, 'lib/phlex/icons/flag/me'
autoload :Mf, 'lib/phlex/icons/flag/mf'
autoload :Mg, 'lib/phlex/icons/flag/mg'
autoload :Mh, 'lib/phlex/icons/flag/mh'
autoload :Mk, 'lib/phlex/icons/flag/mk'
autoload :Ml, 'lib/phlex/icons/flag/ml'
autoload :Mm, 'lib/phlex/icons/flag/mm'
autoload :Mn, 'lib/phlex/icons/flag/mn'
autoload :Mo, 'lib/phlex/icons/flag/mo'
autoload :Mp, 'lib/phlex/icons/flag/mp'
autoload :Mq, 'lib/phlex/icons/flag/mq'
autoload :Mr, 'lib/phlex/icons/flag/mr'
autoload :Ms, 'lib/phlex/icons/flag/ms'
autoload :Mt, 'lib/phlex/icons/flag/mt'
autoload :Mu, 'lib/phlex/icons/flag/mu'
autoload :Mv, 'lib/phlex/icons/flag/mv'
autoload :Mw, 'lib/phlex/icons/flag/mw'
autoload :Mx, 'lib/phlex/icons/flag/mx'
autoload :My, 'lib/phlex/icons/flag/my'
autoload :Mz, 'lib/phlex/icons/flag/mz'
autoload :Na, 'lib/phlex/icons/flag/na'
autoload :Nc, 'lib/phlex/icons/flag/nc'
autoload :Ne, 'lib/phlex/icons/flag/ne'
autoload :Nf, 'lib/phlex/icons/flag/nf'
autoload :Ng, 'lib/phlex/icons/flag/ng'
autoload :Ni, 'lib/phlex/icons/flag/ni'
autoload :Nl, 'lib/phlex/icons/flag/nl'
autoload :No, 'lib/phlex/icons/flag/no'
autoload :Np, 'lib/phlex/icons/flag/np'
autoload :Nr, 'lib/phlex/icons/flag/nr'
autoload :Nu, 'lib/phlex/icons/flag/nu'
autoload :Nz, 'lib/phlex/icons/flag/nz'
autoload :Om, 'lib/phlex/icons/flag/om'
autoload :Pa, 'lib/phlex/icons/flag/pa'
autoload :Pc, 'lib/phlex/icons/flag/pc'
autoload :Pe, 'lib/phlex/icons/flag/pe'
autoload :Pf, 'lib/phlex/icons/flag/pf'
autoload :Pg, 'lib/phlex/icons/flag/pg'
autoload :Ph, 'lib/phlex/icons/flag/ph'
autoload :Pk, 'lib/phlex/icons/flag/pk'
autoload :Pl, 'lib/phlex/icons/flag/pl'
autoload :Pm, 'lib/phlex/icons/flag/pm'
autoload :Pn, 'lib/phlex/icons/flag/pn'
autoload :Pr, 'lib/phlex/icons/flag/pr'
autoload :Ps, 'lib/phlex/icons/flag/ps'
autoload :Pt, 'lib/phlex/icons/flag/pt'
autoload :Pw, 'lib/phlex/icons/flag/pw'
autoload :Py, 'lib/phlex/icons/flag/py'
autoload :Qa, 'lib/phlex/icons/flag/qa'
autoload :Re, 'lib/phlex/icons/flag/re'
autoload :Ro, 'lib/phlex/icons/flag/ro'
autoload :Rs, 'lib/phlex/icons/flag/rs'
autoload :Ru, 'lib/phlex/icons/flag/ru'
autoload :Rw, 'lib/phlex/icons/flag/rw'
autoload :Sa, 'lib/phlex/icons/flag/sa'
autoload :Sb, 'lib/phlex/icons/flag/sb'
autoload :Sc, 'lib/phlex/icons/flag/sc'
autoload :Sd, 'lib/phlex/icons/flag/sd'
autoload :Se, 'lib/phlex/icons/flag/se'
autoload :Sg, 'lib/phlex/icons/flag/sg'
autoload :Sh, 'lib/phlex/icons/flag/sh'
autoload :ShAc, 'lib/phlex/icons/flag/sh_ac'
autoload :ShHl, 'lib/phlex/icons/flag/sh_hl'
autoload :ShTa, 'lib/phlex/icons/flag/sh_ta'
autoload :Si, 'lib/phlex/icons/flag/si'
autoload :Sj, 'lib/phlex/icons/flag/sj'
autoload :Sk, 'lib/phlex/icons/flag/sk'
autoload :Sl, 'lib/phlex/icons/flag/sl'
autoload :Sm, 'lib/phlex/icons/flag/sm'
autoload :Sn, 'lib/phlex/icons/flag/sn'
autoload :So, 'lib/phlex/icons/flag/so'
autoload :Sr, 'lib/phlex/icons/flag/sr'
autoload :Ss, 'lib/phlex/icons/flag/ss'
autoload :St, 'lib/phlex/icons/flag/st'
autoload :Sv, 'lib/phlex/icons/flag/sv'
autoload :Sx, 'lib/phlex/icons/flag/sx'
autoload :Sy, 'lib/phlex/icons/flag/sy'
autoload :Sz, 'lib/phlex/icons/flag/sz'
autoload :Tc, 'lib/phlex/icons/flag/tc'
autoload :Td, 'lib/phlex/icons/flag/td'
autoload :Tf, 'lib/phlex/icons/flag/tf'
autoload :Tg, 'lib/phlex/icons/flag/tg'
autoload :Th, 'lib/phlex/icons/flag/th'
autoload :Tj, 'lib/phlex/icons/flag/tj'
autoload :Tk, 'lib/phlex/icons/flag/tk'
autoload :Tl, 'lib/phlex/icons/flag/tl'
autoload :Tm, 'lib/phlex/icons/flag/tm'
autoload :Tn, 'lib/phlex/icons/flag/tn'
autoload :To, 'lib/phlex/icons/flag/to'
autoload :Tr, 'lib/phlex/icons/flag/tr'
autoload :Tt, 'lib/phlex/icons/flag/tt'
autoload :Tv, 'lib/phlex/icons/flag/tv'
autoload :Tw, 'lib/phlex/icons/flag/tw'
autoload :Tz, 'lib/phlex/icons/flag/tz'
autoload :Ua, 'lib/phlex/icons/flag/ua'
autoload :Ug, 'lib/phlex/icons/flag/ug'
autoload :Um, 'lib/phlex/icons/flag/um'
autoload :Un, 'lib/phlex/icons/flag/un'
autoload :Us, 'lib/phlex/icons/flag/us'
autoload :Uy, 'lib/phlex/icons/flag/uy'
autoload :Uz, 'lib/phlex/icons/flag/uz'
autoload :Va, 'lib/phlex/icons/flag/va'
autoload :Vc, 'lib/phlex/icons/flag/vc'
autoload :Ve, 'lib/phlex/icons/flag/ve'
autoload :Vg, 'lib/phlex/icons/flag/vg'
autoload :Vi, 'lib/phlex/icons/flag/vi'
autoload :Vn, 'lib/phlex/icons/flag/vn'
autoload :Vu, 'lib/phlex/icons/flag/vu'
autoload :Wf, 'lib/phlex/icons/flag/wf'
autoload :Ws, 'lib/phlex/icons/flag/ws'
autoload :Xk, 'lib/phlex/icons/flag/xk'
autoload :Xx, 'lib/phlex/icons/flag/xx'
autoload :Ye, 'lib/phlex/icons/flag/ye'
autoload :Yt, 'lib/phlex/icons/flag/yt'
autoload :Za, 'lib/phlex/icons/flag/za'
autoload :Zm, 'lib/phlex/icons/flag/zm'
autoload :Zw, 'lib/phlex/icons/flag/zw'
# auto-generated autoload: end

class << self
def configuration
Expand Down
Loading