Skip to content

Instantly share code, notes, and snippets.

@iamntz-gists
Created September 6, 2014 06:48
Show Gist options
  • Save iamntz-gists/065f42f092764788872a to your computer and use it in GitHub Desktop.
Save iamntz-gists/065f42f092764788872a to your computer and use it in GitHub Desktop.
var fs = require('fs');
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment