BVB Source Codes

reactide Show copy-directory.js Source code

Return Download reactide: download copy-directory.js Source code - Download reactide Source code - Type:.js
  1. 'use strict'
  2.  
  3. const fs = require('fs');
  4. const path = require('path');
  5.  
  6. module.exports = (source, destination) => {
  7.   //create recursive function
  8.   function recurseThroughSource(source, destination) {
  9.     //check whether if source is file or directory
  10.     const dest = path.join(destination, path.basename(source));
  11.  
  12.     const stats = fs.statSync(source);
  13.     if (stats.isFile()) {
  14.       //if file read then write to destination
  15.       let data = fs.readFileSync(source);
  16.       fs.writeFileSync(dest, data);
  17.     }
  18.     //if directory exists don't overwrite, otherwise mkdir
  19.     //should ask user if he wants to overwrite everything and overwrite everything if yes
  20.     else {
  21.       try {
  22.         fs.accessSync(dest);
  23.         console.log('directory found, won\'t overwrite');
  24.       } catch (e) {
  25.         fs.mkdirSync(dest);
  26.         const files = fs.readdirSync(source);
  27.         files.forEach((file) => {
  28.           recurseThroughSource(path.join(source, path.basename(file)), dest);
  29.         });
  30.       }
  31.     }
  32.     //then recurses with path to that directory
  33.   }
  34.   recurseThroughSource(source, destination);
  35. }
downloadcopy-directory.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top