#!/usr/bin/env node
const inquirer = require('inquirer');
const updateNotifier = require('update-notifier');
const pkg = require('./package.json');

updateNotifier({ pkg }).notify();

const { getStations, loadStationByName } = require('./lib/station');
const { createFilesByList } = require('./lib/wizard');

const getStationId = async stations => {
  return ( await inquirer.prompt(stations)).stationId;
};

(async () => {
  try {
    const stationsCollection = await getStations();

    const stationsPathMap = stationsCollection.reduce( (m, station) => {

      const pathStations = m[station.stationsPath] || [];
      pathStations.push(station);

      return {
        ...m,
        [station.stationsPath]: pathStations
      };
    }, {} );

    let stationChoices = [];

    for( let stationsPath in stationsPathMap ) {

      stationChoices.push(new inquirer.Separator(`Stations from "${stationsPath}"`));

      stationChoices = stationChoices.concat(stationsPathMap[stationsPath]);
    }

    if (stationChoices.length === 0) {
      console.log('No takeoff stations found.');
      process.exit(1);
    }

    const chooseBetweenAvailableStations = [{
      type: 'list',
      name: 'stationId',
      message: 'What do you want to create?',
      choices: stationChoices
    }];

    const stationId = await getStationId(chooseBetweenAvailableStations);

    const { name, stationsPath } = stationsCollection.find(({ value }) => value === stationId);

    const station = await loadStationByName({ name, stationsPath });

    const requiredStationProps = [];

    station.requiredProps && station.requiredProps.forEach(prop => {
      if (typeof prop === 'string') {
        requiredStationProps.push({
          type: 'input',
          name: prop,
          message: prop
        });
      } else {
        requiredStationProps.push(prop);
      }
    });

    const stationProps = await inquirer.prompt(requiredStationProps);

    const { files } = station.run(stationProps);

    await createFilesByList(files);

    console.log('Done');

  } catch (err) {
    console.error(err);
    process.exit(1);
  }
})();

@@ -54,133 +54,8 @@
 r');
-%0Aconst updateNotifier = require('update-notifier');%0Aconst pkg = require('./package.json');%0A%0AupdateNotifier(%7B pkg %7D).notify();
 %0A%0Aco
@@ -537,23 +537,30 @@
 urn 
-%7B%0A        ...m,
+Object.assign(%7B%7D, m, %7B
 %0A   
@@ -608,16 +608,17 @@
 %0A      %7D
+)
 ;%0A    %7D,
@@ -963,16 +963,50 @@
 ound.');
+ // eslint-disable-line no-console
 %0A      p
@@ -1965,16 +1965,50 @@
 'Done');
+ // eslint-disable-line no-console
 %0A%0A  %7D ca
@@ -2042,16 +2042,50 @@
 or(err);
+ // eslint-disable-line no-console
 %0A    pro

replace updateNotifier and replace object-sprite