bin/plezi in plezi-0.10.10 vs bin/plezi in plezi-0.10.11

- old
+ new

@@ -32,15 +32,33 @@ # end # class AppTemplate def initialize - require 'rubygems' - # set end comments @end_comments = [] @app_tree ||= {} + end + def app_tree + @app_tree ||= {} + end + def build_mini + require 'plezi/version' + @app_tree["#{ARGV[1]}"] ||= IO.read( ::File.expand_path(File.join("..", "..", "resources" ,"mini_exec.rb"), __FILE__)).gsub('appname', ARGV[1]) + @app_tree["#{ARGV[1]}.rb"] ||= IO.read( ::File.expand_path(File.join("..", "..", "resources" ,"mini_app.rb"), __FILE__)).gsub('appname', ARGV[1]).gsub('appsecret', "#{ARGV[1]}_#{SecureRandom.hex}") + app_tree["Procfile"] ||= "" + app_tree["Procfile"] << "\nweb: bundle exec ruby ./#{ARGV[1]} -p $PORT\n" + app_tree["Gemfile"] ||= '' + app_tree["Gemfile"] << "source 'https://rubygems.org'\n\n####################\n# core gems\n\n# include the basic plezi framework and server\ngem 'plezi', '~> #{Plezi::VERSION}'\n" + app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n" + finalize + end + def build + require 'plezi/version' + # plezi run script + @app_tree["#{ARGV[1]}"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"code.rb"), __FILE__) + # set up application files app_tree["app"] ||= {} app_tree["app"]["controllers"] ||= {} app_tree["app"]["controllers"]["sample_controller.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"controller.rb"), __FILE__)) app_tree["app"]["models"] ||= {} @@ -66,14 +84,15 @@ # app core files. app_tree["environment.rb"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"environment.rb"), __FILE__) app_tree["routes.rb"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"routes.rb"), __FILE__) app_tree["rakefile"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"rakefile"), __FILE__) app_tree["Procfile"] ||= "" - app_tree["Procfile"] << "\nweb: bundle exec ./#{ARGV[1]} -p $PORT\n" + app_tree["Procfile"] << "\nweb: bundle exec ruby ./#{ARGV[1]} -p $PORT\n" app_tree["Gemfile"] ||= '' app_tree["Gemfile"] << "source 'https://rubygems.org'\n\n####################\n# core gems\n\n# include the basic plezi framework and server\ngem 'plezi', '~> #{Plezi::VERSION}'\n" app_tree["Gemfile"] << IO.read( ::File.expand_path(File.join("..", "..", "resources" ,"Gemfile"), __FILE__)) + app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n" # set up config files app_tree["config"] ||= {} app_tree["config"]["oauth.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"oauth_config.rb"), __FILE__)) app_tree["config"]["active_record.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"db_ac_config.rb"), __FILE__)) @@ -106,31 +125,23 @@ # set up a public folder for static file service app_tree["public"] ||= {} app_tree["public"]["assets"] ||= {} app_tree["public"]["assets"]["stylesheets"] ||= {} app_tree["public"]["assets"]["javascripts"] ||= {} - app_tree["public"]["images"] ||= {} - + app_tree["public"]["images"] ||= {} + finalize end - - def app_tree - @app_tree ||= {} - end - def build - # require 'pry' - # binding.pry - app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n" + def finalize begin Dir.mkdir ARGV[1] puts "created the #{ARGV[1]} application directory.".green rescue Exception => e puts "the #{ARGV[1]} application directory exists - trying to rebuild (no overwrite).".pink end Dir.chdir ARGV[1] puts "starting to write template data...".red puts "" - @app_tree["#{ARGV[1]}"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"code.rb"), __FILE__) write_files app_tree File.chmod 0775, "#{ARGV[1]}" puts "tried to update execution permissions. this is system dependent and might have failed.".pink puts "use: chmod +x ./#{ARGV[1]} to set execution permissions on Unix machines." puts "" @@ -214,14 +225,13 @@ # update with http://ruby-doc.org/stdlib-2.2.0/libdoc/optparse/rdoc/OptionParser.html # require 'optparser' -if ARGV[0] == 'new' || ARGV[0] == 'n' || ARGV[0] == "force" +if ARGV[0] == 'new' || ARGV[0] == 'n' || ARGV[0] == "force" || ARGV[0] == 'mini' || ARGV[0] == 'm' ######### ## set up building environment - require 'plezi/version' NO_PLEZI_AUTO_START = true ARGV[1] = ARGV[1].gsub /[^a-zA-Z0-9]/, '_' if Dir.exists?(ARGV[1]) && ARGV[0] != "force" puts "" puts "WARNING: app/folder alread exists, use `plezi fource #{ARGV[1]}` to attempt rebuild (no files will be overwritten).".red @@ -232,43 +242,13 @@ Dir.chdir ARGV[1] require ::File.expand_path(::Dir["."][0], ( ARGV[1] + ".rb") ) Dir.chdir '..' end - if ARGV.count > 3 && (ARGV[2] == 'with' || ARGV[2] == 'w') - - # gem loading - local_gems = Gem::Specification.map {|g| g.name} - # this will load all requested gems and allow them to update the AppTemplate - if ARGV[3] == "all" - puts "loading gems and giving each gem a chance to update the app template:".yellow - local_gems.each do |g| - begin - puts "loaded the #{g} gem." if require g - rescue Exception => e - puts "couldn't load the #{g} gem... moving on.".red - end - end - else - require 'pathname' - ARGV[3..-1].each do |g| - if local_gems.include? g - require g - puts "loaded the #{g} gem, and gave it a change to update the template." - else - puts "Error, the gem: #{g} could not be found!".red - puts "try first running: gem install #{g}".green - exit - end - end - end - true - end - # building template = AppTemplate.new - template.build + (ARGV[0] == 'mini' || ARGV[0] == 'm' ) ? template.build_mini : template.build elsif ARGV[0] == 'server' || ARGV[0] == 'start' || ARGV[0] == 's' ARGV.shift load File.expand_path(Dir["."][0], (File.expand_path(Dir["."][0]).split(/[\\\/]/).last) ) rescue load( File.expand_path(Dir["."][0], (File.expand_path(Dir["."][0]).split(/[\\\/]/).last ) ) ) elsif ARGV[0] == 'console' || ARGV[0] == 'c' NO_PLEZI_AUTO_START ||= true @@ -286,28 +266,22 @@ puts "==============================".green puts "new app options:".pink puts "option description".yellow puts "new <appname> creates a new application called <appname>." puts "n alias for new." - puts "new app with gem 'new' accepts the 'with' paramater (or w for short)." + puts "mini <appname> creates a new mini-application called <appname>." + puts "m alias for mini." puts "starting up an app:".pink - puts "start runs the app. accepts any parameters the app supports." + puts "start attempts to run the app. accepts any parameters the app supports." puts "s alias for start/server." puts "start console innsead of services:".pink puts "console runs the app. accepts any parameters the app supports." puts "c alias for start/server." puts "==============================".green - puts "create an app with specific plugins:".pink - puts "plezi new app with gem1 gem2" - puts "loads the specific gem(s) and allows them to update the template before building the app.".green puts "" - puts "create an app with ALL plugins:".pink - puts "plezi n app w all" - puts "loads the all available gem(s) and allows them to update the template before building the app.".green - puts "" - puts "start the application with any parameters it supports:".pink - puts "plezi s -p 80" - puts "loads the app with parameters -p 80".green + puts "Run the app using the app's script with an optional: -p {port number}. i.e." + puts " cd ./appname".pink + puts " ./appname -p 8080".pink puts "" end