Skip to content
Browse files

Moved exists/existsSync

  • Loading branch information...
1 parent 2f913bf commit d7355b10b96f5d8f3d3271c7fc789b091a18f22f Alex Young committed Jul 14, 2012
Showing with 20 additions and 15 deletions.
  1. +2 −2 lib/server.js
  2. +7 −5 lib/site_builder.js
  3. +2 −0 lib/utils.js
  4. +1 −1 package.json
  5. +8 −7 test/cli_tools.test.js
View
4 lib/server.js
@@ -7,7 +7,7 @@
/**
* Module dependencies and local variables.
*/
-var path = require('path')
+var existsSync = require('./utils').existsSync
, watch = require('nodewatch')
, siteBuilder
, log = require(__dirname + '/log');
@@ -29,7 +29,7 @@ function server() {
app.get('*', function(req, res) {
var postPath = siteBuilder.outputRoot + req.url + '/';
// TODO: Security
- if (req.url.match(/[^/]$/) && path.existsSync(postPath)) {
+ if (req.url.match(/[^/]$/) && existsSync(postPath)) {
res.redirect(req.url + '/');
} else {
res.send('404');
View
12 lib/site_builder.js
@@ -8,6 +8,8 @@
* Module dependencies.
*/
var textile = require('stextile')
+ , existsSync = require('./utils').existsSync
+ , exists = require('./utils').exists
, fs = require('./graceful')
, path = require('path')
, jade = require('jade')
@@ -35,17 +37,17 @@ function SiteBuilder(config, fileMap) {
this.root = config.root;
var helperFile = path.join(this.root, '_lib', 'helpers.js');
- if (path.existsSync(helperFile)) {
+ if (existsSync(helperFile)) {
userHelpers = require(helperFile);
}
var filterFile = path.join(this.root, '_lib', 'filters.js');
- if (path.existsSync(filterFile)) {
+ if (existsSync(filterFile)) {
userFilters = require(filterFile);
}
var postFilterFile = path.join(this.root, '_lib', 'post-filters.js');
- if (path.existsSync(postFilterFile)) {
+ if (existsSync(postFilterFile)) {
userPostFilters = require(postFilterFile);
}
@@ -473,7 +475,7 @@ SiteBuilder.prototype.cacheIncludes = function() {
toRead--;
}
- path.exists(path.join(this.root, '_includes'), function(exists) {
+ exists(path.join(this.root, '_includes'), function(exists) {
if (!exists) {
done();
} else {
@@ -545,7 +547,7 @@ SiteBuilder.prototype.renderTemplate = function(templateFile, post, content) {
throw(e);
}
- path.exists(dirName, function(exists) {
+ exists(dirName, function(exists) {
if (exists) {
self.write(fileName, html);
} else {
View
2 lib/utils.js
@@ -0,0 +1,2 @@
+exports.existsSync = require('fs').existsSync || require('path').existsSync;
+exports.exists = require('fs').exists || require('path').exists;
View
2 package.json
@@ -1,6 +1,6 @@
{ "name": "pop"
, "description": "A static website and blog generator"
-, "version": "0.1.7"
+, "version": "0.1.8"
, "url": "http://popjs.com"
, "author": "Alex R. Young <alex@helicoid.net>"
, "engines": ["node >= 0.4.7"]
View
15 test/cli_tools.test.js
@@ -3,6 +3,7 @@ var assert = require('assert')
, log = require(__dirname + '/../lib/log')
, fs = require(__dirname + '/../lib/graceful')
, pop = require(__dirname + '/../lib/pop')
+ , existsSync = require(__dirname + '/../lib/utils').existsSync
, cliTools = pop.cliTools
, config;
@@ -14,7 +15,7 @@ config = {
, root: '/tmp/pop-tests/'
};
-if (!path.existsSync(config.root))
+if (!existsSync(config.root))
fs.mkdirSync(config.root, 0777);
exports['test datePad'] = function() {
@@ -35,7 +36,7 @@ exports['test makePost'] = function() {
fs.mkdir_p(path.join(config.root, '_posts'), 0777, function() {
cliTools.makePost(config, title, function() {
- assert.ok(path.existsSync(fileName));
+ assert.ok(existsSync(fileName));
fs.unlinkSync(fileName);
});
});
@@ -45,11 +46,11 @@ exports['test makeSite'] = function() {
var fileName = config.root + 'make-site-' + (new Date).getTime().toString();
cliTools.makeSite(fileName, function() {
- assert.ok(path.existsSync(fileName));
- assert.ok(path.existsSync(fileName + '/_config.json'));
- assert.ok(path.existsSync(fileName + '/index.jade'));
- assert.ok(path.existsSync(fileName + '/robots.txt'));
- assert.ok(path.existsSync(fileName + '/_layouts/default.jade'));
+ assert.ok(existsSync(fileName));
+ assert.ok(existsSync(fileName + '/_config.json'));
+ assert.ok(existsSync(fileName + '/index.jade'));
+ assert.ok(existsSync(fileName + '/robots.txt'));
+ assert.ok(existsSync(fileName + '/_layouts/default.jade'));
});
};

0 comments on commit d7355b1

Please sign in to comment.
Something went wrong with that request. Please try again.