require 'gli' require 'fileutils' module GLI module Commands class Scaffold #:nodoc: def self.create_scaffold(root_dir, create_test_dir, create_ext_dir, project_name, commands, force=false, dry_run=false, create_rvmrc=false) dirs = [File.join(root_dir,project_name,'lib')] dirs << File.join(root_dir,project_name,'bin') dirs << File.join(root_dir,project_name,'test') if create_test_dir dirs << File.join(root_dir,project_name,'ext') if create_ext_dir if mkdirs(dirs,force,dry_run) mk_binfile(root_dir,create_ext_dir,force,dry_run,project_name,commands) mk_readme(root_dir,dry_run,project_name) mk_gemspec(root_dir,dry_run,project_name) mk_rakefile(root_dir,dry_run,project_name,create_test_dir) mk_lib_files(root_dir,dry_run,project_name) if create_rvmrc rvmrc = File.join(root_dir,project_name,".rvmrc") File.open(rvmrc,'w') do |file| file.puts "rvm use #{ENV['rvm_ruby_string']}@#{project_name} --create" end puts "Created #{rvmrc}" end end end def self.mk_readme(root_dir,dry_run,project_name) return if dry_run File.open("#{root_dir}/#{project_name}/README.rdoc",'w') do |file| file << "= #{project_name}\n\n" file << "Describe your project here\n\n" file << ":include:#{project_name}.rdoc\n\n" end puts "Created #{root_dir}/#{project_name}/README.rdoc" File.open("#{root_dir}/#{project_name}/#{project_name}.rdoc",'w') do |file| file << "= #{project_name}\n\n" file << "Generate this with\n #{project_name} rdoc\nAfter you have described your command line interface" end puts "Created #{root_dir}/#{project_name}/#{project_name}.rdoc" end def self.mk_gemspec(root_dir,dry_run,project_name) return if dry_run File.open("#{root_dir}/#{project_name}/#{project_name}.gemspec",'w') do |file| file.puts < :features task 'cucumber:wip' => 'features:wip' task :wip => 'features:wip' EOS end if create_test_dir file.puts < [:test,:features] EOS File.open("#{root_dir}/#{project_name}/test/default_test.rb",'w') do |test_file| test_file.puts < :package\n" end end puts "Created #{root_dir}/#{project_name}/Rakefile" File.open("#{root_dir}/#{project_name}/Gemfile",'w') do |bundler_file| bundler_file.puts "source 'https://rubygems.org'" bundler_file.puts "gemspec" end puts "Created #{root_dir}/#{project_name}/Gemfile" if create_test_dir features_dir = File.join(root_dir,project_name,'features') FileUtils.mkdir features_dir FileUtils.mkdir File.join(features_dir,"step_definitions") FileUtils.mkdir File.join(features_dir,"support") File.open(File.join(features_dir,"#{project_name}.feature"),'w') do |file| file.puts <