Comparing version 0.1.4 to 0.1.5
@@ -20,2 +20,16 @@ #!/usr/bin/env node | ||
var generateDirectory = process.cwd(); | ||
/** | ||
* Dispatch commands from command line | ||
*/ | ||
commander | ||
.version(require('../package.json').version) | ||
.option('-a, --application <name>', 'Generate application in specified folder (default: application)', 'application') | ||
.option('-m, --module <name>', 'Generate new module structure in application', 'Default') | ||
.option('-f, --folder <path>', 'Where to generate? (default: generateDirectory)', generateDirectory) | ||
.parse(process.argv); | ||
generateDirectory = commander.folder; | ||
var defaultOptions = { | ||
@@ -30,3 +44,3 @@ tweeVersion: require('../package').version, | ||
applicationName: 'application', | ||
applicationFolder: process.cwd() + '/' + this.applicationName, | ||
applicationFolder: generateDirectory + '/' + this.applicationName, | ||
tweeModuleNameTemplate: '_Twee-MNT_', | ||
@@ -40,14 +54,5 @@ tweeModuleNameTemplateLowerCased: '_Twee-MNT-LC_', | ||
/** | ||
* Dispatch commands from command line | ||
*/ | ||
commander | ||
.version(require('../package.json').version) | ||
.option('-a, --application <name>', 'Generate application in specified folder (default: application)', 'application') | ||
.option('-m, --module <name>', 'Generate new module structure in application', 'Default') | ||
.parse(process.argv); | ||
// User generates new application | ||
defaultOptions.applicationName = commander.application.replace(/\s\t/gi, ''); | ||
defaultOptions.applicationFolder = process.cwd() + '/' + defaultOptions.applicationName; | ||
defaultOptions.applicationFolder = generateDirectory + '/' + defaultOptions.applicationName; | ||
defaultOptions.moduleName = commander.module.replace(/[^a-zA-Z-_.]+/gi, '').capitalize(); | ||
@@ -64,3 +69,3 @@ defaultOptions.moduleNameLowerCase = defaultOptions.moduleName.toLowerCase(); | ||
console.error(colors.cyan('[TWEE] ') + colors.red('Module folder exists: ' + newModuleFolder)); | ||
return; | ||
process.exit(1); | ||
} | ||
@@ -165,3 +170,3 @@ defaultOptions.generateOnlyModule = true; | ||
// Turning module ON | ||
var modulesAppConfig = path.join(process.cwd(), options.applicationName, 'configs/modules.js') | ||
var modulesAppConfig = path.join(generateDirectory, options.applicationName, 'configs/modules.js') | ||
, modulesConfig = require(modulesAppConfig); | ||
@@ -168,0 +173,0 @@ |
@@ -32,4 +32,4 @@ module.exports = { | ||
"Twee View Engine": { | ||
"module": "twee-extensions/view/engine/swig" | ||
"Twee View Engines": { | ||
"module": "twee-extensions/view/engines" | ||
}, | ||
@@ -120,17 +120,7 @@ | ||
"viewEngine": { | ||
"swig": { | ||
"engineExtension": "html", | ||
"options": { | ||
"cache": null | ||
} | ||
"view": { | ||
"engines": { | ||
"html": "swig" | ||
}, | ||
"jade": { | ||
"engineExtension": "jade", | ||
"options": { | ||
"pretty": true, | ||
"compileDebug": false | ||
} | ||
}, | ||
"disabled": false | ||
"defaultEngine": "html" | ||
}, | ||
@@ -137,0 +127,0 @@ |
57
index.js
@@ -156,3 +156,3 @@ /** | ||
self.error('Caught exception: ' + err.stack || err.toString()); | ||
self.emit('twee.Exception', err); | ||
self.emit('twee.Exception', err, self); | ||
}); | ||
@@ -163,4 +163,13 @@ | ||
self.emit('twee.Exit'); | ||
self.log('EXIT'); | ||
process.exit(0); | ||
if (self.__env == 'development') { | ||
self.log('Immediate exit in development'); | ||
process.exit(0); | ||
} else { | ||
// Giving a chance to all modules to finish | ||
self.log('EXIT in 30sec'); | ||
setTimeout(function(){ | ||
process.exit(0); | ||
}, 30000); | ||
} | ||
}); | ||
@@ -274,3 +283,3 @@ | ||
// This route will be used to write user that he did not sat up any configuration file for framework | ||
this.__setupRouteForEmptyConfiguration(); | ||
this.__handle404(); | ||
}; | ||
@@ -495,19 +504,35 @@ | ||
*/ | ||
twee.prototype.__setupRouteForEmptyConfiguration = function() { | ||
twee.prototype.__handle404 = function() { | ||
var self = this; | ||
this.emit('twee.__setupRouteForEmptyConfiguration.Start'); | ||
this.__app.use(function(req, res){ | ||
res.status(404); | ||
// Here we can rewrite environment with framework extending | ||
this.emit('twee.__handle404.Start'); | ||
this.__app.use(function(err, req, res, next){ | ||
var message = '404 - Not found!'; | ||
if (err) { | ||
res.status(500); | ||
if (self.__env == 'development') { | ||
message = err.toString(); | ||
} | ||
} else { | ||
res.status(404); | ||
err = new Error('The page you requested has not been found!'); | ||
} | ||
if (req.xhr) { | ||
res.json({message: 'Please Configure Twee Framework', error: 404}); | ||
var jsonMessage = {message: message, error_code: 404}; | ||
if (self.__env == 'development') { | ||
jsonMessage['stack'] = err.stack || err.toString(); | ||
} | ||
res.json(jsonMessage); | ||
} else { | ||
if (self.__app.get('viewEngineType')) { | ||
res.render(self.getConfig('twee:options:errorPages:404:viewTemplate')); | ||
if (self.__app.get('view engine')) { | ||
res.render(self.getConfig('twee:options:errorPages:404:viewTemplate'), {error: err}); | ||
} else { | ||
res.send('<h1>404 - Not found!</h1>'); | ||
res.send('<h1>' + message + '</h1>'); | ||
} | ||
} | ||
}); | ||
this.emit('twee.__setupRouteForEmptyConfiguration.End'); | ||
this.emit('twee.__handle404.End'); | ||
}; | ||
@@ -697,2 +722,3 @@ | ||
this.log('NODE_ENV: ' + this.__env); | ||
this.__app.locals.env = this.__env; | ||
return this; | ||
@@ -1227,5 +1253,10 @@ }; | ||
}); | ||
this.emit('twee.run.master', process.pid); | ||
} else { | ||
this.__createServer(); | ||
this.emit('twee.run.fork', process.pid); | ||
} | ||
this.emit('twee.run', process.pid); | ||
}; | ||
@@ -1232,0 +1263,0 @@ |
{ | ||
"name": "twee", | ||
"preferGlobal": false, | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"author": "Dmitri Mesin <dmitri.mesin@gmail.com>", | ||
@@ -14,3 +14,3 @@ "homepage": "https://github.com/mesin/twee", | ||
"dependencies": { | ||
"twee-extensions": ">= 0.0.6", | ||
"twee-extensions": ">= 0.0.7", | ||
"express": "*", | ||
@@ -31,3 +31,3 @@ "path": "*", | ||
"scripts": { | ||
"test": "test" | ||
"test": "mocha tests" | ||
}, | ||
@@ -34,0 +34,0 @@ "repository": { |
@@ -1,17 +0,29 @@ | ||
twee | ||
Twee Framework | ||
==== | ||
*- The most powerful, elegant and extensive framework for Node.js based on Express.js* | ||
![TweeLogo](https://pbs.twimg.com/profile_banners/2958425874/1421160388/1500x500) | ||
![Travis Build Status](https://travis-ci.org/mesin/twee.svg) | ||
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mesin/twee?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) | ||
[![Dependency Status](https://gemnasium.com/mesin/twee.svg)](https://gemnasium.com/mesin/twee) | ||
[![npm version](https://badge.fury.io/js/twee.svg)](http://badge.fury.io/js/twee) | ||
Why do we need one more framework for Node.js? | ||
==== | ||
Twee JavaScript Framework for Node.js, based on Express.js and helps to be not as BlackBox like another frameworks, but to use Express.js like you're using only it. | ||
The second idea is modular structure. You are able to create modules. Each module can include: | ||
- extensions (core code) | ||
- head middleware list (runs before all the controllers) | ||
- tail middleware list (runs after all the controllers) | ||
- controllers (each controller has it's own actions and all actions can be configured for some route) | ||
- module prefixes (for example blog module can have `blog` prefix. If controller has action `list`, then this action will be accessable via `blog/list` url) | ||
- extendable configs, with regarding of environment | ||
- extra configurable core | ||
- support for many template engines | ||
Raw `Node.js` application is *very* low-level. You need to handle all the requests by your own. It is pain in the ass.. | ||
Another pain in the same place is when you try to use very big framework with tons of agreements and conventions. Most of today's frameworks (full-stack or rails like) - are big and mostly like a black boxes. You never know how they work inside! And if you know - then you're probably simply one of it's developers :-) | ||
For all other developers it is still black box. Most of them can feel inconfortable because of it. You doing something, you see that it works, but you don't feel control over your application that handles by this big closed monster! | ||
Don't panic. | ||
There is one of the most usable and downloadable frameworks with great tested architecture and nice middleware-conventions: `Express.js`. It downloads 10x times more than all the other frameworks, and it sais about it's quality and strong concepts. And it could be perfect, but you still need some tricks and efforts to build structure on it, that can be great for scalable big enterprise-ready applications. | ||
Enterprice-ready means not only good stable code that could be safe and could work weeks and years. It also means good structure of all the application, how easy and understandable will be to manage big complex application in hard enterprise environment. | ||
Unfortunately `Express.js` doesn't solve these problems. | ||
And here `Twee.io` comes. |
@@ -10,3 +10,5 @@ { | ||
"dependencies": { | ||
"twee": ">= __TWEE_VERSION__", | ||
"twee": ">= __TWEE_VERSION__" | ||
}, | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "*", | ||
@@ -13,0 +15,0 @@ "grunt-contrib-concat": "*", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112655
53
2583
30
24
4
Updatedtwee-extensions@>= 0.0.7