wordpress_tools 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +22 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/bin/wordpress +4 -0
- data/lib/wordpress_tools.rb +1 -0
- data/lib/wordpress_tools/cli.rb +65 -0
- data/lib/wordpress_tools/cli_helper.rb +42 -0
- data/lib/wordpress_tools/version.rb +3 -0
- data/spec/cli_helper_spec.rb +68 -0
- data/spec/cli_spec.rb +59 -0
- data/spec/fixtures/wordpress_stub.zip +0 -0
- data/spec/fixtures/zipped_file.zip +0 -0
- data/spec/spec_helper.rb +43 -0
- data/wordless.gemspec +22 -0
- metadata +102 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-c
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wordpress_tools (0.0.1)
|
5
|
+
thor
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
fakeweb (1.3.0)
|
12
|
+
rspec (2.8.0)
|
13
|
+
rspec-core (~> 2.8.0)
|
14
|
+
rspec-expectations (~> 2.8.0)
|
15
|
+
rspec-mocks (~> 2.8.0)
|
16
|
+
rspec-core (2.8.0)
|
17
|
+
rspec-expectations (2.8.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.8.0)
|
20
|
+
thor (0.14.6)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
fakeweb
|
27
|
+
rspec
|
28
|
+
wordpress_tools!
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Étienne Després
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# WordPress Tools
|
2
|
+
|
3
|
+
A command line tool to help manage your WordPress sites.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install wordpress_tools
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
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
|
+
wordpress new mysite
|
14
|
+
wordpress new mysite --locale=fr_FR
|
15
|
+
|
16
|
+
Get some help:
|
17
|
+
|
18
|
+
wordpress help
|
19
|
+
|
20
|
+
## Caveats
|
21
|
+
|
22
|
+
- If you attempt to download a WordPress localization that's outdated, the latest English version will be downloaded instead.
|
23
|
+
- Only tested on Mac OS X
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Add some specs
|
30
|
+
4. Commit your changes (`git commit -am 'Added some feature'`)
|
31
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/wordpress
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "wordpress_tools/version"
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'thor'
|
2
|
+
# require 'thor/shell/basic'
|
3
|
+
require 'net/http'
|
4
|
+
require 'rbconfig'
|
5
|
+
require 'tempfile'
|
6
|
+
require 'wordpress_tools/cli_helper'
|
7
|
+
|
8
|
+
module WordPressTools
|
9
|
+
class CLI < Thor
|
10
|
+
include Thor::Actions
|
11
|
+
include WordPressTools::CLIHelper
|
12
|
+
|
13
|
+
@@lib_dir = File.expand_path(File.dirname(__FILE__))
|
14
|
+
|
15
|
+
desc "new [DIR_NAME]", "download the latest stable version of WordPress in a new directory with specified name (default is wordpress)"
|
16
|
+
method_option :locale, :aliases => "-l", :desc => "WordPress locale (default is en_US)"
|
17
|
+
method_option :bare, :aliases => "-b", :desc => "Remove default themes and plugins"
|
18
|
+
def new(dir_name = 'wordpress')
|
19
|
+
download_url, version, locale = Net::HTTP.get('api.wordpress.org', "/core/version-check/1.5/?locale=#{options[:locale]}").split[2,3]
|
20
|
+
downloaded_file = Tempfile.new('wordpress')
|
21
|
+
begin
|
22
|
+
puts "Downloading WordPress #{version} (#{locale})..."
|
23
|
+
|
24
|
+
unless download(download_url, downloaded_file.path)
|
25
|
+
error "Couldn't download WordPress."
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
unless unzip(downloaded_file.path, dir_name)
|
30
|
+
error "Couldn't unzip WordPress."
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
subdirectory = Dir["#{dir_name}/*/"].first # This is probably 'wordpress', but don't assume
|
35
|
+
FileUtils.mv Dir["#{subdirectory}*"], dir_name # Remove unnecessary directory level
|
36
|
+
Dir.delete subdirectory
|
37
|
+
ensure
|
38
|
+
downloaded_file.close
|
39
|
+
downloaded_file.unlink
|
40
|
+
end
|
41
|
+
|
42
|
+
success %Q{Installed WordPress in directory "#{dir_name}".}
|
43
|
+
|
44
|
+
if options[:bare]
|
45
|
+
dirs = %w(themes plugins).map {|d| "#{dir_name}/wp-content/#{d}"}
|
46
|
+
FileUtils.rm_rf dirs
|
47
|
+
FileUtils.mkdir dirs
|
48
|
+
dirs.each do |dir|
|
49
|
+
FileUtils.cp "#{dir_name}/wp-content/index.php", dir
|
50
|
+
end
|
51
|
+
success "Removed default themes and plugins."
|
52
|
+
end
|
53
|
+
|
54
|
+
if git_installed?
|
55
|
+
if run "cd #{dir_name} && git init", :verbose => false, :capture => true
|
56
|
+
success "Initialized git repository."
|
57
|
+
else
|
58
|
+
error "Couldn't initialize git repository."
|
59
|
+
end
|
60
|
+
else
|
61
|
+
warning "Didn't initialize git repository because git isn't installed."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module WordPressTools
|
4
|
+
module CLIHelper
|
5
|
+
def error(message)
|
6
|
+
say message, :red
|
7
|
+
end
|
8
|
+
|
9
|
+
def success(message)
|
10
|
+
say message, :green
|
11
|
+
end
|
12
|
+
|
13
|
+
def warning(message)
|
14
|
+
say message, :yellow
|
15
|
+
end
|
16
|
+
|
17
|
+
def download(url, destination)
|
18
|
+
begin
|
19
|
+
f = open(destination, "wb")
|
20
|
+
f.write(open(url).read) ? true : false
|
21
|
+
rescue
|
22
|
+
false
|
23
|
+
ensure
|
24
|
+
f.close
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def unzip(file, destination)
|
29
|
+
run "unzip #{file} -d #{destination}", :verbose => false, :capture => true
|
30
|
+
end
|
31
|
+
|
32
|
+
def git_installed?
|
33
|
+
# http://stackoverflow.com/questions/4597490/platform-independent-way-of-detecting-if-git-is-installed
|
34
|
+
void = RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null'
|
35
|
+
system "git --version >>#{void} 2>&1"
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_git_repo(repo, destination)
|
39
|
+
run "git clone #{repo} #{destination}", :verbose => false, :capture => true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WordPressTools::CLIHelper do
|
4
|
+
# def shell
|
5
|
+
# @shell ||= Thor::Shell::Basic.new
|
6
|
+
# end
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@cli = WordPressTools::CLI.new
|
10
|
+
end
|
11
|
+
|
12
|
+
context "::download" do
|
13
|
+
before(:each) do
|
14
|
+
@tempfile = Tempfile.new("download_test")
|
15
|
+
@valid_url = "http://www.example.com/test"
|
16
|
+
FakeWeb.register_uri(:get, @valid_url, :body => "Download test")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "downloads a file to the specified location" do
|
20
|
+
@cli.download(@valid_url, @tempfile.path)
|
21
|
+
open(@tempfile.path).read.should eq("Download test")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns true on success" do
|
25
|
+
@cli.download(@valid_url, @tempfile.path).should eq true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns false on failure" do
|
29
|
+
@cli.download("http://an.invalid.url", @tempfile.path).should eq false
|
30
|
+
end
|
31
|
+
|
32
|
+
after(:each) do
|
33
|
+
@tempfile.close!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "::unzip" do
|
38
|
+
it "unzips a file" do
|
39
|
+
@cli.unzip(File.expand_path('spec/fixtures/zipped_file.zip'), 'tmp/unzip')
|
40
|
+
File.exists?('tmp/unzip/zipped_file').should be true
|
41
|
+
end
|
42
|
+
|
43
|
+
after(:each) do
|
44
|
+
FileUtils.rm_rf('tmp/unzip') if File.directory? 'tmp/unzip'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "::error" do
|
49
|
+
it "displays an error" do
|
50
|
+
$stdout.should_receive(:puts).with("\e[31mI am an error\e[0m")
|
51
|
+
@cli.error("I am an error")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "::success" do
|
56
|
+
it "displays a success message" do
|
57
|
+
$stdout.should_receive(:puts).with("\e[32mI am a success message\e[0m")
|
58
|
+
@cli.success("I am a success message")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "::warning" do
|
63
|
+
it "displays a warning" do
|
64
|
+
$stdout.should_receive(:puts).with("\e[33mI am a warning\e[0m")
|
65
|
+
@cli.warning("I am a warning")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WordPressTools::CLI do
|
4
|
+
before :each do
|
5
|
+
@original_wd = Dir.pwd
|
6
|
+
wp_api_response = <<-eof
|
7
|
+
upgrade
|
8
|
+
http://wordpress.org/download/
|
9
|
+
http://wordpress.org/wordpress-3.3.1.zip
|
10
|
+
3.3.1
|
11
|
+
en_US
|
12
|
+
5.2.4
|
13
|
+
5.0
|
14
|
+
eof
|
15
|
+
FakeWeb.register_uri(:get, %r|http://api.wordpress.org/core/version-check/1.5/.*|, :body => wp_api_response)
|
16
|
+
FakeWeb.register_uri(:get, "http://wordpress.org/wordpress-3.3.1.zip", :body => File.expand_path('spec/fixtures/wordpress_stub.zip'))
|
17
|
+
Dir.chdir('tmp')
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#new" do
|
21
|
+
context "with no arguments" do
|
22
|
+
it "downloads a copy of WordPress" do
|
23
|
+
WordPressTools::CLI.start ['new']
|
24
|
+
File.exists?('wordpress/wp-content/index.php').should eq true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "initializes a git repository" do
|
28
|
+
WordPressTools::CLI.start ['new']
|
29
|
+
File.directory?('wordpress/.git').should eq true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "doesn't leave a stray 'wordpress' directory" do
|
33
|
+
WordPressTools::CLI.start ['new']
|
34
|
+
File.directory?('wordpress/wordpress').should eq false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with a custom directory name" do
|
39
|
+
it "downloads a copy of WordPress in directory 'myapp'" do
|
40
|
+
WordPressTools::CLI.start ['new', 'myapp']
|
41
|
+
File.exists?('myapp/wp-content/index.php').should eq true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with the 'bare' option" do
|
46
|
+
it "downloads a copy of WordPress and removes default plugins and themes" do
|
47
|
+
WordPressTools::CLI.start ['new', '--bare']
|
48
|
+
(File.exists?('wordpress/wp-content/plugins/hello.php') || File.directory?('wordpress/wp-content/themes/twentyeleven')).should eq false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
after :each do
|
54
|
+
Dir.chdir(@original_wd)
|
55
|
+
%w(tmp/wordpress tmp/myapp).each do |dir|
|
56
|
+
FileUtils.rm_rf(dir) if File.directory? dir
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
Binary file
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'wordpress_tools/cli'
|
2
|
+
require 'fakeweb'
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
# Set shell to basic
|
6
|
+
# $0 = "thor"
|
7
|
+
# $thor_runner = true
|
8
|
+
# ARGV.clear
|
9
|
+
# Thor::Base.shell = Thor::Shell::Basic
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
FakeWeb.allow_net_connect = false
|
13
|
+
|
14
|
+
$stdout = StringIO.new
|
15
|
+
|
16
|
+
# Stub Wordless::CLI#wordless_repo to avoid hitting the network when testing Wordless installation
|
17
|
+
# FIXME - Need to be able to selectively stub this
|
18
|
+
# config.before(:each, :stub_wordless_install => true) do
|
19
|
+
# module Wordless
|
20
|
+
# class CLI
|
21
|
+
# no_tasks do
|
22
|
+
# def wordless_repo
|
23
|
+
# File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'wordless_stub'))
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
|
30
|
+
FileUtils.mkdir('tmp') unless File.directory? 'tmp'
|
31
|
+
|
32
|
+
def capture(stream)
|
33
|
+
begin
|
34
|
+
stream = stream.to_s
|
35
|
+
eval "$#{stream} = StringIO.new"
|
36
|
+
yield
|
37
|
+
result = eval("$#{stream}").string
|
38
|
+
ensure
|
39
|
+
eval("$#{stream} = #{stream.upcase}")
|
40
|
+
end
|
41
|
+
result
|
42
|
+
end
|
43
|
+
end
|
data/wordless.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/wordpress_tools/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Étienne Després"]
|
6
|
+
gem.email = ["etienne@molotov.ca"]
|
7
|
+
gem.description = %q{Command line tool to manage WordPress installations.}
|
8
|
+
gem.summary = %q{Manage WordPress installations.}
|
9
|
+
gem.homepage = "http://github.com/etienne/wordpress_tools"
|
10
|
+
|
11
|
+
gem.add_dependency "thor"
|
12
|
+
|
13
|
+
gem.add_development_dependency 'rspec'
|
14
|
+
gem.add_development_dependency 'fakeweb'
|
15
|
+
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
gem.name = "wordpress_tools"
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.version = WordPressTools::VERSION
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordpress_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Étienne Després
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &70097507191120 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70097507191120
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70097507190440 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70097507190440
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: fakeweb
|
38
|
+
requirement: &70097507189680 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70097507189680
|
47
|
+
description: Command line tool to manage WordPress installations.
|
48
|
+
email:
|
49
|
+
- etienne@molotov.ca
|
50
|
+
executables:
|
51
|
+
- wordpress
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .rspec
|
57
|
+
- Gemfile
|
58
|
+
- Gemfile.lock
|
59
|
+
- LICENSE
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- bin/wordpress
|
63
|
+
- lib/wordpress_tools.rb
|
64
|
+
- lib/wordpress_tools/cli.rb
|
65
|
+
- lib/wordpress_tools/cli_helper.rb
|
66
|
+
- lib/wordpress_tools/version.rb
|
67
|
+
- spec/cli_helper_spec.rb
|
68
|
+
- spec/cli_spec.rb
|
69
|
+
- spec/fixtures/wordpress_stub.zip
|
70
|
+
- spec/fixtures/zipped_file.zip
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
- wordless.gemspec
|
73
|
+
homepage: http://github.com/etienne/wordpress_tools
|
74
|
+
licenses: []
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.17
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Manage WordPress installations.
|
97
|
+
test_files:
|
98
|
+
- spec/cli_helper_spec.rb
|
99
|
+
- spec/cli_spec.rb
|
100
|
+
- spec/fixtures/wordpress_stub.zip
|
101
|
+
- spec/fixtures/zipped_file.zip
|
102
|
+
- spec/spec_helper.rb
|