diff --git a/src/exposed/fs/copy.ts b/src/exposed/fs/copy.ts index 619c9df..08dc539 100644 --- a/src/exposed/fs/copy.ts +++ b/src/exposed/fs/copy.ts @@ -55,17 +55,14 @@ function copy(src: string, dest: string, ...args: any[]): () => Promise { }; const srcExist = await exists(src, { fail: options.fail }); - if (!srcExist) return; - - if ( - !(await confirm( - `Copy "${relatives.src}" to "${relatives.dest}"?`, - options - )) - ) { + if (!srcExist) { + logger.info(`Copy skipped: "${relatives.src}" to "${relatives.dest}"`); return; } + const msg = `Copy "${relatives.src}" to "${relatives.dest}"?`; + if (!(await confirm(msg, options))) return; + await fs .copy(src, dest, { overwrite: options.overwrite, @@ -73,6 +70,6 @@ function copy(src: string, dest: string, ...args: any[]): () => Promise { filter }) .catch(rejects); - logger.info(`Copied "${relatives.src}" to "${relatives.dest}"`); + logger.info(`Copied: "${relatives.src}" to "${relatives.dest}"`); }; } diff --git a/src/exposed/fs/mkdir.ts b/src/exposed/fs/mkdir.ts index 4ff1425..ad4b48a 100644 --- a/src/exposed/fs/mkdir.ts +++ b/src/exposed/fs/mkdir.ts @@ -55,8 +55,14 @@ function mkdir( : '') ); - if (!nonExistingPaths.length) return; - + if (!nonExistingPaths.length) { + logger.info( + `Create skipped: "${relatives.existing + .concat(relatives.nonExisting) + .join('", "')}"` + ); + return; + } if (!(await confirm('Create?', options))) return; await parallel.each(nonExistingPaths, async (absolute, i) => { @@ -65,7 +71,6 @@ function mkdir( const relative = relatives.nonExisting[i]; logger.debug(`Created: ${relative}`); }); - logger.info(`Created: "${relatives.nonExisting.join('", "')}"`); }; } diff --git a/src/exposed/fs/move.ts b/src/exposed/fs/move.ts index 61ac647..623d5ba 100644 --- a/src/exposed/fs/move.ts +++ b/src/exposed/fs/move.ts @@ -33,26 +33,26 @@ function move( }; const srcExist = await exists(src, { fail: options.fail }); - if (!srcExist) return; + if (!srcExist) { + logger.info(`Move skipped: "${relatives.src}" to "${relatives.dest}"`); + return; + } const destExists = await exists(dest); if (destExists) { if (options.fail) { throw Error(`Destination already exists: ${relatives.dest}`); } - if (!options.overwrite) return; + if (!options.overwrite) { + logger.info(`Move skipped: "${relatives.src}" to "${relatives.dest}"`); + return; + } } - if ( - !(await confirm( - `Move "${relatives.src}" to "${relatives.dest}"?`, - options - )) - ) { - return; - } + const msg = `Move "${relatives.src}" to "${relatives.dest}"?`; + if (!(await confirm(msg, options))) return; await fs.move(src, dest, { overwrite: options.overwrite }).catch(rejects); - logger.info(`Moved "${relatives.src}" to "${relatives.dest}"`); + logger.info(`Moved: "${relatives.src}" to "${relatives.dest}"`); }; } diff --git a/src/exposed/fs/remove.ts b/src/exposed/fs/remove.ts index 0c6df07..24e27af 100644 --- a/src/exposed/fs/remove.ts +++ b/src/exposed/fs/remove.ts @@ -53,7 +53,14 @@ function remove( : '') ); - if (!existingPaths.length) return; + if (!existingPaths.length) { + logger.info( + `Remove skipped: "${relatives.existing + .concat(relatives.nonExisting) + .join('", "')}"` + ); + return; + } if (!(await confirm('Remove?', options))) return; await parallel.each(existingPaths, async (absolute, i) => { @@ -62,7 +69,6 @@ function remove( const relative = relatives.existing[i]; logger.debug(`Removed: ${relative}`); }); - logger.info(`Removed: "${relatives.existing.join('", "')}"`); }; } diff --git a/src/exposed/fs/rw.ts b/src/exposed/fs/rw.ts index 4b76fd9..f6fe77c 100644 --- a/src/exposed/fs/rw.ts +++ b/src/exposed/fs/rw.ts @@ -7,6 +7,7 @@ import expose from '~/utils/expose'; import confirm from './utils/confirm'; import { IFsOptions } from './types'; import write from './utils/write'; +import logger from '~/utils/logger'; export default expose(rw); @@ -35,9 +36,14 @@ function rw( : undefined; const response = await fn(raw); - if (response !== undefined) { - if (!(await confirm(`Write "${relative}"?`, options))) return; - await write(file, relative, response); + if (response === undefined) { + logger.info(`Write skipped: ${relative}`); + return; } + + if (!(await confirm(`Write "${relative}"?`, options))) return; + + await write(file, response); + logger.info(`Written: ${relative}`); }; } diff --git a/src/exposed/fs/utils/write.ts b/src/exposed/fs/utils/write.ts index b19e445..75cb0e0 100644 --- a/src/exposed/fs/utils/write.ts +++ b/src/exposed/fs/utils/write.ts @@ -1,15 +1,12 @@ import path from 'path'; import fs from 'fs-extra'; -import logger from '~/utils/logger'; import ensure from '../../tags/ensure'; import { rejects } from 'errorish'; export default async function write( file: string, - relative: string, content: string ): Promise { await ensure.fn(path.parse(file).dir); await fs.writeFile(file, String(content)).catch(rejects); - logger.info(`Written: ${relative}`); } diff --git a/src/exposed/fs/write.ts b/src/exposed/fs/write.ts index 2971f79..e0b0ecb 100644 --- a/src/exposed/fs/write.ts +++ b/src/exposed/fs/write.ts @@ -5,6 +5,7 @@ import { IFsWriteOptions } from './types'; import { exists, absolute } from '~/utils/file'; import confirm from './utils/confirm'; import _write from './utils/write'; +import logger from '~/utils/logger'; export default expose(write) as TExposedOverload< typeof write, @@ -43,9 +44,14 @@ function write(file: string, ...args: any[]): () => Promise { throw Error(`File already exists: ${relative}`); } - if (!doesExist || options.overwrite) { - if (!(await confirm(`Write "${relative}"?`, options))) return; - await _write(file, relative, raw); + if (doesExist && !options.overwrite) { + logger.info(`Write skipped: ${relative}`); + return; } + + if (!(await confirm(`Write "${relative}"?`, options))) return; + + await _write(file, raw); + logger.info(`Written: ${relative}`); }; }