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-1.1.2 lib/gonative/plugins/ios/create.rb
gonative-cli-1.1.1 lib/gonative/plugins/ios/create.rb
gonative-cli-1.1.0 lib/gonative/plugins/ios/create.rb
gonative-cli-1.0.6 lib/gonative/plugins/ios/create.rb
gonative-cli-1.0.5 lib/gonative/plugins/ios/create.rb
gonative-cli-1.0.4 lib/gonative/plugins/ios/create.rb
gonative-cli-1.0.3 lib/gonative/plugins/ios/create.rb
gonative-cli-1.0.2 lib/gonative/plugins/ios/create.rb
gonative-cli-1.0.1 lib/gonative/plugins/ios/create.rb
gonative-cli-1.0.0 lib/gonative/plugins/ios/create.rb
gonative-cli-0.9.3 lib/gonative/plugins/ios/create.rb
gonative-cli-0.9.2 lib/gonative/plugins/ios/create.rb
gonative-cli-0.9.1 lib/gonative/plugins/ios/create.rb
gonative-cli-0.9.0 lib/gonative/plugins/ios/create.rb
gonative-cli-0.8.1 lib/gonative/plugins/ios/create.rb
gonative-cli-0.8.0 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.17 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.16 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.15 lib/gonative/plugins/ios/create.rb
gonative-cli-0.7.14 lib/gonative/plugins/ios/create.rb