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