Class: Deano::NewProjectGenerator

Inherits:
NameCommand show all
Defined in:
lib/deano/commands/new_project_generator_command.rb

Instance Attribute Summary

Attributes inherited from NameCommand

#args, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NameCommand

#clean_string, inherited, #underscored

Methods inherited from Command

#app_path, #cmd, commands, inherited, #rm, #rm_r, #template_path

Constructor Details

#initialize(*args) ⇒ NewProjectGenerator

Returns a new instance of NewProjectGenerator.



12
13
14
15
# File 'lib/deano/commands/new_project_generator_command.rb', line 12

def initialize(*args)
  super
  @app_dir = File.expand_path(File.join(FileUtils.pwd, self.underscored))
end

Class Method Details

.commandObject



4
5
6
# File 'lib/deano/commands/new_project_generator_command.rb', line 4

def self.command
  "new"
end

.helpObject



8
9
10
# File 'lib/deano/commands/new_project_generator_command.rb', line 8

def self.help
  "name"
end

Instance Method Details

#callObject



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
# File 'lib/deano/commands/new_project_generator_command.rb', line 21

def call
  FileUtils.mkdir self.underscored, verbose: true
  Dir[template_path("**", "*")].each do |f|
    if File.directory?(f)
      FileUtils.mkdir_p clean_string(f), verbose: true
    else
      FileUtils.mkdir_p clean_string(File.dirname(f)), verbose: true
      File.open(clean_string(f), 'w') do |file|
        file.puts clean_string(File.read(f))
      end
    end
  end
  File.open(app_path(".gitignore"), "w") do |f|
    f.puts File.read(template_path(".gitignore"))
  end
  rm app_path("Gemfile.lock")
  Dir[app_path("**", "*")].each do |file|
    if File.directory?(file)
      if Dir[File.join(file, "**", "*")].empty?
        File.open(File.join(file, ".git-keep"), 'w') {|f| f.puts ""}
      end
    end
  end
  FileUtils.cd app_path
  system "bundle"
  system "git init"
  system "git add ."
  system "git commit -a -m 'Initial Commit'"
end

#classifiedObject



17
18
19
# File 'lib/deano/commands/new_project_generator_command.rb', line 17

def classified
  "#{self.name.classify}App"
end