Skip to content

Instantly share code, notes, and snippets.

@iamntz
Forked from iamntz-gists/make-vvv.js
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamntz/690cc13fde8e6529c898 to your computer and use it in GitHub Desktop.
Save iamntz/690cc13fde8e6529c898 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var path = require('path');
var readline = require('readline');
var args = process.argv.slice(2);
var clientName, projectName;
clientName = projectName = args[0];
if( args[1] ){
projectName = args[1];
}
var dbName = clientName + '_' + projectName;
var nginxConfigPath = "config/nginx-config/sites/" + dbName + ".conf";
if( fs.existsSync(nginxConfigPath) ){
console.log('Project already exists');
return;
}
console.log('Creating project: ', projectName);
var nginxConfig = fs.readFileSync( "config/nginx-config/sites/wp-mu.conf-sample", "utf8" );
nginxConfig = nginxConfig.replace(/\{\{__client__\}\}/g, clientName);
nginxConfig = nginxConfig.replace(/\{\{__project__\}\}/g, projectName);
fs.writeFileSync( nginxConfigPath, nginxConfig, 'utf8');
var database = "\n\nCREATE DATABASE IF NOT EXISTS `" + dbName + "`;\n";
database += "GRANT ALL PRIVILEGES ON `" + dbName + "`.* TO 'wp'@'localhost' IDENTIFIED BY 'wp';";
fs.appendFileSync("database/init-custom.sql", database, 'utf8');
var projectPath = 'www';
var projectPathParts = [ clientName, projectName ];
for (var i = 0; i < projectPathParts.length; i++) {
projectPath += path.sep + projectPathParts[i];
if( !fs.existsSync( projectPath ) ){
fs.mkdirSync( projectPath )
}
};
var hostsFile = "www/" + clientName + "/vvv-hosts";
var hostFileEntry = "\n" + projectName + ".wordpress.dev";
if( fs.existsSync(hostsFile) ){
fs.appendFileSync( hostsFile, hostFileEntry, 'utf8');
}else {
fs.writeFileSync( hostsFile, hostFileEntry, 'utf8');
}

Usage:

  1. copy wp-mu.conf-sample to config/nginx-config/sites/wp-mu.conf-sample
  2. copy make-vvv.js to VVV root
  3. Run node make-vvv.js your-client project-name

Don't forget to restart your vagrant (vagrant reload --provision)

server {
listen 80;
listen 443 ssl;
server_name {{__project}}.wordpress.dev *.{{__project}}.wordpress.dev;
root /srv/www/{{__client__}}/{{__project}};
include /etc/nginx/nginx-wp-common.conf;
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}
location ~ \.php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { deny all; access_log off; log_not_found off; }
access_log /srv/www/{{__client__}}/{{__project}}/access.log;
error_log /srv/www/{{__client__}}/{{__project}}/error.log;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment