utilities.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var fs = require('fs')
  2. const chalk = require('chalk');
  3. const logSymbols = require('log-symbols');
  4. module.exports.copyFile = function(original_path, destination_path){
  5. try {
  6. fs.copyFileSync(original_path, destination_path);
  7. return true;
  8. } catch (err){
  9. if(err.code == 'ENOENT'){
  10. if(global.isVerbose) {
  11. console.log(logSymbols.error, chalk.red(`ERROR: File not found: \'${original_path}\'`))
  12. }
  13. } else {
  14. if(global.isVerbose) console.log(logSymbols.error, chalk.red('An error occured: '));
  15. if(global.isVerbose) console.log(err);
  16. }
  17. return false;
  18. }
  19. }
  20. module.exports.getDirectories = function(source) {
  21. return fs.readdirSync(source, { withFileTypes: true })
  22. .filter(item => item.isDirectory())
  23. .map(item => item.name);
  24. }
  25. module.exports.fileExists = function(path){
  26. if (fs.existsSync(path)) return true;
  27. else return false;
  28. }
  29. module.exports.createDirectory = function(dir){
  30. if (!fs.existsSync(dir)){
  31. fs.mkdirSync(dir);
  32. }
  33. }