Class: Wordless::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/wordless/cli.rb

Instance Method Summary collapse

Instance Method Details

#installObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wordless/cli.rb', line 58

def install
  unless git_installed?
    puts "Git is not available. Please install git.".red
    return
  end

  unless File.directory? 'wp-content/plugins'
    puts "Directory 'wp-content/plugins' not found. Make sure you're at the root level of a WordPress installation.".red
    return
  end

  if system "git submodule add git://github.com/welaika/wordless.git wp-content/plugins/wordless && git submodule init && git submodule update"
    puts "Installed Wordless plugin.".green
  end
end

#new(name) ⇒ Object



53
54
55
# File 'lib/wordless/cli.rb', line 53

def new(name)
  # upcoming
end

#wp(dir_name = 'wordpress') ⇒ Object



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
# File 'lib/wordless/cli.rb', line 12

def wp(dir_name = 'wordpress')
  download_url, version, locale = Net::HTTP.get('api.wordpress.org', "/core/version-check/1.5/?locale=#{options[:locale]}").split[2,3]
  downloaded_file = Tempfile.new('wordpress')
  begin
    puts "Downloading WordPress #{version} (#{locale})..."
    `curl #{download_url} > #{downloaded_file.path} && unzip #{downloaded_file.path} -d #{dir_name}`
    subdirectory = Dir["#{dir_name}/*/"].first # This is probably 'wordpress', but don't assume
    FileUtils.mv Dir["#{subdirectory}*"], dir_name # Remove unnecessary directory level
    FileUtils.rmdir subdirectory
  ensure
     downloaded_file.close
     downloaded_file.unlink
  end
  
  puts %Q{Installed WordPress in directory "#{dir_name}".}.green
  
  if options[:bare]
    dirs = %w(themes plugins).map {|d| "#{dir_name}/wp-content/#{d}"}
    FileUtils.rm_rf dirs
    FileUtils.mkdir dirs
    dirs.each do |dir|
      FileUtils.cp "#{dir_name}/wp-content/index.php", dir
    end
    puts "Removed default themes and plugins.".green
  end
  
  # http://stackoverflow.com/questions/4597490/platform-independent-way-of-detecting-if-git-is-installed
  void = RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null'
  if git_installed?
    if system 'git init'
      puts "Initialized git repository.".green
    else
      puts "Couldn't initialize git repository.".red
    end
  else
    puts "Didn't initialize git repository because git isn't installed.".yellow
  end
end