#! /usr/bin/env ruby # script to automate creation of cms for a new/old Sinatra project require 'ostruct' require 'colorize' require 'zing' # make sure ARGV has values if ARGV.size == 0 puts "ERROR: Parameters needed. Run with -h to view options".red end # parse option from command line options = OpenStruct.new begin Zing::CommandParser.parse(ARGV, options) rescue Exception => e exit! end # default directories path setting project_absolute_dir = options.project_absolute_dir app_name = options.app_name models_directory = project_absolute_dir + "/models" views_directory = project_absolute_dir + "/views" routes_directory = project_absolute_dir + "/routes" push_directory = project_absolute_dir + "/push" helpers_directory = project_absolute_dir + "/helpers" scss_directory = project_absolute_dir + "/public/sass" css_directory = project_absolute_dir + "/public/css" images_directory = project_absolute_dir + "/public/images" # check if config.ru and app_name.rb exist unless File.exist?(project_absolute_dir + "/config.ru") and File.exist?(project_absolute_dir + "/#{app_name}.rb") puts "ERROR: Are you in the project directory before trying to Zing?".red exit! end # Base # # This will be the base CMS, the rest will not function without this if options.base begin puts "Zinging Base CMS" # copy cms images from gem to the app images directory zing_images = `gem contents zing`.split("\n").select {|e| e.match(/\.png/i)} FileUtils.cp zing_images, images_directory # check if database config exist and connection successful Zing::DbHelper.connect_db(project_absolute_dir + "/models.rb") # create AdminUser table Zing::DbHelper.create_admin_user_table # copy_file_templates Zing::FileHelper.copy_file_templates(options, "options_base") rescue Exception => e puts "ERROR: #{e.message}".red puts "" exit! end end # Push # # create push folder if not exist if options.push begin puts "Zinging push CMS" Zing::FileHelper.create_directory(push_directory) # check if database config exist and connection successful Zing::DbHelper.connect_db(project_absolute_dir + "/models.rb") # create Token Table Zing::DbHelper.create_token_table # create Notification Table Zing::DbHelper.create_notification_table # create ApnLog Table Zing::DbHelper.create_apn_log_table # copy file templates Zing::FileHelper.copy_file_templates(options, "options_push") # completion puts "Dont forget to place your '".yellow + "#{app_name}_push_certificate.pem".red + "' file in '".yellow + "/push".red + "' folder".yellow rescue Exception => e puts "ERROR: #{e.message}".red puts "" exit! end end