checkRequiredFiles.js 856 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. 'use strict';
  8. var fs = require('fs');
  9. var path = require('path');
  10. var chalk = require('chalk');
  11. function checkRequiredFiles(files) {
  12. var currentFilePath;
  13. try {
  14. files.forEach(filePath => {
  15. currentFilePath = filePath;
  16. fs.accessSync(filePath, fs.F_OK);
  17. });
  18. return true;
  19. } catch (err) {
  20. var dirName = path.dirname(currentFilePath);
  21. var fileName = path.basename(currentFilePath);
  22. console.log(chalk.red('Could not find a required file.'));
  23. console.log(chalk.red(' Name: ') + chalk.cyan(fileName));
  24. console.log(chalk.red(' Searched in: ') + chalk.cyan(dirName));
  25. return false;
  26. }
  27. }
  28. module.exports = checkRequiredFiles;