presspass 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/presspass/cli/new_project_generator.rb +98 -0
- data/lib/presspass/cli.rb +7 -73
- data/lib/presspass/presspass.rb +2 -1
- metadata +64 -7
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module PressPass
|
4
|
+
module Cli
|
5
|
+
|
6
|
+
class NewProjectGenerator
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@options = {:php => nil}
|
10
|
+
|
11
|
+
@app_name = ARGV.first
|
12
|
+
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: presspass new <app_name> [options]"
|
15
|
+
|
16
|
+
opts.on("--php PATH", "Path to PHP CGI binary") do |php_path|
|
17
|
+
@options[:php] = php_path
|
18
|
+
end
|
19
|
+
|
20
|
+
end.parse!(ARGV)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
create_project_directory
|
26
|
+
|
27
|
+
download_wordpress
|
28
|
+
|
29
|
+
extract_wordpress_into_project_directory
|
30
|
+
|
31
|
+
add_rack_config(:php_cgi_path => @options[:php])
|
32
|
+
|
33
|
+
puts "WordPress installation created at #{@app_name}."
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def create_project_directory
|
39
|
+
if Dir.exists?(@app_name)
|
40
|
+
puts "A directory with name #{@app_name} already exists."
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def download_wordpress
|
46
|
+
if !File.exists?("/tmp/wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
|
47
|
+
puts "Downloading wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz..."
|
48
|
+
|
49
|
+
Net::HTTP.start('wordpress.org') do |http|
|
50
|
+
resp = http.get("/wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
|
51
|
+
open("/tmp/wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz", 'w') do |file|
|
52
|
+
file.write(resp.body)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
puts "wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz downloaded."
|
58
|
+
end
|
59
|
+
|
60
|
+
def extract_wordpress_into_project_directory
|
61
|
+
filestamp = Time.now.to_i
|
62
|
+
download_location = File.join('/tmp', "wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
|
63
|
+
tmp_dir = "/tmp/wordpress-latest-#{filestamp}"
|
64
|
+
|
65
|
+
Dir.mkdir(tmp_dir)
|
66
|
+
`cd #{tmp_dir}; tar -xzf #{download_location}`
|
67
|
+
|
68
|
+
FileUtils.mv("#{tmp_dir}/wordpress", @app_name)
|
69
|
+
FileUtils.rm_r(tmp_dir)
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_rack_config(opts = {})
|
73
|
+
options = { :php_cgi_path => nil }
|
74
|
+
options.merge!(opts)
|
75
|
+
|
76
|
+
config_ru = <<EOF
|
77
|
+
require 'rack'
|
78
|
+
require 'rack-legacy'
|
79
|
+
require 'rack-rewrite'
|
80
|
+
|
81
|
+
INDEXES = ['index.html','index.php', 'index.cgi']
|
82
|
+
|
83
|
+
ENV['SERVER_PROTOCOL'] = "HTTP/1.1"
|
84
|
+
|
85
|
+
use Rack::Legacy::Php, Dir.getwd<% if options[:php_cgi_path] %>, '<%= options[:php_cgi_path] %>' <% end %>
|
86
|
+
run Rack::File.new Dir.getwd
|
87
|
+
EOF
|
88
|
+
config_ru_template = ERB.new(config_ru)
|
89
|
+
|
90
|
+
puts "Adding config.ru for usage with Pow."
|
91
|
+
|
92
|
+
File.open(File.join(@app_name, "config.ru"), "w") do |file|
|
93
|
+
file.write(config_ru_template.result(binding))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/presspass/cli.rb
CHANGED
@@ -3,81 +3,15 @@ require 'fileutils'
|
|
3
3
|
require 'optparse'
|
4
4
|
|
5
5
|
require 'presspass'
|
6
|
+
require 'presspass/cli/new_project_generator'
|
6
7
|
|
7
8
|
if ARGV.first == "new"
|
8
|
-
|
9
|
+
ARGV.shift
|
9
10
|
|
10
|
-
ARGV.
|
11
|
-
|
12
|
-
options = {:php => "/usr/bin/php-cgi"}
|
13
|
-
|
14
|
-
OptionParser.new do |opts|
|
15
|
-
opts.banner = "Usage: presspass new <app_name> [options]"
|
16
|
-
|
17
|
-
opts.on("--php [OPTIONAL]", "Path to PHP CGI binary") do |php_path|
|
18
|
-
options[:php] = php_path
|
19
|
-
end
|
20
|
-
end.parse!
|
21
|
-
|
22
|
-
if Dir.exists?(app_name)
|
23
|
-
puts "A directory with name #{app_name} already exists."
|
24
|
-
else
|
25
|
-
|
26
|
-
if !File.exists?("wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
|
27
|
-
puts "Downloading wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz..."
|
28
|
-
|
29
|
-
Net::HTTP.start('wordpress.org') do |http|
|
30
|
-
resp = http.get("/wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
|
31
|
-
open("/tmp/wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz", 'w') do |file|
|
32
|
-
file.write(resp.body)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
puts "wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz downloaded."
|
38
|
-
|
39
|
-
filestamp = Time.now.to_i
|
40
|
-
download_location = File.join('/tmp', "wordpress-#{PressPass::WORDPRESS_VERSION}.tar.gz")
|
41
|
-
tmp_dir = "/tmp/wordpress-latest-#{filestamp}"
|
42
|
-
|
43
|
-
Dir.mkdir(tmp_dir)
|
44
|
-
`cd #{tmp_dir}; tar -xzf #{download_location}`
|
45
|
-
|
46
|
-
FileUtils.mv("#{tmp_dir}/wordpress", app_name)
|
47
|
-
FileUtils.rm_r(tmp_dir)
|
48
|
-
FileUtils.rm(download_location)
|
49
|
-
|
50
|
-
config_ru = <<EOF
|
51
|
-
require 'rack'
|
52
|
-
require 'rack-legacy'
|
53
|
-
require 'rack-rewrite'
|
54
|
-
|
55
|
-
INDEXES = ['index.html','index.php', 'index.cgi']
|
56
|
-
|
57
|
-
ENV['SERVER_PROTOCOL'] = "HTTP/1.1"
|
58
|
-
|
59
|
-
use Rack::Rewrite do
|
60
|
-
rewrite %r{(.*/$)}, lambda {|match, rack_env|
|
61
|
-
INDEXES.each do |index|
|
62
|
-
if File.exists?(File.join(Dir.getwd, rack_env['PATH_INFO'], index))
|
63
|
-
return rack_env['PATH_INFO'] + index
|
64
|
-
end
|
65
|
-
end
|
66
|
-
rack_env['PATH_INFO']
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
use Rack::Legacy::Php, Dir.getwd, '#{options[:php]}'
|
71
|
-
use Rack::Legacy::Cgi, Dir.getwd
|
72
|
-
run Rack::File.new Dir.getwd
|
73
|
-
EOF
|
74
|
-
|
75
|
-
puts "Adding config.ru for usage with Pow."
|
76
|
-
|
77
|
-
File.open(File.join(app_name, "config.ru"), "w") do |file|
|
78
|
-
file.write(config_ru)
|
79
|
-
end
|
80
|
-
|
81
|
-
puts "WordPress installation created at #{app_name}."
|
11
|
+
if ARGV.first.nil?
|
12
|
+
ARGV << "--help"
|
82
13
|
end
|
14
|
+
|
15
|
+
generator = PressPass::Cli::NewProjectGenerator.new
|
16
|
+
generator.run
|
83
17
|
end
|
data/lib/presspass/presspass.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: presspass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,61 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2012-09-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rack-legacy
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack-rewrite
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: ! " PressPass is a command-line tool that helps you do WordPress development.\n\n
|
63
|
+
\ It lets you install the latest WordPress version on your local development machine\n
|
64
|
+
\ and sets it up for usage with PHP and Pow so you can run it along side your\n
|
65
|
+
\ Rails apps if you want to.\n\n It contains generation tools similar to the
|
66
|
+
rails command for generating themes\n and plugins.\n"
|
15
67
|
email: michiel@firmhouse.com
|
16
68
|
executables:
|
17
69
|
- presspass
|
@@ -21,10 +73,15 @@ files:
|
|
21
73
|
- lib/presspass.rb
|
22
74
|
- lib/presspass/presspass.rb
|
23
75
|
- lib/presspass/cli.rb
|
76
|
+
- lib/presspass/cli/new_project_generator.rb
|
24
77
|
- bin/presspass
|
25
78
|
homepage: http://github.com/firmhouse/presspass
|
26
|
-
licenses:
|
27
|
-
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
post_install_message: ! " Thank you for installing PressPass! Now get started with
|
82
|
+
setting up a \n WordPress installation in your current directory:\n\n presspass
|
83
|
+
new my_blog\n\n If you need help, please create an issue at\n https://github.com/firmhouse/presspass/issues\n
|
84
|
+
\ \n"
|
28
85
|
rdoc_options: []
|
29
86
|
require_paths:
|
30
87
|
- lib
|
@@ -45,5 +102,5 @@ rubyforge_project:
|
|
45
102
|
rubygems_version: 1.8.24
|
46
103
|
signing_key:
|
47
104
|
specification_version: 3
|
48
|
-
summary: PressPass
|
105
|
+
summary: PressPass makes doing WordPress development awesome
|
49
106
|
test_files: []
|