require 'commander/blank' require 'commander/command' module Analytics module Command # A class that's called from CLI's 'generate' argument, # and used to generate analytics files from the resource JSON file. class Generate include Helpers::Terminal def perform unless File.file?(config_src_path) prompt.error("Unable to find #{config_src_path}") return end prompt.say('Generating analytics files...') generate prompt.ok('Analytics files are successfully generated!') end ## The following methods are used to generate analytics files, ## based on settings defined in 'analytics.yml' configuration file. private ## Retrieving values from configuration file. def config Analytics::IO::Config.read end def config_lang config[:language] end def config_analytics_path config[:analyticsFilesPath] end def config_src_path config[:sourcePath] end ## Generating def generate json_file = File.open(config_src_path) json_src = JSON.load(json_file) case config_lang when 'swift' FileUtils.mkdir_p config_analytics_path unless File.exist? config_analytics_path Analytics::Serializer::Swift.new(json_src).save(config_analytics_path) when 'objc' FileUtils.mkdir_p config_analytics_path unless File.exist? config_analytics_path Analytics::Serializer::ObjC.new(json_src).save(config_analytics_path) when 'swift-objc' swift_path = config_analytics_path + '/Swift' objc_path = config_analytics_path + '/ObjC' FileUtils.mkdir_p swift_path unless File.exist? swift_path FileUtils.mkdir_p objc_path unless File.exist? objc_path Analytics::Serializer::Swift.new(json_src).save(swift_path) Analytics::Serializer::ObjC.new(json_src).save(objc_path) else prompt.error("Unsupported value '#{config_lang}' for 'language'. Supported values are:\n"\ "- 'swift' - if You're using only Swift in Your project,\n"\ "- 'objc' - if You're using only ObjC in Your project,\n"\ "- 'swift-objc' if You're using both Swift & ObjC in Your project.") return end end end end end