sleeping_king_studios-tasks 0.1.0 → 0.2.0.rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +6 -0
- data/README.md +4 -2
- data/lib/sleeping_king_studios/tasks/ci/eslint_results.rb +112 -0
- data/lib/sleeping_king_studios/tasks/ci/eslint_runner.rb +51 -0
- data/lib/sleeping_king_studios/tasks/ci/eslint_task.rb +32 -0
- data/lib/sleeping_king_studios/tasks/ci/jest_results.rb +106 -0
- data/lib/sleeping_king_studios/tasks/ci/jest_runner.rb +51 -0
- data/lib/sleeping_king_studios/tasks/ci/jest_task.rb +43 -0
- data/lib/sleeping_king_studios/tasks/ci/rspec_each_task.rb +17 -1
- data/lib/sleeping_king_studios/tasks/ci/rspec_task.rb +11 -1
- data/lib/sleeping_king_studios/tasks/ci/tasks.thor +4 -0
- data/lib/sleeping_king_studios/tasks/configuration.rb +23 -2
- data/lib/sleeping_king_studios/tasks/file/new_task.rb +13 -11
- data/lib/sleeping_king_studios/tasks/file/templates/rspec.erb +13 -0
- data/lib/sleeping_king_studios/tasks/file/templates/ruby.erb +28 -0
- data/lib/sleeping_king_studios/tasks/version.rb +3 -3
- metadata +13 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: ecf773989f8f4674aaa32d70e9292f1990cb43a6903c3a41077eb6465f195246
         | 
| 4 | 
            +
              data.tar.gz: 0c8a09ca897e182933446ed099d1fd83f503aa359acbc8f8b565e4e3150ea093
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 40172813dfed6cb6f781d02d2997d192aebf44107fc781e13c235d3bb5432fd8b59e1f469755aeaa9af742465c7ee6685a0b4e6b2f6bc197bae5d915bf164e50
         | 
| 7 | 
            +
              data.tar.gz: c6fe927bc9d5532d3c58f1995215a5341a010f94376f4004338925f6b16a9b3252a127071b2c6ffe1ed1a86be9076bb969b36c166b807a6e69992ffc51c5a91c
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -169,9 +169,11 @@ In addition, the cucumber step has the additional option: | |
| 169 169 |  | 
| 170 170 | 
             
            - `default_files [Array]`: Files that are always loaded when running Cucumber, such as step definitions or support files. By default, this includes 'step_definitions.rb' and the 'step_definitions' directory inside 'features'.
         | 
| 171 171 |  | 
| 172 | 
            -
            `config.ci.rspec [Hash]`: Step configuration for the RSpec step. Has the same options as `config.ci.cucumber`, above, except for the aforementioned `default_files` option.
         | 
| 172 | 
            +
            `config.ci.rspec [Hash]`: Step configuration for the RSpec step. Has the same options as `config.ci.cucumber`, above, except for the aforementioned `default_files` option. In addition, the RSpec task has the following option:
         | 
| 173 173 |  | 
| 174 | 
            -
            ` | 
| 174 | 
            +
            - `format [String]`: The RSpec formatter used to format the spec results. Defaults to 'documentation'.
         | 
| 175 | 
            +
             | 
| 176 | 
            +
            `config.ci.rspec_each [Hash]`: Step configuration for the RSpec Each step. Has the same configuration options as the RSpec step.
         | 
| 175 177 |  | 
| 176 178 | 
             
            `config.ci.rubocop [Hash]`: Step configuration for the RuboCop step.
         | 
| 177 179 |  | 
| @@ -0,0 +1,112 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'sleeping_king_studios/tasks/ci'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module SleepingKingStudios::Tasks::Ci
         | 
| 6 | 
            +
              # Encapsulates the results of an Eslint call.
         | 
| 7 | 
            +
              class EslintResults
         | 
| 8 | 
            +
                # @param results [Hash] The raw results of the Eslint call.
         | 
| 9 | 
            +
                def initialize results
         | 
| 10 | 
            +
                  @results = results
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                # @param other [EslintResults] The other results object to compare.
         | 
| 14 | 
            +
                #
         | 
| 15 | 
            +
                # @return [Boolean] True if the results are equal, otherwise false.
         | 
| 16 | 
            +
                def == other
         | 
| 17 | 
            +
                  if other.is_a?(Array)
         | 
| 18 | 
            +
                    empty? ? other.empty? : @results == other
         | 
| 19 | 
            +
                  elsif other.is_a?(EslintResults)
         | 
| 20 | 
            +
                    to_h == other.to_h
         | 
| 21 | 
            +
                  else
         | 
| 22 | 
            +
                    false
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                # @return [Boolean] True if there are no inspected files, otherwise false.
         | 
| 27 | 
            +
                def empty?
         | 
| 28 | 
            +
                  inspected_file_count.zero?
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                # @return [Integer] The total number of error results across all files.
         | 
| 32 | 
            +
                def error_count
         | 
| 33 | 
            +
                  @error_count ||= @results.map { |hsh| hsh['errorCount'] }.sum
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                # @return [Boolean] True if there are no errors or warnings, otherwise
         | 
| 37 | 
            +
                #   false.
         | 
| 38 | 
            +
                def failing?
         | 
| 39 | 
            +
                  !(error_count.zero? && warning_count.zero?)
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                # @return [Integer] The number of inspected files.
         | 
| 43 | 
            +
                def inspected_file_count
         | 
| 44 | 
            +
                  @results.size
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                # @return [Boolean] Always false. Both warnings and errors trigger a failure
         | 
| 48 | 
            +
                #   state.
         | 
| 49 | 
            +
                def pending?
         | 
| 50 | 
            +
                  false
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                # @return [Hash] The hash representation of the results.
         | 
| 54 | 
            +
                def to_h
         | 
| 55 | 
            +
                  {
         | 
| 56 | 
            +
                    'inspected_file_count' => inspected_file_count,
         | 
| 57 | 
            +
                    'error_count'          => error_count,
         | 
| 58 | 
            +
                    'warning_count'        => warning_count
         | 
| 59 | 
            +
                  }
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                # @return [String] The string representation of the results.
         | 
| 63 | 
            +
                def to_s # rubocop:disable Metrics/AbcSize
         | 
| 64 | 
            +
                  str = +"#{pluralize inspected_file_count, 'file'} inspected"
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  str << ", #{pluralize error_count, 'error'}"
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  str << ", #{pluralize warning_count, 'warning'}"
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  str << "\n" unless non_empty_results.empty?
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  non_empty_results.each do |hsh|
         | 
| 73 | 
            +
                    str << "\n    #{format_result_item(hsh)}"
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  str
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                # @return [Integer] The total number of warning results across all files.
         | 
| 80 | 
            +
                def warning_count
         | 
| 81 | 
            +
                  @warning_count ||= @results.map { |hsh| hsh['warningCount'] }.sum
         | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                private
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                def format_result_item hsh
         | 
| 87 | 
            +
                  str = +relative_path(hsh['filePath'])
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  str << ": #{pluralize hsh['errorCount'], 'error'}"
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                  str << ", #{pluralize hsh['warningCount'], 'warning'}"
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                def non_empty_results
         | 
| 95 | 
            +
                  @results.reject do |hsh|
         | 
| 96 | 
            +
                    hsh['errorCount'].zero? && hsh['warningCount'].zero?
         | 
| 97 | 
            +
                  end
         | 
| 98 | 
            +
                end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                def pluralize count, singular, plural = nil
         | 
| 101 | 
            +
                  "#{count} #{tools.integer.pluralize count, singular, plural}"
         | 
| 102 | 
            +
                end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                def relative_path path
         | 
| 105 | 
            +
                  path.sub(/\A#{Dir.getwd}#{File::SEPARATOR}?/, '')
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                def tools
         | 
| 109 | 
            +
                  SleepingKingStudios::Tools::Toolbelt.instance
         | 
| 110 | 
            +
                end
         | 
| 111 | 
            +
              end
         | 
| 112 | 
            +
            end
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'sleeping_king_studios/tasks/ci'
         | 
| 4 | 
            +
            require 'sleeping_king_studios/tasks/process_runner'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module SleepingKingStudios::Tasks::Ci
         | 
| 7 | 
            +
              # Service object to run Eslint as an external process with the specified
         | 
| 8 | 
            +
              # parameters.
         | 
| 9 | 
            +
              class EslintRunner < SleepingKingStudios::Tasks::ProcessRunner
         | 
| 10 | 
            +
                def call env: {}, files: [], options: [], report: true
         | 
| 11 | 
            +
                  report  = 'tmp/ci/eslint.json' if report && !report.is_a?(String)
         | 
| 12 | 
            +
                  command =
         | 
| 13 | 
            +
                    build_command(
         | 
| 14 | 
            +
                      :env     => env,
         | 
| 15 | 
            +
                      :files   => files,
         | 
| 16 | 
            +
                      :options => options,
         | 
| 17 | 
            +
                      :report  => report
         | 
| 18 | 
            +
                    )
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  stream_process(command)
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  report ? load_report(:report => report) : []
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                private
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def base_command
         | 
| 28 | 
            +
                  'yarn eslint'
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def build_options files:, options:, report:, **_kwargs
         | 
| 32 | 
            +
                  files = default_files if files.empty?
         | 
| 33 | 
            +
                  options += ['--format=json', "--output-file=#{report}"] if report
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  super :files => files, :options => options
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                def default_files
         | 
| 39 | 
            +
                  SleepingKingStudios::Tasks.configuration.ci.eslint.
         | 
| 40 | 
            +
                    fetch(:default_files, '"**/*.js"')
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def load_report report:
         | 
| 44 | 
            +
                  raw = File.read report
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  JSON.parse raw
         | 
| 47 | 
            +
                rescue
         | 
| 48 | 
            +
                  []
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
| @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'sleeping_king_studios/tasks/ci'
         | 
| 4 | 
            +
            require 'sleeping_king_studios/tasks/ci/eslint_results'
         | 
| 5 | 
            +
            require 'sleeping_king_studios/tasks/ci/eslint_runner'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module SleepingKingStudios::Tasks::Ci
         | 
| 8 | 
            +
              # Defines a Thor task for running the Eslint linter.
         | 
| 9 | 
            +
              class EslintTask < SleepingKingStudios::Tasks::Task
         | 
| 10 | 
            +
                def self.description
         | 
| 11 | 
            +
                  'Runs the ESLint linter.'
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def self.task_name
         | 
| 15 | 
            +
                  'eslint'
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def call *files
         | 
| 19 | 
            +
                  results = eslint_runner.call(:files => files)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  EslintResults.new(results)
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                private
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def eslint_runner
         | 
| 27 | 
            +
                  opts = %w(--color)
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  EslintRunner.new(:options => opts)
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
| @@ -0,0 +1,106 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'sleeping_king_studios/tasks/ci'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module SleepingKingStudios::Tasks::Ci
         | 
| 6 | 
            +
              # Encapsulates the results of a Jest call.
         | 
| 7 | 
            +
              class JestResults
         | 
| 8 | 
            +
                # @param results [Hash] The raw results of the Jest call.
         | 
| 9 | 
            +
                def initialize results
         | 
| 10 | 
            +
                  @results = results
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                # @param other [JestResults] The other results object to compare.
         | 
| 14 | 
            +
                #
         | 
| 15 | 
            +
                # @return [Boolean] True if the results are equal, otherwise false.
         | 
| 16 | 
            +
                def == other
         | 
| 17 | 
            +
                  if other.is_a?(Hash)
         | 
| 18 | 
            +
                    empty? ? other.empty? : @results == other
         | 
| 19 | 
            +
                  elsif other.is_a?(JestResults)
         | 
| 20 | 
            +
                    to_h == other.to_h
         | 
| 21 | 
            +
                  else
         | 
| 22 | 
            +
                    false
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                # @return [Float] The duration value, in seconds.
         | 
| 27 | 
            +
                def duration
         | 
| 28 | 
            +
                  (end_time - start_time).to_f / 1000
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                # @return [Boolean] True if there are no tests, otherwise false.
         | 
| 32 | 
            +
                def empty?
         | 
| 33 | 
            +
                  test_count.zero?
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                # @return [Boolean] True if there are any failing tests, otherwise false.
         | 
| 37 | 
            +
                def failing?
         | 
| 38 | 
            +
                  !failure_count.zero?
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                # @return [Integer] The number of failing tests.
         | 
| 42 | 
            +
                def failure_count
         | 
| 43 | 
            +
                  @results.fetch('numFailedTests', 0)
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                # @return [Boolean] True if there are any pending tests, otherwise false.
         | 
| 47 | 
            +
                def pending?
         | 
| 48 | 
            +
                  !pending_count.zero?
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                # @return [Intger] The number of pending tests.
         | 
| 52 | 
            +
                def pending_count
         | 
| 53 | 
            +
                  @results.fetch('numPendingTests', 0)
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                # @return [Integer] The total number of tests.
         | 
| 57 | 
            +
                def test_count
         | 
| 58 | 
            +
                  @results.fetch('numTotalTests', 0)
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                # @return [Hash] The hash representation of the results.
         | 
| 62 | 
            +
                def to_h
         | 
| 63 | 
            +
                  {
         | 
| 64 | 
            +
                    'duration'      => duration,
         | 
| 65 | 
            +
                    'failure_count' => failure_count,
         | 
| 66 | 
            +
                    'pending_count' => pending_count,
         | 
| 67 | 
            +
                    'test_count'    => test_count
         | 
| 68 | 
            +
                  }
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                # @return [String] The string representation of the results.
         | 
| 72 | 
            +
                def to_s # rubocop:disable Metrics/AbcSize
         | 
| 73 | 
            +
                  str = +pluralize(test_count, 'test')
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                  str << ', ' << pluralize(failure_count, 'failure')
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  str << ', ' << pending_count.to_s << ' pending' if pending?
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  str << " in #{duration.round(2)} seconds"
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                private
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                def end_time
         | 
| 85 | 
            +
                  return 0 unless @results['testResults']
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                  @results['testResults'].
         | 
| 88 | 
            +
                    map { |test_result| test_result['endTime'] }.
         | 
| 89 | 
            +
                    reduce do |memo, time|
         | 
| 90 | 
            +
                      [memo, time].max
         | 
| 91 | 
            +
                    end
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                def pluralize count, singular, plural = nil
         | 
| 95 | 
            +
                  "#{count} #{tools.integer.pluralize count, singular, plural}"
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                def start_time
         | 
| 99 | 
            +
                  @results['startTime'] || 0
         | 
| 100 | 
            +
                end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                def tools
         | 
| 103 | 
            +
                  SleepingKingStudios::Tools::Toolbelt.instance
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
              end
         | 
| 106 | 
            +
            end
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'json'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require 'sleeping_king_studios/tasks/ci'
         | 
| 6 | 
            +
            require 'sleeping_king_studios/tasks/process_runner'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            module SleepingKingStudios::Tasks::Ci
         | 
| 9 | 
            +
              # Service object to run Jest as an external process with the specified
         | 
| 10 | 
            +
              # parameters.
         | 
| 11 | 
            +
              class JestRunner < SleepingKingStudios::Tasks::ProcessRunner
         | 
| 12 | 
            +
                def call env: {}, files: [], options: [], report: true
         | 
| 13 | 
            +
                  report  = 'tmp/ci/jest.json' if report && !report.is_a?(String)
         | 
| 14 | 
            +
                  command =
         | 
| 15 | 
            +
                    build_command(
         | 
| 16 | 
            +
                      :env     => env,
         | 
| 17 | 
            +
                      :files   => files,
         | 
| 18 | 
            +
                      :options => options,
         | 
| 19 | 
            +
                      :report  => report
         | 
| 20 | 
            +
                    )
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  stream_process(command)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  report ? load_report(:report => report) : {}
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                private
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def base_command
         | 
| 30 | 
            +
                  'yarn jest'
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def build_options files:, options:, report:, **_kwargs
         | 
| 34 | 
            +
                  options += ['--json', "--outputFile=#{report}"] if report
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  super :files => files, :options => options
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def load_report report:
         | 
| 40 | 
            +
                  raw = File.read report
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  return {} if raw.empty?
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  JSON.parse raw
         | 
| 45 | 
            +
                rescue
         | 
| 46 | 
            +
                  # :nocov:
         | 
| 47 | 
            +
                  {}
         | 
| 48 | 
            +
                  # :nocov:
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
| @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'sleeping_king_studios/tasks/ci'
         | 
| 4 | 
            +
            require 'sleeping_king_studios/tasks/ci/jest_results'
         | 
| 5 | 
            +
            require 'sleeping_king_studios/tasks/ci/jest_runner'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module SleepingKingStudios::Tasks::Ci
         | 
| 8 | 
            +
              # Defines a Thor task for running the full Jest (JavaScript) test suite.
         | 
| 9 | 
            +
              class JestTask < SleepingKingStudios::Tasks::Task
         | 
| 10 | 
            +
                def self.description
         | 
| 11 | 
            +
                  'Runs the Jest test suite.'
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def self.task_name
         | 
| 15 | 
            +
                  'jest'
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                option :verbose,
         | 
| 19 | 
            +
                  :type => :boolean,
         | 
| 20 | 
            +
                  :desc => 'Output individual test results.'
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def call *files
         | 
| 23 | 
            +
                  results = jest_runner.call(:files => files)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  JestResults.new(results)
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                private
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def default_verbose
         | 
| 31 | 
            +
                  SleepingKingStudios::Tasks.configuration.ci.jest.
         | 
| 32 | 
            +
                    fetch(:verbose, false)
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                def jest_runner
         | 
| 36 | 
            +
                  env  = options.fetch('__env__', {})
         | 
| 37 | 
            +
                  opts = %w(--color)
         | 
| 38 | 
            +
                  opts << "--verbose=#{options.fetch('verbose', default_verbose)}"
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  JestRunner.new(:env => env, :options => opts)
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
            end
         | 
| @@ -21,6 +21,9 @@ module SleepingKingStudios::Tasks::Ci | |
| 21 21 | 
             
                  'rspec_each'
         | 
| 22 22 | 
             
                end # class method task_name
         | 
| 23 23 |  | 
| 24 | 
            +
                option :format,
         | 
| 25 | 
            +
                  :type    => :string,
         | 
| 26 | 
            +
                  :desc    => 'The RSpec formatter to use. Defaults to the configuration.'
         | 
| 24 27 | 
             
                option :quiet,
         | 
| 25 28 | 
             
                  :aliases => '-q',
         | 
| 26 29 | 
             
                  :type    => :boolean,
         | 
| @@ -73,6 +76,11 @@ module SleepingKingStudios::Tasks::Ci | |
| 73 76 | 
             
                  } # end results
         | 
| 74 77 | 
             
                end # method build_totals
         | 
| 75 78 |  | 
| 79 | 
            +
                def default_format
         | 
| 80 | 
            +
                  SleepingKingStudios::Tasks.configuration.ci.rspec_each.
         | 
| 81 | 
            +
                    fetch(:format, :documentation)
         | 
| 82 | 
            +
                end # method default_format
         | 
| 83 | 
            +
             | 
| 76 84 | 
             
                def files_list groups
         | 
| 77 85 | 
             
                  groups = %w(spec) if groups.empty?
         | 
| 78 86 |  | 
| @@ -132,7 +140,15 @@ module SleepingKingStudios::Tasks::Ci | |
| 132 140 | 
             
                end # method rspec_runner
         | 
| 133 141 |  | 
| 134 142 | 
             
                def run_file file
         | 
| 135 | 
            -
                   | 
| 143 | 
            +
                  opts   = []
         | 
| 144 | 
            +
                  format = options.fetch('format', default_format)
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                  if format && !quiet?
         | 
| 147 | 
            +
                    opts = %w(--color --tty)
         | 
| 148 | 
            +
                    opts << "--format=#{format}"
         | 
| 149 | 
            +
                  end # if
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                  results = rspec_runner.call(:files => [file], :options => opts)
         | 
| 136 152 | 
             
                  results = RSpecResults.new(results)
         | 
| 137 153 |  | 
| 138 154 | 
             
                  say "#{set_color results_state(results), results_color(results)} #{file}"
         | 
| @@ -18,6 +18,9 @@ module SleepingKingStudios::Tasks::Ci | |
| 18 18 | 
             
                option :coverage,
         | 
| 19 19 | 
             
                  :type    => :boolean,
         | 
| 20 20 | 
             
                  :desc    => 'Enable or disable coverage with SimpleCov, if available.'
         | 
| 21 | 
            +
                option :format,
         | 
| 22 | 
            +
                  :type    => :string,
         | 
| 23 | 
            +
                  :desc    => 'The RSpec formatter to use. Defaults to the configuration.'
         | 
| 21 24 | 
             
                option :gemfile,
         | 
| 22 25 | 
             
                  :type    => :string,
         | 
| 23 26 | 
             
                  :desc    => 'The Gemfile used to run the specs.',
         | 
| @@ -41,6 +44,11 @@ module SleepingKingStudios::Tasks::Ci | |
| 41 44 |  | 
| 42 45 | 
             
                private
         | 
| 43 46 |  | 
| 47 | 
            +
                def default_format
         | 
| 48 | 
            +
                  SleepingKingStudios::Tasks.configuration.ci.rspec.
         | 
| 49 | 
            +
                    fetch(:format, :documentation)
         | 
| 50 | 
            +
                end # method default_format
         | 
| 51 | 
            +
             | 
| 44 52 | 
             
                def default_gemfile
         | 
| 45 53 | 
             
                  File.join(Dir.pwd, 'Gemfile')
         | 
| 46 54 | 
             
                end # method default_gemfile
         | 
| @@ -62,8 +70,10 @@ module SleepingKingStudios::Tasks::Ci | |
| 62 70 | 
             
                  env[:bundle_gemfile] = gemfile if gemfile
         | 
| 63 71 | 
             
                  env[:coverage]       = false unless coverage
         | 
| 64 72 |  | 
| 73 | 
            +
                  format = options.fetch('format', default_format)
         | 
| 74 | 
            +
             | 
| 65 75 | 
             
                  opts = %w(--color --tty)
         | 
| 66 | 
            -
                  opts <<  | 
| 76 | 
            +
                  opts << "--format=#{format}" unless quiet?
         | 
| 67 77 |  | 
| 68 78 | 
             
                  RSpecRunner.new(:env => env, :options => opts)
         | 
| 69 79 | 
             
                end # method rspec_runner
         | 
| @@ -1,6 +1,8 @@ | |
| 1 1 | 
             
            # lib/sleeping_king_studios/tasks/ci/tasks.thor
         | 
| 2 2 |  | 
| 3 3 | 
             
            require 'sleeping_king_studios/tasks/ci/cucumber_task'
         | 
| 4 | 
            +
            require 'sleeping_king_studios/tasks/ci/eslint_task'
         | 
| 5 | 
            +
            require 'sleeping_king_studios/tasks/ci/jest_task'
         | 
| 4 6 | 
             
            require 'sleeping_king_studios/tasks/ci/rspec_task'
         | 
| 5 7 | 
             
            require 'sleeping_king_studios/tasks/ci/rspec_each_task'
         | 
| 6 8 | 
             
            require 'sleeping_king_studios/tasks/ci/rubocop_task'
         | 
| @@ -12,6 +14,8 @@ module SleepingKingStudios::Tasks::Ci | |
| 12 14 | 
             
                namespace :ci
         | 
| 13 15 |  | 
| 14 16 | 
             
                task SleepingKingStudios::Tasks::Ci::CucumberTask
         | 
| 17 | 
            +
                task SleepingKingStudios::Tasks::Ci::EslintTask
         | 
| 18 | 
            +
                task SleepingKingStudios::Tasks::Ci::JestTask
         | 
| 15 19 | 
             
                task SleepingKingStudios::Tasks::Ci::RSpecTask
         | 
| 16 20 | 
             
                task SleepingKingStudios::Tasks::Ci::RSpecEachTask
         | 
| 17 21 | 
             
                task SleepingKingStudios::Tasks::Ci::RuboCopTask
         | 
| @@ -5,6 +5,8 @@ require 'sleeping_king_studios/tools/toolbox/configuration' | |
| 5 5 | 
             
            require 'sleeping_king_studios/tasks'
         | 
| 6 6 |  | 
| 7 7 | 
             
            module SleepingKingStudios::Tasks
         | 
| 8 | 
            +
              # rubocop:disable Metrics/ClassLength
         | 
| 9 | 
            +
             | 
| 8 10 | 
             
              # Task configuration options, grouped by namespace.
         | 
| 9 11 | 
             
              class Configuration < SleepingKingStudios::Tools::Toolbox::Configuration
         | 
| 10 12 | 
             
                # rubocop:disable Metrics/BlockLength
         | 
| @@ -55,18 +57,36 @@ module SleepingKingStudios::Tasks | |
| 55 57 | 
             
                      :default_files => ['step_definitions', 'step_definitions.rb']
         | 
| 56 58 | 
             
                    } # end cucumber
         | 
| 57 59 |  | 
| 60 | 
            +
                  option :eslint, :default =>
         | 
| 61 | 
            +
                    {
         | 
| 62 | 
            +
                      :class         => 'SleepingKingStudios::Tasks::Ci::EslintTask',
         | 
| 63 | 
            +
                      :default_files => '"**/*.js"',
         | 
| 64 | 
            +
                      :require       => 'sleeping_king_studios/tasks/ci/eslint_task',
         | 
| 65 | 
            +
                      :title         => 'ESLint'
         | 
| 66 | 
            +
                    }
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  option :jest, :default =>
         | 
| 69 | 
            +
                    {
         | 
| 70 | 
            +
                      :class   => 'SleepingKingStudios::Tasks::Ci::JestTask',
         | 
| 71 | 
            +
                      :require => 'sleeping_king_studios/tasks/ci/jest_task',
         | 
| 72 | 
            +
                      :title   => 'Jest',
         | 
| 73 | 
            +
                      :verbose => false
         | 
| 74 | 
            +
                    }
         | 
| 75 | 
            +
             | 
| 58 76 | 
             
                  option :rspec, :default =>
         | 
| 59 77 | 
             
                    {
         | 
| 60 78 | 
             
                      :require => 'sleeping_king_studios/tasks/ci/rspec_task',
         | 
| 61 79 | 
             
                      :class   => 'SleepingKingStudios::Tasks::Ci::RSpecTask',
         | 
| 62 | 
            -
                      :title   => 'RSpec'
         | 
| 80 | 
            +
                      :title   => 'RSpec',
         | 
| 81 | 
            +
                      :format  => 'documentation'
         | 
| 63 82 | 
             
                    } # end rspec
         | 
| 64 83 |  | 
| 65 84 | 
             
                  option :rspec_each, :default =>
         | 
| 66 85 | 
             
                    {
         | 
| 67 86 | 
             
                      :require => 'sleeping_king_studios/tasks/ci/rspec_each_task',
         | 
| 68 87 | 
             
                      :class   => 'SleepingKingStudios::Tasks::Ci::RSpecEachTask',
         | 
| 69 | 
            -
                      :title   => 'RSpec (Each)'
         | 
| 88 | 
            +
                      :title   => 'RSpec (Each)',
         | 
| 89 | 
            +
                      :format  => nil
         | 
| 70 90 | 
             
                    } # end rspec
         | 
| 71 91 |  | 
| 72 92 | 
             
                  option :rubocop, :default =>
         | 
| @@ -111,4 +131,5 @@ module SleepingKingStudios::Tasks | |
| 111 131 | 
             
                  option :template_paths, :default => [default_template_path]
         | 
| 112 132 | 
             
                end # namespace
         | 
| 113 133 | 
             
              end # class
         | 
| 134 | 
            +
              # rubocop:enable Metrics/ClassLength
         | 
| 114 135 | 
             
            end # module
         | 
| @@ -11,6 +11,8 @@ module SleepingKingStudios::Tasks::File | |
| 11 11 |  | 
| 12 12 | 
             
              # Thor task for generating a new Ruby source file.
         | 
| 13 13 | 
             
              class NewTask < SleepingKingStudios::Tasks::Task
         | 
| 14 | 
            +
                class MissingTemplateError < StandardError; end
         | 
| 15 | 
            +
             | 
| 14 16 | 
             
                def self.description
         | 
| 15 17 | 
             
                  'Creates a Ruby source file and corresponding spec file.'
         | 
| 16 18 | 
             
                end # class method description
         | 
| @@ -56,8 +58,8 @@ module SleepingKingStudios::Tasks::File | |
| 56 58 |  | 
| 57 59 | 
             
                  return unless prompt_confirmation
         | 
| 58 60 |  | 
| 59 | 
            -
                  create_source_file
         | 
| 60 | 
            -
                  create_spec_file
         | 
| 61 | 
            +
                  create_source_file unless dry_run?
         | 
| 62 | 
            +
                  create_spec_file   unless dry_run?
         | 
| 61 63 |  | 
| 62 64 | 
             
                  say 'Complete!', :green
         | 
| 63 65 | 
             
                end # method file_name
         | 
| @@ -78,10 +80,16 @@ module SleepingKingStudios::Tasks::File | |
| 78 80 | 
             
                  raise "file already exists at #{file_path}" unless force?
         | 
| 79 81 | 
             
                end # method check_for_existing_file
         | 
| 80 82 |  | 
| 83 | 
            +
                def create_directories *directory_names
         | 
| 84 | 
            +
                  directory_path = directory_names.compact.join(File::SEPARATOR)
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  FileUtils.mkdir_p directory_path unless directory_path.empty?
         | 
| 87 | 
            +
                end # method create_directories
         | 
| 88 | 
            +
             | 
| 81 89 | 
             
                def create_source_file
         | 
| 82 90 | 
             
                  create_directories directory, *relative_path
         | 
| 83 91 |  | 
| 84 | 
            -
                  File.write file_path, rendered_source | 
| 92 | 
            +
                  File.write file_path, rendered_source
         | 
| 85 93 | 
             
                end # method create_file
         | 
| 86 94 |  | 
| 87 95 | 
             
                def create_spec_file
         | 
| @@ -91,15 +99,9 @@ module SleepingKingStudios::Tasks::File | |
| 91 99 |  | 
| 92 100 | 
             
                  create_directories 'spec', *relative_path
         | 
| 93 101 |  | 
| 94 | 
            -
                  File.write spec_path, rendered_spec | 
| 102 | 
            +
                  File.write spec_path, rendered_spec
         | 
| 95 103 | 
             
                end # method create_spec_file
         | 
| 96 104 |  | 
| 97 | 
            -
                def create_directories *directory_names
         | 
| 98 | 
            -
                  return if dry_run?
         | 
| 99 | 
            -
             | 
| 100 | 
            -
                  FileUtils.mkdir_p directory_names.compact.join(File::SEPARATOR)
         | 
| 101 | 
            -
                end # method create_directories
         | 
| 102 | 
            -
             | 
| 103 105 | 
             
                def find_template name
         | 
| 104 106 | 
             
                  template_paths.each do |template_dir|
         | 
| 105 107 | 
             
                    template_path = File.expand_path(File.join template_dir, name)
         | 
| @@ -109,7 +111,7 @@ module SleepingKingStudios::Tasks::File | |
| 109 111 | 
             
                    return File.read(template_path)
         | 
| 110 112 | 
             
                  end # each
         | 
| 111 113 |  | 
| 112 | 
            -
                   | 
| 114 | 
            +
                  raise MissingTemplateError, "No template found for \"#{name}\""
         | 
| 113 115 | 
             
                end # method find_template
         | 
| 114 116 |  | 
| 115 117 | 
             
                def preview
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            <%# lib/sleeping_king_studios/tasks/file/templates/ruby.rspec %>
         | 
| 2 | 
            +
            <% require 'sleeping_king_studios/tools' %>
         | 
| 3 | 
            +
            <% tools = SleepingKingStudios::Tools::Toolbelt.new %>
         | 
| 4 | 
            +
            <% full_path = [*relative_path, file_name.sub(/_spec\z/, '')] %>
         | 
| 5 | 
            +
            require '<%= full_path.join('/') %>'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            <%
         | 
| 8 | 
            +
              qualified_module =
         | 
| 9 | 
            +
                full_path.map { |rel| tools.string.camelize(rel) }.join('::')
         | 
| 10 | 
            +
            %>
         | 
| 11 | 
            +
            RSpec.describe <%= qualified_module %> do
         | 
| 12 | 
            +
              pending
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            <%# lib/sleeping_king_studios/tasks/file/templates/ruby.erb %>
         | 
| 2 | 
            +
            <% require 'sleeping_king_studios/tools' %>
         | 
| 3 | 
            +
            <% tools = SleepingKingStudios::Tools::Toolbelt.new %>
         | 
| 4 | 
            +
            <% if relative_path.empty? %>
         | 
| 5 | 
            +
            <% if defined?(superclass) %>
         | 
| 6 | 
            +
            class <%= tools.string.camelize file_name %> < <%= superclass %>
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
            <% else %>
         | 
| 10 | 
            +
            module <%= tools.string.camelize file_name %>
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            end
         | 
| 13 | 
            +
            <% end %>
         | 
| 14 | 
            +
            <% else %>
         | 
| 15 | 
            +
            require '<%= relative_path.join('/') %>'
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            module <%= relative_path.map { |rel| tools.string.camelize(rel) }.join('::') %>
         | 
| 18 | 
            +
              <% if defined?(superclass) %>
         | 
| 19 | 
            +
              class <%= tools.string.camelize file_name %> < <%= superclass %>
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
              <% else %>
         | 
| 23 | 
            +
              module <%= tools.string.camelize file_name %>
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
              <% end %>
         | 
| 27 | 
            +
            end
         | 
| 28 | 
            +
            <% end %>
         | 
| @@ -11,13 +11,13 @@ module SleepingKingStudios | |
| 11 11 | 
             
                  # Major version.
         | 
| 12 12 | 
             
                  MAJOR = 0
         | 
| 13 13 | 
             
                  # Minor version.
         | 
| 14 | 
            -
                  MINOR =  | 
| 14 | 
            +
                  MINOR = 2
         | 
| 15 15 | 
             
                  # Patch version.
         | 
| 16 16 | 
             
                  PATCH = 0
         | 
| 17 17 | 
             
                  # Prerelease version.
         | 
| 18 | 
            -
                  PRERELEASE =  | 
| 18 | 
            +
                  PRERELEASE = :rc
         | 
| 19 19 | 
             
                  # Build metadata.
         | 
| 20 | 
            -
                  BUILD =  | 
| 20 | 
            +
                  BUILD = 0
         | 
| 21 21 |  | 
| 22 22 | 
             
                  class << self
         | 
| 23 23 | 
             
                    # Generates the gem version string from the Version constants.
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sleeping_king_studios-tasks
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0.rc.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Rob "Merlin" Smith
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2019-09-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rake
         | 
| @@ -232,6 +232,12 @@ files: | |
| 232 232 | 
             
            - lib/sleeping_king_studios/tasks/ci/cucumber_results.rb
         | 
| 233 233 | 
             
            - lib/sleeping_king_studios/tasks/ci/cucumber_runner.rb
         | 
| 234 234 | 
             
            - lib/sleeping_king_studios/tasks/ci/cucumber_task.rb
         | 
| 235 | 
            +
            - lib/sleeping_king_studios/tasks/ci/eslint_results.rb
         | 
| 236 | 
            +
            - lib/sleeping_king_studios/tasks/ci/eslint_runner.rb
         | 
| 237 | 
            +
            - lib/sleeping_king_studios/tasks/ci/eslint_task.rb
         | 
| 238 | 
            +
            - lib/sleeping_king_studios/tasks/ci/jest_results.rb
         | 
| 239 | 
            +
            - lib/sleeping_king_studios/tasks/ci/jest_runner.rb
         | 
| 240 | 
            +
            - lib/sleeping_king_studios/tasks/ci/jest_task.rb
         | 
| 235 241 | 
             
            - lib/sleeping_king_studios/tasks/ci/results_helpers.rb
         | 
| 236 242 | 
             
            - lib/sleeping_king_studios/tasks/ci/rspec_each_results.rb
         | 
| 237 243 | 
             
            - lib/sleeping_king_studios/tasks/ci/rspec_each_task.rb
         | 
| @@ -250,6 +256,8 @@ files: | |
| 250 256 | 
             
            - lib/sleeping_king_studios/tasks/file.rb
         | 
| 251 257 | 
             
            - lib/sleeping_king_studios/tasks/file/new_task.rb
         | 
| 252 258 | 
             
            - lib/sleeping_king_studios/tasks/file/tasks.thor
         | 
| 259 | 
            +
            - lib/sleeping_king_studios/tasks/file/templates/rspec.erb
         | 
| 260 | 
            +
            - lib/sleeping_king_studios/tasks/file/templates/ruby.erb
         | 
| 253 261 | 
             
            - lib/sleeping_king_studios/tasks/process_runner.rb
         | 
| 254 262 | 
             
            - lib/sleeping_king_studios/tasks/task.rb
         | 
| 255 263 | 
             
            - lib/sleeping_king_studios/tasks/task_group.rb
         | 
| @@ -269,12 +277,11 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 269 277 | 
             
                  version: '0'
         | 
| 270 278 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 271 279 | 
             
              requirements:
         | 
| 272 | 
            -
              - - " | 
| 280 | 
            +
              - - ">"
         | 
| 273 281 | 
             
                - !ruby/object:Gem::Version
         | 
| 274 | 
            -
                  version:  | 
| 282 | 
            +
                  version: 1.3.1
         | 
| 275 283 | 
             
            requirements: []
         | 
| 276 | 
            -
             | 
| 277 | 
            -
            rubygems_version: 2.6.11
         | 
| 284 | 
            +
            rubygems_version: 3.0.3
         | 
| 278 285 | 
             
            signing_key: 
         | 
| 279 286 | 
             
            specification_version: 4
         | 
| 280 287 | 
             
            summary: A tasks toolkit for rapid development.
         |