Comparing version 0.1.12 to 0.1.13
@@ -14,3 +14,3 @@ // Initializes the framework | ||
util = require('util'), | ||
appPath = module.parent.parent.filename.replace(/(.*)\/.+\.js$/, '$1'), | ||
appPath = path.dirname(module.parent.parent.filename), | ||
defaultConfig = { | ||
@@ -20,7 +20,12 @@ mode: 'production', | ||
app: appPath, | ||
logs: appPath + '/logs', | ||
on: appPath + '/on', | ||
controllers: appPath + '/patterns/controllers', | ||
models: appPath + '/patterns/models', | ||
views: appPath + '/patterns/views', | ||
// logs: appPath + '/logs', | ||
logs: path.join(appPath, '/logs'), | ||
// on: appPath + '/on', | ||
on: path.join(appPath, '/on'), | ||
// controllers: appPath + '/patterns/controllers', | ||
controllers: path.join(appPath, '/patterns/controllers'), | ||
// models: appPath + '/patterns/models', | ||
models: path.join(appPath, '/patterns/models'), | ||
// views: appPath + '/patterns/views', | ||
views: path.join(appPath, '/patterns/views'), | ||
public: path.resolve(appPath, '../public') | ||
@@ -128,3 +133,3 @@ }, | ||
function getConfig() { | ||
var configDirectory = appPath + '/config', | ||
var configDirectory = path.join(appPath, '/config'), | ||
files = [], | ||
@@ -148,3 +153,3 @@ config = {}; | ||
if ( citizenRegex.test(file) ) { | ||
citizenConfig = JSON.parse(fs.readFileSync(configDirectory + '/' + file)); | ||
citizenConfig = JSON.parse(fs.readFileSync(path.join(configDirectory, '/', file))); | ||
if ( citizenConfig.hostname && citizenConfig.hostname === os.hostname() ) { | ||
@@ -156,3 +161,3 @@ config.citizen = citizenConfig; | ||
fileSafeName = fileSafeName.replace('.json', ''); | ||
config[fileSafeName] = JSON.parse(fs.readFileSync(configDirectory + '/' + file)); | ||
config[fileSafeName] = JSON.parse(fs.readFileSync(path.join(configDirectory, '/', file))); | ||
} | ||
@@ -163,3 +168,3 @@ }); | ||
try { | ||
config.citizen = JSON.parse(fs.readFileSync(configDirectory + '/citizen.json')); | ||
config.citizen = JSON.parse(fs.readFileSync(path.join(configDirectory, '/citizen.json'))); | ||
} catch ( e ) { | ||
@@ -189,3 +194,3 @@ // No big deal, citizen will start under the default configuration | ||
fileSafeName = file.replace('.js', ''); | ||
on[fileSafeName] = require(finalConfig.directories.on + '/' + file); | ||
on[fileSafeName] = require(path.join(finalConfig.directories.on, '/', file)); | ||
} | ||
@@ -213,12 +218,12 @@ }); | ||
views = fs.readdirSync(finalConfig.directories.views); | ||
} catch ( e ) { | ||
getGroupedPatterns(); | ||
return; | ||
} catch ( err ) { | ||
throw { | ||
thrownBy: 'citizen.getPatterns()', | ||
message: 'There was an error while attempting to traverse the pattern directories. Check your file structure and make sure you have all the required directories (controllers, models, and views).' | ||
}; | ||
} | ||
controllers.forEach( function (file, index, array) { | ||
var fileSafeName; | ||
if ( jsRegex.test(file) ) { | ||
fileSafeName = file.replace('.js', ''); | ||
patterns.controllers[fileSafeName] = require(finalConfig.directories.controllers + '/' + file); | ||
patterns.controllers[path.basename(file, '.js')] = require(path.join(finalConfig.directories.controllers, '/', file)); | ||
} | ||
@@ -228,6 +233,4 @@ }); | ||
models.forEach( function (file, index, array) { | ||
var fileSafeName; | ||
if ( jsRegex.test(file) ) { | ||
fileSafeName = file.replace('.js', ''); | ||
patterns.models[fileSafeName] = require(finalConfig.directories.models + '/' + file); | ||
patterns.models[path.basename(file, '.js')] = require(path.join(finalConfig.directories.models, '/', file)); | ||
} | ||
@@ -238,4 +241,4 @@ }); | ||
var viewFiles; | ||
if ( fs.statSync(finalConfig.directories.views + '/' + directory).isDirectory() ) { | ||
viewFiles = fs.readdirSync(finalConfig.directories.views + '/' + directory); | ||
if ( fs.statSync(path.join(finalConfig.directories.views, '/', directory)).isDirectory() ) { | ||
viewFiles = fs.readdirSync(path.join(finalConfig.directories.views, '/', directory)); | ||
patterns.views[directory] = {}; | ||
@@ -249,3 +252,3 @@ viewFiles.forEach( function (file, index, array) { | ||
viewName = path.basename(file, fileExtension); | ||
viewContents = fs.readFileSync(finalConfig.directories.views + '/' + directory + '/' + file, { 'encoding': 'utf8' }); | ||
viewContents = fs.readFileSync(path.join(finalConfig.directories.views, '/', directory, '/', file), { 'encoding': 'utf8' }); | ||
switch ( fileExtension ) { | ||
@@ -280,34 +283,1 @@ case '.hbs': | ||
} | ||
function getGroupedPatterns() { | ||
var patterns = {}, | ||
patternFiles = fs.readdirSync(config.directories.patterns), | ||
patternName = '', | ||
patternFileName = '', | ||
viewContents = '', | ||
regex = new RegExp(/^([A-Za-z0-9-_])*$/); | ||
patternFiles.forEach( function (patternFileName, index, array) { | ||
if ( regex.test(patternFileName) ) { | ||
patternName = patternFileName.replace('/-/g', '_'); | ||
try { | ||
viewContents = fs.readFileSync(config.directories.patterns + '/' + patternFileName + '/' + patternFileName + '.html', { 'encoding': 'utf8' }); | ||
viewContents = viewContents.replace(/[\n|\t|\r]/g, ''); | ||
viewContents = viewContents.replace(/'/g, "\\'"); | ||
patterns[patternName] = { | ||
model: require(config.directories.patterns + '/' + patternFileName + '/' + patternFileName + '-model'), | ||
controller: require(config.directories.patterns + '/' + patternFileName + '/' + patternFileName + '-controller'), | ||
view: { | ||
raw: viewContents, | ||
compiled: handlebars.compile(viewContents) | ||
} | ||
}; | ||
} catch (e) { | ||
console.log(util.inspect(e)); | ||
throw e; | ||
} | ||
} | ||
}); | ||
return patterns; | ||
} |
{ | ||
"name": "citizen", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": "An event-driven MVC framework for Node.js web applications.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -9,5 +9,3 @@ # citizen | ||
** A note on Windows compatibility: ** I developed citizen using Mac and Linux environments. Windows support is first on my list of testing/fixes. | ||
## Getting Started with citizen | ||
@@ -14,0 +12,0 @@ |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
6
86403
1304
1064