Class: Commandly::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/commandly/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



8
9
10
# File 'lib/commandly/generator.rb', line 8

def self.source_root
  File.dirname(__FILE__) + '/../../templates'
end

Instance Method Details

#copy_android_templatesObject



45
46
47
# File 'lib/commandly/generator.rb', line 45

def copy_android_templates
  directory "android", "android"
end

#copy_ios_templatesObject



12
13
14
# File 'lib/commandly/generator.rb', line 12

def copy_ios_templates
  directory "ios", "ios"
end

#find_replace_android_textObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/commandly/generator.rb', line 49

def find_replace_android_text
  project_name = File.basename(destination_root)
  files = Dir.glob(destination_root + "/android/**/**")
  files -= Dir.glob(destination_root + "/android/**/**/gradle-wrapper.jar")
  files -= Dir.glob(destination_root + "/android/**/**/*.png")
  files.each do |name|
    next if Dir.exists? name
    puts name
    text = File.read(name)
    text = text.gsub("Commandly", project_name)
    text = text.gsub("commandly", project_name.downcase)
    File.open(name, "w") { |file| file.puts text }
  end
end

#find_replace_ios_textObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/commandly/generator.rb', line 16

def find_replace_ios_text
  project_name = File.basename(destination_root)
  files = Dir.glob(destination_root + "/ios/**/**")
  files.each do |name|
    next if Dir.exists? name
    text = File.read(name)
    text = text.gsub("Commandly", project_name)
    File.open(name, "w") { |file| file.puts text }
  end
end

#rename_android_filesObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/commandly/generator.rb', line 64

def rename_android_files
  project_name = File.basename(destination_root)
  if Dir.exist? destination_root + "/android/app/src/androidTest/java/com/vuebly/commandly"
    File.rename(destination_root + "/android/app/src/androidTest/java/com/vuebly/commandly", destination_root + "/android/app/src/androidTest/java/com/vuebly/" + project_name.downcase)
  end
  if Dir.exist? destination_root + "/android/app/src/main/java/com/vuebly/commandly"
    File.rename(destination_root + "/android/app/src/main/java/com/vuebly/commandly", destination_root + "/android/app/src/main/java/com/vuebly/" + project_name.downcase)
  end
  if Dir.exist? destination_root + "/android/app/src/test/java/com/vuebly/commandly"
    File.rename(destination_root + "/android/app/src/test/java/com/vuebly/commandly", destination_root + "/android/app/src/test/java/com/vuebly/" + project_name.downcase)
  end
end

#rename_ios_filesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/commandly/generator.rb', line 27

def rename_ios_files
  project_name = File.basename(destination_root)
  if Dir.exist? destination_root + "/ios/Commandly.xcodeproj"
    File.rename(destination_root + "/ios/Commandly.xcodeproj", destination_root + "/ios/" + project_name + ".xcodeproj")
  end
  if Dir.exist? destination_root + "/ios/Commandly"
    File.rename(destination_root + "/ios/Commandly", destination_root + "/ios/" + project_name)
  end
  if Dir.exist? destination_root + "/ios/CommandlyTests"
    File.rename(destination_root + "/ios/CommandlyTests/CommandlyTests.m", destination_root + "/ios/CommandlyTests/" + project_name + "Tests.m")
    File.rename(destination_root + "/ios/CommandlyTests", destination_root + "/ios/" + project_name + "Tests")
  end
  if Dir.exist? destination_root + "/ios/CommandlyUITests"
    File.rename(destination_root + "/ios/CommandlyUITests/CommandlyUITests.m", "/ios/CommandlyTests/" + project_name + "UITests.m")
    File.rename(destination_root + "/ios/CommandlyUITests", destination_root + "/ios/" + project_name + "UITests")
  end
end