Sha256: e2270d6954a2467c83456599b70a366b6a16bdce0bc70b0b2b9813267607ab8d

Contents?: true

Size: 1.73 KB

Versions: 60

Compression:

Stored size: 1.73 KB

Contents

require 'commands/meta/command'
require 'fileutils'

module Nutella
  class New < Command
    @description = 'Creates a new nutella application'
  
    def run(args=nil)
      app_id = args[0]
    
      # If no other arguments, show help and quit here
      if args.empty?
        console.warn 'You need to specify a name for your new application'
        return
      end
    
      # Check that a directory (i.e. an app) with the same name doesn't already exist
      # If it does it looks into it to see if there is a nutella.json file and displays
      # the proper error message
      if File.directory? app_id
        if File.exist? "#{app_id}/nutella.json"
          console.warn "An application named #{app_id} already exists"
          return
        else
          console.warn "A directory named #{app_id} already exists"
          return
        end
      end
    
      # If all seems good, generate the application skeleton
      create_dir_structure app_id

      # Display a nice success message and return
      console.success "Your new nutella application #{app_id} is ready!"
    end
    
    
    private 
  
  
    def create_dir_structure( app_id )
      # Create directories
      FileUtils.mkdir_p("#{app_id}/bots")
      FileUtils.mkdir_p("#{app_id}/interfaces")
      # Create nutella.json hash
      config_file_hash = {
        :name => app_id,
        :version => '0.1.0',
        :nutella_version => File.open("#{Nutella::NUTELLA_HOME}VERSION", 'rb').read,
        :type => 'application',
        :description => 'A quick description of your application'
      }
      # Write nutella.json hash
      File.open("#{app_id}/nutella.json", 'w') do |f|
        f.write(JSON.pretty_generate(config_file_hash))
      end
    end
  
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
nutella_framework-0.9.2 lib/commands/new.rb
nutella_framework-0.9.1 lib/commands/new.rb
nutella_framework-0.9.0 lib/commands/new.rb
nutella_framework-0.8.0 lib/commands/new.rb
nutella_framework-0.7.3 lib/commands/new.rb
nutella_framework-0.7.2 lib/commands/new.rb
nutella_framework-0.7.1 lib/commands/new.rb
nutella_framework-0.7.0 lib/commands/new.rb
nutella_framework-0.6.21 lib/commands/new.rb
nutella_framework-0.6.20 lib/commands/new.rb
nutella_framework-0.6.19 lib/commands/new.rb
nutella_framework-0.6.18 lib/commands/new.rb
nutella_framework-0.6.17 lib/commands/new.rb
nutella_framework-0.6.16 lib/commands/new.rb
nutella_framework-0.6.15 lib/commands/new.rb
nutella_framework-0.6.13 lib/commands/new.rb
nutella_framework-0.6.12 lib/commands/new.rb
nutella_framework-0.6.11 lib/commands/new.rb
nutella_framework-0.6.10 lib/commands/new.rb
nutella_framework-0.6.9 lib/commands/new.rb