Sha256: e7cd3c45558340d5226917040ba61b17c19c48dd6a61c28b7c2e869608d769b4

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Inertia
  module Generators
    module Helpers
      ### FS Helpers
      def js_destination_path
        return ViteRuby.config.source_code_dir if defined?(ViteRuby)

        if file?('config/vite.json')
          source_code_dir = JSON.parse(File.read(file_path('config/vite.json'))).dig('all', 'sourceCodeDir')
          return source_code_dir if source_code_dir
        end

        'app/frontend'
      end

      def js_destination_root
        file_path(js_destination_path)
      end

      def js_file_path(*relative_path)
        File.join(js_destination_root, *relative_path)
      end

      def file?(*relative_path)
        File.file?(file_path(*relative_path))
      end

      def file_path(*relative_path)
        File.join(destination_root, *relative_path)
      end

      # Interactivity Helpers
      def ask(*)
        unless options[:interactive]
          say_error 'Specify all options when running the generator non-interactively.', :red
          exit(1)
        end

        super
      end

      def yes?(*)
        return false unless options[:interactive]

        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inertia_rails-3.5.0 lib/generators/inertia/install/helpers.rb