Permalink
Browse files

Binary generates 1 page app by default

  • Loading branch information...
1 parent af5e38c commit d7134c05136bc9bb676cd68bc94b7a275bd91ced @juzerali committed Nov 8, 2012
Showing with 35 additions and 13 deletions.
  1. +35 −13 bin/express
View
@@ -22,6 +22,7 @@ program
.option('-H, --hogan', 'add hogan.js engine support')
.option('-c, --css <engine>', 'add stylesheet <engine> support (less|stylus) (defaults to plain css)')
.option('-f, --force', 'force on non-empty directory')
+ .option('-Y, --struct', 'Make directory structure, if not used all the server code will be in app.js')
.parse(process.argv);
// Path
@@ -42,31 +43,38 @@ if (program.hogan) program.template = 'hjs';
/**
* Routes index template.
*/
+var indexFn = [
+ 'function(req, res){'
+ , ' res.render(\'index\', { title: \'Express\' });'
+ , '}'
+].join(eol);
+
var index = [
''
, '/*'
, ' * GET home page.'
, ' */'
, ''
- , 'exports.index = function(req, res){'
- , ' res.render(\'index\', { title: \'Express\' });'
- , '};'
+ , 'exports.index = ' + indexFn + ';'
].join(eol);
/**
* Routes users template.
*/
+var usersFn = [
+ 'function(req, res){'
+ , ' res.send("respond with a resource");'
+ , '}'
+ ].join(eol);
var users = [
''
, '/*'
, ' * GET users listing.'
, ' */'
, ''
- , 'exports.list = function(req, res){'
- , ' res.send("respond with a resource");'
- , '};'
+ , 'exports.list = ' + usersFn + ';'
].join(eol);
/**
@@ -232,15 +240,27 @@ var app = [
, ' app.use(express.errorHandler());'
, '});'
, ''
- , 'app.get(\'/\', routes.index);'
- , 'app.get(\'/users\', user.list);'
+ , ''
+ , '/*'
+ , ' * GET home page.'
+ , ' */'
+ , ''
+ , 'app.get(\'/\', ' + (program.struct?'routes.index': indexFn) + ');'
+ , ''
+ , '/*'
+ , ' * GET users listing.'
+ , ' */'
+ , ''
+ , 'app.get(\'/users\', ' + (program.struct?'users.list': usersFn) + ');'
, ''
, 'http.createServer(app).listen(app.get(\'port\'), function(){'
, ' console.log("Express server listening on port " + app.get(\'port\'));'
, '});'
, ''
].join(eol);
+
+
// Generate application
(function createApplication(path) {
@@ -295,11 +315,13 @@ function createApplicationAt(path) {
}
});
- mkdir(path + '/routes', function(){
- write(path + '/routes/index.js', index);
- write(path + '/routes/user.js', users);
- });
-
+ if(program.struct){
+ mkdir(path + '/routes', function(){
+ write(path + '/routes/index.js', index);
+ write(path + '/routes/user.js', users);
+ });
+ }
+
mkdir(path + '/views', function(){
switch (program.template) {
case 'ejs':

0 comments on commit d7134c0

Please sign in to comment.