Created
June 3, 2015 14:38
-
-
Save wess/ce8b47bd257f157cb52a to your computer and use it in GitHub Desktop.
CenterStage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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