Class: Almanack::CLI
- Inherits:
-
Thor
- Object
- Thor
- Almanack::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/almanack/cli.rb
Constant Summary collapse
- SKIP_THEMES =
%w( starter )
Class Method Summary collapse
Instance Method Summary collapse
- #deploy(name = nil) ⇒ Object
- #new(path) ⇒ Object
- #start ⇒ Object
- #theme(name) ⇒ Object
- #version ⇒ Object
Class Method Details
.available_themes ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/almanack/cli.rb', line 13 def self.available_themes dirs = Pathname(__dir__).join("themes").children.select(&:directory?) dirs.map do |path| path.basename.to_s unless SKIP_THEMES.include?(path.basename.to_s) end.compact end |
.exit_on_failure? ⇒ Boolean
140 141 142 |
# File 'lib/almanack/cli.rb', line 140 def self.exit_on_failure? true end |
.source_root ⇒ Object
144 145 146 |
# File 'lib/almanack/cli.rb', line 144 def self.source_root Pathname(__dir__).parent.parent end |
Instance Method Details
#deploy(name = nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/almanack/cli.rb', line 79 def deploy(name = nil) remotes = `git remote -v` heroku_remote = remotes.lines.find do |remote| remote.split(' ').first == "heroku" end if !heroku_remote say "No Heroku remote detected." create_heroku_app(name) end current_branch = git("rev-parse --abbrev-ref HEAD") say "Deploying #{current_branch}..." run "git push heroku #{current_branch}:master --force" end |
#new(path) ⇒ Object
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 |
# File 'lib/almanack/cli.rb', line 35 def new(path) @path = Pathname(path).cleanpath directory "templates/new", @path if [:git] template('templates/gitignore', @path.join(".gitignore")) end create_file @path.join('tmp/.keep') inside @path do say_status :installing, "bundler dependencies" system "bundle install --quiet" if [:git] say_status :git, "initializing repository" git "init" end say say "==> Run your new calendar!" say say " cd #{@path}" say " almanack start" say end end |
#start ⇒ Object
28 29 30 |
# File 'lib/almanack/cli.rb', line 28 def start exec "bundle exec rackup #{[:config]}" end |
#theme(name) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/almanack/cli.rb', line 65 def theme(name) directory "lib/almanack/themes/starter", "themes/#{name}" config_file = Pathname("config.ru") if config_file.exist? say_status :update, "config.ru" set_theme_pattern = /\.theme\s*=\s*['"].*?['"]/ replacement = config_file.read.gsub(set_theme_pattern, ".theme = '#{name}'") config_file.open('w') { |file| file.puts replacement } end end |