Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Commit

Permalink
avoid deprecation warnings if running node >= v0.8 - refs tilemill-pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Jul 11, 2012
1 parent b691080 commit edd69c3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
8 changes: 5 additions & 3 deletions commands/core.bones
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions commands/export.bones
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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.
Expand All @@ -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 + '')
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/fsutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ? '\\' : '/';

Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion models/Library.server.bones
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 &&
Expand Down

0 comments on commit edd69c3

Please sign in to comment.