Sha256: 772fc79674eb28d2cce88a96ea78bb4aa57ed2eb6bd7302e85c06a2b3a08ccb2

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"

require "pakyow/assets/external"

module Pakyow
  class Application
    module Behavior
      module Assets
        module Externals
          extend Support::Extension

          def external_script(name, version = nil, package: nil, files: nil)
            assets_config = if is_a?(Plugin)
              parent.config.assets
            else
              config.assets
            end

            assets_config.externals.scripts << Pakyow::Assets::External.new(
              name, version: version, package: package, files: files, config: assets_config
            )
          end

          private def pakyow_js_version
            "^1.0.0"
          end

          apply_extension do
            after "boot", "fetch.assets.externals" do
              if config.assets.externals.pakyow
                external_script :pakyow, pakyow_js_version, package: "@pakyow/js", files: [
                  "dist/pakyow.js",
                  "dist/components/confirmable.js",
                  "dist/components/form.js",
                  "dist/components/freshener.js",
                  "dist/components/navigator.js",
                  "dist/components/socket.js",
                  "dist/components/submittable.js"
                ]
              end

              if config.assets.externals.fetch
                fetched = false

                config.assets.externals.scripts.each do |external_script|
                  unless external_script.exist?
                    external_script.fetch!
                    fetched = true
                  end
                end

                if fetched
                  FileUtils.mkdir_p "./tmp"
                  FileUtils.touch "./tmp/restart.txt"
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pakyow-assets-1.0.2 lib/pakyow/application/behavior/assets/externals.rb