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 = () => new Promise((resolve, reject) => {
	resolve({});
});

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

@@ -113,33 +113,34 @@
 e, reject) =%3E %7B%0A
-%09
+  
 const stationsFo
@@ -187,17 +187,18 @@
 ons');%0A%0A
-%09
+  
 fs.readd
@@ -239,18 +239,20 @@
 %5D) =%3E %7B%0A
-%09%09
+    
 if (err)
@@ -254,19 +254,22 @@
 (err) %7B%0A
-%09%09%09
+      
 reject(e
@@ -273,22 +273,26 @@
 t(err);%0A
-%09%09%7D%0A%09%09
+    %7D%0A    
 resolve(
@@ -455,17 +455,18 @@
      );%0A
-%09
+  
 %7D);%0A%7D);%0A
@@ -533,17 +533,18 @@
 t) =%3E %7B%0A
-%09
+  
 const st
@@ -599,17 +599,18 @@
 eoff');%0A
-%09
+  
 if (fs.e
@@ -638,18 +638,20 @@
 der)) %7B%0A
-%09%09
+    
 fs.readd
@@ -692,19 +692,22 @@
 %5D) =%3E %7B%0A
-%09%09%09
+      
 if (err)
@@ -713,12 +713,16 @@
 ) %7B%0A
-%09%09%09%09
+        
 reje
@@ -734,16 +734,22 @@
 r);%0A
-%09%09%09%7D%0A%09%09%09
+      %7D%0A      
 reso
@@ -840,15 +840,18 @@
 ));%0A
-%09%09
+    
 %7D);%0A
-%09
+  
 %7D el
@@ -859,10 +859,12 @@
 e %7B%0A
-%09%09
+    
 reso
@@ -872,17 +872,18 @@
 ve(%5B%5D);%0A
-%09
+  
 %7D%0A%7D);%0A%0Ac
@@ -904,24 +904,40 @@
 onByName = (
+stationName = ''
 ) =%3E new Pro
@@ -945,42 +945,189 @@
 ise(
-(
 resolve
-, reject) =%3E %7B%0A%09resolve(%7B%7D
+ =%3E %7B%0A  const stationPath = path.resolve(__dirname, '../.takeoff', stationName, '__station__.js');%0A%0A  const requiredStation = require(stationPath);%0A%0A  resolve(requiredStation
 );%0A%7D

update station