#!/usr/bin/env ruby require 'fileutils' working_dir = Dir.pwd spec = Gem::Specification.find_by_name("shopify-sinatra-app") gem_root = spec.gem_dir gem_lib = gem_root + "/lib" generator_dir = gem_lib + "/generator" if ARGV.length < 2 puts "Usage:\n./shopify-sinatra-app new " else app_name = ARGV[1] app_dir = working_dir + "/" + app_name begin Dir.mkdir(app_dir) FileUtils.cp_r(generator_dir + "/config", app_dir + "/config") FileUtils.cp_r(generator_dir + "/db", app_dir + "/db") FileUtils.cp_r(generator_dir + "/lib", app_dir + "/lib") FileUtils.cp_r(generator_dir + "/public", app_dir + "/public") FileUtils.cp_r(generator_dir + "/views", app_dir + "/views") FileUtils.cp(generator_dir + "/.gitignore", app_dir + "/.gitignore") FileUtils.cp(generator_dir + "/config.ru", app_dir + "/config.ru") FileUtils.cp(generator_dir + "/Procfile", app_dir + "/Procfile") FileUtils.cp(generator_dir + "/Rakefile", app_dir + "/Rakefile") FileUtils.cp(generator_dir + "/Gemfile", app_dir + "/Gemfile") FileUtils.cp(generator_dir + "/README.md", app_dir + "/README.md") FileUtils.touch(app_dir + "/.env") Dir.chdir(app_dir) pipe = IO.popen("bundle install") while (line = pipe.gets) print line end pipe = IO.popen("bundle exec rake db:migrate") while (line = pipe.gets) print line end rescue Errno::EEXIST => e puts "App directory alread exists, pick a new app name or delete the existing folder" end end