# encoding: utf-8 require 'fedux_org_stdlib/require_files' require 'fedux_org_stdlib/rake/task' require_library %w(i18n) require 'tmpdir' require 'fileutils' require 'digest/sha2' module FeduxOrgStdlib module Rake # Webserver Task # # @see Rakefile class WebserverTask < Task # @!attribute [r] report # The report to be generated attr_reader :repository, :build_directory, :directory # Create a new webserver task # # @param [String] directory # The directory where the generated server should be stored # @param [String] repository_url # The url which should be used to fetch the remote repository # @param [Array] build_directory (/tmp/webserver.xxx) # The directory where the executables should be build # @param [Array] build_script (build.sh) # The script which should be used to build the executables # # @example Create new task # FeduxOrgStdlib::Rake::WebserverTask.new def initialize( directory: File.expand_path('utils/server'), repository_url: 'https://github.com/dg-ratiodata/local_webserver', build_directory: Dir.mktmpdir('webserver'), build_script: 'build.sh', **args ) super(**args) @repository = FeduxOrgStdlib::RemoteRepository.new(repository_url) @directory = File.expand_path(directory) @build_directory = File.expand_path(build_directory) @build_script = build_script end # @private def run_task(_verbose) create_build_directory fetch_repository build_server copy_files_to_destination_directory end private def create_build_directory FileUtils.mkdir_p build_directory end def fetch_repository repository.clone_to build_directory end def build_server Dir.chdir build_directory do system File.join('.', build_script) end end def copy_files_to_destination_directory FileUtils.mkdir_p directory FileUtils.cp new_executable_files, directory end def new_executable_files Dir.glob(File.join(build_directory, '**', '*')).select { |f| File.executable? f } end end end end