Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion generator/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,26 @@ WordpressGenerator.prototype.promptForName = function() {
};

WordpressGenerator.prototype.promptForDomain = function() {
var existing = function() {
try {
var groupVars = this.readFileAsString(path.join(this.env.cwd, 'provisioning', 'group_vars', 'webservers'));

var matches = groupVars.match(/^domain:[\t ]*(\S+)\s/m);

if (matches) {
return matches[1];
}
} catch(e) {};
}.bind(this);

this.prompts.push({
required: true,
type: 'text',
name: 'domain',
message: 'Domain name (e.g. mysite.com)',
default: path.basename(this.env.cwd).toLowerCase(),
default: function() {
return existing() || path.basename(this.env.cwd).toLowerCase();
}.bind(this),
validate: function(input) {
if (/^[\w-]+\.\w+(?:\.\w{2,3})?$/.test(input)) {
return true;
Expand All @@ -84,6 +98,42 @@ WordpressGenerator.prototype.promptForDomain = function() {
});
};

WordpressGenerator.prototype.promptForAliases = function() {
var existing = function() {
try {
var groupVars = this.readFileAsString(path.join(this.env.cwd, 'provisioning', 'group_vars', 'webservers'));

var matches = groupVars.match(/^aliases:(?:\s+-[ ]+\S+)+/m);

if (matches) {
var aliases = matches[0].split(/\s+-[ ]+/);
aliases.shift();

return aliases.join(' ');
}
} catch(e) {};
}.bind(this);

this.prompts.push({
required: true,
type: 'text',
name: 'aliases',
message: 'Domain aliases, space delimited (e.g. mysite.net mysite.org)',
default: function() {
return existing() || '';
}.bind(this),
validate: function(input) {
if (/^([\w-]+\.\w+(?:\.\w{2,3})?(?:[ ]+)?)+$/.test(input)) {
return true;
} else if (!input) {
return true;
}

return chalk.yellow(input) + ' does not match the example';
}
});
};

WordpressGenerator.prototype.promptForGenesis = function() {
this.prompts.push({
type: 'text',
Expand Down
3 changes: 2 additions & 1 deletion generator/app/templates/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Vagrant.configure("2") do |config|

config.vm.define :local do |box|
box.vm.hostname = "local.<%= props.domain %>"

<% if (props.aliases) { %> box.hostmanager.aliases = %w(<%= props.aliases.split(/\s+/).map(function (alias) { return 'local.' + alias; }).join(' ') %>)
<% } %>
# Static IP for testing.
box.vm.network :private_network, ip: "<%= props.ip %>"
box.vm.network :forwarded_port, guest: 22, host: <%= props.ip.split('.').join('').split('0').join('').slice(-4) %>, auto_correct: true
Expand Down
2 changes: 2 additions & 0 deletions generator/app/templates/provisioning/group_vars/webservers
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
domain: <%= props.domain %>
aliases:<% if (props.aliases) { props.aliases.split(/\s+/).forEach(function (alias) { %>
- <%= alias %><% }); } else { %> []<% } %>
mysql:
name: <%= props.DB_NAME %>
user: <%= props.DB_USER %>
Expand Down
9 changes: 8 additions & 1 deletion generator/app/templates/web/htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ SetEnvIf Host ^local\. allow_wp_install
# Rules to help reduce spam
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^(.*)wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !^(.*)<%= props.domain %>.*
RewriteCond %{HTTP_REFERER} !^(.*)<%
if (props.aliases) {
%>(<%= props.domain %>|<%
%><%= props.aliases.split(/\s+/).join('|') %>)<%
} else {
%><%= props.domain %><%
}
%>.*
RewriteCond %{HTTP_REFERER} !^http://jetpack\.wordpress\.com/jetpack-comment/ [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule ^(.*)$ - [F]
Expand Down
4 changes: 4 additions & 0 deletions provisioning/roles/wordpress/templates/vhosts/000-local
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

ServerName local.{{ domain }}

{% for alias in aliases %}
ServerAlias local.{{ alias }}
{% endfor %}

DocumentRoot /vagrant/web
<Directory />
Options FollowSymLinks
Expand Down
4 changes: 4 additions & 0 deletions provisioning/roles/wordpress/templates/vhosts/001-staging
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

ServerName staging.{{ domain }}

{% for alias in aliases %}
ServerAlias staging.{{ alias }}
{% endfor %}

DocumentRoot /var/www/{{ domain }}/master/current/web
<Directory />
Options FollowSymLinks
Expand Down
4 changes: 4 additions & 0 deletions provisioning/roles/wordpress/templates/vhosts/002-branch
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
ServerName branch.staging.{{ domain }}
ServerAlias *.staging.{{ domain }}

{% for alias in aliases %}
ServerAlias branch.staging.{{ alias }} *.staging.{{ alias }}
{% endfor %}

VirtualDocumentRoot /var/www/{{ domain }}/%1/current/web
<Directory />
Options FollowSymLinks
Expand Down
4 changes: 4 additions & 0 deletions provisioning/roles/wordpress/templates/vhosts/003-production
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
ServerAlias www.{{ domain }}
ServerAlias *.{{ domain }}

{% for alias in aliases %}
ServerAlias {{ alias }} production.{{ alias }} www.{{ alias }} *.{{ alias }}
{% endfor %}

DocumentRoot /var/www/{{ domain }}/master/current/web
<Directory />
Options FollowSymLinks
Expand Down