lib/jekyll/bower_plugin.rb in jekyll-bower-1.0.7 vs lib/jekyll/bower_plugin.rb in jekyll-bower-1.1.0

- old
+ new

@@ -1,6 +1,6 @@ - +require 'uri' module Jekyll class Bower def initialize() print "Checking if NPM is available\n" fail unless system('which npm') @@ -12,15 +12,39 @@ system('npm install -g bower') print "Installation completed\n" else print "Great, Bower is available\n" end - 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 + + 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 - print "Bower dependencies resolved successfully\n" end end end \ No newline at end of file