wordpress_tools 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c7a019519ee5592c3482dc69dfcf6786fdb1016
4
- data.tar.gz: 2ed984042fe8f127177e51c3ab74b99ab500aa64
3
+ metadata.gz: 4b158a3f54b8df76d7aaf093171982b26b83990f
4
+ data.tar.gz: fbfee8583490f2b38c77fef8456e33adacdc37d7
5
5
  SHA512:
6
- metadata.gz: 56d361c0f8545a6e46552442aef4bef6109e2c0b3b52f3c004977aca6987f980bf092d1a933ffe75115203ef53575a99a092417d2cb2370259df45d050b7d9c2
7
- data.tar.gz: 540e7784b4f7427fc20241d85158bd5ef5c5d07c0bc30837d2d0a76a9b53bc7eb5852f52120a2ebc3e600cebf3deb20d6a16684f0bf66bf56f87a97d668a0cfd
6
+ metadata.gz: b7bbbd7d500b569896c9541013eca7aa2d97685e34e8857b2bf806639312e5602d7a069c819bda2f1b514933f64941fac6d0b42e21b94d15a2265365f1224de6
7
+ data.tar.gz: a57fea0dd9ce145fd71aac30609b3de5008fa24cac695259e4aa4279a283c70e3509a3185abc4af951d72f046171bb5d0b533da360bb2866f79f65495d69d83a
data/.gitignore CHANGED
@@ -1,18 +1,14 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- .rvmrc
7
- .DS_Store
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec CHANGED
@@ -1 +1,2 @@
1
- -c
1
+ --color
2
+ --require spec_helper
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0-p247
1
+ 2.2.0
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 weLaika
1
+ Copyright (c) 2013-2015 weLaika
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # WordPress Tools
2
2
 
3
- A command line tool to help manage your WordPress sites.
3
+ A command line tool to help manage your WordPress sites in development.
4
+
5
+ [![Build Status](https://travis-ci.org/welaika/wordpress_tools.png?branch=master)](https://travis-ci.org/welaika/wordpress_tools)
4
6
 
5
7
  ## Installation
6
8
 
@@ -8,17 +10,39 @@ A command line tool to help manage your WordPress sites.
8
10
 
9
11
  ## Usage
10
12
 
11
- Create a new WordPress site in directory `mysite`. This downloads the latest stable release of WordPress (you can also specify a locale):
12
-
13
13
  wordpress new mysite
14
- wordpress new mysite --locale=fr_FR
14
+
15
+ It installs and configures [WP-CLI](http://wp-cli.org/), [WP-CLI/server-command](https://github.com/wp-cli/server-command) and, finally, the latest version of [WordPress](http://wordpress.org) in `mysite` directory.
15
16
 
16
17
  Get some help:
17
18
 
18
- wordpress help
19
+ wordpress help new
20
+
21
+ ```bash
22
+ Options:
23
+ -l, [--locale=LOCALE] # WordPress locale
24
+ # Default: en_US
25
+ -b, [--bare=BARE] # Remove default themes and plugins
26
+ [--admin-user=ADMIN_USER] # WordPress admin user
27
+ # Default: admin
28
+ [--admin-email=ADMIN_EMAIL] # WordPress admin email
29
+ # Default: admin@example.com
30
+ [--admin-password=ADMIN_PASSWORD] # WordPress admin password
31
+ # Default: password
32
+ [--db-user=DB_USER] # MySQL database user
33
+ # Default: root
34
+ [--db-password=DB_PASSWORD] # MySQL database pasword
35
+ [--site-url=SITE_URL] # Wordpress site URL
36
+ # Default: http://localhost:8080
37
+ ```
38
+
39
+ Example
40
+
41
+ wordpress new mysite --locale=it_IT --bare
19
42
 
20
43
  ## Caveats
21
44
 
45
+ - Default db-password is no password
22
46
  - If you attempt to download a WordPress localization that's outdated, the latest English version will be downloaded instead.
23
47
  - Not tested on Windows.
24
48
 
@@ -35,7 +59,7 @@ Get some help:
35
59
 
36
60
  (The MIT License)
37
61
 
38
- Copyright © 2013 weLaika
62
+ Copyright © 2013-2015 weLaika
39
63
 
40
64
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
41
65
 
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
- #!/usr/bin/env rake
2
-
3
1
  require "bundler/gem_tasks"
4
- require 'rspec/core/rake_task'
5
2
 
6
- RSpec::Core::RakeTask.new(:spec)
7
- task :default => :spec
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task default: :spec
7
+ rescue LoadError
8
+ # no rspec available
9
+ end
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wordpress_tools"
5
+ require "pry"
6
+
7
+ Pry.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/wordpress ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'wordpress_tools'
7
+
8
+ WordPressTools::CLI.start
@@ -1,16 +1,24 @@
1
- require 'thor'
2
- require 'wordpress_tools/wordpress_cli'
3
-
4
1
  module WordPressTools
5
2
  class CLI < Thor
6
- include Thor::Actions
3
+ include CLIHelper
7
4
 
8
5
  desc "new [DIR_NAME]", "download the latest stable version of WordPress in a new directory with specified name (default is wordpress)"
9
- method_option :locale, :aliases => "-l", :desc => "WordPress locale (default is en_US)"
10
- method_option :bare, :aliases => "-b", :desc => "Remove default themes and plugins"
11
-
6
+ add_method_options(shared_options)
12
7
  def new(dir_name = 'wordpress')
13
- WordPressCLI.new(options, dir_name, self).download!
8
+ if File.exist?(dir_name)
9
+ say "Directory #{dir_name} already exists.", :red
10
+ exit
11
+ end
12
+
13
+ info("Starting...")
14
+
15
+ WPCLICore.new.invoke :install
16
+ WPCLIServer.new.invoke :install
17
+ Database.new.invoke :create, [dir_name], options
18
+ WordPress.new.invoke :download, [dir_name], options
19
+ WordPress.new.invoke :setup, [dir_name], options
20
+
21
+ success("All done. Run 'wp server' inside '#{dir_name}' and visit '#{options[:site_url]}'")
14
22
  end
15
23
  end
16
24
  end
@@ -1,54 +1,70 @@
1
- require 'open-uri'
2
-
3
1
  module WordPressTools
4
2
  module CLIHelper
3
+ extend ActiveSupport::Concern
4
+ include Thor::Actions
5
+
6
+ class_methods do
7
+ def shared_options
8
+ [
9
+ [:locale, { aliases: "-l", desc: "WordPress locale", default: Configuration.for(:locale)}],
10
+ [:bare, {aliases: "-b", desc: "Remove default themes and plugins"}],
11
+ [:admin_user, { desc: "WordPress admin user", default: Configuration.for(:admin_user)}],
12
+ [:admin_email, {desc: "WordPress admin email", default: Configuration.for(:admin_email)}],
13
+ [:admin_password, {desc: "WordPress admin password", default: Configuration.for(:admin_password)}],
14
+ [:db_user, {desc: "MySQL database user", default: Configuration.for(:db_user)}],
15
+ [:db_password, {desc: "MySQL database pasword", default: Configuration.for(:db_password)}],
16
+ [:site_url, {desc: "Wordpress site URL", default: Configuration.for(:site_url)}]
17
+ ]
18
+ end
19
+
20
+ def add_method_options(options)
21
+ options.each do |option|
22
+ method_option(*option)
23
+ end
24
+ end
25
+ end
26
+
5
27
  def info(message)
6
- log_message message
28
+ say message
7
29
  end
8
30
 
9
31
  def error(message)
10
- log_message message, :red
32
+ say message, :red
11
33
  exit
12
34
  end
13
35
 
14
36
  def success(message)
15
- log_message message, :green
37
+ say message, :green
16
38
  end
17
39
 
18
40
  def warning(message)
19
- log_message message, :yellow
41
+ say message, :yellow
20
42
  end
21
43
 
22
- def download(url, destination)
23
- begin
24
- f = open(destination, "wb")
25
- f.write(open(url).read) ? true : false
26
- rescue
27
- false
28
- ensure
29
- f.close
30
- end
44
+ def git_installed?
45
+ run_command("git --version")
31
46
  end
32
47
 
33
- def unzip(file, destination)
34
- run_command "unzip #{file} -d #{destination}"
48
+ def unzip(file, destination, extra_options = '')
49
+ run_command("unzip #{extra_options} #{file} -d #{destination}")
35
50
  end
36
51
 
37
- def git_installed?
38
- # http://stackoverflow.com/questions/4597490/platform-independent-way-of-detecting-if-git-is-installed
39
- void = RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null'
40
- system "git --version >>#{void} 2>&1"
52
+ def move_command(from, to, need_sudo = false)
53
+ sudo = 'sudo' if need_sudo
54
+ "#{sudo} mv '#{from}' '#{to}'"
41
55
  end
42
56
 
43
- private
57
+ def executable_bit_command(path, need_sudo = false)
58
+ sudo = 'sudo' if need_sudo
59
+ "#{sudo} chmod 755 '#{path}'"
60
+ end
44
61
 
45
- def log_message(message, color = nil)
46
- say message, color
62
+ def void
63
+ RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null'
47
64
  end
48
65
 
49
66
  def run_command(command)
50
- run command, verbose: false, capture: true
67
+ system("#{command} >>#{void} 2>&1")
51
68
  end
52
-
53
69
  end
54
70
  end
@@ -0,0 +1,24 @@
1
+ module WordPressTools
2
+ class Configuration
3
+
4
+ DEFAULT_CONFIG = {
5
+ wp_cli_download_url: "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar",
6
+ wp_cli_path: "/usr/local/bin/wp",
7
+ wp_cli_config_path: "~/.wp-cli/config.yml",
8
+ wp_server_download_url: "https://github.com/wp-cli/server-command/archive/master.zip",
9
+ wp_server_directory: "~/.wp-cli/commands/server",
10
+ admin_user: "admin",
11
+ admin_email: "admin@example.com",
12
+ admin_password: "password",
13
+ db_user: "root",
14
+ db_password: "",
15
+ site_url: "http://localhost:8080",
16
+ locale: "en_US"
17
+ }.freeze
18
+
19
+ def self.for(key)
20
+ DEFAULT_CONFIG[key]
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ module WordPressTools
2
+ class Database < Thor
3
+ include CLIHelper
4
+
5
+ attr_reader :db_name
6
+
7
+ desc "create [DB_NAME]", "create MySQL database for WordPress"
8
+ add_method_options(shared_options)
9
+ def create(db_name = "wordpress")
10
+ @db_name = db_name
11
+
12
+ info("Creating database '#{db_name}'...")
13
+ test_login
14
+ create_database
15
+ success("Database #{db_name} created")
16
+ end
17
+
18
+ no_tasks do
19
+ def create_database
20
+ run_command(mysql_create_command) || error("Cannot create database '#{db_name}'. Already exists?")
21
+ end
22
+
23
+ def test_login
24
+ run_command("#{mysql_command} --execute='QUIT'") || error("Cannot login to MySQL. Wrong credentials?")
25
+ end
26
+
27
+ def mysql_create_command
28
+ "#{mysql_command} --execute='CREATE DATABASE #{db_name}'"
29
+ end
30
+
31
+ def mysql_command
32
+ "mysql --user='#{db_user}' --password='#{db_password}'"
33
+ end
34
+
35
+ def db_user
36
+ options[:db_user]
37
+ end
38
+
39
+ def db_password
40
+ options[:db_password]
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module WordPressTools
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,90 @@
1
+ module WordPressTools
2
+ class WordPress < Thor
3
+ include CLIHelper
4
+
5
+ attr_reader :dir_name
6
+
7
+ desc "download [DIR_NAME]", "download WordPress"
8
+ add_method_options(shared_options)
9
+ def download(dir_name = "wordpress")
10
+ @dir_name = dir_name
11
+
12
+ download_wordpress
13
+ configure_bare
14
+ initialize_git_repo
15
+ end
16
+
17
+ desc "setup [DIR_NAME]", "automatic '5 minutes' installation"
18
+ add_method_options(shared_options)
19
+ def setup(dir_name = "wordpress")
20
+ @dir_name = dir_name
21
+
22
+ inside(dir_name) do
23
+ create_wp_config_file
24
+ install
25
+ end
26
+ end
27
+
28
+ no_tasks do
29
+ def tempfile
30
+ @tempfile ||= Tempfile.new('wordpress')
31
+ end
32
+
33
+ def download_wordpress
34
+ download_url, version, locale = Net::HTTP.get('api.wordpress.org', "/core/version-check/1.5/?locale=#{options[:locale]}").split[2,3]
35
+
36
+ info("Downloading WordPress #{version} (#{locale})...")
37
+ get(download_url, tempfile.path, force: true, verbose: false) || error("Could not download WordPress")
38
+ unzip(tempfile.path, dir_name) || error("Could not unzip WordPress")
39
+ remove_nested_subdirectory
40
+
41
+ success("Downloaded WordPress in directory '#{dir_name}'")
42
+ end
43
+
44
+ def remove_nested_subdirectory
45
+ subdirectory = Dir["#{dir_name}/*/"].first # This is probably 'wordpress', but don't assume
46
+ FileUtils.mv Dir["#{subdirectory}*"], dir_name # Remove unnecessary directory level
47
+ Dir.delete subdirectory
48
+ end
49
+
50
+ def configure_bare
51
+ if options[:bare]
52
+ info("Removing default themes and plugins...")
53
+ dirs = %w(themes plugins).map {|d| "#{dir_name}/wp-content/#{d}"}
54
+ FileUtils.rm_rf dirs
55
+ FileUtils.mkdir dirs
56
+ dirs.each do |dir|
57
+ FileUtils.cp "#{dir_name}/wp-content/index.php", dir
58
+ end
59
+ success("Removed default themes and plugins")
60
+ end
61
+ end
62
+
63
+ def initialize_git_repo
64
+ info("Initializing git repository...")
65
+ if git_installed?
66
+ if run_command("cd #{dir_name} && git init")
67
+ success("Initialized git repository")
68
+ else
69
+ error("Could not initialize git repository")
70
+ end
71
+ else
72
+ warning("Could not find git installation")
73
+ end
74
+ end
75
+
76
+ def create_wp_config_file
77
+ db_password = options[:db_password].present? ? "--dbpass='#{options[:db_password]}'" : ""
78
+ info("Creating 'wp-config.php' file...")
79
+ run_command("wp core config --dbname='#{dir_name}' --dbuser='#{options[:db_user]}' #{db_password} --locale='#{options[:locale]}'") || error("Cannot create 'wp-config.php' file")
80
+ success("Created 'wp-config.php' file")
81
+ end
82
+
83
+ def install
84
+ info("Running the 5 minutes installation...")
85
+ run_command("wp core install --url='#{options[:site_url]}' --title='#{dir_name}' --admin_user='#{options[:admin_user]}' --admin_password='#{options[:admin_password]}' --admin_email='#{options[:admin_email]}'") || error("Cannot finish the 5-minutes installation")
86
+ success("Finished the 5 minutes installation")
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,74 @@
1
+ module WordPressTools
2
+ class WPCLICore < Thor
3
+ include CLIHelper
4
+
5
+ desc "install", ""
6
+ def install
7
+ return unless overwrite?
8
+
9
+ download
10
+ move
11
+ make_executable
12
+
13
+ if installed?
14
+ success "WP-CLI installed"
15
+ else
16
+ error "Could not install WP-CLI"
17
+ end
18
+ end
19
+
20
+ no_tasks do
21
+ def overwrite?
22
+ if installed?
23
+ yes? "WP-CLI already installed [#{install_path}]. Do you want to overwite it? [y]es, [N]o"
24
+ else
25
+ true
26
+ end
27
+ end
28
+
29
+ def installed?
30
+ run_command("which wp")
31
+ end
32
+
33
+ def download
34
+ info("Downloading WP-CLI...")
35
+ get(download_url, download_path, verbose: false, force: true) || error("Cannot download WP-CLI")
36
+ success("Downloaded WP-CLI")
37
+ end
38
+
39
+ def move
40
+ info("Installing WP-CLI...")
41
+ need_sudo = !File.writable?(install_dir)
42
+ run_command(move_command(download_path, install_path, need_sudo)) || error("Cannot install WP-CLI in '#{install_path}'")
43
+ success("Installed WP-CLI in '#{install_path}'")
44
+ end
45
+
46
+ def make_executable
47
+ info("Making WP-CLI executable...")
48
+ need_sudo = !File.writable?(install_dir)
49
+ run_command(executable_bit_command(install_path, need_sudo)) || error("Cannot make WP-CLI executable")
50
+ success("WP-CLI is now executable")
51
+ end
52
+
53
+ def download_url
54
+ Configuration.for(:wp_cli_download_url)
55
+ end
56
+
57
+ def download_path
58
+ @download_path ||= Tempfile.new('wp_cli').path
59
+ end
60
+
61
+ def install_path
62
+ if installed?
63
+ run("which wp", verbose: false, capture: true).strip
64
+ else
65
+ Configuration.for(:wp_cli_path)
66
+ end
67
+ end
68
+
69
+ def install_dir
70
+ File.dirname(install_path)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,65 @@
1
+ module WordPressTools
2
+ class WPCLIServer < Thor
3
+ include CLIHelper
4
+
5
+ desc "install", ""
6
+ def install
7
+ return unless overwrite?
8
+
9
+ remove_existing
10
+ download
11
+ configure
12
+ end
13
+
14
+ no_tasks do
15
+ def overwrite?
16
+ if installed?
17
+ yes? "WP-CLI server command already installed [#{install_dir}]. Do you want to overwite it? [y]es, [N]o"
18
+ else
19
+ true
20
+ end
21
+ end
22
+
23
+ def installed?
24
+ File.exist?(File.join(install_dir, 'command.php'))
25
+ end
26
+
27
+ def remove_existing
28
+ FileUtils.rm_rf([install_dir, wp_cli_config_path])
29
+ end
30
+
31
+ def download
32
+ info("Installing WP-CLI server command...")
33
+ get(download_url, download_path, verbose: false, force: true) || error("Cannot download WP-CLI server command")
34
+
35
+ FileUtils.mkdir_p(install_dir)
36
+ unzip(download_path, install_dir, "-j")
37
+
38
+ success("Installed WP-CLI server command in '#{install_dir}'")
39
+ end
40
+
41
+ def configure
42
+ info("Configuring WP-CLI server command...")
43
+ FileUtils.mkdir_p(File.dirname(wp_cli_config_path))
44
+ FileUtils.cp(File.expand_path("../../../templates/wp_cli_config.yml", __FILE__), wp_cli_config_path)
45
+ success("WP-CLI server command configured")
46
+ end
47
+
48
+ def download_url
49
+ Configuration.for(:wp_server_download_url)
50
+ end
51
+
52
+ def install_dir
53
+ @install_dir ||= File.expand_path(Configuration.for(:wp_server_directory))
54
+ end
55
+
56
+ def download_path
57
+ @download_path ||= Tempfile.new('wp_server').path
58
+ end
59
+
60
+ def wp_cli_config_path
61
+ File.expand_path(Configuration.for(:wp_cli_config_path))
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1 +1,14 @@
1
+ require "tempfile"
2
+ require "net/http"
3
+ require "thor"
4
+ require "active_support"
5
+ require "active_support/all"
6
+
1
7
  require "wordpress_tools/version"
8
+ require "wordpress_tools/config"
9
+ require "wordpress_tools/cli_helper"
10
+ require "wordpress_tools/cli"
11
+ require "wordpress_tools/wordpress"
12
+ require "wordpress_tools/wp_cli_core"
13
+ require "wordpress_tools/wp_cli_server"
14
+ require "wordpress_tools/database"
@@ -0,0 +1,2 @@
1
+ require:
2
+ - commands/server/command.php
@@ -1,23 +1,32 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/wordpress_tools/version', __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "wordpress_tools/version"
3
5
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Étienne Després", "Ju Liu"]
6
- gem.email = ["etienne@molotov.ca", "ju.liu@welaika.com"]
7
- gem.description = %q{Command line tool to manage WordPress installations.}
8
- gem.summary = %q{Manage WordPress installations.}
9
- gem.homepage = "http://github.com/welaika/wordpress_tools"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wordpress_tools"
8
+ spec.version = WordPressTools::VERSION
9
+ spec.authors = ["Étienne Després", "Alessandro Fazzi", "Filippo Gangi Dino", "Ju Liu", "Fabrizio Monti"]
10
+ spec.email = ["etienne@molotov.ca", "alessandro.fazzi@welaika.com", "filippo.gangidino@welaika.com", "ju.liu@welaika.com", "fabrizio.monti@welaika.com"]
11
+ spec.summary = %q{Manage WordPress installations.}
12
+ spec.description = %q{Command line tool to manage WordPress installations.}
13
+ spec.homepage = "http://github.com/welaika/wordpress_tools"
14
+ spec.license = "MIT"
10
15
 
11
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
- gem.files = `git ls-files`.split("\n")
13
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
- gem.name = "wordpress_tools"
15
- gem.require_paths = ["lib"]
16
- gem.version = WordPressTools::VERSION
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
17
20
 
18
- gem.add_dependency "rake"
19
- gem.add_dependency "thor"
21
+ spec.required_ruby_version = ">= 2.1.2"
20
22
 
21
- gem.add_development_dependency 'rspec'
22
- gem.add_development_dependency 'fakeweb'
23
+ spec.add_dependency "thor", "~> 0.19.1"
24
+ spec.add_dependency "activesupport", "~> 4.2"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.4"
28
+ spec.add_development_dependency "rspec", "~> 3.2"
29
+ spec.add_development_dependency "fakeweb", "~> 1.3"
30
+ spec.add_development_dependency "pry-byebug", "~> 3.0"
31
+ spec.add_development_dependency "priscilla", "~> 1.0"
23
32
  end
metadata CHANGED
@@ -1,104 +1,170 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordpress_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Étienne Després
7
+ - "Étienne Després"
8
+ - Alessandro Fazzi
9
+ - Filippo Gangi Dino
8
10
  - Ju Liu
11
+ - Fabrizio Monti
9
12
  autorequire:
10
- bindir: bin
13
+ bindir: exe
11
14
  cert_chain: []
12
- date: 2013-08-30 00:00:00.000000000 Z
15
+ date: 2015-02-20 00:00:00.000000000 Z
13
16
  dependencies:
14
17
  - !ruby/object:Gem::Dependency
15
- name: rake
18
+ name: thor
16
19
  requirement: !ruby/object:Gem::Requirement
17
20
  requirements:
18
- - - '>='
21
+ - - "~>"
19
22
  - !ruby/object:Gem::Version
20
- version: '0'
23
+ version: 0.19.1
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - '>='
28
+ - - "~>"
26
29
  - !ruby/object:Gem::Version
27
- version: '0'
30
+ version: 0.19.1
28
31
  - !ruby/object:Gem::Dependency
29
- name: thor
32
+ name: activesupport
30
33
  requirement: !ruby/object:Gem::Requirement
31
34
  requirements:
32
- - - '>='
35
+ - - "~>"
33
36
  - !ruby/object:Gem::Version
34
- version: '0'
37
+ version: '4.2'
35
38
  type: :runtime
36
39
  prerelease: false
37
40
  version_requirements: !ruby/object:Gem::Requirement
38
41
  requirements:
39
- - - '>='
42
+ - - "~>"
40
43
  - !ruby/object:Gem::Version
41
- version: '0'
44
+ version: '4.2'
45
+ - !ruby/object:Gem::Dependency
46
+ name: bundler
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: '1.8'
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '1.8'
59
+ - !ruby/object:Gem::Dependency
60
+ name: rake
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '10.4'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '10.4'
42
73
  - !ruby/object:Gem::Dependency
43
74
  name: rspec
44
75
  requirement: !ruby/object:Gem::Requirement
45
76
  requirements:
46
- - - '>='
77
+ - - "~>"
47
78
  - !ruby/object:Gem::Version
48
- version: '0'
79
+ version: '3.2'
49
80
  type: :development
50
81
  prerelease: false
51
82
  version_requirements: !ruby/object:Gem::Requirement
52
83
  requirements:
53
- - - '>='
84
+ - - "~>"
54
85
  - !ruby/object:Gem::Version
55
- version: '0'
86
+ version: '3.2'
56
87
  - !ruby/object:Gem::Dependency
57
88
  name: fakeweb
58
89
  requirement: !ruby/object:Gem::Requirement
59
90
  requirements:
60
- - - '>='
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '1.3'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '1.3'
101
+ - !ruby/object:Gem::Dependency
102
+ name: pry-byebug
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
61
106
  - !ruby/object:Gem::Version
62
- version: '0'
107
+ version: '3.0'
63
108
  type: :development
64
109
  prerelease: false
65
110
  version_requirements: !ruby/object:Gem::Requirement
66
111
  requirements:
67
- - - '>='
112
+ - - "~>"
68
113
  - !ruby/object:Gem::Version
69
- version: '0'
114
+ version: '3.0'
115
+ - !ruby/object:Gem::Dependency
116
+ name: priscilla
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '1.0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '1.0'
70
129
  description: Command line tool to manage WordPress installations.
71
130
  email:
72
131
  - etienne@molotov.ca
132
+ - alessandro.fazzi@welaika.com
133
+ - filippo.gangidino@welaika.com
73
134
  - ju.liu@welaika.com
135
+ - fabrizio.monti@welaika.com
74
136
  executables:
75
137
  - wordpress
76
138
  extensions: []
77
139
  extra_rdoc_files: []
78
140
  files:
79
- - .gitignore
80
- - .rspec
81
- - .ruby-version
82
- - .travis.yml
141
+ - ".gitignore"
142
+ - ".rspec"
143
+ - ".ruby-version"
144
+ - ".travis.yml"
83
145
  - Gemfile
84
- - Gemfile.lock
85
146
  - LICENSE
86
147
  - README.md
87
148
  - Rakefile
88
- - bin/wordpress
149
+ - bin/console
150
+ - bin/rake
151
+ - bin/rspec
152
+ - bin/setup
153
+ - exe/wordpress
89
154
  - lib/wordpress_tools.rb
90
155
  - lib/wordpress_tools/cli.rb
91
156
  - lib/wordpress_tools/cli_helper.rb
157
+ - lib/wordpress_tools/config.rb
158
+ - lib/wordpress_tools/database.rb
92
159
  - lib/wordpress_tools/version.rb
93
- - lib/wordpress_tools/wordpress_cli.rb
94
- - spec/cli_helper_spec.rb
95
- - spec/cli_spec.rb
96
- - spec/fixtures/wordpress_stub.zip
97
- - spec/fixtures/zipped_file.zip
98
- - spec/spec_helper.rb
160
+ - lib/wordpress_tools/wordpress.rb
161
+ - lib/wordpress_tools/wp_cli_core.rb
162
+ - lib/wordpress_tools/wp_cli_server.rb
163
+ - templates/wp_cli_config.yml
99
164
  - wordpress_tools.gemspec
100
165
  homepage: http://github.com/welaika/wordpress_tools
101
- licenses: []
166
+ licenses:
167
+ - MIT
102
168
  metadata: {}
103
169
  post_install_message:
104
170
  rdoc_options: []
@@ -106,23 +172,18 @@ require_paths:
106
172
  - lib
107
173
  required_ruby_version: !ruby/object:Gem::Requirement
108
174
  requirements:
109
- - - '>='
175
+ - - ">="
110
176
  - !ruby/object:Gem::Version
111
- version: '0'
177
+ version: 2.1.2
112
178
  required_rubygems_version: !ruby/object:Gem::Requirement
113
179
  requirements:
114
- - - '>='
180
+ - - ">="
115
181
  - !ruby/object:Gem::Version
116
182
  version: '0'
117
183
  requirements: []
118
184
  rubyforge_project:
119
- rubygems_version: 2.0.3
185
+ rubygems_version: 2.4.5
120
186
  signing_key:
121
187
  specification_version: 4
122
188
  summary: Manage WordPress installations.
123
- test_files:
124
- - spec/cli_helper_spec.rb
125
- - spec/cli_spec.rb
126
- - spec/fixtures/wordpress_stub.zip
127
- - spec/fixtures/zipped_file.zip
128
- - spec/spec_helper.rb
189
+ test_files: []
data/Gemfile.lock DELETED
@@ -1,30 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- wordpress_tools (0.0.2)
5
- rake
6
- thor
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- diff-lcs (1.2.4)
12
- fakeweb (1.3.0)
13
- rake (10.1.0)
14
- rspec (2.14.1)
15
- rspec-core (~> 2.14.0)
16
- rspec-expectations (~> 2.14.0)
17
- rspec-mocks (~> 2.14.0)
18
- rspec-core (2.14.5)
19
- rspec-expectations (2.14.2)
20
- diff-lcs (>= 1.1.3, < 2.0)
21
- rspec-mocks (2.14.3)
22
- thor (0.18.1)
23
-
24
- PLATFORMS
25
- ruby
26
-
27
- DEPENDENCIES
28
- fakeweb
29
- rspec
30
- wordpress_tools!
data/bin/wordpress DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'wordpress_tools/cli'
4
- WordPressTools::CLI.start
@@ -1,76 +0,0 @@
1
- require 'tempfile'
2
- require 'net/http'
3
- require 'wordpress_tools/cli_helper'
4
-
5
- module WordPressTools
6
- class WordPressCLI
7
- include WordPressTools::CLIHelper
8
- attr_reader :options, :dir_name, :thor
9
-
10
- [ :say, :run ].each do |sym|
11
- define_method sym do |*args|
12
- thor.send(sym, *args)
13
- end
14
- end
15
-
16
- def initialize(options = {}, dir_name = 'wordpress', thor = nil)
17
- @options = options
18
- @dir_name = dir_name
19
- @thor = thor
20
- end
21
-
22
- def download!
23
- download_wordpress
24
- configure_bare_install
25
- initialize_git_repo
26
- end
27
-
28
- private
29
-
30
- def tempfile
31
- @tempfile ||= Tempfile.new('wordpress')
32
- end
33
-
34
- def download_wordpress
35
- download_url, version, locale = Net::HTTP.get('api.wordpress.org', "/core/version-check/1.5/?locale=#{options[:locale]}").split[2,3]
36
-
37
- info "Downloading WordPress #{version} (#{locale})..."
38
- download(download_url, tempfile.path) || error("Could not download WordPress.")
39
- unzip(tempfile.path, dir_name) || error("Could not unzip WordPress.")
40
- remove_nested_subdirectory
41
-
42
- success %Q{Installed WordPress in directory "#{dir_name}".}
43
- end
44
-
45
- def remove_nested_subdirectory
46
- subdirectory = Dir["#{dir_name}/*/"].first # This is probably 'wordpress', but don't assume
47
- FileUtils.mv Dir["#{subdirectory}*"], dir_name # Remove unnecessary directory level
48
- Dir.delete subdirectory
49
- end
50
-
51
- def configure_bare_install
52
- if options[:bare]
53
- dirs = %w(themes plugins).map {|d| "#{dir_name}/wp-content/#{d}"}
54
- FileUtils.rm_rf dirs
55
- FileUtils.mkdir dirs
56
- dirs.each do |dir|
57
- FileUtils.cp "#{dir_name}/wp-content/index.php", dir
58
- end
59
- success "Removed default themes and plugins."
60
- end
61
- end
62
-
63
- def initialize_git_repo
64
- if git_installed?
65
- if run_command "cd #{dir_name} && git init"
66
- success "Initialized git repository."
67
- else
68
- error "Could not initialize git repository."
69
- end
70
- else
71
- warning "Could not find git installation."
72
- end
73
- end
74
-
75
- end
76
- end
@@ -1,75 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WordPressTools::CLIHelper do
4
- let(:cli) { WordPressTools::WordPressCLI.new }
5
-
6
- context "::download" do
7
- let(:valid_url) { "http://www.example.com/test" }
8
- let(:tempfile) { Tempfile.new("download_test") }
9
-
10
- before(:each) do
11
- FakeWeb.register_uri(:get, valid_url, :body => "Download test")
12
- end
13
-
14
- it "downloads a file to the specified location" do
15
- cli.download(valid_url, tempfile.path)
16
- open(tempfile.path).read.should eq("Download test")
17
- end
18
-
19
- it "returns true on success" do
20
- cli.download(valid_url, tempfile.path).should eq true
21
- end
22
-
23
- it "returns false on failure" do
24
- cli.download("http://an.invalid.url", tempfile.path).should eq false
25
- end
26
- end
27
-
28
- context "::unzip" do
29
- let(:path) { File.expand_path('spec/fixtures/zipped_file.zip') }
30
- let(:destination) { "tmp/unzip" }
31
-
32
- it "unzips a file" do
33
- cli.should_receive(:run_command).with("unzip #{path} -d #{destination}")
34
- cli.unzip(path, destination)
35
- end
36
- end
37
-
38
- context "::info" do
39
- let(:message) { "I am an info" }
40
-
41
- it "displays an info" do
42
- cli.should_receive(:log_message).with(message)
43
- cli.info(message)
44
- end
45
- end
46
-
47
- context "::error" do
48
- let(:message) { "I am an error" }
49
-
50
- it "displays an error" do
51
- cli.should_receive(:log_message).with(message, :red)
52
- cli.should_receive(:exit)
53
- cli.error(message)
54
- end
55
- end
56
-
57
- context "::success" do
58
- let(:message) { "I am a success message" }
59
-
60
- it "displays a success message" do
61
- cli.should_receive(:log_message).with(message, :green)
62
- cli.success(message)
63
- end
64
- end
65
-
66
- context "::warning" do
67
- let(:message) { "I am a warning" }
68
-
69
- it "displays a warning" do
70
- cli.should_receive(:log_message).with(message, :yellow)
71
- cli.warning(message)
72
- end
73
- end
74
- end
75
-
data/spec/cli_spec.rb DELETED
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WordPressTools::CLI do
4
- before do
5
- @original_wd = Dir.pwd
6
- Dir.chdir('tmp')
7
- end
8
-
9
- after do
10
- Dir.chdir(@original_wd)
11
- Dir["tmp/*"].each do |dir|
12
- FileUtils.rm_rf(dir) if File.directory? dir
13
- end
14
- end
15
-
16
- context "#new" do
17
- context "with no arguments" do
18
- it "downloads WordPress and initializes a git repo" do
19
- WordPressTools::CLI.start ['new']
20
- File.exists?('wordpress/wp-content/index.php').should eq true
21
- File.directory?('wordpress/wordpress').should eq false
22
- File.directory?('wordpress/.git').should eq true
23
- end
24
- end
25
-
26
- context "with a custom directory name" do
27
- it "downloads a copy of WordPress in directory 'myapp'" do
28
- WordPressTools::CLI.start ['new', 'myapp']
29
- File.exists?('myapp/wp-content/index.php').should eq true
30
- end
31
- end
32
-
33
- context "with the 'bare' option" do
34
- it "downloads a copy of WordPress and removes default plugins and themes" do
35
- WordPressTools::CLI.start ['new', '--bare']
36
- (File.exists?('wordpress/wp-content/plugins/hello.php') || File.directory?('wordpress/wp-content/themes/twentyeleven')).should eq false
37
- end
38
- end
39
- end
40
- end
41
-
Binary file
Binary file
data/spec/spec_helper.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'wordpress_tools/cli'
2
- require 'fakeweb'
3
- require 'thor'
4
-
5
- RSpec.configure do |config|
6
- $stdout = StringIO.new
7
- FileUtils.mkdir('tmp') unless File.directory? 'tmp'
8
-
9
- FakeWeb.allow_net_connect = false
10
- WP_API_RESPONSE = <<-eof
11
- upgrade
12
- http://wordpress.org/download/
13
- http://wordpress.org/wordpress-3.6.zip
14
- 3.6
15
- en_US
16
- 5.2.4
17
- 5.0
18
- eof
19
- FakeWeb.register_uri(:get, %r|http://api.wordpress.org/core/version-check/1.5/.*|, :body => WP_API_RESPONSE)
20
- FakeWeb.register_uri(:get, "http://wordpress.org/wordpress-3.6.zip", :body => File.expand_path('spec/fixtures/wordpress_stub.zip'))
21
-
22
- def capture(stream)
23
- begin
24
- stream = stream.to_s
25
- eval "$#{stream} = StringIO.new"
26
- yield
27
- result = eval("$#{stream}").string
28
- ensure
29
- eval("$#{stream} = #{stream.upcase}")
30
- end
31
- result
32
- end
33
- end
34
-