Sha256: eacf4acb253121af3b2ea6b5c9b31dea6c05b2b6cdfb3c9efb5a19657ebd7dcc

Contents?: true

Size: 1.47 KB

Versions: 9

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2016-2022, by Samuel Williams.

def update
	require 'fileutils'
	require 'utopia/path'
	
	root = Pathname.new(context.root)
	package_root = root + "node_modules"
	
	# This is a legacy path:
	unless package_root.directory?
		package_root = root + "lib/components"
	end
	
	install_root = root + "public/_components"
	
	package_paths = expand_package_paths(package_root)
	
	package_paths.each do |package_path|
		package_directory = package_path.relative_path_from(package_root)
		install_path = install_root + package_directory
		
		dist_path = package_path + 'dist'
		
		FileUtils::Verbose.rm_rf(install_path)
		FileUtils::Verbose.mkpath(install_path.dirname)
		
		# If a package has a dist directory, we only symlink that... otherwise we have to do the entire package, and hope that bower's ignore was setup correctly:
		if dist_path.exist?
			link_path = Utopia::Path.shortest_path(dist_path, install_path)
		else
			link_path = Utopia::Path.shortest_path(package_path, install_path)
		end
		
		FileUtils::Verbose.cp_r File.expand_path(link_path, install_path), install_path
	end
end

private

def expand_package_paths(root, into = [])
	paths = root.children.select(&:directory?)
	
	paths.each do |path|
		basename = path.basename.to_s
		# Handle organisation sub-directories which start with an '@' symbol:
		if basename.start_with?('@')
			expand_package_paths(path, into)
		else
			into << path
		end
	end
	
	return into
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
utopia-2.25.0 bake/utopia/node.rb
utopia-2.24.4 bake/utopia/node.rb
utopia-2.24.3 bake/utopia/node.rb
utopia-2.24.1 bake/utopia/node.rb
utopia-2.23.0 bake/utopia/node.rb
utopia-2.22.2 bake/utopia/node.rb
utopia-2.22.1 bake/utopia/node.rb
utopia-2.22.0 bake/utopia/node.rb
utopia-2.21.0 bake/utopia/node.rb