Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport of Nanoc::CLI.after_setup functionality #407

Merged
merged 4 commits into from Mar 31, 2014

Conversation

Projects
None yet
2 participants
@barraq
Copy link
Contributor

commented Mar 26, 2014

This commit backport the useful Nanoc::CLI.after_setup functionality from Nanoc 4.x to Nanoc 3.x

This backport is really useful to initiate the migration from Nanoc 3.x to Nanoc 4.x since developers can already start packaging their plugins following the Nanoc 4.x packaging style!

For instance, the plugin nanoc-photomator is packaged as follow for Nanoc 3.x

# encoding: utf-8

$LOAD_PATH.unshift(File.expand_path('../lib/', __FILE__))
require 'nanoc/photomator/version'

Gem::Specification.new do |s|
  s.name = 'nanoc-photomator'
  s.version = Nanoc::Photomator::VERSION
  s.homepage = 'https://github.com/barraq/nanoc-photomator'
  s.summary = 'Photo automation tools for Nanoc'
  s.description = 'Provides a set of commands and user interfaces for working with pictures in Nanoc'

  s.author = 'Rémi Barraquand'
  s.email = 'dev@remibarraquand.com'
  s.license = 'MIT'

  s.required_ruby_version = '>= 1.9.3'

  s.files = Dir['[A-Z]*'] +
      Dir['{lib,test}/**/*'] +
      ['nanoc-photomator.gemspec']
  s.require_paths = ['lib']

  s.rdoc_options = ['--main', 'README.md']
  s.extra_rdoc_files = ['LICENSE', 'README.md']

  # For Nanoc 4.x
  #s.add_runtime_dependency('nanoc-core')
  #s.add_runtime_dependency('nanoc-cli')

 # For Nanoc 3.x
  s.add_runtime_dependency('nanoc', '>= 3.6.7', '< 4.0.0')


  # Autoloading
  s.add_development_dependency('bundler', '~> 1.5')
end
bin/nanoc Outdated

# Require
if defined?(Bundler)
Bundler.require(:default)

This comment has been minimized.

Copy link
@ddfreyne

ddfreyne Mar 26, 2014

Member

Can you undo the changes to bin/nanoc? These changes are not required for the after_setup_procs feature to work. I’d like to limit the changes made to nanoc 3.x as much as possible to prevent difficult merges later on.

This comment has been minimized.

Copy link
@barraq

barraq Mar 27, 2014

Author Contributor

@ddfreyne well I first tried with the original bin/nanoc but the weird thing is that it does not work as expected. I am maybe doing something wrong but when I use the original/nanoc my plugin is not loaded and therefore my custom plugin's command is not showing up in the list of available commands (when doing 'nanoc --help'), also I cannot execute the command neither.

I guess I still need the Bundler.require(:default) after the require 'bundler/setup'? Should not be something like this?

# Try loading bundler if it's possible
begin
  require 'bundler/setup'
  Bundler.require(:default)
rescue LoadError
  # no problem
end

This comment has been minimized.

Copy link
@ddfreyne
self.setup_cleaning_streams
self.setup_commands
self.load_custom_commands
self.after_setup_procs.each { |b| b.call }
end

This comment has been minimized.

Copy link
@ddfreyne

ddfreyne Mar 26, 2014

Member

Can you get rid of the self.s here? This will make the diff smaller.

This comment has been minimized.

Copy link
@barraq

barraq Mar 27, 2014

Author Contributor

Yes. My bad.

@ddfreyne

This comment has been minimized.

Copy link
Member

commented Mar 26, 2014

👍 apart from remarks.

@ddfreyne

This comment has been minimized.

Copy link
Member

commented Mar 29, 2014

Looks good. Will run some tests locally to make sure this doesn’t break anything, but if it doesn’t, I’ll merge.

@barraq

This comment has been minimized.

Copy link
Contributor Author

commented Mar 29, 2014

Concerning the test, in nanoc-cli you have one test concerning the after_setup that maybe we should also add to the merge: https://github.com/nanoc/nanoc-cli/blob/8e49e1907741c54bcd053de8b7ae4eb732f82d0d/test/cli/test_cli.rb#L105

@ddfreyne

This comment has been minimized.

Copy link
Member

commented Mar 29, 2014

Yup, would be great if you could move that over too.

@barraq

This comment has been minimized.

Copy link
Contributor Author

commented Mar 29, 2014

ok, I'm running the test too before commiting

ddfreyne added a commit that referenced this pull request Mar 31, 2014

Merge pull request #407 from barraq/feature/backport-cli-after_setup
Backport Nanoc::CLI.after_setup functionality from nanoc 4.0

@ddfreyne ddfreyne merged commit 70020f3 into nanoc:master Mar 31, 2014

1 check passed

default The Travis CI build passed
Details
@ddfreyne

This comment has been minimized.

Copy link
Member

commented Mar 31, 2014

Cool stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.