Module: FalkorLib::Bootstrap
- Defined in:
- lib/falkorlib/bootstrap/git.rb,
lib/falkorlib/bootstrap/base.rb,
lib/falkorlib/bootstrap/link.rb,
lib/falkorlib/bootstrap/ruby.rb,
lib/falkorlib/bootstrap/latex.rb,
lib/falkorlib/bootstrap/mkdocs.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Link
Class Method Summary collapse
-
.get_badge(subject, status, color = 'blue', options = {}) ⇒ Object
get_badge ###### Return a Markdown-formatted string for a badge to display, typically in a README.
-
.get_project_name(dir = Dir.pwd, _options = {}) ⇒ Object
get_project_name ###### Return a “reasonable” project name from a given [sub] directory i.e.
-
.guess_project_config(dir = Dir.pwd, options = {}) ⇒ Object
guess_project_config ###### Guess the project configuration.
-
.latex(dir = Dir.pwd, type = :beamer, options = {}) ⇒ Object
latex ###### Bootstrap a LaTeX sub-project of type <type> within a given repository <dir>.
-
.license(dir = Dir.pwd, license = , authors = '', options = { :filename => 'LICENSE' }) ⇒ Object
license ###### Generate the licence file.
-
.mkdocs(dir = Dir.pwd, options = {}) ⇒ Object
mkdocs ###### Initialize MkDocs in the current directory Supported options: * :force [boolean] force overwritting.
-
.motd(dir = Dir.pwd, options = {}) ⇒ Object
motd ###### Generate a new motd (Message of the Day) file Supported options: * :force [boolean] force action * :title [string] title of the motd (in figlet) * :support [string] email address to use for getting support * :hostname [string] hostname of the server to mention in the motd * :width [number] width of the line used.
-
.readme(dir = Dir.pwd, options = {}) ⇒ Object
readme ###### Bootstrap a README file for various context Supported options: * :no_interaction [boolean]: do not interact * :force [boolean] force overwritting * :license [string] License to use * :licensefile [string] License filename (default: LICENSE) * :latex [boolean] describe a LaTeX project * :octopress [boolean] octopress site.
-
.repo(name, options = {}) ⇒ Object
repo ###### Initialize a Git repository for a project with my favorite layout Supported options: * :no_interaction [boolean]: do not interact * :gitflow [boolean]: bootstrap with git-flow * :license [string] License to use * :licensefile [string] License filename (default: LICENSE) * :interactive [boolean] Confirm Gitflow branch names * :master [string] Branch name for production releases * :develop [string] Branch name for development commits * :make [boolean] Use a Makefile to pilot the repository actions * :rake [boolean] Use a Rakefile (and FalkorLib) to pilot the repository action * :remote_sync [boolean] Operate a git remote synchronization * :latex [boolean] Initiate a LaTeX project **NOT YET IMPLEMENTED** * :gem [boolean] Initiate a Ruby gem project **NOT YET IMPLEMENTED** * :mkdocs [boolean] Initiate MkDocs within your project * :rvm [boolean] Initiate a RVM-based Ruby project * :pyenv [boolean] Initiate a pyenv-based Python project **NOT YET IMPLEMENTED** * :octopress [boolean] Initiate an Octopress web site **NOT YET IMPLEMENTED**.
-
.rvm(dir = Dir.pwd, options = {}) ⇒ Object
rvm ###### Initialize RVM in the current directory Supported options: * :force [boolean] force overwritting * :ruby [string] Ruby version to configure for RVM * :versionfile [string] Ruby Version file * :gemset [string] RVM Gemset to configure * :gemsetfile [string] RVM Gemset file * :commit [boolean] Commit the changes NOT YET USED.
-
.select_forge(default = :gforge, _options = {}) ⇒ Object
Select the forge (gforge, github, etc.) hosting the project sources.
-
.select_licence(default_licence = , _options = {}) ⇒ Object
select_licence ###### Select a given licence for the project.
-
.trash(path = Dir.pwd, dirname = , _options = {}) ⇒ Object
Initialize a trash directory in path.
-
.versionfile(dir = Dir.pwd, options = {}) ⇒ Object
versionfile ###### Bootstrap a VERSION file at the root of a project Supported options: * :file [string] filename * :version [string] version to mention in the file.
Class Method Details
.get_badge(subject, status, color = 'blue', options = {}) ⇒ Object
get_badge ###### Return a Markdown-formatted string for a badge to display, typically in a README. Based on shields.io/ Supported options:
* :style [string] style of the badge, Elligible: ['plastic', 'flat', 'flat-square']
471 472 473 474 475 476 |
# File 'lib/falkorlib/bootstrap/base.rb', line 471 def get_badge(subject, status, color = 'blue', = {}) st = status.gsub(/-/, '--').gsub(/_/, '__') res = "https://img.shields.io/badge/#{subject}-#{st}-#{color}.svg" res += "?style=#{[:style]}" if [:style] res end |
.get_project_name(dir = Dir.pwd, _options = {}) ⇒ Object
get_project_name ###### Return a “reasonable” project name from a given [sub] directory i.e. its basename
481 482 483 484 485 |
# File 'lib/falkorlib/bootstrap/base.rb', line 481 def get_project_name(dir = Dir.pwd, = {}) path = normalized_path(dir) path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path) File.basename(path) end |
.guess_project_config(dir = Dir.pwd, options = {}) ⇒ Object
guess_project_config ###### Guess the project configuration
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/falkorlib/bootstrap/base.rb', line 420 def guess_project_config(dir = Dir.pwd, = {}) path = normalized_path(dir) use_git = FalkorLib::Git.init?(path) rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path local_config = FalkorLib::Config.get(rootdir, :local) return local_config[:project] if local_config[:project] # Otherwise, guess the rest of the configuration config = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].clone # Apply options (if provided) [ :name, :forge ].each do |k| config[k.to_sym] = [k.to_sym] if [k.to_sym] end config[:name] = ask("\tProject name: ", get_project_name(dir)) if config[:name].empty? if (use_git) config[:origin] = FalkorLib::Git.config('remote.origin.url') if config[:origin] =~ /((gforge|gitlab|github)[\.\w_-]+)[:\d\/]+(\w*)/ config[:forge] = Regexp.last_match(2).to_sym config[:by] = Regexp.last_match(3) elsif config[:forge].empty? config[:forge] = select_forge(config[:forge]).to_sym end end forges = FalkorLib::Config::Bootstrap::DEFAULTS[:forge][ config[:forge].to_sym ] default_source = case config[:forge] when :gforge 'https://' + forges[:url] + "/projects/" + config[:name].downcase when :github, :gitlab 'https://' + forges[:url] + "/" + config[:by] + "/" + config[:name].downcase else "" end config[:source] = config[:project_page] = default_source config[:issues_url] = "#{config[:project_page]}/issues" config[:license] = select_licence if config[:license].empty? [ :summary ].each do |k| config[k.to_sym] = ask( "\t" + Kernel.format("Project %-20s", k.to_s)) end config[:description] = config[:summary] config[:gitflow] = FalkorLib::GitFlow.guess_gitflow_config(rootdir) config[:make] = File.exists?(File.join(rootdir, 'Makefile')) config[:rake] = File.exists?(File.join(rootdir, 'Rakefile')) config end |
.latex(dir = Dir.pwd, type = :beamer, options = {}) ⇒ Object
latex ###### Bootstrap a LaTeX sub-project of type <type> within a given repository <dir>.
* :beamer LaTeX Beamer Slides
* :article LaTeX article
* :ieee LaTeX IEEE conference article
* :ieee_jnl LaTeX IEEE journal
* :acm LaTeX ACM conference article
* :letter LaTeX Letter
Supported options:
* :force [boolean] force action
* :no_interaction [boolean]: do not interact
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/falkorlib/bootstrap/latex.rb', line 36 def latex(dir = Dir.pwd, type = :beamer, = {}) ap if [:debug] error "Unsupported type" unless [ :beamer, :article, :ieee, :letter ].include?( type ) path = normalized_path(dir) config = FalkorLib::Config::Bootstrap::DEFAULTS[:latex].clone if type == :letter config.merge!(FalkorLib::Config::Bootstrap::DEFAULTS[:letter].clone) [ :title, :subtitle, :image ].each { |k| config.delete k } end config.deep_merge!(FalkorLib::Config::Bootstrap::DEFAULTS[:letter].clone) if type == :letter # initiate the repository if needed unless File.directory?( path ) warn "The directory '#{path}' does not exists and will be created" really_continue? unless [:no_interaction] run %( mkdir -p #{path} ) end repo(path, ) unless FalkorLib::Git.init?(path) rootdir = FalkorLib::Git.rootdir(path) info "Initiate a LaTeX #{type} project from the Git root directory: '#{rootdir}'" really_continue? unless [:no_interaction] relative_path_to_root = (Pathname.new( FalkorLib::Git.rootdir(dir) ).relative_path_from Pathname.new( File.realpath(path))).to_s config[:name] = ([:name]) ? [:name] : ask("\tEnter the name of the #{type} LaTeX project: ", File.basename(path)) raise FalkorLib::ExecError "Empty project name" if config[:name].empty? default_project_dir = (Pathname.new( File.realpath(path) ).relative_path_from Pathname.new( FalkorLib::Git.rootdir(dir))).to_s if relative_path_to_root == '.' default_project_dir = case type when :article, :ieee "articles/#{Time.now.year}/#{config[:name]}" when :beamer "slides/#{Time.now.year}/#{config[:name]}" when :bookchapter "chapters/#{config[:name]}" when :letter "letters/#{Time.now.year}/#{config[:name]}" else (config[:name]).to_s end else default_project_dir += "/#{config[:name]}" unless default_project_dir =~ /#{config[:name]}$/ end project_dir = ([:dir]) ? [:dir] : default_project_dir project_dir = ask("\tLaTeX Sources directory (relative to the Git root directory)", project_dir.to_s) unless [:no_interaction] raise FalkorLib::ExecError "Empty project directory" if project_dir.empty? src_project_dir = File.join(project_dir, 'src') srcdir = File.join(rootdir, src_project_dir) if File.exist?(File.join(srcdir, '.root')) warn "The directory '#{project_dir}' seems to have been already initialized" really_continue? unless [:no_interaction] end FalkorLib::GitFlow.start('feature', config[:name], rootdir) if FalkorLib::GitFlow.init?(rootdir) # === prepare Git submodules === info " ==> prepare the relevant Git submodules" submodules = {} if [ :article, :beamer, :bookchapter].include?(type) submodules['Makefiles'] = { :url => 'https://github.com/Falkor/Makefiles.git', :branch => 'devel' } end submodules['beamerthemeFalkor'] = { :url => 'https://github.com/Falkor/beamerthemeFalkor' } if type == :beamer FalkorLib::Git.submodule_init(rootdir, submodules) info "bootstrapping the #{type} project sources in '#{src_project_dir}'" # Create the project directory Dir.chdir( rootdir ) do run %( mkdir -p #{src_project_dir}/images ) unless File.directory?("#{srcdir}/images") end info "populating '#{src_project_dir}'" #FalkorLib::Bootstrap::Link.root(srcdir, { :verbose => true} ) FalkorLib::Bootstrap::Link.makefile(srcdir, :no_interaction => true) [ '_style.sty', '.gitignore' ].each do |f| Dir.chdir( srcdir ) do dst = ".makefile.d/latex/#{f}" run %( ln -s #{dst} #{f} ) unless File.exist?( File.join(srcdir, f) ) end end if type == :beamer f = 'beamerthemeFalkor.sty' dst = "#{FalkorLib.config[:git][:submodulesdir]}/beamerthemeFalkor/#{f}" Dir.chdir( srcdir ) do run %( ln -s .root/#{dst} #{f} ) unless File.exist?( File.join(srcdir, f) ) end end # Bootstrap the directory src_templatedir = File.join( FalkorLib.templates, 'latex') unless File.exist?( File.join(srcdir, "#{config[:name]}.tex")) info "gathering information for the LaTeX templates" prefix = case type when :article, :ieee, :acm 'Article ' when :ieee_journal 'IEEE Journal ' when :beamer 'Slides ' when :bookchapter 'Book Chapter ' when :letter 'Letter ' else '' end config.each do |k, v| next if k == :name config[k.to_sym] = ask( "\t" + Kernel.format("%-20s", "#{prefix}#{k.capitalize}"), v) unless [:no_interaction] end templates = [ File.join(src_templatedir, type.to_s) ] if [ :ieee, :ieee_journal, :acm].include?( type ) templates << File.join(src_templatedir, 'article') templates << File.join(src_templatedir, "article-#{type}") end if type == :article templates << File.join(src_templatedir, 'ieee') templates << File.join(src_templatedir, 'article-ieee') end templates.each do |templatedir| info "**** using templatedir = #{templatedir}" init_from_template(templatedir, srcdir, config, :no_interaction => true, :no_commit => true) end # Rename the main file Dir.chdir( srcdir ) do run %( mv main.tex #{config[:name]}.tex ) end end # Create the trash directory trash(srcdir) # populate the images/ directory baseimages = File.join( FalkorLib.templates, 'latex', 'images') #images_makefile_src = "#{FalkorLib.config[:git][:submodulesdir]}/Makefiles/generic/Makefile.insrcdir" images = File.join(srcdir, 'images') info "populating the image directory" Dir.chdir( images ) do run %( rsync -avzu #{baseimages}/ . ) run %( ln -s ../.root .root ) unless File.exist?(File.join(images, '.root')) #run %{ ln -s .root/#{images_makefile_src} Makefile } unless File.exists?(File.join(images, 'Makefile')) end FalkorLib::Bootstrap::Link.makefile(images, :images => true, :no_interaction => true ) # Prepare the src/ directory FalkorLib::Bootstrap::Link.makefile(File.join(rootdir, project_dir), :src => true, :no_interaction => true ) # default_project_dir = case type # when :beamer # "slides/#{Time.new.yea}" # end end |
.license(dir = Dir.pwd, license = , authors = '', options = { :filename => 'LICENSE' }) ⇒ Object
license ###### Generate the licence file
Supported options:
* :force [boolean] force action
* :filename [string] License file name
* :organization [string] Organization
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/falkorlib/bootstrap/base.rb', line 398 def license(dir = Dir.pwd, license = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata][:license], = '', = { :filename => 'LICENSE' }) return if (license.empty? or license == :none or license =~ /^CC/) return unless FalkorLib::Config::Bootstrap::DEFAULTS[:licenses].keys.include?( license ) info "Generate the licence file" path = normalized_path(dir) use_git = FalkorLib::Git.init?(path) rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path Dir.chdir( rootdir ) do run %( licgen #{license.downcase} #{} ) run %( mv LICENSE #{[:filename]} ) if( [:filename] and [:filename] != 'LICENSE') end end |
.mkdocs(dir = Dir.pwd, options = {}) ⇒ Object
mkdocs ###### Initialize MkDocs in the current directory Supported options:
* :force [boolean] force overwritting
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/falkorlib/bootstrap/mkdocs.rb', line 28 def mkdocs(dir = Dir.pwd, = {}) info "Initialize MkDocs (see http://www.mkdocs.org/)" path = normalized_path(dir) use_git = FalkorLib::Git.init?(path) rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path templatedir = File.join( FalkorLib.templates, 'mkdocs') config = guess_project_config(rootdir, ) config[:sitename] = ask("\tSite name: ", config[:name].capitalize) puts config.to_yaml #FalkorLib::GitFlow.start('feature', 'mkdocs', rootdir) if (use_git && FalkorLib::GitFlow.init?(rootdir)) init_from_template(templatedir, rootdir, config, :no_interaction => true, :no_commit => true) Dir.chdir( File.join(rootdir, 'docs')) do run %(ln -s README.md index.md ) run %(ln -s README.md contributing/index.md ) run %(ln -s README.md setup/index.md ) end #exit_status.to_i end |
.motd(dir = Dir.pwd, options = {}) ⇒ Object
motd ###### Generate a new motd (Message of the Day) file Supported options:
* :force [boolean] force action
* :title [string] title of the motd (in figlet)
* :support [string] email address to use for getting support
* :hostname [string] hostname of the server to mention in the motd
* :width [number] width of the line used
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/falkorlib/bootstrap/base.rb', line 209 def motd(dir = Dir.pwd, = {}) config = FalkorLib::Config::Bootstrap::DEFAULTS[:motd].merge!(::ActiveSupport::HashWithIndifferentAccess.new().symbolize_keys) path = normalized_path(dir) erbfile = File.join( FalkorLib.templates, 'motd', 'motd.erb') outfile = (config[:file] =~ /^\//) ? config[:file] : File.join(path, config[:file]) info "Generate a motd (Message of the Day) file '#{outfile}'" FalkorLib::Config::Bootstrap::DEFAULTS[:motd].keys.each do |k| next if [:file, :width].include?(k) config[k.to_sym] = ask( "\t" + format("Message of the Day (MotD) %-10s", k.to_s), config[k.to_sym]) unless [:no_interaction] end config[:os] = Facter.value(:lsbdistdescription) if Facter.value(:lsbdistdescription) config[:os] = "Mac " + Facter.value(:sp_os_version) if Facter.value(:sp_os_version) unless [:nodemodel] config[:nodemodel] = Facter.value(:sp_machine_name) if Facter.value(:sp_machine_name) config[:nodemodel] += " (#{Facter.value(:sp_cpu_type)}" if Facter.value(:sp_cpu_type) config[:nodemodel] += " " + Facter.value(:sp_current_processor_speed) if Facter.value(:sp_current_processor_speed) config[:nodemodel] += " #{Facter.value(:sp_number_processors)} cores )" if Facter.value(:sp_number_processors) end config[:nodemodel] = Facter.value(:sp_machine_name) unless [:nodemodel] write_from_erb_template(erbfile, outfile, config, ) end |
.readme(dir = Dir.pwd, options = {}) ⇒ Object
readme ###### Bootstrap a README file for various context Supported options:
* :no_interaction [boolean]: do not interact
* :force [boolean] force overwritting
* :license [string] License to use
* :licensefile [string] License filename (default: LICENSE)
* :latex [boolean] describe a LaTeX project
* :octopress [boolean] octopress site
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/falkorlib/bootstrap/base.rb', line 243 def readme(dir = Dir.pwd, = {}) info "Bootstrap a README file for this project" # get the local configuration local_config = FalkorLib::Config.get(dir) config = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].clone name = get_project_name(dir) if local_config[:project] config.deep_merge!( local_config[:project]) else config[:name] = ask("\tProject name: ", name) unless [:name] end if [:rake] [:make] = false [:rvm] = true end config[:license] = [:license] if [:license] config[:type] << :rvm if [:rake] # Type of project config[:type] << :latex if [:latex] if config[:type].empty? t = select_from( FalkorLib::Config::Bootstrap::DEFAULTS[:types], 'Select the type of project to describe:', 1) config[:type] << t config[:type] << [ :ruby, :rvm ] if [ :gem, :rvm, :octopress, :puppet_module ].include?( t ) config[:type] << :python if t == :pyenv end config[:type].uniq! #ap config config[:type] = config[:type].uniq.flatten # Apply options (if provided) [ :name, :forge ].each do |k| config[k.to_sym] = [k.to_sym] if [k.to_sym] end path = normalized_path(dir) config[:filename] = ([:filename]) ? [:filename] : File.join(path, 'README.md') if ( FalkorLib::Git.init?(dir) && FalkorLib::Git.remotes(dir).include?( 'origin' )) config[:origin] = FalkorLib::Git.config('remote.origin.url') if config[:origin] =~ /((gforge|gitlab|github)[\.\w_-]+)[:\d\/]+(\w*)/ config[:forge] = Regexp.last_match(2).to_sym config[:by] = Regexp.last_match(3) end elsif config[:forge].empty? config[:forge] = select_forge(config[:forge]).to_sym end forges = FalkorLib::Config::Bootstrap::DEFAULTS[:forge][ config[:forge].to_sym ] #ap config default_source = case config[:forge] when :gforge 'https://' + forges[:url] + "/projects/" + name.downcase when :github, :gitlab 'https://' + forges[:url] + "/" + config[:by] + "/" + name.downcase else "" end FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].each do |k, v| next if v.is_a?(Array) || [ :license, :forge ].include?( k ) next if (k == :name) && !config[:name].empty? next if (k == :issues_url) && ![ :github, :gitlab ].include?( config[:forge] ) #next unless [ :name, :summary, :description ].include?(k.to_sym) default_answer = case k when :author (config[:by] == 'ULHPC') ? 'UL HPC Team' : config[:author] when :mail (config[:by] == 'ULHPC') ? '[email protected]' : config[:mail] when :description (config[:description].empty?) ? (config[:summary]).to_s : (config[:description]).to_s when :source (config[:source].empty?) ? default_source : (config[:source]).to_s when :project_page (config[:source].empty?) ? v : config[:source] when :issues_url (config[:project_page].empty?) ? v : "#{config[:project_page]}/issues" else (config[k.to_sym].empty?) ? v : config[k.to_sym] end config[k.to_sym] = ask( "\t" + Kernel.format("Project %-20s", k.to_s), default_answer) end = ask("\tKeywords (comma-separated list of tags)", config[:tags].join(',')) config[:tags] = .split(',') config[:license] = select_licence if config[:license].empty? # stack the ERB files required to generate the README templatedir = File.join( FalkorLib.templates, 'README') erbfiles = [ 'header_readme.erb' ] [ :latex ].each do |type| erbfiles << "readme_#{type}.erb" if [type.to_sym] && File.exist?( File.join(templatedir, "readme_#{type}.erb")) end erbfiles << "readme_issues.erb" erbfiles << "readme_git.erb" if FalkorLib::Git.init?(dir) erbfiles << "readme_gitflow.erb" if FalkorLib::GitFlow.init?(dir) erbfiles << "readme_rvm.erb" if config[:type].include?(:rvm) erbfiles << "readme_mkdocs.erb" if [:mkdocs] erbfiles << "footer_readme.erb" content = "" erbfiles.each do |f| erbfile = File.join(templatedir, f) content += ERB.new(File.read(erbfile.to_s), nil, '<>').result(binding) end show_diff_and_write(content, config[:filename], ) # Force save/upgrade local config info "=> saving customization of the FalkorLib configuration in #{FalkorLib.config[:config_files][:local]}" # really_continue? FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].keys.each do |k| local_config[:project] = {} unless local_config[:project] local_config[:project][k.to_sym] = config[k.to_sym] end if FalkorLib::GitFlow.init?(dir) local_config[:gitflow] = {} unless local_config[:gitflow] local_config[:gitflow][:branches] = FalkorLib.config[:gitflow][:branches].clone unless local_config[:gitflow][:branches] [ :master, :develop ].each do |b| local_config[:gitflow][:branches][b.to_sym] = FalkorLib::GitFlow.branches(b.to_sym) end end FalkorLib::Config.save(dir, local_config, :local) # end |
.repo(name, options = {}) ⇒ Object
repo ###### Initialize a Git repository for a project with my favorite layout Supported options:
-
:no_interaction [boolean]: do not interact
-
:gitflow [boolean]: bootstrap with git-flow
-
:license [string] License to use
-
:licensefile [string] License filename (default: LICENSE)
-
:interactive [boolean] Confirm Gitflow branch names
-
:master [string] Branch name for production releases
-
:develop [string] Branch name for development commits
-
:make [boolean] Use a Makefile to pilot the repository actions
-
:rake [boolean] Use a Rakefile (and FalkorLib) to pilot the repository action
-
:remote_sync [boolean] Operate a git remote synchronization
-
:latex [boolean] Initiate a LaTeX project **NOT YET IMPLEMENTED**
-
:gem [boolean] Initiate a Ruby gem project **NOT YET IMPLEMENTED**
-
:mkdocs [boolean] Initiate MkDocs within your project
-
:rvm [boolean] Initiate a RVM-based Ruby project
-
:pyenv [boolean] Initiate a pyenv-based Python project **NOT YET IMPLEMENTED**
-
:octopress [boolean] Initiate an Octopress web site **NOT YET IMPLEMENTED**
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/falkorlib/bootstrap/git.rb', line 44 def repo(name, = {}) ap if [:debug] path = normalized_path(name) project = File.basename(path) use_git = FalkorLib::Git.init?(path) if [:rake] [:make] = false [:rvm] = true end info "Bootstrap a [Git] repository for the project '#{project}'" if use_git warning "Git is already initialized for the repository '#{name}'" really_continue? unless [:force] end if [:git_flow] info " ==> initialize Git flow in #{path}" FalkorLib::GitFlow.init(path, ) gitflow_branches = {} [ :master, :develop ].each do |t| gitflow_branches[t.to_sym] = FalkorLib::GitFlow.branches(t, path) end else FalkorLib::Git.init(path, ) end # === prepare Git submodules === info " ==> prepare the relevant Git submodules" submodules = {} #'gitstats' => { :url => 'https://github.com/hoxu/gitstats.git' } # } if [:make] submodules['Makefiles'] = { :url => 'https://github.com/Falkor/Makefiles.git', :branch => 'devel' } end FalkorLib::Git.submodule_init(path, submodules) # === Prepare root [M|R]akefile === if [:make] info " ==> prepare Root Makefile" makefile = File.join(path, "Makefile") if File.exist?( makefile ) puts " ... not overwriting the root Makefile which already exists" else src_makefile = File.join(path, FalkorLib.config.git[:submodulesdir], 'Makefiles', 'repo', 'Makefile') FileUtils.cp src_makefile, makefile info "adapting Makefile to the gitflow branches" Dir.chdir( path ) do run %( sed -i '' \ -e \"s/^GITFLOW_BR_MASTER=production/GITFLOW_BR_MASTER=#{gitflow_branches[:master]}/\" \ -e \"s/^GITFLOW_BR_DEVELOP=devel/GITFLOW_BR_DEVELOP=#{gitflow_branches[:develop]}/\" \ Makefile ) end FalkorLib::Git.add(makefile, 'Initialize root Makefile for the repo') end end if [:rake] info " ==> prepare Root Rakefile" rakefile = File.join(path, "Rakefile") unless File.exist?( rakefile ) templatedir = File.join( FalkorLib.templates, 'Rakefile') erbfiles = [ 'header_rakefile.erb' ] erbfiles << 'rakefile_gitflow.erb' if FalkorLib::GitFlow.init?(path) erbfiles << 'footer_rakefile.erb' write_from_erb_template(erbfiles, rakefile, {}, :srcdir => templatedir.to_s) end end # === VERSION file === FalkorLib::Bootstrap.versionfile(path, :tag => 'v0.0.0') unless [:gem] # === RVM ==== FalkorLib::Bootstrap.rvm(path, ) if [:rvm] # === README === FalkorLib::Bootstrap.readme(path, ) # This should also save the project configuration # collect the set options local_config = FalkorLib::Config.get(path) # === MkDocs === FalkorLib::Bootstrap.mkdocs(path, ) if [:mkdocs] # === Licence === if (local_config[:project] and local_config[:project][:license]) = local_config[:project][:author] ? local_config[:project][:author] : FalkorLib::Config::Bootstrap::DEFAULTS[:metadata][:author] FalkorLib::Bootstrap.licence(path, local_config[:project][:license], , ) end # #===== remote synchro ======== if [:remote_sync] remotes = FalkorLib::Git.remotes(path) if remotes.include?( 'origin' ) info "perform remote synchronization" [ :master, :develop ].each do |t| FalkorLib::Git.publish(gitflow_branches[t.to_sym], path, 'origin') end else warning "no Git remote 'origin' found, thus no remote synchronization performed" end end end |
.rvm(dir = Dir.pwd, options = {}) ⇒ Object
rvm ###### Initialize RVM in the current directory Supported options:
* :force [boolean] force overwritting
* :ruby [string] Ruby version to configure for RVM
* :versionfile [string] Ruby Version file
* :gemset [string] RVM Gemset to configure
* :gemsetfile [string] RVM Gemset file
* :commit [boolean] Commit the changes NOT YET USED
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/falkorlib/bootstrap/ruby.rb', line 35 def rvm(dir = Dir.pwd, = {}) info "Initialize Ruby Version Manager (RVM)" ap if [:debug] path = normalized_path(dir) use_git = FalkorLib::Git.init?(path) rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path files = {} exit_status = 1 [:versionfile, :gemsetfile].each do |type| f = ([type.to_sym].nil?) ? FalkorLib.config[:rvm][type.to_sym] : [type.to_sym] if File.exist?( File.join( rootdir, f )) content = `cat #{File.join( rootdir, f)}`.chomp warning "The RVM file '#{f}' already exists (and contains '#{content}')" next unless [:force] warning "... and it WILL BE overwritten" end files[type.to_sym] = f end # ==== Ruby version === unless files[:versionfile].nil? file = File.join(rootdir, files[:versionfile]) v = FalkorLib.config[:rvm][:version] if [:ruby] v = [:ruby] else select_from(FalkorLib.config[:rvm][:rubies], "Select RVM ruby to configure for this directory", (FalkorLib.config[:rvm][:rubies].find_index(FalkorLib.config[:rvm][:version]) + 1)) end info " ==> configuring RVM version file '#{files[:versionfile]}' for ruby version '#{v}'" File.open(file, 'w') do |f| f.puts v end exit_status = (File.exist?(file) && (`cat #{file}`.chomp == v)) ? 0 : 1 FalkorLib::Git.add(File.join(rootdir, files[:versionfile])) if use_git end # === Gemset === if files[:gemsetfile] file = File.join(rootdir, files[:gemsetfile]) default_gemset = File.basename(rootdir) default_gemset = `cat #{file}`.chomp if File.exist?( file ) g = ([:gemset]) ? [:gemset] : ask("Enter RVM gemset name for this directory", default_gemset) info " ==> configuring RVM gemset file '#{files[:gemsetfile]}' with content '#{g}'" File.open( File.join(rootdir, files[:gemsetfile]), 'w') do |f| f.puts g end exit_status = (File.exist?(file) && (`cat #{file}`.chomp == g)) ? 0 : 1 FalkorLib::Git.add(File.join(rootdir, files[:gemsetfile])) if use_git end # ==== Gemfile === gemfile = File.join(rootdir, 'Gemfile') unless File.exist?( gemfile ) # Dir.chdir(rootdir) do # run %{ bundle init } # end info " ==> configuring Gemfile with Falkorlib" File.open( gemfile, 'a') do |f| f.puts "source 'https://rubygems.org'" f.puts "" f.puts "gem 'falkorlib' #, :path => '~/git/github.com/Falkor/falkorlib'" end FalkorLib::Git.add(gemfile) if use_git end exit_status.to_i end |
.select_forge(default = :gforge, _options = {}) ⇒ Object
Select the forge (gforge, github, etc.) hosting the project sources
365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/falkorlib/bootstrap/base.rb', line 365 def select_forge(default = :gforge, = {}) forge = FalkorLib::Config::Bootstrap::DEFAULTS[:forge] #ap forge default_idx = forge.keys.index(default) default_idx = 0 if default_idx.nil? v = select_from(forge.map { |_k, u| u[:name] }, "Select the Forge hosting the project sources", default_idx + 1, forge.keys) v end |
.select_licence(default_licence = , _options = {}) ⇒ Object
select_licence ###### Select a given licence for the project
380 381 382 383 384 385 386 387 388 |
# File 'lib/falkorlib/bootstrap/base.rb', line 380 def select_licence(default_licence = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata][:license], = {}) list_license = FalkorLib::Bootstrap::DEFAULTS[:licenses].keys idx = list_license.index(default_licence) unless default_licence.nil? select_from(list_license, 'Select the license index for this project:', (idx.nil?) ? 1 : idx + 1) #licence end |
.trash(path = Dir.pwd, dirname = , _options = {}) ⇒ Object
Initialize a trash directory in path
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/falkorlib/bootstrap/base.rb', line 134 def trash(path = Dir.pwd, dirname = FalkorLib.config[:templates][:trashdir], = {}) #args = method(__method__).parameters.map { |arg| arg[1].to_s }.map { |arg| { arg.to_sym => eval(arg) } }.reduce Hash.new, :merge #ap args exit_status = 0 trashdir = File.join(File.realpath(path), dirname) if Dir.exist?(trashdir) warning "The trash directory '#{dirname}' already exists" return 1 end Dir.chdir(path) do info "creating the trash directory '#{dirname}'" exit_status = run %( mkdir -p #{dirname} echo '*' > #{dirname}/.gitignore ) if FalkorLib::Git.init?(path) exit_status = FalkorLib::Git.add(File.join(trashdir.to_s, '.gitignore' ), 'Add Trash directory', :force => true ) end end exit_status.to_i end |
.versionfile(dir = Dir.pwd, options = {}) ⇒ Object
versionfile ###### Bootstrap a VERSION file at the root of a project Supported options:
-
:file [string] filename
-
:version [string] version to mention in the file
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/falkorlib/bootstrap/base.rb', line 164 def versionfile(dir = Dir.pwd, = {}) file = ([:file]) ? [:file] : 'VERSION' version = ([:version]) ? [:version] : '0.0.0' info " ==> bootstrapping a VERSION file" path = normalized_path(dir) path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path) unless Dir.exist?( path ) warning "The directory #{path} does not exists and will be created" really_continue? FileUtils.mkdir_p path end versionfile = File.join(path, file) if File.exist?( versionfile ) puts " ... not overwriting the #{file} file which already exists" else FalkorLib::Versioning.set_version(version, path, :type => 'file', :source => { :filename => file }) Dir.chdir( path ) do run %( git tag #{[:tag]} ) if [:tag] end end # unless File.exists?( versionfile ) # run %{ echo "#{version}" > #{versionfile} } # if FalkorLib::Git.init?(path) # FalkorLib::Git.add(versionfile, "Initialize #{file} file") # Dir.chdir( path ) do # run %{ git tag #{options[:tag]} } if options[:tag] # end # end # else # puts " ... not overwriting the #{file} file which already exists" # end end |