Module: FalkorLib::Bootstrap

Defined in:
lib/falkorlib/bootstrap/base.rb

Class Method Summary collapse

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']


644
645
646
647
648
649
# File 'lib/falkorlib/bootstrap/base.rb', line 644

def get_badge(subject, status, color = 'blue', options = {})
    st = status.gsub(/-/, '--').gsub(/_/, '__')
    res = "https://img.shields.io/badge/#{subject}-#{st}-#{color}.svg"
    res += "?style=#{options[:style]}" if options[: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



654
655
656
657
658
# File 'lib/falkorlib/bootstrap/base.rb', line 654

def get_project_name(dir = Dir.pwd, options = {})
    path = normalized_path(dir)
    path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
    File.basename(path)
end

.latex(dir = Dir.pwd, type = :beamer, options = {}) ⇒ Object

latex ###### Bootstrap a LaTeX sub-project within a given repository Supported options:

* :force [boolean] force action


499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/falkorlib/bootstrap/base.rb', line 499

def latex(dir = Dir.pwd, type = :beamer, options = {})
    ap options if options[:debug]
    path   = normalized_path(dir)
    config = FalkorLib::Config::Bootstrap::DEFAULTS[:latex].clone
    # initiate the repository if needed
    unless File.directory?( path )
        warn "The directory '#{path}' does not exists and will be created"
        really_continue? unless options[:force]
        run %{ mkdir -p #{path} }
    end
    repo(path, options) 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 options[:force]
    relative_path_to_root = (Pathname.new( FalkorLib::Git.rootdir(dir) ).relative_path_from Pathname.new( File.realpath(path))).to_s
    config[:name] = options[:name] ? options[:name] : ask("\tEnter the name of the #{type} 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
                                  "articles/#{Time.now.year}/#{config[:name]}"
                              when :beamer
                                  "slides/#{Time.now.year}/#{config[:name]}/"
                              when :bookchapter
                                  "chapters/#{config[:name]}"
                              else
                                  "#{config[:name]}"
                              end
    else
        default_project_dir += "/#{config[:name]}" unless default_project_dir =~ /#{config[:name]}$/
    end
    project_dir = ask("\tLaTeX Project directory (relative to the Git root directory)", default_project_dir)
    raise FalkorLib::ExecError "Empty project directory" if project_dir.empty?
    subdir = File.join(rootdir, project_dir)
    if File.exists?(File.join(subdir, '.root'))
        warn "The directory '#{project_dir}' seems to have been already initialized"
        really_continue? unless options[:force]
    end
    FalkorLib::GitFlow.start('feature', config[:name], rootdir) if FalkorLib::GitFlow.init?(rootdir)
    # === prepare Git submodules ===
    info " ==> prepare the relevant Git submodules"
    submodules = {}
    submodules['Makefiles'] = { :url   => 'https://github.com/Falkor/Makefiles.git',
                               :branch => 'devel'
                              } if [ :article, :beamer, :bookchapter].include?(type)
    submodules['beamerthemeFalkor'] = { :url => 'https://github.com/Falkor/beamerthemeFalkor' } if type == :beamer
    FalkorLib::Git.submodule_init(rootdir, submodules)
    info "bootstrapping the #{type} project '#{project_dir}'"
    # Create the project directory
    Dir.chdir( rootdir ) do
        run %{ mkdir -p #{project_dir}/images } unless File.directory?("#{subdir}/images")
    end
    info "populating '#{project_dir}'"
    rootlink(subdir, { :verbose => true} )
    # Prepare the links from the sub-module files
    [ 'Makefile', '_style.sty', '.gitignore', 'beamerthemeFalkor.sty' ].each do |f|
        next if (f =~ /beamer/) and (type != :beamer)
        submoduledir = (f =~ /beamer/) ? 'beamerthemeFalkor' : 'Makefiles/latex'
        dst = "#{FalkorLib.config[:git][:submodulesdir]}/#{submoduledir}/#{f}"
        Dir.chdir( subdir ) do
            run %{ ln -s .root/#{dst} #{f} } unless File.exist?( File.join(subdir, f) )
        end
    end
    # Bootstrap the directory
    templatedir = File.join( FalkorLib.templates, 'latex', "#{type}")
    unless File.exists?( File.join(subdir, "#{config[:name]}.tex"))
        info "gathering information for the LaTeX templates"
        prefix = case type
                 when :article
                     'Article '
                 when :beamer
                     'Slides '
                 when :bookchapter
                     'Book Chapter '
                 else
                     ''
                 end
        config.each do |k,v|
            next if k == :name
            config[k.to_sym] = ask( "\t" + sprintf("%-20s", "#{prefix}#{k.capitalize}"), v)
        end
        init_from_template(templatedir, subdir, config, {:no_interaction => true,
                                                         :no_commit      => true })
        # Rename the main file
        Dir.chdir( subdir ) do
            run %{ mv main.tex #{config[:name]}.tex }
        end
    end
    # Create the trash directory
    trash(subdir)
    
    # populate the images/ directory
    baseimages  = File.join( FalkorLib.templates, 'latex', 'images')
    images_makefile_src = "#{FalkorLib.config[:git][:submodulesdir]}/Makefiles/generic/Makefile.insubdir"
    images = File.join(subdir, 'images')
    info "populating the image directory"
    Dir.chdir( images ) do
        run %{ rsync -avzu #{baseimages}/ . }
        run %{ ln -s ../.root .root } unless File.exists?(File.join(images, '.root'))
        run %{ ln -s .root/#{images_makefile_src} Makefile } unless File.exists?(File.join(images, 'Makefile'))
    end


    # default_project_dir = case type
    #               when :beamer
    #                   "slides/#{Time.new.yea}"
    #               end
end

.motd(dir = Dir.pwd, options = {}) ⇒ Object

motd ###### Generate a new motd (Message of the Day) file Supported options:

* :force [boolean] force action


354
355
356
357
358
359
360
361
362
363
# File 'lib/falkorlib/bootstrap/base.rb', line 354

def motd(dir = Dir.pwd, options = {})
    config = FalkorLib::Config::Bootstrap::DEFAULTS[:motd].merge!(options)
    path = normalized_path(dir)
    erbfile = File.join( FalkorLib.templates, 'motd', 'motd.erb')
    outfile = (options[:file] =~ /^\//) ? options[:file] : File.join(path, options[:file])
    info "Generate a motd (Message of the Day) file '#{outfile}'"
    config[:os] = Facter.value(:lsbdistdescription) if Facter.value(:lsbdistdescription)
    config[:os] = "Mac " + Facter.value(:sp_os_version) if Facter.value(:sp_os_version)
    write_from_erb_template(erbfile, outfile, config, options)
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
* :latex     [boolean] describe a LaTeX project
* :octopress [boolean] octopress site


375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
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
463
464
465
466
467
468
469
470
# File 'lib/falkorlib/bootstrap/base.rb', line 375

def readme(dir = Dir.pwd, options = {})
    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
    if local_config[:project]
        config.deep_merge!( local_config[:project])
    else
        config[:name]     = ask("\tProject name: ", get_project_name(dir)) unless options[:name]
    end
    # Type of project
    config[:type] << :latex if options[: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] = config[:type].uniq.flatten
    # Apply options (if provided)
    [ :name, :forge ].each do |k|
        config[k.to_sym] = options[k.to_sym] if options[k.to_sym]
    end
    path = normalized_path(dir)
    config[:filename] = options[:filename] ? options[:filename] : File.join(path, 'README.md')
    config[:forge] = select_forge(config[:forge]).to_sym if config[:forge].empty?
    forges = FalkorLib::Config::Bootstrap::DEFAULTS[:forge][ config[:forge].to_sym ]
    default_source = case config[:forge]
                     when :gforge
                         forges[:url] + "/projects/" + config[:name].downcase
                     when :github
                         forges[:url] + "/" + forges[:login] + "/" + config[:name].downcase
                     when :gitlab
                         forges[:url] + "/" + forges[:name].downcase
                     else
                         ""
                     end
    ap config
    FalkorLib::Config::Bootstrap::DEFAULTS[:metadata].each do |k,v|
        next if v.kind_of?(Array) or [ :license, :forge ].include?( k )
        next if k == :name and ! config[:name].empty?
        next if k == :issues_url and ! [ :github, :gitlab ].include?( config[:forge] )
        #next unless [ :name, :summary, :description ].include?(k.to_sym)
        default_answer = case k
                         when :description
                             config[:description].empty? ? "#{config[:summary]}" : "#{config[:description]}"
                         when :source
                             config[:source].empty? ? default_source : "#{config[:source]}"
                         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" + sprintf("Project %-20s", "#{k}"), default_answer)
    end
    tags = ask("\tKeywords (comma-separated list of tags)", config[:tags].join(','))
    config[:tags]    = 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 options[type.to_sym] and File.exist?( File.join(templatedir, "readme_#{type}.erb"))
    end
    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 << "footer_readme.erb"

    content = ""
    erbfiles.each do |f|
        erbfile = File.join(templatedir, f)
        content += ERB.new(File.read("#{erbfile}"), nil, '<>').result(binding)
    end
    show_diff_and_write(content, config[:filename], options)

    # Eventually 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

  • :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

  • :gem [boolean] Initiate a Ruby gem project

  • :rvm [boolean] Initiate a RVM-based Ruby project

  • :pyenv [boolean] Initiate a pyenv-based Python project

  • :octopress [boolean] Initiate an Octopress web site



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
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
# File 'lib/falkorlib/bootstrap/base.rb', line 214

def repo(name, options = {})
    ap options if options[:debug]
    path    = normalized_path(name)
    project = File.basename(path)
    use_git = FalkorLib::Git.init?(path)
    options[:make] = false if options[:rake]
    info "Bootstrap a [Git] repository for the project '#{project}'"
    if use_git
        warning "Git is already initialized for the repository '#{name}'"
        really_continue? unless options[:force]
    end
    if options[:git_flow]
        info " ==> initialize Git flow in #{path}"
        FalkorLib::GitFlow.init(path, options)
        gitflow_branches = {}
        [ :master, :develop ].each do |t|
            gitflow_branches[t.to_sym] = FalkorLib::GitFlow.branches(t, path)
        end
    else
        FalkorLib::Git.init(path, options)
    end
    # === prepare Git submodules ===
    info " ==> prepare the relevant Git submodules"
    submodules = {
                  'gitstats' => { :url => 'https://github.com/hoxu/gitstats.git' }
                 }
    if options[: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 options[:make]
        info " ==> prepare Root Makefile"
        makefile = File.join(path, "Makefile")
        unless File.exist?( makefile )
            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')
        else
            puts "  ... not overwriting the root Makefile which already exists"
        end
    end
    if options[: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}" })
        end
    end

    # === VERSION file ===
    FalkorLib::Bootstrap.versionfile(path, :tag => 'v0.0.0')

    # === RVM ====
    FalkorLib::Bootstrap.rvm(path, options) if options[:rvm]

    # === README ===
    FalkorLib::Bootstrap.readme(path, options)

    #===== remote synchro ========
    if options[: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

rootlink ###### Create a symlink ‘.root’ targeting the relative path to the git root directory Supported options:

* :name [string] name of the symlink ('.root' by default)


477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/falkorlib/bootstrap/base.rb', line 477

def rootlink(dir = Dir.pwd, options = {})
    raise FalkorLib::ExecError "Not used in a Git repository" unless FalkorLib::Git.init?
    path  = normalized_path(dir)
    relative_path_to_root = (Pathname.new( FalkorLib::Git.rootdir(dir) ).relative_path_from Pathname.new( File.realpath(path)))
    FalkorLib::Common.error "Already at the root directory of the Git repository" if "#{relative_path_to_root}" == "."
    target = options[:name] ? options[:name] : '.root'
    unless File.exists?( File.join(path, target))
        warning "creating the symboling link '#{target}' which points to '#{relative_path_to_root}'" if options[:verbose]
        # Format: ln_s(old, new, options = {}) -- Creates a symbolic link new which points to old.
        #FileUtils.ln_s "#{relative_path_to_root}", "#{target}"
        Dir.chdir( path ) do
            run %{ ln -s #{relative_path_to_root} #{target} }
        end
        FalkorLib::Git.add(File.join(path, target), "Add symlink to the root directory as .root")
    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


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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/falkorlib/bootstrap/base.rb', line 147

def rvm(dir = Dir.pwd, options = {})
    info "Initialize Ruby Version Manager (RVM)"
    ap options if options[: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 = options[type.to_sym].nil? ? FalkorLib.config[:rvm][type.to_sym] : options[type.to_sym]
        if File.exists?( File.join( rootdir, f ))
            content = `cat #{File.join( rootdir, f)}`.chomp
            warning "The RVM file '#{f}' already exists (and contains '#{content}')"
            next unless options[: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 =
          options[:ruby] ?
          options[:ruby] :
          select_from(FalkorLib.config[:rvm][:rubies],
                      "Select RVM ruby to configure for this directory",
                      1)
        info " ==>  configuring RVM version file '#{files[:versionfile]}' for ruby version '#{v}'"
        File.open(file, 'w') do |f|
            f.puts v
        end
        exit_status = (File.exists?(file) and `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.exists?( file )
        g = options[:gemset] ? options[: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.exists?(file) and `cat #{file}`.chomp == g) ? 0 : 1
        FalkorLib::Git.add(File.join(rootdir, files[:gemsetfile])) if use_git
    end
    exit_status
end

.select_forge(default = :gforge, options = {}) ⇒ Object

Select the forge (gforge, github, etc.) hosting the project sources



613
614
615
616
617
618
619
620
621
622
623
# File 'lib/falkorlib/bootstrap/base.rb', line 613

def select_forge(default = :gforge, options = {})
    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,v| v[: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



628
629
630
631
632
633
634
635
636
# File 'lib/falkorlib/bootstrap/base.rb', line 628

def select_licence(default_licence = FalkorLib::Config::Bootstrap::DEFAULTS[:metadata][:license],
                   options = {})
    list_license    = FalkorLib::Config::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



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/falkorlib/bootstrap/base.rb', line 113

def trash(path = Dir.pwd, dirname = FalkorLib.config[:templates][:trashdir], options = {})
    #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(path, dirname)
    if Dir.exists?(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(path, dirname, '.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



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
# File 'lib/falkorlib/bootstrap/base.rb', line 311

def versionfile(dir = Dir.pwd, options = {})
    file    = options[:file]    ? options[:file]    : 'VERSION'
    version = options[:version] ? options[: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.exists?( path )
        warning "The directory #{path} does not exists and will be created"
        really_continue?
        FileUtils.mkdir_p path
    end
    versionfile = File.join(path, file)
    unless File.exists?( versionfile )
        FalkorLib::Versioning.set_version(version, path, {
                                                          :type => 'file',
                                                          :source => { :filename => file }
                                                         })
        Dir.chdir( path ) do
            run %{ git tag #{options[:tag]} } if options[:tag]
        end
    else
        puts "  ... not overwriting the #{file} file which already exists"
    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