Sha256: 9162f66977b749935282fb0c0d023ede4ef814be8f78db99b2d0ec8cebc2817f

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"

require "pakyow/assets/external"

module Pakyow
  module Assets
    module Behavior
      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 << External.new(
            name, version: version, package: package, files: files, config: assets_config
          )
        end

        apply_extension do
          after "boot", "fetch.assets.externals" do
            if config.assets.externals.pakyow
              external_script :pakyow, "^1.0.0-alpha.17", package: "@pakyow/js", files: [
                "dist/pakyow.js",
                "dist/components/confirmable.js",
                "dist/components/form.js",
                "dist/components/freshener.js",
                "dist/components/navigable.js",
                "dist/components/socket.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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pakyow-assets-1.0.0.rc2 lib/pakyow/assets/behavior/externals.rb
pakyow-assets-1.0.0.rc1 lib/pakyow/assets/behavior/externals.rb