Permalink
Browse files

Remove the promzard extravaganza and add i18n support

  • Loading branch information...
1 parent 0411a4c commit 9626bb548023bdf495856f7811577127370dfb40 @saintedlama committed Feb 20, 2013
Showing with 81 additions and 34 deletions.
  1. +18 −10 lib/commands.js
  2. +0 −17 lib/input-files/app.js
  3. +51 −0 lib/prompt/app.js
  4. +3 −0 lib/prompt/index.js
  5. +1 −1 package.json
  6. +8 −6 templates/ejs/app.js.ejs
View
@@ -4,7 +4,7 @@ var path = require('path'),
fs = require('fs'),
ejs = require('ejs'),
wrench = require('wrench'),
- PZ = require('promzard').PromZard,
+ prompt = require('./prompt'),
disectModules = require('./disect-modules');
var writeTemplate = function(template, targetPath, options) {
@@ -26,11 +26,7 @@ var createApp = function(data) {
if (!fs.existsSync(source)) {
throw 'Directory "' + source + '" does not exist!';
}
-
- if (data.mongoSessionStore == "yes" && data.dependencies.indexOf("connect-mongo") == -1) {
- data.dependencies += ", connect-mongo: 0.3.x";
- }
-
+
data.dependencies = disectModules(data.dependencies);
data.devDependencies = disectModules(data.devDependencies);
@@ -44,18 +40,30 @@ var createApp = function(data) {
wrench.copyDirSyncRecursive(source, target, { preserve : true });
writeTemplate(appTemplate, path.join(target, "app.js"), data);
+ // Delete prompted properties that should not be part of package
+ delete data.mongoSessionStore
+ delete data.i18n
+
fs.writeFile(path.resolve(target, 'package.json'), JSON.stringify(data, null, ' '), function(err) {
+ console.log();
console.log('Initialized app in directory "' + target + '"');
- console.log('To start the generated app run:\n cd ' + target + '\n npm install');
+ console.log();
+ console.log('To start the generated app run:');
+ console.log(' cd ' + target);
+ console.log(' npm install');
+ console.log(' npm start OR node app.js');
});
};
var commands = {
app : function(options) {
- var name = options.model.singular;
- var input = path.resolve(__dirname, 'input-files/app.js');
+ prompt.app({ name : options.model.singular }, options.switches, function(err, result) {
+ if (err) {
+ return;
+ }
- PZ(input, {name : name}).on('data', createApp.bind(options));
+ createApp.bind(options)(result);
+ });
},
scaffold : function(options) {
View
@@ -1,17 +0,0 @@
-"use strict";
-
-module.exports = {
- "name" : prompt('name', name),
- "version" : prompt('version', "0.0.0"),
- "description" : prompt("description"),
- "private" : true,
- "main" : prompt("main", "app.js"),
- "dependencies" : prompt("dependencies", "express: 3.1.x, jade: >0.0.1, mongoose: 3.5.x"),
- "devDependencies" : prompt("devDependencies", "mocha: *"),
- "mongoSessionStore": prompt("Use mongodb as session store ", "yes"),
- "scripts" : prompt("scripts/start", "nodemon app.js -wmodels -wconfig -wroutes"),
- "repository" : prompt("repository", ""),
- "keywords" : prompt("keywords", "express, jade"),
- "author" : prompt("author", ""),
- "license" : prompt('license', 'BSD')
-};
View
@@ -0,0 +1,51 @@
+var prompt = require('prompt');
+
+module.exports = function(defaults, override, cb) {
+ prompt.message = 'bumm'.grey;
+ prompt.delimiter = ': ';
+
+ prompt.override = override;
+
+ prompt.start();
+
+ prompt.get({
+ properties: {
+ 'name' : { description: 'name'.green, default : defaults.name },
+ 'version' : { description:'version'.green, default: '0.0.0' },
+ 'description' : { description: 'description'.green },
+ 'main' : { description: 'main'.green, default: 'app.js' },
+ 'dependencies' : { description: 'dependencies'.green, default: 'express: 3.1.x, jade: >0.0.1, mongoose: 3.5.x' },
+ 'devDependencies' : { description: 'devDependencies'.green, default: 'mocha: *' },
+ 'mongoSessionStore': { description: 'use mongodb as session store'.green, default: 'yes' },
+ 'i18n' : { description: 'use i18n internationalization module'.green, default: 'no' },
+ 'scripts' : { description:'scripts/start'.green, default: 'nodemon app.js -wmodels -wconfig -wroutes' },
+ 'repository' : { description:'repository'.green }
+ }
+ }, function(err, result) {
+ if (err) {
+ return cb(err);
+ }
+
+ var rewriteTruthyInput = function(property) {
+ if (result[property]) {
+ result[property] = (result[property].toLowerCase() == 'yes' || result[property].toLowerCase() == 'y');
+ }
+ }
+
+ rewriteTruthyInput('i18n');
+ rewriteTruthyInput('mongoSessionStore');
+
+ if (result.i18n && result.dependencies.indexOf('i18n-2') == -1) {
+ result.dependencies += ', i18n-2: 0.4.x';
+ }
+
+ if (result.mongoSessionStore && result.dependencies.indexOf('connect-mongo') == -1) {
+ result.dependencies += ', connect-mongo: 0.3.x';
+ }
+
+ result.private = true;
+
+ cb(undefined, result);
+ });
+}
+
View
@@ -0,0 +1,3 @@
+module.exports = {
+ app : require('./app')
+}
View
@@ -17,7 +17,7 @@
"optimist": "0.3.x",
"wrench": "1.3.x",
"fleck": "0.5.x",
- "promzard": "0.2.0"
+ "prompt": "0.2.x"
},
"devDependencies": {
"mocha": "1.4.x",
View
@@ -2,11 +2,10 @@ var path = require('path'),
express = require('express'),
http = require('http'),
mongoose = require('mongoose'),
- config = require('./config');
+ config = require('./config')<% if(mongoSessionStore) { %>,
+ MongoStore = require('connect-mongo')(express)<% } %><% if(i18n) { %>,
+ i18n = require('i18n-2')<% } -%>;
-<% if(mongoSessionStore == "yes") { -%>
-var MongoStore = require('connect-mongo')(express);
-<% } -%>
var mongooseConnection = mongoose.connect(config.db.url, function(err) {
if (err) {
@@ -32,7 +31,7 @@ app.configure(function(){
app.use(express.cookieParser(config.secret));
-<% if(mongoSessionStore == "yes") { -%>
+<% if(mongoSessionStore) { -%>
app.use(express.session({
secret: config.sessionSecret,
store: new MongoStore({
@@ -49,8 +48,11 @@ app.configure(function(){
app.use(express.session());
<% } -%>
- app.use(app.router);
+<% if(i18n) { -%>
+ i18n.expressBind(app, { locals: ['en', 'es', 'fr', 'de'] });
+<% } -%>
+ app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});

0 comments on commit 9626bb5

Please sign in to comment.