Skip to content

Commit

Permalink
create site: choose data dir + small output errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoppieters committed Apr 16, 2015
1 parent 9737fbc commit 5972714
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 73 deletions.
5 changes: 4 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@

## 3.3.5 - 29/03/2015
* changed the directory structure to more reflect the hosting setup
* changes create script and you now have a startupscript in your cody-dev directory per project
* changes create script and you now have a startupscript in your cody-dev directory per project

## 3.3.10 - 10/04/2015
* better setup, small corrections.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Johan Coppieters - Howest.
Copyright (c) 2015 Johan Coppieters - Howest.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Have a look at the generated config.json file to see which configuration variabl
## License
Copyright (c) 2012-2014 Johan Coppieters, Howest Brugge. See the LICENSE.md file for license rights and
Copyright (c) 2012-2015 Johan Coppieters, Howest Brugge. See the LICENSE.md file for license rights and
limitations. This project is licensed under the terms of the MIT license.
Expand Down
146 changes: 76 additions & 70 deletions bin/create_site.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var path = require("path");

var rootwd = process.cwd();
var codywd = rootwd + "/node_modules/cody";
var datadir = "/usr/local/data/"; // Windows ???

// https://gist.github.com/tkihira/3014700
var mkdir = function (dir) {
Expand Down Expand Up @@ -78,89 +77,98 @@ var rl = readline.createInterface({
output: process.stdout
});

console.log("Creating project in ", rootwd + "/");
rl.question("1) Enter projectname: ", function (sitename) {
console.log("Note: also using $sitename as database name.");
console.log("\nCreating project in ", rootwd + "/");

rl.question("\n1) Enter projectname: ", function (sitename) {
console.log("Note: also using " + sitename + " as database name.");
console.log("Note: by default the mysql root user has no password so you can just hit enter, if you forgot the root password http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html");
rl.question("2) Enter root password for mysql so we can create a new database and user: ", function (dbrootpw) {
rl.question("3) Enter site database user: ", function (dbuser) {
rl.question("4) Enter site database password: ", function (dbpass) {
rl.question("5) Enter hostname for site: ", function (hostname) {

rl.question("\n2) Enter root password for mysql so we can create a new database and user: ", function (dbrootpw) {

rl.question("\n3) Enter site database user: ", function (dbuser) {

rl.question("\n4) Enter site database password: ", function (dbpass) {

rl.question("\n5) Enter hostname for site: ", function (hostname) {
var con = mysql.createConnection({
host: 'localhost',
user: 'root',
password: dbrootpw,
multipleStatements: true
});
con.connect();
con.query("create database " + sitename + " default charset utf8", function (err) {
if (err) console.log(err);
con.query("grant all on " + sitename + ".* to '" + dbuser + "'@'%' identified by '" + dbpass + "'", function (err) {
if (err) console.log(err);

con.query("grant all on " + sitename + ".* to '" + dbuser + "'@'localhost' identified by '" + dbpass + "'", function (err) {
rl.question("\n6) Enter a location for storing documents: ", function (datadir) {

console.log("");
con.connect();
con.query("create database " + sitename + " default charset utf8", function (err) {
if (err) console.log(err);
con.query("grant all on " + sitename + ".* to '" + dbuser + "'@'%' identified by '" + dbpass + "'", function (err) {
if (err) console.log(err);

con.end();
con = mysql.createConnection({
host: 'localhost',
user: dbuser,
database: sitename,
password: dbpass,
multipleStatements: true
});
con.connect();
con.query("grant all on " + sitename + ".* to '" + dbuser + "'@'localhost' identified by '" + dbpass + "'", function (err) {
if (err) console.log(err);

mkdir(path.join(rootwd, sitename));
fs.readdirSync(codywd + "/doc/empty").forEach(function (src) {
copyRecursiveSync(path.join(codywd,"doc","empty", src), path.join(rootwd, sitename , src));
con.end();
con = mysql.createConnection({
host: 'localhost',
user: dbuser,
database: sitename,
password: dbpass,
multipleStatements: true
});
fs.readFile(path.join(rootwd, sitename, "empty.sql"), function (err, initstatements) {
if (err) throw err;
con.connect();

con.query(initstatements.toString(), function (err) {
mkdir(path.join(rootwd, sitename));
fs.readdirSync(codywd + "/doc/empty").forEach(function (src) {
copyRecursiveSync(path.join(codywd,"doc","empty", src), path.join(rootwd, sitename , src));
});
fs.readFile(path.join(rootwd, sitename, "empty.sql"), function (err, initstatements) {
if (err) throw err;

fs.writeFileSync(path.join(rootwd, sitename, "config.json"), JSON.stringify(
{ name: sitename,
mailFrom: "info@"+hostname,
hostnames:"localhost,"+hostname,
db: sitename,
dbuser: dbuser,
dbpassword: dbpass,
dbhost: "localhost",
smtp: "smtpmailer."+hostname,
version: "V0.1",
defaultlanguage: "en",
datapath: "/usr/local/data/"+sitename,
port: 3001
}));
copy(path.join(rootwd, sitename, "index.js"), path.join(rootwd, sitename+".js"));

mkdir(datadir);
mkdir(path.join(datadir,sitename));
console.log("created "+sitename+"/");
mkdir(path.join(datadir,sitename,"images"));
console.log("created "+sitename+"/images");
mkdir(path.join(datadir,sitename,"files"));
console.log("created "+sitename+"/files");


console.log("---")
console.log("Site '" + sitename + "' has been prepared.\n")
console.log("Please create DNS entries, or add to /etc/hosts:");
console.log("127.0.0.1 " + hostname);
console.log("Also check index.js and config.json to fine-tune extra parameters, encryption key, ...");
console.log("---")
console.log("Start your site using:");
console.log("$ forever start " + sitename + ".js");
console.log(" or");
console.log("$ node " + sitename + ".js");
con.end();
rl.close();
con.query(initstatements.toString(), function (err) {
if (err) throw err;

fs.writeFileSync(path.join(rootwd, sitename, "config.json"), JSON.stringify(
{ name: sitename,
mailFrom: "info@"+hostname,
hostnames:"localhost,"+hostname,
db: sitename,
dbuser: dbuser,
dbpassword: dbpass,
dbhost: "localhost",
smtp: "smtpmailer."+hostname,
version: "V0.1",
defaultlanguage: "en",
datapath: "/usr/local/data/"+sitename,
port: 3001
}));
copy(path.join(rootwd, sitename, "index.js"), path.join(rootwd, sitename+".js"));

mkdir(datadir);
mkdir(path.join(datadir,sitename));
console.log("created "+datadir+"/"+sitename+"/");
mkdir(path.join(datadir,sitename,"images"));
console.log("created "+datadir+"/"+sitename+"/images");
mkdir(path.join(datadir,sitename,"files"));
console.log("created "+datadir+"/"+sitename+"/files");


console.log("---")
console.log("Site '" + sitename + "' has been prepared.\n")
console.log("Please create DNS entries, or add to /etc/hosts:");
console.log("127.0.0.1 " + hostname);
console.log("Also check index.js and config.json to fine-tune extra parameters, encryption key, ...");
console.log("---")
console.log("Start your site using:");
console.log("$ forever start " + sitename + ".js");
console.log(" or");
console.log("$ node " + sitename + ".js");
con.end();
rl.close();
});
});
});

});
});
});
});
Expand All @@ -169,5 +177,3 @@ rl.question("1) Enter projectname: ", function (sitename) {
});
});
});


0 comments on commit 5972714

Please sign in to comment.