const fs = require('fs');
const path = require('path');

const getPredefinedStations = () => new Promise((resolve, reject) => {
  const stationsFolder = path.resolve(__dirname, '../stations');

  fs.readdir(stationsFolder, (err, files = []) => {
    if (err) {
      reject(err);
    }
    resolve(
      files
        .filter(file => !/.DS_Store|_shared/.test(file))
        .filter(file => fs.lstatSync(path.join(stationsFolder, file)).isDirectory())
      );
  });
});

const getCustomStations = () => new Promise((resolve, reject) => {
  const stationsFolder = path.resolve(process.cwd(), '.takeoff');
  if (fs.existsSync(stationsFolder)) {
    fs.readdir(stationsFolder, (err, files = []) => {
      if (err) {
        reject(err);
      }
      resolve(files.filter(file => fs.lstatSync(path.join(stationsFolder, file)).isDirectory()));
    });
  } else {
    resolve([]);
  }
});

const loadStationByName = (stationName = '') => new Promise((resolve, reject) => {
  const stationPath = path.resolve(__dirname, '../.takeoff', stationName, '__station__.js');
  let requiredStation = {};

  if (fs.existsSync(stationPath)) {
    requiredStation = require(stationPath);
  } else {
    reject(new Error(`Station "${stationName}" not found.`));
  }

  resolve(requiredStation);
});

module.exports = {getPredefinedStations, getCustomStations, loadStationByName};

@@ -924,16 +924,24 @@
 ame = ''
+, source
 ) =%3E new
@@ -1022,21 +1022,22 @@
 me, 
-'../.takeoff'
+%60../$%7Bsource%7D%60
 , st
@@ -1057,18 +1057,16 @@
 _station
-__
 .js');%0A 

update station lib