Skip to content

Instantly share code, notes, and snippets.

@wess
Created November 24, 2014 22:36
Show Gist options
  • Save wess/bf1257da6b007edb0c59 to your computer and use it in GitHub Desktop.
Save wess/bf1257da6b007edb0c59 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'thor'
require 'open-uri'
require 'fileutils'
require 'etc'
require 'zip'
require 'erb'
URL = "https://github.com/wess/center-stage/archive/master.zip"
HOME_DIR = Etc.getpwuid.dir
CENTER_STAGE_DIR = "#{HOME_DIR}/.center-stage"
CONFIG_TEMPLATE = <<-BLOCK
app_name: <%= name %>
development:
db:
user: username
name: database
production:
db:
user: username
name: database
BLOCK
class CenterStage < Thor
desc "init", "Sets up CenterStage for use"
def init
if File.directory?(CENTER_STAGE_DIR)
FileUtils.rm_rf CENTER_STAGE_DIR
end
FileUtils.mkdir_p(CENTER_STAGE_DIR)
zip_path = "#{CENTER_STAGE_DIR}/center-stage.zip"
open zip_path, 'wb' do |file|
file << open(URL).read
end
Zip::File.open zip_path do |zip_file|
zip_file.each do |entry|
path_array = entry.name.split("/").drop(1)
path = "#{CENTER_STAGE_DIR}/#{path_array.join("/")}"
entry.extract path
end
end
File.delete zip_path
puts "Init complete"
end
desc "create NAME", "Creates a new Sinatra/Datamapper app"
def create(name)
app_dir = "#{Dir.pwd}/#{name}"
app_name = name.slice(0, 1).capitalize + name.slice(1..-1)
FileUtils.cp_r CENTER_STAGE_DIR, app_dir
Dir.glob("#{app_dir}/**/*.*") do |file|
template = ERB.new File.read(file)
File.open(file, 'w') do |f|
f.write template.result(binding)
end
end
# render = ERB.new(CONFIG_TEMPLATE)
# File.open "#{Dir.pwd}/#{name}/config.yml", "w" do |file|
# file.write render.result(binding)
# end
end
end
CenterStage.start(ARGV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment