Class: Wordless::WordlessCLI

Inherits:
Object
  • Object
show all
Includes:
CLIHelper
Defined in:
lib/wordless/wordless_cli.rb

Defined Under Namespace

Modules: PATH

Constant Summary collapse

DEFAULT_PATHS =
{
  PATH::WORDFILE   => 'Wordfile',
  PATH::WP_CONTENT => 'wp-content',
  PATH::PLUGINS    => 'wp-content/plugins',
  PATH::THEMES     => 'wp-content/themes'
}.freeze
GLOBAL_NODE_MODULES =
%w[foreman yarn].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thor, options = {}) ⇒ WordlessCLI

Returns a new instance of WordlessCLI.



23
24
25
26
# File 'lib/wordless/wordless_cli.rb', line 23

def initialize(thor, options = {})
  @options = options
  @thor = thor
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/wordless/wordless_cli.rb', line 5

def options
  @options
end

#thorObject (readonly)

Returns the value of attribute thor.



5
6
7
# File 'lib/wordless/wordless_cli.rb', line 5

def thor
  @thor
end

Instance Method Details

#install_global_node_modulesObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/wordless/wordless_cli.rb', line 63

def install_global_node_modules
  info("Check for necessary global NPM packages")
  run_command('which npm') ||
    error("Node isn't installed. Head to https://nodejs.org/en/download/package-manager")

  global_node_modules = GLOBAL_NODE_MODULES.dup

  global_node_modules.reject! do |m|
    run_command("npm list -g #{m}")
  end

  if global_node_modules.empty?
    success("Global NPM packages needed by Wordless already installed. Good job!")
    return true
  end

  global_node_modules.each do |m|
    run_command("npm install -g #{m}") && success("Installed NPM package #{m} globally")
  end
  success("Done!")
end

#install_wordlessObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wordless/wordless_cli.rb', line 48

def install_wordless
  ensure_wp_cli_installed!

  info("Installing and activating plugin...")

  at_wordpress_root do
    error("Directory '#{plugins_path}' not found.") unless File.directory?(plugins_path)
    if run_command("wp plugin install wordless --activate")
      success("Done!")
    else
      error("There was an error installing and/or activating the Wordless plugin.")
    end
  end
end

#start(name) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/wordless/wordless_cli.rb', line 28

def start(name)
  install_global_node_modules
  install_wordpress_and_wp_cli(name)

  Dir.chdir(name)

  install_wordless
  create_and_activate_theme(name)
  set_permalinks

  Dir.chdir("wp-content/themes/#{name}")

  info("Installing theme's node modules...")
  run_command("yarn install") || error("Problem installing theme's node modules")

  success("All done! Now yor're ready to use Wordless with following commands:")
  info("`cd #{name}/wp-content/themes/#{name}`")
  info("`yarn run server`")
end