11const { exec, spawn } = require ( 'child_process' ) ;
22const fs = require ( 'fs' ) ;
33const path = require ( 'path' ) ;
4+ const os = require ( 'os' ) ;
5+
6+ /**
7+ * Resolve a path even if is using shell specific for home
8+ * @param {String } oPath The path to resolve
9+ * @return {String } The resolved path
10+ */
11+ function resolvePath ( oPath ) {
12+ let fPath = '' ;
13+ fPath = oPath . replace ( '~' , os . homedir ( ) ) ;
14+ fPath = path . resolve ( fPath ) ;
15+ return fPath ;
16+ }
417
518/**
619 * Replace a string using a given dictionary
@@ -31,8 +44,8 @@ function normalizeName(filepath) {
3144 * @param {String } [destPath='../new'] The destination path
3245 */
3346function copyDirRecursive ( currentPath = './' , destPath = '../new' ) {
34- let dest = path . resolve ( destPath ) ;
35- let current = path . resolve ( currentPath ) ;
47+ let dest = resolvePath ( destPath ) ;
48+ let current = resolvePath ( currentPath ) ;
3649
3750 // Create the dest folder
3851 if ( ! fs . existsSync ( dest ) ) {
@@ -43,8 +56,8 @@ function copyDirRecursive(currentPath = './', destPath = '../new') {
4356 // Read files in folder
4457 let files = fs . readdirSync ( current ) ;
4558 for ( file of files ) {
46- src = path . resolve ( path . join ( current , file ) ) ;
47- dest = path . resolve ( path . join ( destPath , file ) ) ;
59+ src = resolvePath ( path . join ( current , file ) ) ;
60+ dest = resolvePath ( path . join ( destPath , file ) ) ;
4861
4962 if ( fs . lstatSync ( src ) . isDirectory ( ) ) {
5063 // Recursive copy for folders
@@ -58,10 +71,10 @@ function copyDirRecursive(currentPath = './', destPath = '../new') {
5871}
5972
6073function deleteDirRecursive ( folderPath ) {
61- const dirPath = path . resolve ( folderPath ) ;
74+ const dirPath = resolvePath ( folderPath ) ;
6275 if ( fs . existsSync ( dirPath ) ) {
6376 fs . readdirSync ( dirPath ) . forEach ( ( file ) => {
64- const curPath = path . resolve ( path . join ( dirPath , file ) ) ;
77+ const curPath = resolvePath ( path . join ( dirPath , file ) ) ;
6578 if ( fs . lstatSync ( curPath ) . isDirectory ( ) ) { // recurse
6679 deleteDirRecursive ( curPath ) ;
6780 } else { // delete file
@@ -128,4 +141,5 @@ module.exports = {
128141 execp,
129142 spawnp,
130143 normalizeName,
144+ resolvePath,
131145} ;
0 commit comments