From 1dd149f995b6a6f2e833405ce15099f2b24bf24b Mon Sep 17 00:00:00 2001 From: Thadeu Cotts Date: Thu, 26 Nov 2020 09:08:05 -0300 Subject: [PATCH] [refactor] [m]: split fun to validate and parser path --- packages/create-portal-app/helpers/copy.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/create-portal-app/helpers/copy.js b/packages/create-portal-app/helpers/copy.js index 6be74ed5..38c846a2 100644 --- a/packages/create-portal-app/helpers/copy.js +++ b/packages/create-portal-app/helpers/copy.js @@ -2,15 +2,22 @@ const path = require("path"); const fs = require('fs'); const spawn = require('cross-spawn'); -function _parserPath(path){ - return [process.cwd(), destination].join(path.sep) +function _parserPath(projectPath){ + return [process.cwd(), projectPath].join(path.sep) } -module.exports = function copy(root,destination){ + +function copy(root,destination){ const destinationPath = _parserPath(destination) - //TODO Move this method to validate in another function to throw a error and prompt another name - if(fs.existsSync(destinationPath)){ - if(fs.readdirSync(destinationPath).length > 0) return Promise.reject(`directory ${destinationPath} exist and not empty`); - } return spawn.sync('cp', ['-r', root, destinationPath]); } +function isPathInUse(projectPath){ + const fullPath = _parserPath(projectPath) + const isPathExists = fs.existsSync(fullPath) + if(isPathExists) { + return fs.readdirSync(fullPath).length + } + return isPathExists +} + +module.exports = { copy, isPathInUse } \ No newline at end of file