bin/nanoc in nanoc-2.2.2 vs bin/nanoc in nanoc-3.0.0a1

- old
+ new

@@ -1,15 +1,33 @@ #!/usr/bin/env ruby +# encoding: utf-8 -# Add lib to load path -$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) +# Find version +version_file_path = File.expand_path('~/.nanoc-select-version') +if !File.exist?(version_file_path) + warn 'WARNING: No nanoc version has been selected; using nanoc 3.x by default. Select a version using `nanoc-select` to make this warning go away.' + version = 3 +else + version = File.read(version_file_path).to_i +end -# Load nanoc -require 'nanoc' -require 'nanoc/cli' +# Determine nanoc executable name +VERSION_MAP = { + 2 => 'nanoc2', + 3 => 'nanoc3' +} +name = VERSION_MAP[version] +if name.nil? + $stderr.puts "Unsupported nanoc version number: #{version}. Supported versions: #{VERSION_MAP.keys.join(', ')}." + exit 1 +end -# Load custom code that can't be load later -Dir['lib/commands/*.rb'].each { |f| require f } -Dir['lib/data_sources/*.rb'].each { |f| require f } - -# Run base -Nanoc::CLI::Base.new.run(ARGV) +# Run nanoc +begin + exec name, *ARGV +rescue Errno::ENOENT + $stderr.puts "Could not execute #{name}, which is your selected nanoc version. Make sure that #{name} is installed and that it is in your $PATH." + $stderr.puts + $stderr.puts "* To install #{name}, run `gem install #{name}`." + $stderr.puts "* To select a different version of nanoc, run `nanoc-select`." + exit 1 +end