From 9529f35ffdc99dec7731d1f0c68f8b2d5e43d3cc Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Tue, 21 Feb 2023 16:50:10 +0000 Subject: [PATCH] switch to fs.rm --- packages/io/src/io-util.ts | 1 + packages/io/src/io.ts | 102 +++++++++++++++++++++---------------- 2 files changed, 59 insertions(+), 44 deletions(-) diff --git a/packages/io/src/io-util.ts b/packages/io/src/io-util.ts index 79674762..766b4049 100644 --- a/packages/io/src/io-util.ts +++ b/packages/io/src/io-util.ts @@ -9,6 +9,7 @@ export const { readdir, readlink, rename, + rm, rmdir, stat, symlink, diff --git a/packages/io/src/io.ts b/packages/io/src/io.ts index 5131aa51..bff17f60 100644 --- a/packages/io/src/io.ts +++ b/packages/io/src/io.ts @@ -129,51 +129,65 @@ export async function rmRF(inputPath: string): Promise { try { const cmdPath = ioUtil.getCmdPath() - const p = new Promise(async resolve => { - setTimeout(() => { - resolve('timeout') - }, 500) - - let result: childProcess.ChildProcess - if (await ioUtil.isDirectory(inputPath, true)) { - const files = await ioUtil.readdir(inputPath) - for (const file of files) { - console.log(`first ioUtil.readdir: ${file}`) - } - - result = childProcess.spawn( - cmdPath, - ['/s', '/c', 'rd', '/s', '/q', `"${inputPath}"`] - ) - } else { - result = childProcess.spawn( - cmdPath, - ['/s', '/c', 'del', '/f', '/q', '/a', `"${inputPath}"`] - ) - } - - result.on('spawn', () => { - console.log(`spawn: ${result.spawnargs}`) - }) - - result.stdout?.on('data', data => { - console.log(`stdout: ${data}`) - }) - - result.stderr?.on('data', data => { - console.log(`stderr: ${data}`) - }) - - result.on('error', err => { - console.log(`error: ${err}`) - }) - - result.on('close', code => { - console.log(`close: ${code}`) - resolve(code) - }) + await ioUtil.rm(inputPath, { + recursive: true, + force: true }) - await p + + // const p = new Promise(async resolve => { + // setTimeout(() => { + // resolve('timeout') + // }, 500) + + // let result: childProcess.ChildProcess + // if (await ioUtil.isDirectory(inputPath, true)) { + // const files = await ioUtil.readdir(inputPath) + // for (const file of files) { + // console.log(`first ioUtil.readdir: ${file}`) + // } + + // result = childProcess.spawn(cmdPath, [ + // '/s', + // '/c', + // 'rd', + // '/s', + // '/q', + // `"${inputPath}"` + // ]) + // } else { + // result = childProcess.spawn(cmdPath, [ + // '/s', + // '/c', + // 'del', + // '/f', + // '/q', + // '/a', + // `"${inputPath}"` + // ]) + // } + + // result.on('spawn', () => { + // console.log(`spawn: ${result.spawnargs}`) + // }) + + // result.stdout?.on('data', data => { + // console.log(`stdout: ${data}`) + // }) + + // result.stderr?.on('data', data => { + // console.log(`stderr: ${data}`) + // }) + + // result.on('error', err => { + // console.log(`error: ${err}`) + // }) + + // result.on('close', code => { + // console.log(`close: ${code}`) + // resolve(code) + // }) + // }) + // await p } catch (err) { // if you try to delete a file that doesn't exist, desired result is achieved // other errors are valid