Class: Mayu::Commands::Build
- Extended by:
- T::Sig
- Defined in:
- lib/mayu/commands/build.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Mayu::Commands::Base
Instance Method Details
#call(argv) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mayu/commands/build.rb', line 13 def call(argv) require "fileutils" Async do started_at = Time.now.to_f metrics = AppMetrics.setup(Prometheus::Client.registry) environment = Environment.new(configuration, metrics) environment.init_js resources = environment.resources components = [] components.push(File.join("/app", "root")) environment.routes.each do |route| route.layouts.each do |layout| components.push(File.join("/app", "pages", layout)) end components.push(File.join("/app", "pages", route.template)) end components.each do |component| resources.load_resource(component).type.component end File.write("app-graph.md", <<~EOF) ```mermaid #{resources.dependency_graph.to_mermaid_source.chomp} ``` EOF mermaid_url = resources.mermaid_url assets_dir = environment.path(:assets) FileUtils.mkdir_p(assets_dir) files_to_remove = Dir.glob(File.join(assets_dir, "*")) unless files_to_remove.empty? puts "\e[33mRemoving #{files_to_remove.size} files from #{assets_dir}\e[0m" FileUtils.rm(files_to_remove) end puts "\e[35mGenerating assets\e[0m" resources.generate_assets( assets_dir, concurrency: Async::Container.processor_count, forever: false ).wait filename = configuration.paths.bundle_filename puts "\e[35mWriting \e[1m#{filename}\e[0m" File.write(filename, resources.dump) puts puts format( "\e[36mBuilt app in \e[1m%.2f seconds\e[0m", Time.now.to_f - started_at ) puts puts "View the app graph:" puts "\e[34;4m#{resources.mermaid_url}\e[0m" end end |