Updated folder structure

This commit is contained in:
DallonF
2012-06-14 11:29:22 -07:00
parent 56017086cc
commit f366dcbeae
7 changed files with 95 additions and 89 deletions

73
bin/dpd
View File

@@ -5,57 +5,62 @@
*/
var program = require('commander')
, deployd = require('../')
, repl = require('../lib/client/repl')
, shelljs = require('shelljs/global')
, mongod = require('../lib/util/mongod');
, deployd = require('../')
, repl = require('../lib/client/repl')
, shelljs = require('shelljs/global')
, mongod = require('../lib/util/mongod');
/**
* Get the version number from the package.json
*/
program
.version(require('../package').version)
.option('-m, --mongod [path]', 'path to mongod executable (defaults to `mongod`)')
.version(require('../package').version)
.option('-m, --mongod [path]', 'path to mongod executable (defaults to `mongod`)')
/**
* Commands
*/
program
.command('create [project-name]')
.description('\tcreate a project in a new directory\n\teg. `dpd create my-app`')
.action(function(name) {
var name = name || 'my-deployd-app';
mkdir('-p', name);
mkdir('-p', name + '/resources');
mkdir('-p', name + '/public');
mkdir('-p', name + '/.dpd/data');
mkdir('-p', name + '/.dpd/pids');
("{}").to(name + '/.dpd/resources.json');
("").to(name + '/.dpd/pids/mongod');
console.info('To start your app:');
console.info('\t$ cd', name);
console.info('\t$ dpd');
});
.command('create [project-name]')
.description('\tcreate a project in a new directory\n\teg. `dpd create my-app`')
.action(function(name) {
var name = name || 'my-deployd-app';
mkdir('-p', name);
mkdir('-p', name + '/public');
mkdir('-p', name + '/data');
mkdir('-p', name + '/.dpd');
mkdir('-p', name + '/.dpd/pids');
('').to(name + '/.dpd/pids/mongod');
("{}").to(name + '/app.dpd');
console.info('To start your app:');
console.info('\t$ cd', name);
console.info('\t$ dpd');
});
function start(port) {
mongod.restart(program.mongod || 'mongod', function() {
var dpd = deployd({port: port, db: {host: '127.0.0.1', port: 27017, name: '-deployd'}});
dpd.listen();
dpd.on('listening', function () {
console.info('listening on port', port);
repl(dpd);
});
});
if (test('-f', 'app.dpd')) {
mongod.restart(program.mongod || 'mongod', function() {
var dpd = deployd({port: port, db: {host: '127.0.0.1', port: 27017, name: '-deployd'}});
dpd.listen();
dpd.on('listening', function () {
console.info('listening on port', port);
repl(dpd);
});
});
} else {
console.info("This directory does not contain a Deployd app!");
console.info("Use \"dpd create <appname>\" to create a new app");
}
}
program
.command('*')
.description('\t[default] start the server in the current project in development mode\n' +
'\twith an interactive shell/repl for interacting with the running server\n' +
'\teg. `dpd` (start at default port 2403) or `dpd 3000` (port 3000)')
.action(start);
.command('*')
.description('\t[default] start the server in the current project in development mode\n' +
'\twith an interactive shell/repl for interacting with the running server\n' +
'\teg. `dpd` (start at default port 2403) or `dpd 3000` (port 3000)')
.action(start);
/**

View File

@@ -10,7 +10,7 @@ var fs = require('fs')
* @param {Function} callback
*/
module.exports.loadConfig = function(basepath, fn) {
var resourcesPath = path.join(basepath, '/resources.json');
var resourcesPath = path.join(basepath, '/app.dpd');
fs.readFile(resourcesPath, 'utf-8', function(err, data) {
if (err) { return fn(err); }
@@ -36,7 +36,7 @@ module.exports.loadConfig = function(basepath, fn) {
* @param {Function} callback
*/
module.exports.saveConfig = function(resources, basepath, fn) {
var resourcesPath = path.join(basepath, '/resources.json')
var resourcesPath = path.join(basepath, '/app.dpd')
, json = JSON.stringify(resources);
fs.writeFile(resourcesPath, json, 'utf-8', function(err) {

View File

@@ -45,7 +45,7 @@ var build = exports.build = function (resourceConfig, server, fn) {
}
function InternalResources(settings, server) {
settings.configPath = settings.configPath || './.dpd/';
settings.configPath = settings.configPath || './';
Resource.apply(this, arguments);
this.store = server && server.createStore && server.createStore('resources');
this.server = server;

View File

@@ -95,7 +95,7 @@ function Server(options) {
req.session = session;
function route() {
config.loadConfig('./.dpd/', function(err, resourceConfig) {
config.loadConfig('./', function(err, resourceConfig) {
resources.build(resourceConfig, server, function(err, resourcesInstances) {
var router = new Router(resourcesInstances, server);
server.router = router;
@@ -135,7 +135,7 @@ util.inherits(Server, http.Server);
Server.prototype.listen = function(port, host) {
var server = this;
config.loadConfig('./.dpd/', function(err, resourceConfig) {
config.loadConfig('./', function(err, resourceConfig) {
resources.build(resourceConfig, server, function(err, resourcesInstances) {
server.resources = resourcesInstances;
http.Server.prototype.listen.call(server, port || server.options.port, host || server.options.host);

View File

@@ -12,24 +12,24 @@ module.exports = function loadTypes(basepath, fn) {
var path = basepath || './resources';
// read local project resources
fs.readdir(path, function(err, dir) {
dir && dir.forEach(function(file) {
// fs.readdir(path, function(err, dir) {
// dir && dir.forEach(function(file) {
// if(file.indexOf('.js') == file.length - 3) {
// var c = require(require('path').resolve(path) + '/' + file);
// types[c.name] = c;
// }
// });
// read default lib resources
fs.readdir(__dirname + '/resources', function(err, dir) {
dir.forEach(function(file) {
if(file.indexOf('.js') == file.length - 3) {
var c = require(require('path').resolve(path) + '/' + file);
types[c.name] = c;
var c = require(path + '/' + file);
defaults[c.name] = c;
}
});
// read default lib resources
fs.readdir(__dirname + '/resources', function(err, dir) {
dir.forEach(function(file) {
if(file.indexOf('.js') == file.length - 3) {
var c = require(path + '/' + file);
defaults[c.name] = c;
}
});
fn(defaults, types);
});
fn(defaults, types);
});
// });
}

View File

@@ -1,47 +1,48 @@
var fs = require('fs')
, spawn = require('child_process').spawn
, debug = require('debug')('mongod');
, spawn = require('child_process').spawn
, debug = require('debug')('mongod');
/**
* Utility for restarting the current apps mongod instance.
*/
exports.restart = function (mongod, fn) {
var pid;
var pid;
debug('starting %s', mongod);
debug('starting %s', mongod);
try {
pid = JSON.parse(fs.readFileSync('./.dpd/pids/mongod'));
} catch(e) {}
try {
pid = JSON.parse(fs.readFileSync('./.dpd/pids/mongod'));
if(pid) {
debug('pid %s', pid);
process.kill(pid);
} else {
debug('no pid found');
}
if(pid) {
debug('pid %s', pid);
process.kill(pid);
} else {
debug('no pid found');
}
} catch(e) {}
var proc = spawn(mongod, ['--dbpath', './data', '--pidfilepath', './.dpd/pids/mongod'], {title: 'FOOBAR'})
, buf = '';
proc.stdout.on('data', function(data) {
buf += data;
if(~buf.indexOf('waiting for connections on port')) {
proc.emit('listening');
}
debug(data);
});
var proc = spawn(mongod, ['--dbpath', './.dpd/data', '--pidfilepath', './.dpd/pids/mongod'], {title: 'FOOBAR'})
, buf = '';
proc.stdout.on('data', function(data) {
buf += data;
if(~buf.indexOf('waiting for connections on port')) {
proc.emit('listening');
}
debug(data);
});
function kill(e) {
if(e) console.error(e);
debug('killing mongod');
fs.writeFileSync('./.dpd/pids/mongod', '');
proc.kill();
process.exit(0);
}
function kill(e) {
if(e) console.error(e);
debug('killing mongod');
proc.kill();
process.exit(0);
}
// callback
proc.once('listening', fn);
// callback
proc.once('listening', fn);
process.on('exit', kill);
process.on('uncaughtException', kill);
process.on('exit', kill);
process.on('uncaughtException', kill);
}

View File

@@ -25,7 +25,7 @@ describe('config-loader', function() {
, 'test': 'value'
};
fs.writeFileSync(path.join(basepath, '/resources.json'), JSON.stringify({'123': resource1, '456': resource2}));
fs.writeFileSync(path.join(basepath, '/app.dpd'), JSON.stringify({'123': resource1, '456': resource2}));
configLoader.loadConfig(basepath, function(err, resources) {
expect(Object.keys(resources)).to.have.length(2);
@@ -55,7 +55,7 @@ describe('config-loader', function() {
};
configLoader.saveConfig({'123': resource1, '456': resource2}, basepath, function(err) {
var resourcePath = path.join(basepath, '/resources.json');
var resourcePath = path.join(basepath, '/app.dpd');
var resources = JSON.parse(fs.readFileSync(resourcePath));