Check to see if there's a configuration file in the given app directory,
if so, parse it.
@param appDir The base directory in which the application is hosted.
@return A promise resolving to the path of the application-specific
configuration file
325957
function findConfig_p(appDir){
  var filePath = path.join(appDir, ".shiny_app.conf");
  return fsutil.safeStat_p(filePath)
  .then(function(stat){
    if (stat && stat.isFile()){
      return (filePath);
    }
    throw new Error('Invalid app configuration file.');
  });
}
1226015
function findDirRec(dir, callback) {
      var result = path.resolve(dir, dirmod);
      fs.stat(result, function stat(err, stat) {
        if (err || !stat.isDirectory()) {
          if (lastResult == result) {
            callback(new Error('No configuration directory found.'));
            return;
          }
          lastResult = result;
          findDirRec(path.resolve(dir, '..'), callback);
        } else {
          callback(null, result);
        }
      });
    }
890375
function(directory) {
    if (!this.packageJSONFinder) {
      this.packageJSONFinder = new FileFinder(PACKAGE_FILENAME);
    }

    return this.packageJSONFinder.findInDirectoryOrParentsSync(directory || process.cwd());
  }
733658
function startApplication(appName, appDirectory, appList, configStore, sessionStore) {

    let path = appDirectory + '/' + appList[appName] + '/';
    let commonPath = appDirectory + '/apps/common/';
    let config = configStore[appName].get();
    let commonJsDir = commonPath + '/js/';
    let controllerJsDir = path + '/public/js/';

    if (config.isDaemon || config.serverMode === 'api') {
        controllerJsDir = path + '/js/';
    }

    let schema = JSON.parse((readFile(path + '/schema.json') || readFile(commonPath + '/schema.json')).toString());

    let controllerPath = (config.controller || 'controller.js');
    let matches = controllerPath.match(/(.*?)([0-9A-Za-z_]*)\.js$/);
    let prefix = matches[1];
    let prop = matches[2];

    // TODO: Completely change how we do configurations
    config.nconf = configStore[appName]; // Global config
    config.configStore = configStore;

    return setUpInjectObjectTemplate(appName, config, schema)
        .then(buildAppConfigAndLoadTemplates.bind(this, appName, config, controllerJsDir, commonJsDir, sessionStore))
        .spread(finishDaemonIfNeeded.bind(this, config, prop, prefix, appName));
}
256748
private boolean checkAppPathsForVia(Set<String> keySet, List<String> errors) {
        for (String key : keySet) {
            if (!key.equals("defaultKey")) {
                File file = new File(key);
                if (!file.exists()) {
                    errors.add("Effective Usage Analysis will not run if the -appPath parameter references an invalid file path. Check that the -appPath parameter specifies a valid path");
                    return false;
                } else if (!file.isFile()) {
                    errors.add("Effective Usage Analysis will not run if the -appPath parameter references an invalid file path. Check that the -appPath parameter specifies a valid path");
                    return false;
                } else {
                    return true;
                }
            }
        }
        return false;
    }
135226
public static File findInstanceResourcesDirectory( File applicationFilesDirectory, Instance instance ) {
		return findInstanceResourcesDirectory( applicationFilesDirectory, instance.getComponent());
	}
501117
function isModuleDirectory(filePath) {
  try {
    const manifestPath = path.join(filePath, MANIFEST);
    if (fs.statSync(manifestPath).isFile()) {
      const module = require(manifestPath);
      return module && module.main;
    }
  } catch (error) {}
}
847627
function(app) {

  var filepath = path.join(app.dir, APP_CONFIG_FILENAME);

  // Read contents of file.
  return Promise.fromNode(function(cb) {
    fs.readFile(filepath, {encoding: 'utf8'}, cb);
  })
  // Handle no entry error.
  .catch(function(err) {
    if (err.code === 'ENOENT') {
      cacheBadApp(app);
    } else {
      throw new VError(err, 'Failed to load config: %s', filepath);
    }
  })
  // Return appName.
  .then(function(data) {
    var json = util.yaml.dataToJson(data);
    if (!json) {
      return null;
    }
    else if (!json.name) {
      log.debug(format('Does NOT contain %s property!', filepath));
      return null;
    }
    else if (json.name === app.name) {
      cacheApp(app);
      return app;
    }
    else if (json.name !== app.name) {
      cacheBadApp(app);
      return null;
    }
    else {
      return null;
    }
  });

}
104055
private static File findDirectoryOption(String[] args, String option, String name, boolean needed, boolean allow_dups, boolean create)
        throws ProblemException, ProblemException {
        File dir = null;
        for (int i = 0; i<args.length; ++i) {
            if (args[i].equals(option)) {
                if (dir != null) {
                    throw new ProblemException("You have already specified the "+name+" dir!");
                }
                if (i+1 >= args.length) {
                    throw new ProblemException("You have to specify a directory following "+option+".");
                }
                if (args[i+1].indexOf(File.pathSeparatorChar) != -1) {
                    throw new ProblemException("You must only specify a single directory for "+option+".");
                }
                dir = new File(args[i+1]);
                if (!dir.exists()) {
                    if (!create) {
                         throw new ProblemException("This directory does not exist: "+dir.getPath());
                    } else
                    if (!makeSureExists(dir)) {
                        throw new ProblemException("Cannot create directory "+dir.getPath());
                    }
                }
                if (!dir.isDirectory()) {
                    throw new ProblemException("\""+args[i+1]+"\" is not a directory.");
                }
            }
        }
        if (dir == null && needed) {
            throw new ProblemException("You have to specify "+option);
        }
        try {
            if (dir != null)
                return dir.getCanonicalFile();
        } catch (IOException e) {
            throw new ProblemException(""+e);
        }
        return null;
    }
1060892
function dirExist(dirName) {
  return new Promise((resolve, reject) => {
    fs.stat(dirName, (err, stats) => {
      if (err === null && stats.isDirectory()) {
        resolve(dirName);
      } else {
        resolve(false);
      }
    });
  });
}
358468
function getAppContextFromCwdConfig(/*apps*/) {
  return Promise.try(function() {
    var cwd = process.cwd();
    var configFilepath = path.join(cwd, 'kalabox.yml');
    if (fs.existsSync(configFilepath)) {
      var config = kbox.core.config.getAppConfig(cwd);
      if (config.name) {
        return kbox.app.create(config.name, config);
      }
    }
  });
}
645391
function makeDir(file) {
  return new Promise((resolve, reject) => {
    mkdirp(path.extname(file) ? path.dirname(file) : file, (err) => {
      if (err) reject(err);
      resolve();
    });
  });
}
684708
public static Path get(String appName) {
        final Path applicationDataDirectory = getPath(appName);

        try {
            Files.createDirectories(applicationDataDirectory);
        } catch (IOException ioe) {
            throw new RuntimeException("Couldn't find/create AppDataDirectory", ioe);
        }

        return applicationDataDirectory;
    }
120947
public void deployAll(String applicationName, Path directory) throws IOException {
        this.applicationName = applicationName;

        if (Files.isDirectory(directory)) {
            Files.list(directory)
                .filter(ResourceFilter::filterKubernetesResource)
                .map(p -> {
                    try {
                        return Files.newInputStream(p);
                    } catch (IOException e) {
                        throw new IllegalArgumentException(e);
                    }
                })
                .forEach(is -> {
                    try {
                        deploy(is);
                        is.close();
                    } catch (IOException e) {
                        throw new IllegalArgumentException(e);
                    }
                });
        } else {
            throw new IllegalArgumentException(String.format("%s should be a directory", directory));
        }
    }
1173815
function(apps) {

  var filepath = getGlobalConfig().appRegistry;

  var tempFilepath = filepath + '.tmp';

  // Write to temp file.
  return Promise.fromNode(function(cb) {
    fs.writeFile(tempFilepath, JSON.stringify(apps), cb);
    log.debug(format('Setting app registry with %j', apps));
  })
  // Rename temp file to normal file.
  .then(function() {
    return Promise.fromNode(function(cb) {
      fs.rename(tempFilepath, filepath, cb);
    });
  });

}
903114
@Override
  public void parseDirectory(File configurationDirectory) throws Exception {
    this.configurationDirectory = configurationDirectory;
    if(configurationDirectory != null && configurationDirectory.isDirectory() && configurationDirectory.canRead()) {
      Collection<File> configFiles = FileUtils.listFiles(configurationDirectory, new String[] {"yml", "yaml"}, true);
      List<File> files = new ArrayList<File>(configFiles);
      Collections.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR);
      Map<String, Map<String, ?>> configurationMap = new HashMap<String, Map<String, ?>>();
      Yaml yamlParser = new Yaml(getClassTags());
      for(File configFile : files) {
        FileReader reader = null;
        try {
          reader = new FileReader(configFile);
          for(Object parsed : yamlParser.loadAll(reader)){
            mergeConfigs(configurationMap, parsed);
          }
        } finally {
          IOUtils.closeQuietly(reader);
        }
      }
      this.configuration = configurationMap;
    } else if(configurationDirectory != null && configurationDirectory.isDirectory()){
      logger.warn("Directory {} cannot be read.", configurationDirectory);
    } else if(configurationDirectory != null){
      logger.warn("Directory {} is not a directory or does not exist.", configurationDirectory);
    } else {
      throw new IllegalArgumentException("The configurationDirectory must be specified.");
    }
  }
446245
private File resolveIndexDirectoryPath() throws IOException {
        if (StringUtils.isEmpty(indexDirectoryPath)) {
            indexDirectoryPath = System.getProperty("java.io.tmpdir") + appContext.getApplicationName();
        }
        
        File dir = new File(indexDirectoryPath, getClass().getPackage().getName());
        
        if (!dir.exists() && !dir.mkdirs()) {
            throw new IOException("Failed to create help search index directory.");
        }
        
        log.info("Help search index located at " + dir);
        return dir;
    }