11import fs from 'fs-extra' ;
2- import path from 'path' ;
32import { Command } from 'commander' ;
4-
5- const CACHE_DIR = path . join ( '.tmp' , 'cache' ) ;
3+ import { getTmpPath , getDefaultTmpRoot } from '../core/tmp.js' ;
64
75export function registerCacheCommand ( program : Command ) : void {
86 const cache = program . command ( 'cache' ) . description ( 'Manage the CLI cache' ) ;
@@ -12,35 +10,54 @@ export function registerCacheCommand(program: Command): void {
1210 . description ( 'Clear all cached packages and builds' )
1311 . option ( '--packages' , 'Clear only package cache' )
1412 . option ( '--builds' , 'Clear only build cache' )
13+ . option ( '--tmp-dir <dir>' , 'Custom temp directory' )
1514 . action ( async ( options ) => {
15+ const tmpDir = options . tmpDir ;
1616 if ( options . packages ) {
17- await fs . remove ( path . join ( CACHE_DIR , 'packages' ) ) ;
17+ await fs . remove ( getTmpPath ( tmpDir , 'cache' , 'packages' ) ) ;
1818 console . log ( 'Package cache cleared' ) ;
1919 } else if ( options . builds ) {
20- await fs . remove ( path . join ( CACHE_DIR , 'builds' ) ) ;
20+ await fs . remove ( getTmpPath ( tmpDir , 'cache' , 'builds' ) ) ;
2121 console . log ( 'Build cache cleared' ) ;
2222 } else {
23- await fs . remove ( CACHE_DIR ) ;
23+ await fs . remove ( getTmpPath ( tmpDir , 'cache' ) ) ;
2424 console . log ( 'All caches cleared' ) ;
2525 }
2626 } ) ;
2727
2828 cache
2929 . command ( 'info' )
3030 . description ( 'Show cache statistics' )
31- . action ( async ( ) => {
32- const packagesDir = path . join ( CACHE_DIR , 'packages' ) ;
33- const buildsDir = path . join ( CACHE_DIR , 'builds' ) ;
31+ . option ( '--tmp-dir <dir>' , 'Custom temp directory' )
32+ . action ( async ( options ) => {
33+ const tmpDir = options . tmpDir ;
34+ const packagesDir = getTmpPath ( tmpDir , 'cache' , 'packages' ) ;
35+ const buildsDir = getTmpPath ( tmpDir , 'cache' , 'builds' ) ;
3436
3537 const packageCount = await countEntries ( packagesDir ) ;
3638 const buildCount = await countEntries ( buildsDir ) ;
3739
38- console . log ( `Cache directory: ${ CACHE_DIR } ` ) ;
40+ console . log ( `Cache directory: ${ getTmpPath ( tmpDir , 'cache' ) } ` ) ;
3941 console . log ( `Cached packages: ${ packageCount } ` ) ;
4042 console . log ( `Cached builds: ${ buildCount } ` ) ;
4143 } ) ;
4244}
4345
46+ /**
47+ * Register the clean command to clear entire temp directory
48+ */
49+ export function registerCleanCommand ( program : Command ) : void {
50+ program
51+ . command ( 'clean' )
52+ . description ( 'Clear the entire temp directory (.tmp/)' )
53+ . option ( '--tmp-dir <dir>' , 'Custom temp directory' )
54+ . action ( async ( options ) => {
55+ const tmpDir = options . tmpDir || getDefaultTmpRoot ( ) ;
56+ await fs . remove ( tmpDir ) ;
57+ console . log ( `Temp directory cleared: ${ tmpDir } ` ) ;
58+ } ) ;
59+ }
60+
4461async function countEntries ( dir : string ) : Promise < number > {
4562 if ( ! ( await fs . pathExists ( dir ) ) ) return 0 ;
4663 const entries = await fs . readdir ( dir ) ;
0 commit comments