'use strict';

const Promise = require('bluebird');
const path = require('path');
const write = Promise.promisify(require('fs').writeFile);

module.exports = function addRoute(options) {
  const file = path.resolve(options.dir, './hof.settings.json');
  const settings = require(file);
  if (settings.routes.indexOf(`./apps/${options.name}`) === -1) {
    settings.routes.push(`./apps/${options.name}`);
  }

  return write(file, JSON.stringify(settings, null, '  '));
};

'use strict';

const Promise = require('bluebird');
const path = require('path');
const write = Promise.promisify(require('fs').writeFile);

module.exports = function addRoute(options) {

  const file = path.resolve(options.dir, './hof.settings.json');
  try {
    const settings = require(file);
  } catch (e) {
    console.log('WARNING: Could not create new route automatically.');
    console.log(`Add './apps/${options.name}' to your routes manually`);
    return Promise.resolve();
  }
  if (settings.routes.indexOf(`./apps/${options.name}`) === -1) {
    settings.routes.push(`./apps/${options.name}`);
  }

  return write(file, JSON.stringify(settings, null, '  '));
};

Handle case where config was not created by generator
Handle case where config was not created by generator

If hof.settings.json does not exists, it is likely because the top level app was created manually, not using hof-generator. Deal with that, but provide advice about manually adding route.
