Sha256: 806bb2699e4d8c509abeaae46ab94f16dbeb4202e831aed54479440342f868d6

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

module Susanoo
  module Generators
    class Cordova < Thor::Group
      include Thor::Actions

      CORDOVA_VERSION = `cordova -v`
      CORDOVA_PATH = `which cordova`

      def initialize_project
        fname = Susanoo::Project.folder_name.dup

        # Java Package name
        package_name = ask 'Java Package Name: '.colorize(:light_green)
        if package_name.chomp.strip.empty?
          package_name = "com.example.#{fname.gsub("-", "_")}"
        else
          if package_name.chomp.split(".").length < 3
            say "Package name format should be like 'suffix.domain.subdomain'".colorize(:red)
            exit 1
          end
        end

        # Project name
        project_name = ask "Project Name [#{fname.colorize(:light_red)}".colorize(:light_green) + "]: ".colorize(:light_green)

        say "Initializing project with Apache Cordova #{version} at #{CORDOVA_PATH}"
        system "cordova create #{Susanoo::Project.folder_name} #{package_name.chomp} #{project_name.chomp}"
      end

      def platforms
        platforms = ask 'Platforms (comma separated): '.colorize(:light_blue)
        inside Susanoo::Project.folder_name do
          platforms.chomp.split(",").each do |platform|
            say "Adding #{platform.strip} platform ...".colorize(:green)
            system "cordova platform add #{platform.strip}"
          end
          say 'Adding console plugin to project'.colorize(:green)
          system 'cordova plugin add org.apache.cordova.console'
        end
      end

      def remove_default_files
        say "Removing cordova default files . . .".colorize(:yellow)
        inside Susanoo::Project.folder_name do
          inside 'www' do
            remove_file 'index.html'
            remove_file 'js'
            remove_file 'css'
            remove_file 'img'
          end
        end
      end

      def self.is_global_generator?
        true
      end

      private

      def version
        CORDOVA_VERSION.chomp
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
susanoo-0.14.0 lib/susanoo/generators/cordova.rb
susanoo-0.13.2 lib/susanoo/generators/cordova.rb
susanoo-0.13.1 lib/susanoo/generators/cordova.rb
susanoo-0.13.0 lib/susanoo/generators/cordova.rb
susanoo-0.12.3 lib/susanoo/generators/cordova.rb
susanoo-0.12.2 lib/susanoo/generators/cordova.rb
susanoo-0.12.1 lib/susanoo/generators/cordova.rb
susanoo-0.12.0 lib/susanoo/generators/cordova.rb
susanoo-0.11.1 lib/susanoo/generators/cordova.rb