Sha256: 66909463dd29bd18f6720bd6c75bc039d2b837e78d58f99f22bc94f886ea157d

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

#!/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 <app_name>"
else
  app_name = ARGV[1]
  app_dir = working_dir + "/" + app_name

  puts "Generating new app: #{app_name}"
  puts "fullpath: #{app_dir}"

  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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shopify-sinatra-app-0.0.8 bin/shopify-sinatra-app-generator
shopify-sinatra-app-0.0.7 bin/shopify-sinatra-app-generator
shopify-sinatra-app-0.0.6 bin/shopify-sinatra-app-generator
shopify-sinatra-app-0.0.5 bin/shopify-sinatra-app-generator