Sha256: d079b577061c98057814ac7d6bf05d5e05237c9806934ac587962440c3c73668

Contents?: true

Size: 1.48 KB

Versions: 29

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require 'active_support/core_ext/string/inflections'

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

        extend DSL::Serviceable

        TEMPLATE_DIRECTORY_PATH = File.expand_path(File.join(__dir__, '../../../..', 'templates', 'plugins', 'ios'))
        COMMON_TEMPLATES_PATH = File.join(TEMPLATE_DIRECTORY_PATH, 'common')
        
        LANGUAGES = %w[objc swift].freeze
        
        attr_reader :plugin_name, :language
        
        def initialize(plugin_name, language)
          @plugin_name = plugin_name
          @language = language
        end
        
        def call
          assert_not_exists!
          set_working_dir!
          cp_template_files!
          Utils::TemplateInflator.new(plugin_name: plugin_name, repo_name: repo_name).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("#{COMMON_TEMPLATES_PATH}/.", '.')
          system('ditto', File.join(TEMPLATE_DIRECTORY_PATH, 'language-specific', language), '.')
        end
        
        def repo_name
          plugin_name.underscore.dasherize.prepend 'ios-'
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
gonative-cli-0.7.13 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.12 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.11 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.10 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.9 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.8 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.7 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.6 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.5 lib/gonative/plugins/ios/create.rb