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

Commit

Permalink
Use Bones --config flag rather than custom defaults loading system fo…
Browse files Browse the repository at this point in the history
…r .tilemill.json config.
  • Loading branch information
Young Hahn committed Dec 15, 2011
1 parent bbf0ac1 commit 8e249fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ process.title = 'tilemill';
// name.
process.argv[0] = 'node';

// 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.json');
if (path.existsSync(config)) {
var argv = require('bones/node_modules/optimist').argv;
argv.config = argv.config || config;
}

require('tilelive-mapnik').registerProtocols(require('tilelive'));
require('mbtiles').registerProtocols(require('tilelive'));

Expand Down
25 changes: 7 additions & 18 deletions models/Config.server.bones
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@ var paths = {
vendor: path.resolve(__dirname + '/../lib/config.defaults.json')
};

// Catch & ignore invalid user JSON.
try {
models.Config.defaults = {};
models.Config.defaults = JSON.parse(fs.readFileSync(paths.user, 'utf8'));
models.Config.defaults = _(models.Config.defaults)
.defaults(JSON.parse(fs.readFileSync(paths.vendor, 'utf8')));
} catch(e) {
console.error('Ignoring invalid JSON at %s', paths.user);
models.Config.defaults = JSON.parse(fs.readFileSync(paths.vendor, 'utf8'));
}

models.Config.defaults = JSON.parse(fs.readFileSync(paths.vendor, 'utf8'));
models.Config.prototype.sync = function(method, model, success, error) {
if (method === 'delete') return error(new Error('Method not supported.'));

Expand All @@ -35,14 +25,13 @@ models.Config.prototype.sync = function(method, model, success, error) {
break;
case 'create':
case 'update':
// Filter out keys that may not be written.
var allowedKeys = ['bufferSize', 'files', 'syncAccount', 'syncAccessToken'];
var data = model.toJSON();

// Additional data processing.
for (var key in data) {
if (!_(allowedKeys).include(key)) delete data[key];
}
if (data.files) data.files = data.files.replace('~', process.env.HOME);
var data = _(model.toJSON()).reduce(function(memo, val, key) {
if (key === 'files') val = val.replace('~', process.env.HOME);
if (_(allowedKeys).include(key)) memo[key] = val;
return memo;
}, {});

Step(function() {
fs.readFile(paths.user, 'utf8', this);
Expand Down
6 changes: 6 additions & 0 deletions test/support/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ process.argv[2] = 'start';

var exec = require('child_process').exec;
var path = require('path');
var fs = require('fs');

process.env.HOME = path.resolve(__dirname + '/../fixtures/files');

// Remove stale config file if present.
try { fs.unlinkSync(process.env.HOME + '/.tilemill.json'); }
catch (err) { if (err.code !== 'ENOENT') throw err }

// Load application. This file's purpose is to start TileMill only once and
// share the server with all tests.
require('../..');
Expand Down

0 comments on commit 8e249fb

Please sign in to comment.