Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
existsSync changes for Node 0.8 compat.
  • Loading branch information
mde committed Jun 27, 2012
1 parent 118d00f commit de86f04
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
5 changes: 4 additions & 1 deletion bin/cli.js
Expand Up @@ -4,6 +4,7 @@
var geddy = require('../lib/geddy');

var exec = require('child_process').exec
, fs = require('fs')
, path = require('path')
, parseopts = require('../lib/parseopts')
, utils = require('../lib/utils/index')
Expand Down Expand Up @@ -135,7 +136,9 @@ else {
// Just `geddy` -- start the server
else {
var configPath = path.join(cwd, 'config')
, geddyApp = path.existsSync(configPath);
, existsSync = typeof fs.existsSync == 'function' ?
fs.existsSync : path.existsSync
, geddyApp = existsSync(configPath);

if(geddyApp) {
// Start the server
Expand Down
22 changes: 12 additions & 10 deletions lib/app.js
Expand Up @@ -17,9 +17,11 @@
*/

var fs = require('fs')
, path = require('path')
, existsSync = typeof fs.existsSync == 'function' ?
fs.existsSync : path.existsSync
, url = require('url')
, querystring = require('../deps/qs')
, path = require('path')
, cwd = process.cwd()
, errors = require('./response/errors')
, response = require('./response')
Expand Down Expand Up @@ -100,7 +102,7 @@ var App = function () {
, adapterPath
, appAdaptersPath = path.join(cwd, modelDir, '/adapters/');
// May be running entirely model-less
if (!path.existsSync(path.join(cwd, modelDir))) {
if (!existsSync(path.join(cwd, modelDir))) {
next();
}
else {
Expand All @@ -117,10 +119,10 @@ var App = function () {
// - But I couldn't think of a reliable way that would work

// If the app has an adapter that matches the model adapter, use it.
if (path.existsSync(path.join(appAdaptersPath, adapterName.toLowerCase() + '.js')) ||
path.existsSync(path.join(appAdaptersPath, adapterName.toLowerCase() + '.coffee'))) {
if (existsSync(path.join(appAdaptersPath, adapterName.toLowerCase() + '.js')) ||
existsSync(path.join(appAdaptersPath, adapterName.toLowerCase() + '.coffee'))) {

if(path.existsSync(path.join(appAdaptersPath, adapterName.toLowerCase() + '.coffee'))) {
if(existsSync(path.join(appAdaptersPath, adapterName.toLowerCase() + '.coffee'))) {
try {
usingCoffee = usingCoffee || require('coffee-script');
} catch(err) {
Expand All @@ -131,7 +133,7 @@ var App = function () {
geddy.model.adapter[item.ctorName] = require(adapterPath)[adapterName];
}
// if the model has been defined by geddy, use it.
else if (path.existsSync(path.join(__dirname, "./model/adapters/", adapterName.toLowerCase() + '.js'))) {
else if (existsSync(path.join(__dirname, "./model/adapters/", adapterName.toLowerCase() + '.js'))) {
var config = {model: item.ctorName};
adapterPath = path.join(__dirname, "./model/adapters/", adapterName.toLowerCase());
geddy.model.adapter[item.ctorName] = require(adapterPath)[adapterName](config);
Expand All @@ -142,7 +144,7 @@ var App = function () {
}
// if the model doesn't define an adapter, use the default
else if (geddy.config.adapters && geddy.config.adapters.default &&
path.existsSync(path.join(__dirname, "./model/adapters/", geddy.config.adapters.default+".js"))) {
existsSync(path.join(__dirname, "./model/adapters/", geddy.config.adapters.default+".js"))) {
geddy.model.adapter[item.ctorName] = require(path.join(__dirname, "./model/adapters/", geddy.config.adapters.default));
}
// the adapter will be undefined if the model doesn't define it,
Expand Down Expand Up @@ -179,7 +181,7 @@ var App = function () {
// ==================
, _loadRouter = function (next) {
routerCsFile = path.join(cwd, '/config/router.coffee');
if(path.existsSync(routerCsFile)) {
if(existsSync(routerCsFile)) {
try {
require('coffee-script');
} catch(err) {
Expand Down Expand Up @@ -224,7 +226,7 @@ var App = function () {
, _registerTemplatePaths = function (next) {
var viewsPath = path.normalize('app/views');
// May be running entirely viewless
if (!path.existsSync(viewsPath)) {
if (!existsSync(viewsPath)) {
this.templateRegistry = {};
next();
}
Expand Down Expand Up @@ -542,7 +544,7 @@ var App = function () {
// Decode path (e.g. %20)
staticPath = decodeURIComponent(staticPath);

if (path.existsSync(staticPath)) {
if (existsSync(staticPath)) {
staticResp = new response.Response(resp);
staticResp.sendFile(staticPath);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/cluster/master.js
Expand Up @@ -2,6 +2,8 @@ var Master
, cluster
, fs = require('fs')
, path = require('path')
, existsSync = typeof fs.existsSync == 'function' ?
fs.existsSync : path.existsSync
, errors = require('../response/errors')
, watchFiles = require('../watch_files')
, Log = require('../../deps/log')
Expand Down Expand Up @@ -121,7 +123,7 @@ Master.prototype = new (function () {
types.forEach(function (type) {
var currentLog = path.join(dir, type + '.log')
, archivedLog = path.join(dir, type + '.' + now + '.log');
if (path.existsSync(currentLog)) {
if (existsSync(currentLog)) {
try {
fs.renameSync(currentLog, archivedLog);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/init/i18n.js
Expand Up @@ -2,6 +2,8 @@ var i18n = require('../i18n')
, exec = require('child_process').exec
, path = require('path')
, fs = require('fs')
, existsSync = typeof fs.existsSync == 'function' ?
fs.existsSync : path.existsSync
, fileUtils = require('../utils/file');

module.exports = new (function () {
Expand All @@ -17,7 +19,7 @@ module.exports = new (function () {
, loadLocaleData = function () {
localePaths.forEach(function (directory) {
directory = path.normalize(directory);
if (path.existsSync(directory)) {
if (existsSync(directory)) {
var files = fileUtils.readdirR(directory);
for (var i = 0; i < files.length; i++) {
file = files[i];
Expand Down

0 comments on commit de86f04

Please sign in to comment.