seedling 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/AUTHORS +3 -0
  2. data/CHANGELOG +76 -0
  3. data/MANIFEST +42 -0
  4. data/README +28 -0
  5. data/Rakefile +68 -0
  6. data/bin/seedling +15 -0
  7. data/lib/seedling.rb +5 -0
  8. data/lib/seedling/bin.rb +196 -0
  9. data/lib/seedling/extensions/inflector.rb +283 -0
  10. data/lib/seedling/project_creator.rb +147 -0
  11. data/lib/seedling/version.rb +3 -0
  12. data/lib/templates/core/Rakefile.seed +68 -0
  13. data/lib/templates/core/lib/library.rb.seed +5 -0
  14. data/lib/templates/core/lib/library/version.rb.seed +3 -0
  15. data/lib/templates/core/spec/helper.rb.seed +28 -0
  16. data/lib/templates/core/tasks/authors.rake +30 -0
  17. data/lib/templates/core/tasks/bacon.rake +70 -0
  18. data/lib/templates/core/tasks/changelog.rake +18 -0
  19. data/lib/templates/core/tasks/copyright.rake +21 -0
  20. data/lib/templates/core/tasks/gem.rake +23 -0
  21. data/lib/templates/core/tasks/gem_installer.rake +76 -0
  22. data/lib/templates/core/tasks/install_dependencies.rake +6 -0
  23. data/lib/templates/core/tasks/manifest.rake +4 -0
  24. data/lib/templates/core/tasks/rcov.rake +23 -0
  25. data/lib/templates/core/tasks/release.rake +52 -0
  26. data/lib/templates/core/tasks/reversion.rake +8 -0
  27. data/lib/templates/core/tasks/setup.rake.seed +15 -0
  28. data/seedling.gemspec +38 -0
  29. data/spec/helper.rb +28 -0
  30. data/tasks/authors.rake +30 -0
  31. data/tasks/bacon.rake +70 -0
  32. data/tasks/changelog.rake +18 -0
  33. data/tasks/copyright.rake +21 -0
  34. data/tasks/gem.rake +23 -0
  35. data/tasks/gem_installer.rake +76 -0
  36. data/tasks/install_dependencies.rake +6 -0
  37. data/tasks/manifest.rake +4 -0
  38. data/tasks/rcov.rake +23 -0
  39. data/tasks/release.rake +52 -0
  40. data/tasks/reversion.rake +8 -0
  41. data/tasks/setup.rake +15 -0
  42. data/tasks/yard.rake +4 -0
  43. metadata +101 -0
@@ -0,0 +1,147 @@
1
+ # Copyright (c) The Rubyists, LLC.
2
+ # Released under the terms of the MIT License
3
+ #
4
+ # Some files in this distribution are copied from Michael Fellinger's
5
+ # Ramaze or Innate projects and are distributed under
6
+ # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
7
+ # project_creator.rb is one of these files
8
+
9
+ require 'fileutils'
10
+ require 'pathname'
11
+ require 'find'
12
+ require 'erb'
13
+
14
+ module Seedling
15
+ class ProjectCreator
16
+ PROTO = [Pathname.new(__FILE__).dirname.expand_path.join("..", "templates", "core")]
17
+ PROTO.unshift(Pathname.new(ENV["HOME"]).join(".seedling_skel")) if ENV["HOME"] # Guard against Windows
18
+ attr_accessor :pot, :options
19
+
20
+ def initialize(pot, options = {})
21
+ @pot, @options = Pathname.new(pot), options
22
+ puts options.inspect
23
+ end
24
+
25
+ def target
26
+ pot.expand_path
27
+ end
28
+
29
+ def proto
30
+ PROTO.map!{|pr| pr.expand_path }
31
+ proto = options[:proto] ||= PROTO.find{|f| f.directory? }
32
+ layout = options[:layout] || ""
33
+ proto.join(layout).expand_path
34
+ end
35
+
36
+ def create_root?
37
+ return true unless target.directory?
38
+ return true if amend? or force?
39
+ fatal "%p is a directory, choose different project name or use --amend/--force" % target
40
+ end
41
+
42
+ def got_proto?
43
+ return true if proto.directory?
44
+ fatal "Cannot create, %p doesn't exist, use --proto or create the proto directory" % proto
45
+ end
46
+
47
+ def create
48
+ got_proto?
49
+
50
+ puts "Found proto at: %p, proceeding...\n\n" % proto
51
+ mkdir(relate('/')) if create_root?
52
+ proceed
53
+ end
54
+
55
+ def proceed
56
+ files, directories = partition{|path| File.file?(path) }
57
+ proceed_directories(directories)
58
+ proceed_files(files)
59
+ end
60
+
61
+ def proceed_files(files)
62
+ files.each{|file| copy(file, relate(file)) }
63
+ end
64
+
65
+ def proceed_directories(dirs)
66
+ dirs.each{|dir| mkdir(relate(dir)) }
67
+ end
68
+
69
+ def mkdir(dir)
70
+ exists = File.directory?(dir)
71
+ return if exists and amend?
72
+ return if exists and not force?
73
+ puts "mkdir(%p)" % dir
74
+ FileUtils.mkdir_p(dir)
75
+ end
76
+
77
+ def copy(from, to)
78
+ return unless copy_check(to)
79
+ puts "copy(%p, %p)" % [from, to]
80
+ FileUtils.cp(from, to)
81
+ post_process(to)
82
+ end
83
+
84
+ def copy_check(to)
85
+ exists = File.file?(to)
86
+ return false if exists and amend?
87
+ return false if exists and not force?
88
+ return true
89
+ end
90
+
91
+ # Any file in the prototype directory named /\.seed$/
92
+ # will be treated as an ERB template and parsed in the current
93
+ # binding. the @options hash should be used for storing
94
+ # values to be used in the templates
95
+ def post_process(file)
96
+ if File.basename(file.to_s).match(/library/)
97
+ oldfile = file
98
+ file = file.to_s.sub("library", @options[:lib_name_u])
99
+ FileUtils.mv(oldfile, file)
100
+ end
101
+ if File.dirname(file.to_s).split("/").last == "library"
102
+ origdir = File.dirname(file.to_s)
103
+ dirarr = origdir.split("/")
104
+ dirarr[dirarr.size-1] = @options[:lib_name_u]
105
+ new_dir = File.join(dirarr)
106
+ mkdir(new_dir)
107
+ oldfile = file
108
+ file = File.join(new_dir, File.basename(file))
109
+ FileUtils.mv(oldfile, file)
110
+ FileUtils.rmdir(origdir)
111
+ end
112
+ if file.to_s.match(/\.seed$/)
113
+ out_file = Pathname.new(file.to_s.sub(/\.seed$/, ''))
114
+ # Don't overwrite a file of the same name, unless they --force
115
+ if copy_check(out_file)
116
+ template = ::ERB.new(File.read(file))
117
+ # This binding has access to any instance variables of
118
+ # the ProjectCreator instance
119
+ result = template.result(binding)
120
+ File.open(file.to_s.sub(/\.seed$/,''), 'w+') do |io|
121
+ io.puts result
122
+ end
123
+ end
124
+ # Remove the seed file whether we copied or not
125
+ FileUtils.rm_f(file)
126
+ end
127
+ end
128
+
129
+ def relate(path)
130
+ File.join(target, path.to_s.sub(proto.to_s, ''))
131
+ end
132
+
133
+ def amend?; options[:amend] end
134
+ def force?; options[:force] end
135
+
136
+ def fatal(message)
137
+ warn message
138
+ exit 1
139
+ end
140
+
141
+ def each
142
+ Dir["#{proto}/**/*"].each{|path| yield(path) }
143
+ end
144
+
145
+ include Enumerable
146
+ end
147
+ end
@@ -0,0 +1,3 @@
1
+ module Seedling
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,68 @@
1
+ begin; require 'rubygems'; rescue LoadError; end
2
+
3
+ require 'rake'
4
+ require 'rake/clean'
5
+ require 'rake/gempackagetask'
6
+ require 'time'
7
+ require 'date'
8
+ require "lib/<%= @options[:lib_name_u] %>"
9
+
10
+ PROJECT_SPECS = FileList[
11
+ 'spec/**/*.rb'
12
+ ]
13
+
14
+ PROJECT_MODULE = '<%= @options[:lib_name] %>'
15
+ PROJECT_README = 'README'
16
+ #PROJECT_RUBYFORGE_GROUP_ID = 3034
17
+ PROJECT_COPYRIGHT = [
18
+ "# Copyright (c) #{Time.now.year} <%= @options[:author_name] %> <%= @options[:author_email] %>",
19
+ "# Distributed under the terms of the MIT license."
20
+ ]
21
+
22
+ # To release the monthly version do:
23
+ # $ PROJECT_VERSION=2009.03 rake release
24
+ IGNORE_FILES = [/\.gitignore/]
25
+
26
+ GEMSPEC = Gem::Specification.new{|s|
27
+ s.name = '<%= @options[:lib_name_u] %>'
28
+ s.author = "<%= @options[:author_name] %>"
29
+ s.summary = "<%= @options[:summary] %>"
30
+ s.description = "<%= @options[:description] || @options[:description] %>"
31
+ s.email = '<%= @options[:author_email] %>'
32
+ s.homepage = '<%= @options[:project_url] %>'
33
+ s.platform = Gem::Platform::RUBY
34
+ s.version = (ENV['PROJECT_VERSION'] || (begin;Object.const_get(PROJECT_MODULE)::VERSION;rescue;Date.today.strftime("%Y.%m.%d");end))
35
+ s.files = `git ls-files`.split("\n").sort.reject { |f| IGNORE_FILES.detect { |exp| f.match(exp) } }
36
+ s.has_rdoc = true
37
+ s.require_path = 'lib'
38
+ s.bindir = "bin"
39
+ s.executables = ["<%= @options[:lib_name] %>"]
40
+ <% if @options[:rubyforge_project] %>
41
+ s.rubyforge_project = "<%= @options[:rubyforge_project] %>"
42
+ <% end %>
43
+
44
+ s.post_install_message = <<MESSAGE.strip
45
+ ============================================================
46
+
47
+ Thank you for installing <%= @options[:lib_name] %>!
48
+
49
+ ============================================================
50
+ MESSAGE
51
+ }
52
+
53
+ Dir['tasks/*.rake'].each{|f| import(f) }
54
+
55
+ task :default => [:bacon]
56
+
57
+ CLEAN.include %w[
58
+ **/.*.sw?
59
+ *.gem
60
+ .config
61
+ **/*~
62
+ **/{data.db,cache.yaml}
63
+ *.yaml
64
+ pkg
65
+ rdoc
66
+ ydoc
67
+ *coverage*
68
+ ]
@@ -0,0 +1,5 @@
1
+ require "pathname"
2
+ $LOAD_PATH.unshift(Pathname.new(__FILE__).dirname.expand_path.to_s)
3
+ module <%= @options[:lib_name] %>
4
+ end
5
+ require "<%= @options[:lib_name_u] %>/version"
@@ -0,0 +1,3 @@
1
+ module <%= @options[:lib_name] %>
2
+ VERSION = '<%= @options[:version] %>'
3
+ end
@@ -0,0 +1,28 @@
1
+ require "pathname"
2
+ begin
3
+ require "bacon"
4
+ rescue LoadError
5
+ require "rubygems"
6
+ require "bacon"
7
+ end
8
+
9
+ begin
10
+ if (local_path = Pathname.new(__FILE__).dirname.join("..", "lib", "<%= @options[:lib_name_u] %>.rb")).file?
11
+ require local_path
12
+ else
13
+ require "<%= @options[:lib_name_u] %>"
14
+ end
15
+ rescue LoadError
16
+ require "rubygems"
17
+ require "<%= @options[:lib_name_u] %>"
18
+ end
19
+
20
+ Bacon.summary_on_exit
21
+
22
+ describe "Spec Helper" do
23
+ it "Should bring our library namespace in" do
24
+ <%= @options[:lib_name] %>.should == <%= @options[:lib_name] %>
25
+ end
26
+ end
27
+
28
+
@@ -0,0 +1,30 @@
1
+ # Once git has a fix for the glibc in handling .mailmap and another fix for
2
+ # allowing empty mail address to be mapped in .mailmap we won't have to handle
3
+ # them manually.
4
+
5
+ desc 'Update AUTHORS'
6
+ task :authors do
7
+ authors = Hash.new(0)
8
+
9
+ `git shortlog -nse`.scan(/(\d+)\s(.+)\s<(.*)>$/) do |count, name, email|
10
+ case name
11
+ when "bougyman"
12
+ name, email = "TJ Vanderpoel", "bougy.man@gmail.com"
13
+ when /riscfuture/i
14
+ name, email = "Tim Morgan", "riscfuture@gmail.com"
15
+ when "Michael Fellinger m.fellinger@gmail.com"
16
+ name, email = "Michael Fellinger", "m.fellinger@gmail.com"
17
+ end
18
+
19
+ authors[[name, email]] += count.to_i
20
+ end
21
+
22
+ File.open('AUTHORS', 'w+') do |io|
23
+ io.puts "Following persons have contributed to #{GEMSPEC.name}."
24
+ io.puts '(Sorted by number of submitted patches, then alphabetically)'
25
+ io.puts ''
26
+ authors.sort_by{|(n,e),c| [-c, n.downcase] }.each do |(name, email), count|
27
+ io.puts("%6d %s <%s>" % [count, name, email])
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,70 @@
1
+ desc 'Run all bacon specs with pretty output'
2
+ task :bacon => :install_dependencies do
3
+ require 'open3'
4
+ require 'scanf'
5
+ require 'matrix'
6
+
7
+ specs = PROJECT_SPECS
8
+
9
+ some_failed = false
10
+ specs_size = specs.size
11
+ if specs.size == 0
12
+ $stderr.puts "You have no specs! Put a spec in spec/ before running this task"
13
+ exit 1
14
+ end
15
+ len = specs.map{|s| s.size }.sort.last
16
+ total_tests = total_assertions = total_failures = total_errors = 0
17
+ totals = Vector[0, 0, 0, 0]
18
+
19
+ red, yellow, green = "\e[31m%s\e[0m", "\e[33m%s\e[0m", "\e[32m%s\e[0m"
20
+ left_format = "%4d/%d: %-#{len + 11}s"
21
+ spec_format = "%d specifications (%d requirements), %d failures, %d errors"
22
+
23
+ specs.each_with_index do |spec, idx|
24
+ print(left_format % [idx + 1, specs_size, spec])
25
+
26
+ Open3.popen3(RUBY, spec) do |sin, sout, serr|
27
+ out = sout.read.strip
28
+ err = serr.read.strip
29
+
30
+ # this is conventional, see spec/innate/state/fiber.rb for usage
31
+ if out =~ /^Bacon::Error: (needed .*)/
32
+ puts(yellow % ("%6s %s" % ['', $1]))
33
+ else
34
+ total = nil
35
+
36
+ out.each_line do |line|
37
+ scanned = line.scanf(spec_format)
38
+
39
+ next unless scanned.size == 4
40
+
41
+ total = Vector[*scanned]
42
+ break
43
+ end
44
+
45
+ if total
46
+ totals += total
47
+ tests, assertions, failures, errors = total_array = total.to_a
48
+
49
+ if tests > 0 && failures + errors == 0
50
+ puts((green % "%6d passed") % tests)
51
+ else
52
+ some_failed = true
53
+ puts(red % " failed")
54
+ puts out unless out.empty?
55
+ puts err unless err.empty?
56
+ end
57
+ else
58
+ some_failed = true
59
+ puts(red % " failed")
60
+ puts out unless out.empty?
61
+ puts err unless err.empty?
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ total_color = some_failed ? red : green
68
+ puts(total_color % (spec_format % totals.to_a))
69
+ exit 1 if some_failed
70
+ end
@@ -0,0 +1,18 @@
1
+ desc 'update changelog'
2
+ task :changelog do
3
+ File.open('CHANGELOG', 'w+') do |changelog|
4
+ `git log -z --abbrev-commit`.split("\0").each do |commit|
5
+ next if commit =~ /^Merge: \d*/
6
+ ref, author, time, _, title, _, message = commit.split("\n", 7)
7
+ ref = ref[/commit ([0-9a-f]+)/, 1]
8
+ author = author[/Author: (.*)/, 1].strip
9
+ time = Time.parse(time[/Date: (.*)/, 1]).utc
10
+ title.strip!
11
+
12
+ changelog.puts "[#{ref} | #{time}] #{author}"
13
+ changelog.puts '', " * #{title}"
14
+ changelog.puts '', message.rstrip if message
15
+ changelog.puts
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ desc "add copyright to all .rb files in the distribution"
2
+ task :copyright do
3
+ ignore = File.readlines('doc/LEGAL').
4
+ select{|line| line.strip!; File.exist?(line)}.
5
+ map{|file| File.expand_path(file)}
6
+
7
+ puts "adding copyright to files that don't have it currently"
8
+ puts PROJECT_COPYRIGHT
9
+ puts
10
+
11
+ Dir['{lib,test}/**/*{.rb}'].each do |file|
12
+ file = File.expand_path(file)
13
+ next if ignore.include? file
14
+ lines = File.readlines(file).map{|l| l.chomp}
15
+ unless lines.first(PROJECT_COPYRIGHT.size) == PROJECT_COPYRIGHT
16
+ puts "#{file} seems to need attention, first 4 lines:"
17
+ puts lines[0..3]
18
+ puts
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'rake/gempackagetask'
2
+
3
+ desc "make a gemspec"
4
+ task :gemspec => [:manifest, :changelog, :authors] do
5
+ gemspec_file = "#{GEMSPEC.name}.gemspec"
6
+ File.open(gemspec_file, 'w+'){|gs| gs.puts(GEMSPEC.to_ruby) }
7
+ end
8
+
9
+ desc "package and install from gemspec"
10
+ task :install => [:gemspec] do
11
+ sh "gem build #{GEMSPEC.name}.gemspec"
12
+ sh "gem install #{GEMSPEC.name}-#{GEMSPEC.version}.gem"
13
+ end
14
+
15
+ desc "uninstall the gem"
16
+ task :uninstall => [:clean] do
17
+ sh %{gem uninstall -x #{GEMSPEC.name}}
18
+ end
19
+
20
+ Rake::GemPackageTask.new(GEMSPEC) do |p|
21
+ p.need_tar = true
22
+ p.need_zip = true
23
+ end
@@ -0,0 +1,76 @@
1
+ task :gem_installer do
2
+ class GemInstaller
3
+ def initialize(options = {}, &block)
4
+ @gems = []
5
+ @options = options
6
+
7
+ run(&block)
8
+ end
9
+
10
+ def run(&block)
11
+ instance_eval(&block) if block_given?
12
+ end
13
+
14
+ def gem(name, version = nil, options = {})
15
+ if version.respond_to?(:merge!)
16
+ options = version
17
+ else
18
+ options[:version] = version
19
+ end
20
+
21
+ @gems << [name, options]
22
+ end
23
+
24
+ def setup_gemspec(gemspec)
25
+ gemspec.dependencies.each do |dependency|
26
+ dependency.version_requirements.as_list.each do |version|
27
+ gem(dependency.name, version)
28
+ end
29
+ end
30
+
31
+ setup
32
+ end
33
+
34
+ def setup
35
+ require 'rubygems'
36
+ require 'rubygems/dependency_installer'
37
+
38
+ @gems.each do |name, options|
39
+ setup_gem(name, options)
40
+ end
41
+ end
42
+
43
+ def setup_gem(name, options, try_install = true)
44
+ print "activating #{name} ... "
45
+ Gem.activate(name, *[options[:version]].compact)
46
+ require(options[:lib] || name)
47
+ puts "success."
48
+ rescue LoadError => error
49
+ puts error
50
+ install_gem(name, options) if try_install
51
+ setup_gem(name, options, try_install = false)
52
+ end
53
+
54
+ def install_gem(name, options)
55
+ installer = Gem::DependencyInstaller.new(options)
56
+
57
+ temp_argv(options[:extconf]) do
58
+ print "Installing #{name} ... "
59
+ installer.install(name, options[:version])
60
+ puts "done."
61
+ end
62
+ end
63
+
64
+ def temp_argv(extconf)
65
+ if extconf ||= @options[:extconf]
66
+ old_argv = ARGV.clone
67
+ ARGV.replace(extconf.split(' '))
68
+ end
69
+
70
+ yield
71
+
72
+ ensure
73
+ ARGV.replace(old_argv) if extconf
74
+ end
75
+ end
76
+ end