Sha256: 641a57795e2990ebdd69674ac8ec746a31bd5b55b317b1c32982f2013ad9f77c

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'fileutils'

module Pakyow
  module Generators
    class AppGenerator
      class << self
        def start
          case ARGV.first
          when '--help', '-h', nil
            puts File.open(File.join(PAK_PATH, 'commands/USAGE-NEW')).read
          else
            generator = self.new(ARGV.first)
            generator.build
          end
        end
      end

      def initialize(dest)
        @src = "#{File.expand_path('../', __FILE__)}/templates/."
        @dest = dest
      end

      def build
        puts "Generating project: #{@dest}"

        if !File.directory?(@dest) || (Dir.entries(@dest) - ['.', '..']).empty?
          copy
        else
          ARGV.clear
          print "The folder '#{@dest}' is in use. Would you like to populate it anyway? [Yn] "

          if gets.chomp! == 'Y'
            copy
          else
            puts "Aborted!"
            exit
          end
        end

        exec
        puts "Done!"
      end

      protected

      # copies src files to dest
      def copy
        FileUtils.cp_r(@src, @dest)
      end

      # performs and other setup (e.g. bundle install)
      def exec
        puts "Running `bundle install`"
        `cd #{@dest} && bundle install`
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pakyow-0.8.0 lib/generators/pakyow/app/app_generator.rb
pakyow-0.8.rc4 lib/generators/pakyow/app/app_generator.rb