#!/usr/bin/env ruby require 'thor' require 'pyro' # Public: CLI commands for Pyro. # # Examples # # ~/Projects $ pyro new MyApp class PyroCLI < Thor # Public: Create a new Pyro app. # # name - The name of the new app. # # Examples # # ~/Projects $ pyro new MyApp # # Generates a new app into /MyApp. desc 'new NAME', 'Creats a new app' def new(name) FileUtils.cp_r("#{File.dirname(__FILE__)}/../templates/app", name) end # Public: Create a new build of a Pyro app for production. # # * Production builds use prod_src/prod_dir, skip tests, and are minified. # # dir - The directory of the app to burn. Defaults to the current directory. # # Examples # # ~/Projects/MyApp $ pyro burn # ~/Projects $ pyro burn MyApp # Burns the MyApp folder. # # Generates a production build of the app into /pkg/. desc 'burn', 'Builds an app for production' def burn(dir = '.') Pyro.burn('production', false, dir) end # Public: Create a development build in /tmp and runs it on localhost:7976. # # * /tmp gets rebuilt on each refresh. # # --fast - Doesn't rebuild /assets. # --test - Builds with the test helpers. # # Examples # # ~/Projects/MyApp $ pyro serve # # Runs the development build on localhost:7976. desc 'serve', 'Starts a Pyro app on localhost, --fast skips asset reloading, --test includes tests' option :fast option :test def serve require 'pyro/server' if options[:fast] PyroServer.set :fast, true else PyroServer.set :fast, false end PyroServer.set(:target, 'test') if options[:test] PyroServer.run! end # Public: Run a production build on localhost:7976. # # build - The name (timestamp) of the build to run, from /pkg. # # * If no build is specified, the latest is used. # * If no build exists, a new one is generated. # # Examples # # ~/Projects/MyApp $ pyro stage # ~/Projects/MyApp $ pyro stage # # Runs the production build on localhost:7976. desc 'stage BUILD', 'Stages a Pyro build on localhost' def stage(build_num = false) if build_num build_dir = "./pkg/#{build_num}" else Pyro.burn('production', false) if Dir.glob('./pkg/**').count == 0 build_dir = Dir.glob('./pkg/**').last end unless Dir.exists? build_dir puts "That build doesn't exist. Run 'pyro burn' to create a build." exit end require 'pyro/server' PyroServer.set :public_folder, build_dir PyroServer.set :staging, true PyroServer.run! end end # Public: Start the PyroCLI. # # Examples # # ~ $ pyro PyroCLI.start(ARGV)