Sha256: 0eacaefea7a3dc8fd159b665aa1a9aa598d94386110361ee8081c299ee3d85a1

Contents?: true

Size: 1.36 KB

Versions: 35

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require 'active_support/core_ext/string/inflections'

module GoNative
  module Plugins
    module Android
      class Create
        autoload :FileUtils, 'fileutils'

        extend DSL::Serviceable

        TEMPLATE_DIRECTORY_PATH = File.expand_path(File.join(__dir__, '../../../..', 'templates', 'plugins', 'android'))

        attr_reader :plugin_name

        def initialize(plugin_name)
          @plugin_name = Utils::SanitizePluginName.call(plugin_name, 'android')
        end
        
        def call
          assert_not_exists!
          set_working_dir!
          cp_template_files!
          Utils::TemplateInflator.new(plugin_name: capitalized_plugin_name, java_package: java_package).call
        end

        def assert_not_exists!
          return unless File.directory?(plugin_name)
  
          raise Error, "Directory #{plugin_name} already exists"
        end

        def set_working_dir!
          FileUtils.mkdir(plugin_name)
          FileUtils.cd(plugin_name)
        end

        def cp_template_files!
          FileUtils.cp_r("#{TEMPLATE_DIRECTORY_PATH}/.", '.')
          system('ditto', TEMPLATE_DIRECTORY_PATH, '.')
        end
        
        def capitalized_plugin_name
          [plugin_name, 'plugin'].join('_').camelize
        end
        
        def java_package
          plugin_name
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
gonative-cli-1.1.2 lib/gonative/plugins/android/create.rb
gonative-cli-1.1.1 lib/gonative/plugins/android/create.rb
gonative-cli-1.1.0 lib/gonative/plugins/android/create.rb
gonative-cli-1.0.6 lib/gonative/plugins/android/create.rb
gonative-cli-1.0.5 lib/gonative/plugins/android/create.rb
gonative-cli-1.0.4 lib/gonative/plugins/android/create.rb
gonative-cli-1.0.3 lib/gonative/plugins/android/create.rb
gonative-cli-1.0.2 lib/gonative/plugins/android/create.rb
gonative-cli-1.0.1 lib/gonative/plugins/android/create.rb
gonative-cli-1.0.0 lib/gonative/plugins/android/create.rb
gonative-cli-0.9.3 lib/gonative/plugins/android/create.rb
gonative-cli-0.9.2 lib/gonative/plugins/android/create.rb
gonative-cli-0.9.1 lib/gonative/plugins/android/create.rb
gonative-cli-0.9.0 lib/gonative/plugins/android/create.rb
gonative-cli-0.8.1 lib/gonative/plugins/android/create.rb
gonative-cli-0.8.0 lib/gonative/plugins/android/create.rb
gonative-cli-0.7.17 lib/gonative/plugins/android/create.rb
gonative-cli-0.7.16 lib/gonative/plugins/android/create.rb
gonative-cli-0.7.15 lib/gonative/plugins/android/create.rb
gonative-cli-0.7.14 lib/gonative/plugins/android/create.rb