Comparing version 0.1.5 to 0.1.6
@@ -20,2 +20,7 @@ #!/usr/bin/env node | ||
} else { | ||
try { | ||
fs.renameSync(folderName + '/template.gitignore', folderName + '/.gitignore'); | ||
} catch(e) { | ||
//ignore | ||
} | ||
console.log(folderName + ' project created.'); | ||
@@ -22,0 +27,0 @@ } |
module.exports = function(app) { | ||
var conf = include('/conf/conf.js'); | ||
app.conf = conf; | ||
app.isDebug = conf.debug; | ||
//convenience | ||
app.isDebug = conf.isDebug; | ||
} |
var mongoose = require('mongoose'); | ||
var fileUtils = require('../utils/fileUtils'); | ||
var Schema = mongoose.Schema; | ||
var stringUtils = require('../utils/stringUtils'); | ||
module.exports = function(app) { | ||
app.models = new Object(); | ||
getModelsFromDir('/models', function(err, model, opts) { | ||
getModelsFromDir('/models', app, function(err, model, opts) { | ||
var name = opts.name; | ||
@@ -13,12 +14,43 @@ app.models[name] = model; | ||
function hasConnection(connections) { | ||
for (var i in connections) { | ||
return true; | ||
} | ||
function getModelsFromDir(dir, callback) { | ||
return false; | ||
} | ||
function getModelsFromDir(dir, app, callback) { | ||
//do not load models if there's DB | ||
if (!hasConnection(app.connections)) { | ||
if (app.isDebug) { | ||
console.log('No connections found. Ignoring models.'); | ||
} | ||
return; | ||
} | ||
var models = []; | ||
fileUtils.recurseJs(dir, function(err, opts) { | ||
if (!opts.isDirectory()) { | ||
if (!opts.isDirectory() && stringUtils.endsWith(opts.file, '.js')) { | ||
var absPath = opts.absolutePath; | ||
var modelJs = require(absPath); | ||
var conn = connections.mainDb; | ||
var conn; | ||
if (modelJs.connection) { | ||
conn = app.connections.mainDb; | ||
} else { | ||
if (connections.mainDb) { | ||
conn = app.connections.mainDb; | ||
} else { | ||
for (var i in app.connections) { | ||
//get the first connection | ||
conn = app.connections[i]; | ||
break; | ||
} | ||
} | ||
} | ||
var schema = new Schema(modelJs.schema); | ||
@@ -28,2 +60,5 @@ if (modelJs.initSchema) { | ||
} | ||
if (app.isDebug) { | ||
console.log("[model] " + opts.name) | ||
} | ||
var model = conn.model(opts.name, schema); | ||
@@ -30,0 +65,0 @@ |
var fileUtils = require('../utils/fileUtils'); | ||
var customRoutes = include('/conf/routes.js'); | ||
var stringUtils = require('../utils/stringUtils'); | ||
module.exports = function(app) { | ||
@@ -13,3 +14,3 @@ customRoutes(app); | ||
fileUtils.recurseJs(dir, function(err, opts) { | ||
if (!opts.isDirectory()) { | ||
if (!opts.isDirectory() && stringUtils.endsWith(opts.file, '.js')) { | ||
var file = opts.file; | ||
@@ -23,3 +24,3 @@ var subfolder = opts.subfolder; | ||
var controller = require(absPath); | ||
var subPathWithoutExt; | ||
var server = app.server; | ||
@@ -29,16 +30,18 @@ | ||
if (file == 'index.js') { | ||
subPathWithoutExt = subPath.slice(0, -8); | ||
var subPathWithoutExt = subPath.slice(0, -8); | ||
applyRoute(server, subPathWithoutExt, controller); | ||
if (opts.subfolder) { | ||
//for non root index.js apply no '/' | ||
//e.g. http://localhost/admin/ and http://localhost/admi | ||
subPathWithoutExt = subPath.slice(0, -9); | ||
applyRoute(server, subPathWithoutExt, controller); | ||
} | ||
} else { | ||
subPathWithoutExt = subPath.slice(0, -3); | ||
var subPathWithoutExt = subPath.slice(0, -3); | ||
applyRoute(server, subPathWithoutExt, controller); | ||
} | ||
if (oils.isDebug) { | ||
console.log(subPathWithoutExt + ' :: ' + subPath); | ||
} | ||
if (controller.get) { | ||
server.get(subPathWithoutExt, controller.get); | ||
} | ||
if (controller.post) { | ||
post(subPathWithoutExt, controller.post); | ||
} | ||
} | ||
@@ -51,1 +54,17 @@ | ||
} | ||
function applyRoute(server, route, controller) { | ||
if (controller.get) { | ||
if (oils.isDebug) { | ||
console.log('[route] GET ' + route); | ||
} | ||
server.get(route, controller.get); | ||
} | ||
if (controller.post) { | ||
if (oils.isDebug) { | ||
console.log('[route] POST ' + route); | ||
} | ||
post(route, controller.post); | ||
} | ||
} |
var fs = require('fs'); | ||
var stringUtils = require('./stringUtils'); | ||
exports.recurseJs = function(dir, callback, subfolder) { | ||
@@ -16,5 +16,4 @@ subfolder = subfolder || ''; | ||
var file = files[i]; | ||
if (stringUtils.endsWith(file, '.js')) { | ||
handleFile(dir, subfolder, file, callback); | ||
} | ||
handleFile(dir, subfolder, file, callback); | ||
} | ||
@@ -21,0 +20,0 @@ |
{ | ||
"name": "oils", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Oils Js framework built on top of Express.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
oilsjs | ||
oils | ||
====== | ||
@@ -6,3 +6,3 @@ | ||
Oils is a framework built on top of Express framework. It's very flexible and very simple to use, you'll love it! | ||
Oils is a web framework built on top of Express framework. It's very flexible and very simple to use, you'll love it! | ||
@@ -30,20 +30,12 @@ It is primarily used to create Openshift Node JS Applications. You can also use this for other projects as the variable dependencies are just very few and are all in the configuration file. | ||
``` | ||
npm install oils -g | ||
``` | ||
> npm install oils -g | ||
``` | ||
oils new HelloWorld | ||
``` | ||
> oils new HelloWorld | ||
``` | ||
cd HelloWorld | ||
``` | ||
> cd HelloWorld | ||
``` | ||
npm install | ||
``` | ||
> npm install | ||
> node server.js | ||
``` | ||
node server.js | ||
``` | ||
@@ -64,2 +56,21 @@ or you can just simply Download the zip version of this project and copy-paste it to your node js application. | ||
MIT | ||
The MIT License (MIT) | ||
Copyright (c) 2014 Manny | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
/* | ||
Global variables: | ||
global.isProd - checks if running in openshift server | ||
global.isProd - checks if running in openshift server, will expose this later | ||
connections.mainDb - main mongoose db, convenience for oils.connections.mainDb | ||
models.[model name] - returns a Mongoose Model, convenience for oils.models | ||
oils.isDebug - setting to true usually means more logging | ||
configuration below is accessible view oils.conf.[name] | ||
e.g. oils.conf.ipAddress | ||
*/ | ||
@@ -13,3 +16,5 @@ | ||
connections: { | ||
//later support for multiple mongoose databases | ||
//only mongoose connections are support for now | ||
//you can specify multiple connections and specify the connection in your model. | ||
//if you don't need a db, you can remove/comment out mainDb | ||
mainDb : { | ||
@@ -19,4 +24,4 @@ url: (process.env.OPENSHIFT_MONGODB_DB_URL + process.env.OPENSHIFT_APP_NAME) || 'mongodb://localhost/test' | ||
}, | ||
debug: false | ||
isDebug: false | ||
} | ||
module.exports = { | ||
schema: { | ||
author: String, | ||
title: String, | ||
publishDate: Date | ||
} | ||
//mongoose schema, see mongoosejs.com for more info | ||
schema: { | ||
author: String, | ||
title: String, | ||
publishDate: Date | ||
} | ||
/*** Optional attributes | ||
, | ||
initSchema: function(schema) { | ||
//initialize the schema if needed, else this | ||
//methos is optional | ||
}, | ||
connection: 'mainDb' //defaults to 'mainDb' or the first defined connection in conf.js | ||
***/ | ||
} |
@@ -10,2 +10,8 @@ MODELS FOLDER | ||
###schema [required] | ||
Return the attributes of the schema. See Mongoose' Schema for the syntax. | ||
###initSchema [optional] | ||
You can initialize a Schema by adding an initSchema in your model. The Schema is a Mongoose Schema. | ||
@@ -15,8 +21,5 @@ | ||
``` | ||
module.exports = { | ||
schema: { | ||
author: String, | ||
title: String, | ||
publishDate: Date | ||
}, | ||
... | ||
@@ -27,2 +30,15 @@ initSchema: function(schema) { | ||
} | ||
} | ||
} | ||
``` | ||
###connection [optional] | ||
You can specify the connection (defined in conf.js). The default will be 'mainDb' or the first connection defined in conf.js. | ||
``` | ||
module.exports = { | ||
... | ||
connection: 'mainDb' | ||
} | ||
``` |
oils-js-quickstart | ||
================== | ||
### Oils JS | ||
### Oils JS Template | ||
Oils is a simple framework to create Openshift Node JS Applications. You can also use this for non Openshift projects as the variable dependencies are just very few and it will work even if it's not in an Openshift environment. | ||
[Oils JS](https://github.com/mannyvergel/oils-js) is a web framework and this is the template used to create a basic oils js application. | ||
It will automatically read models and controllers. Also features automatic routing for created controllers. | ||
### Set-Up | ||
Directory Structure: | ||
Please see [Oils JS](https://github.com/mannyvergel/oils-js) documentation for the set-up. | ||
|-- controllers | ||
|-- models | ||
|-- views | ||
|-- public | ||
|-- lib | ||
Alternatively, you can also clone this repository, then do an npm install and run server.js. | ||
### Set-Up | ||
### Usage | ||
For OpenShift apps, after creating your node js + mongodb application, clone the project to your local and go to that directory. In the command line, do the ff: | ||
Go to [Oils JS](https://github.com/mannyvergel/oils-js) for more information. | ||
``` | ||
git remote add upstream -m master https://github.com/mannyvergel/oils-js-quickstart.git | ||
``` | ||
### Contact | ||
``` | ||
git pull -s recursive -X theirs upstream master | ||
``` | ||
If you have questions, feel free to drop me an email: manny@mvergel.com | ||
``` | ||
git push | ||
``` | ||
### License | ||
or you can just simply Download the zip version of this project and copy-paste it to your node js application. | ||
The MIT License (MIT) | ||
### Usage | ||
Copyright (c) 2014 Manny | ||
This sample app is self explanatory. Just browse through the directories and files and you will get the hang of it. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
It uses Mongoose for ORM. Mongo DB for the database. Swig for templating. | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
### Contact | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
If you have questions, feel free to drop me an email: manny@mvergel.com | ||
### License | ||
MIT |
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
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
36061
36
423
74