Sha256: e811b4d91590da3765bb9ddeec716c08f04912400a24cd43b9f078c6892ca3ab

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require 'uri'
module Jekyll
	class Bower
		def initialize()
			print "Checking if NPM is available\n"
			fail unless system('which npm')
			print "Great, NPM is available\n"
			print "Checkin if Bower is available\n"
			unless system('which bower')
				print "Bower not available\n"
				print "Installing bower\n"
				system('npm install -g bower')
				print "Installation completed\n"
			else
				print "Great, Bower is available\n"
			end
		end

		def resolve(site)
			if File.exists?("bower.json")
				print "Resolving dependencies with bower\n"
				unless system('bower install')
					print "Looks like bower is run by a sudo user\n"
					print "Trying with --allow-root\n"
					system('bower install --allow-root')
				end
				print "Bower dependencies resolved successfully\n"
			else
				if site.config['bower']
					print "Resolving bower individually configured in config"
					site.config['bower'].each do |name, library| 
						bower_command = 'bower install ' + library
						system(bower_command)
						if library =~ URI::regexp
							print "Identified bower downloaded dependency is a URL"
							print "Performing rename activity if possible"
							uri = URI.parse(library)
							filename = File.basename(uri.path, ".*")
							bowerOld = 'bower_components' + File::SEPARATOR + filename
							bowerNew = 'bower_components' + File::SEPARATOR + name
							File.rename(bowerOld, bowerNew)
							print "Renamed bower ("+filename+") library to " + name
						end
						print "Downloaded bower dependency: " + name
					end
				end
			end
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-bower-1.1.0 lib/jekyll/bower_plugin.rb