From 5ad96e4b49a232ab419fc376f54bdf0a23477786 Mon Sep 17 00:00:00 2001 From: James Prevett Date: Fri, 29 Nov 2024 11:15:29 -0600 Subject: [PATCH] Remove intermediate files --- src/cli.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index cc9d4a4..9ac4d1c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -15,6 +15,7 @@ const { values: options, positionals } = parseArgs({ verbose: { short: 'w', type: 'boolean', default: false }, output: { short: 'o', type: 'string' }, clean: { type: 'boolean', default: false }, + keep: { type: 'boolean', default: false }, node: { short: 'N', type: 'string', default: 'v' + process.versions.node }, target: { short: 't', type: 'string', multiple: true, default: [process.platform + '-' + process.arch] }, }, @@ -33,7 +34,8 @@ Options: --quiet,-q Hide non-error output --verbose,-w Show all output --output,-o The output prefix - --clean Remove temporary files + --clean Remove cached files + --keep Keep intermediate files --node,-N Specify the Node version --target,-t Specify which targets(s) to build for (e.g. linux-arm64, win-x64) `); @@ -125,7 +127,17 @@ async function getNode(archiveBase: string) { gzip: true, cwd: join(tempDir, 'node'), }); - fs.copyFileSync(join(tempDir, 'node', archiveBase, isWindows ? 'node.exe' : 'bin/node'), execName); + const extracted = join(tempDir, 'node', archiveBase); + fs.copyFileSync(join(extracted, isWindows ? 'node.exe' : 'bin/node'), execName); + if (!options.keep) { + _log('Removing intermediate:', extracted); + fs.rmSync(extracted, { recursive: true, force: true }); + } + } + + if (!options.keep) { + _log('Removing intermediate:', archivePath); + fs.unlinkSync(archivePath); } }