UNPKG

nectarjs

Version:

Javascript's God Mode. No VM. No Bytecode. No GC. Just native binaries.

63 lines (59 loc) 1.93 kB
/* * This file is part of NectarJS * Copyright (c) 2017 - 2020 Adrien THIERRY * http://nectarjs.com - https://seraum.com/ * * sources : https://github.com/nectarjs/nectarjs * * NectarJS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * NectarJS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NectarJS. If not, see <http://www.gnu.org/licenses/>. * */ function copyDirSync( source, target ) { var targetFile = target; if ( fs.existsSync( target ) ) { if ( fs.lstatSync( target ).isDirectory() ) { targetFile = path.join( target, path.basename( source ) ); } } fs.copyFileSync(source, targetFile); } function copyFolderRecursiveSync( source, target, _root ) { var files = []; var targetFolder = path.join( target, path.basename( source ) ); if(_root) targetFolder = target; if ( !fs.existsSync( targetFolder ) ) { fs.mkdirSync( targetFolder ); } if ( fs.lstatSync( source ).isDirectory() ) { files = fs.readdirSync( source ); files.forEach( function ( file ) { var curSource = path.join( source, file ); if ( fs.lstatSync( curSource ).isDirectory() ) { copyFolderRecursiveSync( curSource, targetFolder ); } else { copyDirSync( curSource, targetFolder ); } } ); } } module.exports = copyFolderRecursiveSync;