Sha256: 5df945b72d2540bbab60fa9dd162cbdc39be961e03fb0c73c10b85ec060d170a
Contents?: true
Size: 1.99 KB
Versions: 3
Compression:
Stored size: 1.99 KB
Contents
#!/usr/bin/env ruby GEMFILE = <<EOF source 'https://rubygems.org' gem 'nephos-server' EOF ROUTE_RB = <<EOF #get url: "/", controller: "MainController", method: "root" #get url: "/add", controller: "MainController", method: "add_url" #get url: "/rm", controller: "MainController", method: "rm_url" EOF def generate_controller(name, file) if File.exists? file print "The file #{file} already exists. Are you sure to erase it ? (y/N)" r = STDIN.gets.to_s.chomp raise "File #{file} already exists" unless r.match(/y(es)?/) end f = File.open(file, 'w') f << <<EOF class #{name} < Nephos::Controller def root return {plain: "index"} end end EOF puts "Controller \"#{name}\" created at location \"#{file}\"" end def create_application_dir dir raise "Directory #{dir} already exists" if Dir.exists? dir Dir.mkdir dir end def move_to_application_dir dir Dir.chdir dir end def initialize_application raise "Not an empty dir" unless Dir[File.expand_path "*"].empty? File.write "routes.rb", ROUTE_RB File.write "Gemfile", GEMFILE Dir.mkdir "app" begin `git init .` puts "Git repository initialized" rescue Errno::ENOENT => err puts "Warning: git repository not initialized" rescue => err puts "Error: #{err.message}" end exec("bundle install") end require 'optparse' begin OptionParser.new do |opts| opts.banner = "Usage: nephos-generator [controller name] [appli [name]]" end.parse! case ARGV[0] when "c", "controller" if ARGV[1].to_s.match(/[\w_\-\.]+/) generate_controller("#{ARGV[1].capitalize}Controller", "app/#{ARGV[1].downcase}.rb") else puts "error" end when "a", "appli", "application" if not ARGV[1].to_s.empty? create_application_dir(ARGV[1]) puts "Application #{ARGV[1]} created" move_to_application_dir(ARGV[1]) end initialize_application puts "Application initialized" else puts "\"#{ARGV[0]}\" not recognized has a command" end rescue => err puts "Error: #{err.message}" end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nephos-server-0.3.2 | bin/nephos-generator |
nephos-server-0.3.1 | bin/nephos-generator |
nephos-server-0.2.4 | bin/nephos-generator |