<commit_before>#!/usr/bin/env node
const inquirer = require('inquirer');
const updateNotifier = require('update-notifier');
const {green} = require('chalk');
const taskler = require('taskler');
const meow = require('meow');
const pkg = require('./package.json');

updateNotifier({pkg}).notify();

const cli = meow(`
  Usage
    $ takeoff <station>

  Example
    $ takeoff node-module
`);

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

const getStationId = async stations => {

  if (cli.input.length === 0) {

    return ( await inquirer.prompt(stations)).stationId;
  } else {

    return stations[0].choices.find(({name}) => name === cli.input[0]).value;
  }
};

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

    const stationsPathMap = stationsCollection.reduce( (m, s) => ({ ...m, [s.stationsPath]: s}), {});

    let stationChoices = [];

    for( let stationsPath in stationsPathMap ) {

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

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

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

    const stationId = await getStationId(chooseBetweenAvailableStations);

    console.log(stationsCollection, stationId);

    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);

    console.log('🚀  Houston, lift of in 3..2..1');

    const tasks = [];

    if (station.preTakeoff !== undefined) {
      tasks.push({
        title: 'Pre Takeoff',
        task: opts => station.preTakeoff(stationProps, opts)
      });
    }

    tasks.push({
      title: `Create files for station ${name}`,
      task: ({emit, succeed}) => {
        createFilesByList(files, emit).then(succeed);
      }
    });

    if (station.postTakeoff !== undefined) {
      tasks.push({
        title: 'Post Takeoff',
        task: opts => station.postTakeoff(stationProps, opts)
      });
    }

    taskler(tasks, () => {
      console.info(green('🎉  Done'));
    });
  } catch (err) {
    console.error(err);
  }
})();<commit_msg>remove debug output and fix exit code<commit_after>#!/usr/bin/env node
const inquirer = require('inquirer');
const updateNotifier = require('update-notifier');
const {green} = require('chalk');
const taskler = require('taskler');
const meow = require('meow');
const pkg = require('./package.json');

updateNotifier({pkg}).notify();

const cli = meow(`
  Usage
    $ takeoff <station>

  Example
    $ takeoff node-module
`);

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

const getStationId = async stations => {

  if (cli.input.length === 0) {

    return ( await inquirer.prompt(stations)).stationId;
  } else {

    return stations[0].choices.find(({name}) => name === cli.input[0]).value;
  }
};

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

    const stationsPathMap = stationsCollection.reduce( (m, s) => ({ ...m, [s.stationsPath]: s}), {});

    let stationChoices = [];

    for( let stationsPath in stationsPathMap ) {

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

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

    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);

    console.log('🚀  Houston, lift of in 3..2..1');

    const tasks = [];

    if (station.preTakeoff !== undefined) {
      tasks.push({
        title: 'Pre Takeoff',
        task: opts => station.preTakeoff(stationProps, opts)
      });
    }

    tasks.push({
      title: `Create files for station ${name}`,
      task: ({emit, succeed}) => {
        createFilesByList(files, emit).then(succeed);
      }
    });

    if (station.postTakeoff !== undefined) {
      tasks.push({
        title: 'Post Takeoff',
        task: opts => station.postTakeoff(stationProps, opts)
      });
    }

    taskler(tasks, () => {
      console.info(green('🎉  Done'));
      process.exit(0);
    });
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
})();
{'fraction_non_alphanumeric': 0.1556812157625022, 'fraction_numerical': 0.0024739353242622373, 'mean_word_length': 3.045746962115797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '24936', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1667, 'n_words': 372}