Sha256: 68b3b0a92d063c1a09e28b07cd80a00fb48b9755a94ecac5a636e7d0e24cf93f

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 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_r(generator_dir + "/test",       app_dir + "/test")

    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")
    file = File.open(app_dir + "/.env", "w")
    file.write("SHOPIFY_API_KEY=your_api_key\n")
    file.write("SHOPIFY_SHARED_SECRET=your_shared_secret\n")
    file.write("SECRET=random_string_to_encrypt_credentials_with\n")
    file.close

    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

2 entries across 2 versions & 1 rubygems

Version Path
shopify-sinatra-app-0.1.3 bin/shopify-sinatra-app-generator
shopify-sinatra-app-0.1.2 bin/shopify-sinatra-app-generator