From edd69c3975d7a3c43fd962237c1505a3ee7ca4d0 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 11 Jul 2012 13:56:58 -0700 Subject: [PATCH] avoid deprecation warnings if running node >= v0.8 - refs #1568 --- commands/core.bones | 8 +++++--- commands/export.bones | 6 ++++-- index.js | 5 +++-- lib/fsutil.js | 4 +++- models/Library.server.bones | 5 ++++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/commands/core.bones b/commands/core.bones index be2a121d6..a95ca0d3b 100644 --- a/commands/core.bones +++ b/commands/core.bones @@ -7,6 +7,8 @@ var mapnik = require('mapnik'); var semver = require('semver'); var os = require('os'); var crypto = require('crypto'); +// node v6 -> v8 compatibility +var existsSync = require('fs').existsSync || require('path').existsSync; command = Bones.Command.extend(); @@ -117,18 +119,18 @@ command.prototype.bootstrap = function(plugin, callback) { }; var configDir = path.join(process.env.HOME, '.tilemill'); - if (!path.existsSync(configDir)) { + if (!existsSync(configDir)) { console.warn('Creating configuration dir %s', configDir); fsutil.mkdirpSync(configDir, 0755); } - if (!path.existsSync(settings.files)) { + if (!existsSync(settings.files)) { console.warn('Creating files dir %s', settings.files); fsutil.mkdirpSync(settings.files, 0755); } ['export', 'project', 'cache'].forEach(function(key) { var dir = path.join(settings.files, key); - if (!path.existsSync(dir)) { + if (!existsSync(dir)) { console.warn('Creating %s dir %s', key, dir); fsutil.mkdirpSync(dir, 0755); if (key === 'project' && settings.examples) { diff --git a/commands/export.bones b/commands/export.bones index 1a2419a39..57ba5c10a 100644 --- a/commands/export.bones +++ b/commands/export.bones @@ -8,6 +8,8 @@ var Step = require('step'); var http = require('http'); var chrono = require('chrono'); var crashutil = require('../lib/crashutil'); +// node v6 -> v8 compatibility +var existsSync = require('fs').existsSync || require('path').existsSync; command = Bones.Command.extend(); @@ -147,7 +149,7 @@ command.prototype.initialize = function(plugin, callback) { // Validation. if (!opts.project || !opts.filepath) return plugin.help(); - if (!path.existsSync(path.dirname(opts.filepath))) + if (!existsSync(path.dirname(opts.filepath))) return this.error(new Error('Export path does not exist: ' + path.dirname(opts.filepath))); // Format. @@ -170,7 +172,7 @@ command.prototype.initialize = function(plugin, callback) { opts.scale = parseInt(opts.scale, 10); // Rename the output filepath using a random hash if file already exists. - if (path.existsSync(opts.filepath) && + if (existsSync(opts.filepath) && _(['png','pdf','svg','mbtiles']).include(opts.format)) { var hash = crypto.createHash('md5') .update(+new Date + '') diff --git a/index.js b/index.js index d895d430b..f7c6eaa0b 100755 --- a/index.js +++ b/index.js @@ -1,6 +1,8 @@ #!/usr/bin/env node var fs = require('fs'); +// node v6 -> v8 compatibility +var existsSync = require('fs').existsSync || require('path').existsSync; process.title = 'tilemill'; @@ -31,9 +33,8 @@ if (process.platform === 'win32') { // Default --config flag to user's home .tilemill.json config file. // @TODO find a more elegant way to set a default for this value // upstream in bones. -var path = require('path'); var config = path.join(process.env.HOME, '.tilemill/config.json'); -if (path.existsSync(config)) { +if (existsSync(config)) { var argv = require('optimist').argv; argv.config = argv.config || config; } diff --git a/lib/fsutil.js b/lib/fsutil.js index 1a2c630e6..6e6009609 100644 --- a/lib/fsutil.js +++ b/lib/fsutil.js @@ -5,6 +5,8 @@ var path = require('path'); var constants = require('constants'); var _ = require('underscore'); var mkdirp = require('mkdirp'); +// node v6 -> v8 compatibility +var existsSync = require('fs').existsSync || require('path').existsSync; var path_sep = process.platform === 'win32' ? '\\' : '/'; @@ -53,7 +55,7 @@ function mkdirpSync(p, mode) { var created = []; while (ps.length) { created.push(ps.shift()); - if (created.length > 1 && !path.existsSync(created.join(path_sep))) { + if (created.length > 1 && !existsSync(created.join(path_sep))) { var err = fs.mkdirSync(created.join(path_sep), 0755); if (err) return err; } diff --git a/models/Library.server.bones b/models/Library.server.bones index a0c34f4a0..c736f90eb 100644 --- a/models/Library.server.bones +++ b/models/Library.server.bones @@ -8,6 +8,9 @@ var rm = require('../lib/fsutil').rm; var s3 = require('../lib/s3'); var config = Bones.plugin.config; var url = require('url'); +// node v6 -> v8 compatibility +var existsAsync = require('fs').exists || require('path').exists; + // Extensions supported by TileMill. See `millstone.resolve()` for // the source of this list. @@ -61,7 +64,7 @@ models.Library.prototype.sync = function(method, model, success, error) { location = path.join(config.files, 'project', model.get('project'), location); } - path.exists(location, function(exists) { + existsAsync(location, function(exists) { if (!exists) location = process.env.HOME; readdir(location, function(err, files) { if (err &&