'use strict';
import findUp from 'find-up';
import path from 'path';
import removeTrailingSlash from 'remove-trailing-slash';

/**
 * Returns .yo-rc.json dirname
 * @returns {Promise<String>} - .yo-rc.json dirname
 */
function getYoPath() {
  return Promise.resolve(path.dirname(findUp.sync('.yo-rc.json')));
}

/**
 * Return JSON contents of file name from root
 * @param {String} fileName - name of file to read
 * @returns {Promise<Object>} - file contents
 */
function getFileFromRoot(fileName) {
  return getYoPath().then(yoPath => require(path.join(yoPath, fileName)));
}

/**
 * Return build config
 * @returns {Promise<Object>} - build config
 */
function getBuildConfig() {
  return getFileFromRoot('build.config.js');
}

export default {
  getFileFromRoot,
  getYoPath,

  /**
   * Gets the appDir from the root build.config.js without trailing / or \
   * @return {Promise<String>} - app directory path
   */
  getAppDir() {
    return getBuildConfig().then(config => removeTrailingSlash(config.appDir));
  },

  /**
   * Gets the app's name from the root package.json
   * @return {Promise<String>} - app name
   */
  getAppName() {
    return getFileFromRoot('package.json').then(pkg => pkg.name);
  },

  /**
   * Gets the unitTestDir from the root build.config.js
   * @return {Promise<String>} - unit test directory path
   */
  getUnitTestDir() {
    return getBuildConfig().then(config => config.unitTestDir);
  }
};

@@ -207,24 +207,30 @@
 dirname%0A */%0A
+async 
 function get
@@ -253,24 +253,8 @@
 urn 
-Promise.resolve(
 path
@@ -289,17 +289,16 @@
 .json'))
-)
 ;%0A%7D%0A%0A/**
@@ -442,24 +442,30 @@
 ontents%0A */%0A
+async 
 function get
@@ -501,35 +501,8 @@
 turn
- getYoPath().then(yoPath =%3E
  req
@@ -520,14 +520,25 @@
 oin(
-y
+await getY
 oPath
+()
 , fi
@@ -545,17 +545,16 @@
 leName))
-)
 ;%0A%7D%0A%0A/**
@@ -889,24 +889,30 @@
 ath%0A   */%0A  
+async 
 getAppDir() 
@@ -927,40 +927,8 @@
 turn
- getBuildConfig().then(config =%3E
  rem
@@ -948,22 +948,40 @@
 ash(
-c
+(await getBuildC
 onfig
+())
 .appDir)
 );%0A 
@@ -976,17 +976,16 @@
 .appDir)
-)
 ;%0A  %7D,%0A%0A
@@ -1092,16 +1092,22 @@
    */%0A  
+async 
 getAppNa
@@ -1116,32 +1116,39 @@
 () %7B%0A    return 
+(await 
 getFileFromRoot(
@@ -1166,30 +1166,14 @@
 on')
-.then(pkg =%3E pkg
+)
 .name
-)
 ;%0A  
@@ -1304,16 +1304,22 @@
    */%0A  
+async 
 getUnitT
@@ -1340,16 +1340,23 @@
  return 
+(await 
 getBuild
@@ -1367,30 +1367,9 @@
 ig()
-.then(config =%3E config
+)
 .uni
@@ -1376,17 +1376,16 @@
 tTestDir
-)
 ;%0A  %7D%0A%7D;

use async/await