Class: Wytch::CLI
Overview
Command-line interface for Wytch.
Provides commands for creating, developing, and building Wytch sites.
Class Method Summary collapse
-
.source_root ⇒ String
Returns the path to template files used by the generator.
Instance Method Summary collapse
-
#build ⇒ void
Builds the site for production.
-
#new(name) ⇒ void
Creates a new Wytch site with the given name.
-
#server ⇒ void
Starts the development server with hot reloading.
Class Method Details
.source_root ⇒ String
Returns the path to template files used by the generator.
20 21 22 |
# File 'lib/wytch/cli.rb', line 20 def self.source_root File.("templates", __dir__) end |
Instance Method Details
#build ⇒ void
This method returns an undefined value.
Builds the site for production.
First runs npm run build to compile assets with Vite,
then renders all pages to static HTML in the build/ directory.
110 111 112 113 |
# File 'lib/wytch/cli.rb', line 110 def build system("npm run build") || abort("Asset build failed") Builder.new.build end |
#new(name) ⇒ void
This method returns an undefined value.
Creates a new Wytch site with the given name.
Generates a complete site structure including:
- Configuration files (Gemfile, config.rb, package.json, etc.)
- Content directory with sample pages
- Source directory with views and layouts
- Asset pipeline setup (Vite, ReScript, Tailwind)
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 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/wytch/cli.rb', line 36 def new(name) @local_wytch_path = File.("../..", __dir__) if [:local] # Extract site name and create module constant @site_name = File.basename(name) @site_module = classify(@site_name) empty_directory(name) template("Gemfile.tt", "#{name}/Gemfile") template("config.rb.tt", "#{name}/config.rb") template("gitignore.tt", "#{name}/.gitignore") # Asset pipeline configuration template("package.json.tt", "#{name}/package.json") template("vite.config.js.tt", "#{name}/vite.config.js") template("rescript.json.tt", "#{name}/rescript.json") # Assets directory empty_directory("#{name}/assets") template("frontend/Main.res.tt", "#{name}/assets/Main.res") template("frontend/main.css.tt", "#{name}/assets/main.css") # Content directory empty_directory("#{name}/content") template("content/index.rb.tt", "#{name}/content/index.rb") empty_directory("#{name}/content/posts") template("content/posts/hello-world.rb.tt", "#{name}/content/posts/hello-world.rb") template("content/sitemap.rb.tt", "#{name}/content/sitemap.rb") template("content/feed.rb.tt", "#{name}/content/feed.rb") # Src directory with namespaced code empty_directory("#{name}/src") empty_directory("#{name}/src/#{@site_name}") template("src/site/page.rb.tt", "#{name}/src/#{@site_name}/page.rb") template("src/site/layout.rb.tt", "#{name}/src/#{@site_name}/layout.rb") template("src/site/home_view.rb.tt", "#{name}/src/#{@site_name}/home_view.rb") template("src/site/post_view.rb.tt", "#{name}/src/#{@site_name}/post_view.rb") template("src/site/post_helpers.rb.tt", "#{name}/src/#{@site_name}/post_helpers.rb") template("src/site/feed_view.rb.tt", "#{name}/src/#{@site_name}/feed_view.rb") template("src/site/feed_helper.rb.tt", "#{name}/src/#{@site_name}/feed_helper.rb") # Public directory for static assets empty_directory("#{name}/public") template("public/robots.txt.tt", "#{name}/public/robots.txt") say "Created new Wytch site in #{name}/", :green say "\nNext steps:", :green say " cd #{name}" say " bundle install" say " npm install" say "\nTo start developing:" say " npm run dev # Start Vite dev server (Terminal 1)" say " wytch server # Start Wytch dev server (Terminal 2)" say "\nTo build for production:" say " wytch build # Build assets and static site to build/" end |
#server ⇒ void
This method returns an undefined value.
Starts the development server with hot reloading.
99 100 101 |
# File 'lib/wytch/cli.rb', line 99 def server Server.new().start end |