Class: ProjecterCLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/commands/create.rb,
lib/commands/version.rb

Instance Method Summary collapse

Instance Method Details

#create(project) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
# File 'lib/commands/create.rb', line 9

def create(project)
  @project = project

  ProjecterCLI::source_root(File.expand_path('../../..', __FILE__))
  run "git init #{@project}", :capture => true unless File.exist?(File.join(@project, '.git'))

  create_project_dirs

  projecter_file({
    'Gemfile'         => 'Gemfile',
    'Guardfile'       => 'Guardfile',
    'Rakefile'        => 'Rakefile',
    'dot-gitignore'   => '.gitignore',
    'dot-metrics'     => '.metrics',
    'dot-rspec'       => '.rspec',
    'dot-rubocop.yml' => '.rubocop.yml',
  })

  lib_templates = {
    'gemspec.tt' => "#{project}.gemspec",
    'README.md.tt' => 'README.md',
    'reek.tt' => "#{project}.reek",
    'mainlib.rb.tt' => ['lib', "#{project}.rb"],
    'version.rb.tt' => ['lib', project, 'version.rb'],
    'spec_helper.rb.tt' => %w(spec spec_helper.rb),
    'spec_fixtures.rb.tt' => %w(spec fixtures.rb),
    'spec_resources.rb.tt' => %w(spec resources.rb),
  }

  app_templates = {
    'mainapp.tt' => ['bin', project],
    'version-cmd.rb.tt' => %w(lib commands version.rb),
  }

  templates = lib_templates
  templates.merge(app_templates) unless options.library?

  projecter_template(
    templates,
    {
      :project => project,
      :classname => project
                      .split(/[_-]/)
                      .map(&:capitalize)
                      .join,
      :library_only => options.library?
    }
  )

  inside(@project) do
    # XXX: KLUDGE: Add an empty .gitignore file in each empty directory
    # XXX: KLUDGE: so that git can track the dir.
    Find.find('.') do |path|
      next if path.start_with?('./.git/')
      next unless FileTest.directory?(path)
      next unless Dir.entries(path) == %w(. ..)

      create_file File.join(path, '.gitignore'), ''
    end

    run "git add .gitignore", :capture => true
    run "git add .", :capture => true
    run "git commit --allow-empty -m 'Created #{@project} using Projecter #{Projecter::VERSION}.'", :capture => true
  end

end

#versionObject



3
4
5
# File 'lib/commands/version.rb', line 3

def version
  puts "projecter #{Projecter::VERSION}"
end