#!/usr/bin/env ruby $0="Plezi Builder" # count lines of code with: ^[ \t]*[\w\d\"\(\{\@\[\]\}\)\:\'\.\*\&]+.*$ require 'irb' require 'benchmark' require 'securerandom' require 'plezi/builders/builder' require 'plezi/builders/app_builder' ###################################################################### # tweek the string class for termial coloring options class String # colorization def colorize(color_code) "\e[#{color_code}m#{self}\e[0m" end def red colorize(31) end def green colorize(32) end def yellow colorize(33) end def pink colorize(35) end end ###################################################################### ###################################################################### ## ## Start the Build script ## ###################################################################### ###################################################################### # 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" || ARGV[0] == 'mini' || ARGV[0] == 'm' ######### ## set up building environment 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 puts "" exit end if Dir.exists?(ARGV[1]) && ARGV[0] == "force" Dir.chdir ARGV[1] require ::File.expand_path(::Dir["."][0], ( ARGV[1] + ".rb") ) Dir.chdir '..' end # building template = Plezi::Base::AppBuilder.new (ARGV[0] == 'mini' || ARGV[0] == 'm' ) ? template.build_mini(ARGV[1]) : template.build(ARGV[1]) 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' 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) ) ) ARGV.clear Iodine.protocol = nil IRB.start else puts "" puts "Plezi fast web app starter.".pink puts "use: plezi new appname" puts "or: plezi new appname with template-gem-to-put-in another-template-gem-to-put" puts "==============================".green puts "new app options:".pink puts "option description".yellow puts "new creates a new application called ." puts "n alias for new." puts "mini creates a new mini-application called ." puts "m alias for mini." puts "starting up an app:".pink 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 "" 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