Sha256: e1e209296c6268eb7596aab39ccefe41f03ced2944e1dcc82705e5a06ef56013

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true
require_relative "file"
require "pathname"

module ShopifyCLI
  module Theme
    class Root
      attr_reader :root, :ctx

      def initialize(ctx, root:)
        @ctx = ctx
        @root = Pathname.new(root) if root
      end

      def static_asset_files
        glob("assets/*", raise_on_dir: true).reject(&:liquid?)
      end

      def liquid_files
        glob("**/*.liquid")
      end

      def json_files
        glob("**/*.json")
      end

      def glob(pattern, raise_on_dir: false)
        root
          .glob(pattern)
          .select { |path| file?(path, raise_on_dir) }
          .map { |path| File.new(path, root) }
      end

      def static_asset_file?(file)
        static_asset_files.include?(self[file])
      end

      def static_asset_paths
        static_asset_files.map(&:relative_path)
      end

      def [](file)
        case file
        when File
          file
        when Pathname
          File.new(file, root)
        when String
          File.new(root.join(file), root)
        end
      end

      def file?(path, raise_on_dir = false)
        if raise_on_dir && ::File.directory?(path)
          @ctx.abort(@ctx.message("theme.serve.error.invalid_subdirectory", path.to_s))
        end

        ::File.file?(path)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.35.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.34.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.33.1 lib/shopify_cli/theme/root.rb
shopify-cli-2.33.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.32.1 lib/shopify_cli/theme/root.rb
shopify-cli-2.32.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.31.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.30.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.29.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.28.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.27.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.26.0 lib/shopify_cli/theme/root.rb
shopify-cli-2.25.0 lib/shopify_cli/theme/root.rb