Sha256: 4993db7e8afc8c9505550cdb3b951e333a649680e353ec5fdecb814c3452d7fb

Contents?: true

Size: 1.34 KB

Versions: 20

Compression:

Stored size: 1.34 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

20 entries across 20 versions & 1 rubygems

Version Path
gonative-cli-1.4.4 lib/gonative/plugins/android/create.rb
gonative-cli-1.4.3 lib/gonative/plugins/android/create.rb
gonative-cli-1.4.2 lib/gonative/plugins/android/create.rb
gonative-cli-1.4.1 lib/gonative/plugins/android/create.rb
gonative-cli-1.4.0 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.9 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.8 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.7 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.6 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.5 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.4 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.3 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.2 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.1 lib/gonative/plugins/android/create.rb
gonative-cli-1.3.0 lib/gonative/plugins/android/create.rb
gonative-cli-1.2.4 lib/gonative/plugins/android/create.rb
gonative-cli-1.2.3 lib/gonative/plugins/android/create.rb
gonative-cli-1.2.2 lib/gonative/plugins/android/create.rb
gonative-cli-1.2.1 lib/gonative/plugins/android/create.rb
gonative-cli-1.2.0 lib/gonative/plugins/android/create.rb