torch-it 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,15 +24,85 @@ It's surprising how often this just fixes things. 🤞
24
24
 
25
25
  ## Features
26
26
 
27
- - **One command** to clear all local caches, delete `node_modules`, and reinstall dependencies
28
- - **Fully customizable** — specify any directories or files to delete
27
+ - **One command** to clean up 50+ build artifacts, cache directories, log files, and reinstall dependencies
28
+ - **Comprehensive framework support** — handles React, Next.js, Vue, Vite, SvelteKit, Remix, Qwik, Nuxt, Astro, Angular, Solid, and 40+ more
29
+ - **Smart file pattern matching** — removes `*.log`, `*.tgz`, `*.tar.gz`, and other temporary files automatically
30
+ - **Fully customizable** — specify any directories or files to delete via `torchrc.json`
29
31
  - **Docker support** — removes containers, images, and volumes and rebuilds from scratch 🐳
30
32
  - **Cross-platform** — works on Windows, Linux, and macOS
31
33
  - **Zero-dependency** — lightweight and no additional packages required
32
34
 
33
35
  ## Supported Frameworks
34
36
 
35
- React, Next.js, Vue, Vite, SvelteKit, React Native, Expo, and more.
37
+ React, Next.js, Vue, Vite, SvelteKit, React Native, Expo, Remix, Qwik, Nuxt, Astro, Angular, Solid, Docusaurus, and 40+ more frameworks and tools.
38
+
39
+ ## Comprehensive Cleanup Targets
40
+
41
+ `torch-it` cleans up 50+ common build artifacts, cache directories, and temporary files:
42
+
43
+ ### Framework Build Outputs
44
+ - `dist`, `build`, `out`, `.output` - Standard build directories
45
+ - `.next` - Next.js build cache
46
+ - `.nuxt` - Nuxt.js build output
47
+ - `.svelte-kit`, `.svelte` - Svelte/SvelteKit builds
48
+ - `.remix` - Remix framework build output
49
+ - `.qwik` - Qwik framework build output
50
+ - `.astro` - Astro framework build output
51
+ - `.angular`, `.angular/cache` - Angular build artifacts
52
+ - `.solid` - Solid.js build output
53
+ - `.docusaurus` - Docusaurus static site output
54
+ - `.nitro` - Nuxt Nitro server output
55
+
56
+ ### Development Tool Caches
57
+ - `.cache`, `.parcel-cache`, `.webpack`, `.rollup.cache` - Build tool caches
58
+ - `.vite` - Vite build tool cache
59
+ - `.swc`, `.rpt2_cache` - JavaScript transpiler caches
60
+ - `.eslintcache`, `.stylelintcache`, `.sass-cache` - Linter/preprocessor caches
61
+ - `.babel-cache`, `.cache-loader` - Babel and webpack loader caches
62
+
63
+ ### Package Manager Caches
64
+ - `node_modules/.cache` - npm package cache
65
+ - `.npm` - npm global cache
66
+ - `.pnpm-store`, `.pnpm-debug.log` - pnpm caches
67
+ - `.yarn/cache`, `.yarn/unplugged`, `.yarn/install-state.gz` - Yarn caches
68
+
69
+ ### Monorepo & Build Tools
70
+ - `.turbo` - Turborepo cache
71
+ - `.nx/cache` - Nx build system cache
72
+ - `.lerna` - Lerna monorepo cache
73
+ - `.rush` - Rush monorepo cache
74
+ - `.yalc` - Yalc local package manager
75
+
76
+ ### Blockchain & Web3 Tools
77
+ - `.hardhat` - Hardhat Ethereum development
78
+ - `.foundry` - Foundry Ethereum development
79
+ - `.anchor` - Anchor Solana development
80
+
81
+ ### Deployment & Platform Files
82
+ - `.vercel` - Vercel deployment cache
83
+ - `.netlify` - Netlify build cache
84
+ - `.wrangler` - Cloudflare Workers
85
+ - `.amplify` - AWS Amplify
86
+ - `.sst` - SST framework
87
+ - `.firebase` - Firebase hosting files
88
+ - `.serverless` - Serverless framework
89
+
90
+ ### Mobile Development
91
+ - `android/.gradle`, `android/build`, `android/app/build` - Android builds
92
+ - `ios/Pods`, `ios/build` - iOS builds
93
+ - `.expo`, `.expo-shared` - Expo React Native
94
+
95
+ ### File Patterns
96
+ - `*.log` - All log files
97
+ - `*.tgz`, `*.tar.gz` - Compressed archives
98
+ - `tsconfig.tsbuildinfo` - TypeScript incremental build info
99
+ - `coverage`, `.nyc_output` - Test coverage reports
100
+ - `storybook-static`, `.storybook-out` - Storybook builds
101
+
102
+ ### Temporary Files
103
+ - `.tmp`, `tmp`, `temp` - Temporary directories
104
+ - `lib`, `es`, `cjs`, `umd` - Compiled JavaScript outputs
105
+ - `jspm_packages`, `.typings` - Package manager files
36
106
 
37
107
  ## Supported Package Managers
38
108
 
@@ -40,7 +110,8 @@ React, Next.js, Vue, Vite, SvelteKit, React Native, Expo, and more.
40
110
 
41
111
  ### Core Operations (Always Performed)
42
112
 
43
- - **Removes build artifacts and cache directories** for common JavaScript/Node.js frameworks (e.g., `node_modules`, `dist`, `.next`, `.cache`, etc.).
113
+ - **Removes build artifacts and cache directories** for 50+ JavaScript/Node.js frameworks and tools (e.g., `node_modules`, `dist`, `.next`, `.cache`, `.vite`, `.remix`, `.qwik`, etc.).
114
+ - **Removes log files and temporary artifacts** including `*.log`, `*.tgz`, `*.tar.gz`, and build info files.
44
115
  - **Removes custom directories/paths** that you define in `torchrc.json`.
45
116
  - **Cleans package manager caches** for npm, yarn, and pnpm.
46
117
  - **Reinstalls dependencies** using your preferred package manager (npm, yarn, or pnpm).
@@ -146,13 +217,18 @@ torch-it --dockerMode=false --rebuild=false --customPaths=["temp/","logs/"]
146
217
  All configuration options can be overridden using `--optionName=value` syntax. For arrays and objects, use JSON syntax:
147
218
 
148
219
  - `--help` - Show help message and available options
220
+ - `--version, -v` - Show version information and exit
221
+ - `--config` - Show current configuration and exit
149
222
  - `--test` - Run in dry-run mode (preview changes without executing)
150
223
  - `--customPaths=["path1","path2"]`
151
224
  - `--dockerMode=false`
152
225
  - `--rebuild=false`
153
226
  - `--logfile=true`
154
227
 
155
- Command line flags take precedence over `torchrc.json` settings.
228
+ Command line flags take precedence over `torchrc.json` settings.
229
+
230
+ The config option `--config` will show all current settings including those from command line flags and a list of all files and directories that will be cleaned in the current project.
231
+
156
232
 
157
233
 
158
234
  ## Logging
package/dist/torch-it.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var ee=Object.create;var v=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var te=(e,n,s,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of ne(n))!re.call(e,t)&&t!==s&&v(e,t,{get:()=>n[t],enumerable:!(l=oe(n,t))||l.enumerable});return e};var k=(e,n,s)=>(s=e!=null?ee(se(e)):{},te(n||!e||!e.__esModule?v(s,"default",{value:e,enumerable:!0}):s,e));var _=k(require("fs"));var g=(e,n)=>s=>`\x1B[${e}m${s}\x1B[${n}m`,i={BOLD:g("1","22"),CYAN:g("36","39"),GREEN:g("32","39"),RED:g("31","39"),YELLOW:g("33","39"),PURPLE:g("35","39"),RESET:e=>`\x1B[0m${e}`},r={INFO:"\u{1F525}",SUCCESS:"\u2705",FAIL:"\u274C",EXCLAMATION:"\u2757",WARN:"\u26A0\uFE0F",ROCKET:"\u{1F525}",CLEAN:"\u{1F525}",PHOENIX:"\u{1F525}",BUILD:"\u{1F528}",TARGET:"\u{1F525}",CELEBRATE:"\u{1F525}",STARS:"\u2728",BOX:"\u{1F4E6}",CLIPBOARD:"\u{1F4CB}",DOCKER:"\u{1F433}"};var T=k(require("fs")),S=!0;function ie(e){let n=new RegExp("\x1B\\[[0-9;]*m","g");return e.replace(n,"")}var P=e=>{S=e},x=()=>{S&&T.default.writeFileSync("torch-it.log","")},b=e=>{if(!S)return;let n=ie(e).replace(/^\n/,""),s=new Date().toISOString();T.default.appendFileSync("torch-it.log",`[${s}] ${n}
3
- `)};function o(e,n){let s;switch(n){case"info":s=`${i.CYAN(r.INFO)} ${i.BOLD(e)}${i.RESET("")}`;break;case"success":s=`${i.GREEN(r.SUCCESS)} ${e}${i.RESET("")}`;break;case"warn":s=`${i.YELLOW(r.WARN)} ${e}${i.RESET("")}`;break;case"fail":s=`${i.RED(r.FAIL)} ${e}${i.RESET("")}`;break;case"step":s=`
4
- ${i.PURPLE("\u25B6")} ${i.BOLD(e)}${i.RESET("")}`;break;default:s=e}console.log(s),b(s)}function U(){D([` ${r.TARGET} TORCH LIT ${r.ROCKET}`],i.PURPLE);let e=`
2
+ "use strict";var ue=Object.create;var W=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var ge=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var ke=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports);var Ce=(e,n,t,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of me(n))!he.call(e,a)&&a!==t&&W(e,a,{get:()=>n[a],enumerable:!(c=pe(n,a))||c.enumerable});return e};var D=(e,n,t)=>(t=e!=null?ue(ge(e)):{},Ce(n||!e||!e.__esModule?W(t,"default",{value:e,enumerable:!0}):t,e));var fe=ke((to,De)=>{De.exports={name:"torch-it",version:"2.5.0",description:"CLI to reset, clean, and rebuild Node.js project environments.",keywords:["cleanup","cli","docker","node"],homepage:"https://github.com/piyook/torch-it#readme",bugs:{url:"https://github.com/piyook/torch-it/issues"},license:"ISC",author:"",repository:{type:"git",url:"git+https://github.com/piyook/torch-it.git"},bin:{"torch-it":"dist/torch-it.js"},files:["dist","README.md"],type:"commonjs",main:"dist/torch-it.js",scripts:{build:'esbuild src/torch.ts --bundle --outfile=dist/torch-it.js --platform=node --format=cjs --minify --banner:js="#!/usr/bin/env node"',"torch-it":"npm run build && node dist/torch-it.js","torch-it:ts":"ts-node src/torch.ts",lint:"oxlint .","lint:fix":"oxlint . --fix",format:"prettier --check src/**/*.{ts,js,json} package.json package-lock.json .commitlintrc.json","format:write":"prettier --write src/**/*.{ts,js,json} package.json package-lock.json .commitlintrc.json",quality:"npm run lint && npm run format && npm test","validate-branch-name":"validate-branch-name",prepare:"husky",prepublishOnly:"npm run build",test:"tsc --noEmit && vitest run","test:watch":"vitest"},dependencies:{},devDependencies:{"@commitlint/cli":"^20.5.0","@commitlint/config-conventional":"^20.5.0","@types/node":"^25.6.0",esbuild:"^0.28.0",husky:"^9.1.7","lint-staged":"^16.4.0",oxlint:"^1.59.0",prettier:"^3.8.2","ts-node":"^10.9.2",typescript:"^6.0.2","validate-branch-name":"^1.3.2",vitest:"^4.1.4"},"lint-staged":{"*.{ts,tsx,js,jsx,mjs,cjs,json}":["oxlint --fix","prettier --write"]},"validate-branch-name":{pattern:"^(main|dev){1}$|^(feat|fix|hotfix|release|chore)/.+$",errorMsg:"INVALID BRANCH NAME: use format 'feat|fix|hotfix|release|core/your-branch-name'"}}});var j=D(require("fs"));var E=(e,n)=>t=>`\x1B[${e}m${t}\x1B[${n}m`,f={BOLD:E("1","22"),CYAN:E("36","39"),GREEN:E("32","39"),RED:E("31","39"),YELLOW:E("33","39"),PURPLE:E("35","39"),RESET:e=>`\x1B[0m${e}`},i={INFO:"\u{1F525}",SUCCESS:"\u2705",FAIL:"\u274C",EXCLAMATION:"\u2757",WARN:"\u26A0\uFE0F",ROCKET:"\u{1F525}",CLEAN:"\u{1F525}",PHOENIX:"\u{1F525}",BUILD:"\u{1F528}",TARGET:"\u{1F525}",CELEBRATE:"\u{1F525}",STARS:"\u2728",BOX:"\u{1F4E6}",CLIPBOARD:"\u{1F4CB}",DOCKER:"\u{1F433}"};var H=D(require("fs")),K=!0;function ye(e){let n=new RegExp("\x1B\\[[0-9;]*m","g");return e.replace(n,"")}var X=e=>{K=e},q=()=>{K&&H.default.writeFileSync("torch-it.log","")},x=e=>{if(!K)return;let n=ye(e).replace(/^\n/,""),t=new Date().toISOString();H.default.appendFileSync("torch-it.log",`[${t}] ${n}
3
+ `)};function o(e,n){let t;switch(n){case"info":t=`${f.CYAN(i.INFO)} ${f.BOLD(e)}${f.RESET("")}`;break;case"success":t=`${f.GREEN(i.SUCCESS)} ${e}${f.RESET("")}`;break;case"warn":t=`${f.YELLOW(i.WARN)} ${e}${f.RESET("")}`;break;case"fail":t=`${f.RED(i.FAIL)} ${e}${f.RESET("")}`;break;case"step":t=`
4
+ ${f.PURPLE("\u25B6")} ${f.BOLD(e)}${f.RESET("")}`;break;default:t=e}console.log(t),x(t)}function z(){w([` ${i.TARGET} TORCH LIT ${i.ROCKET}`],f.PURPLE);let e=`
5
5
  ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )
6
6
  (( (( (( (( (( (( (( (( (( (( (( (( (( ((
7
7
  ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )
@@ -12,7 +12,7 @@ ${i.PURPLE("\u25B6")} ${i.BOLD(e)}${i.RESET("")}`;break;default:s=e}console.log(
12
12
  | _ \\| | | | |_) | \\| || || \\| | | _
13
13
  | |_) | |_| | _ <| |\\ || || |\\ | |_| |
14
14
  |____/ \\___/|_| \\_\\_| \\_|___|_| \\_|\\____|
15
- `;console.log(e),b(e)}function M(){console.log(""),D([` ${r.PHOENIX} RISING FROM THE ASHES ${r.PHOENIX}`],i.PURPLE)}function F(e){let n=new RegExp("\x1B\\[[0-9;]*m","g");return e.replace(n,"").length}function D(e,n=i.GREEN){let s=Math.max(56,...e.map(t=>F(t))),l=n("\u2550".repeat(s));console.log(n("\u2554"+l+"\u2557")),e.forEach(t=>{if(b(t),t.trim()==="")console.log(n("\u2551"+" ".repeat(s)+"\u2551"));else{let p=s-F(t);console.log(n("\u2551"+t+" ".repeat(p)+"\u2551"))}}),console.log(n("\u255A"+l+"\u255D"))}var y=require("child_process"),B=k(require("os"));function c(e,n={}){try{return(0,y.execSync)(e,{stdio:n.silent?"pipe":"inherit"}),!0}catch{return n.silent||o(`Command failed: ${e}`,"fail"),!1}}function a(e){try{return B.platform()==="win32"?(0,y.execSync)(`where ${e}`,{stdio:"ignore"}):(0,y.execSync)(`command -v ${e}`,{stdio:"ignore"}),!0}catch{return!1}}var m=k(require("fs"));var K=["node_modules","dist","build",".svelte-kit",".svelte",".next",".nuxt","out",".output",".vercel",".netlify",".astro",".angular",".angular/cache",".solid",".docusaurus",".vite",".cache",".parcel-cache",".webpack",".rollup.cache",".rpt2_cache",".swc",".eslintcache",".stylelintcache",".sass-cache",".tmp","tmp","temp","coverage",".nyc_output","storybook-static",".storybook-out",".turbo",".rush",".firebase",".serverless","android/.gradle","android/build","android/app/build","ios/Pods","ios/build",".expo",".expo-shared","lib","es","cjs","umd"],H=[".pnpm-store",".pnpm-debug.log",".yarn/cache",".yarn/unplugged",".yarn/install-state.gz",".yarn/build-state.yml",".npm","node_modules/.cache"],Y=[];var f={customPaths:[],customDirs:[],customFiles:[],protectedPaths:[],dockerMode:!0,logfile:!1,rebuild:!0};var ce=e=>{let n={};for(let s of e){if(!s.startsWith("--"))continue;let[l,t]=s.slice(2).split("=",2);if(!(!l||!t))try{let p=JSON.parse(t);n[l]=p}catch{t==="true"?n[l]=!0:t==="false"?n[l]=!1:n[l]=t}}return n},le=()=>{let e="torchrc.json";if(!m.existsSync(e))return{};try{return JSON.parse(m.readFileSync(e,"utf8"))}catch{return o("Invalid torchrc.json (must be valid JSON) - skipping custom config","warn"),{}}},L=()=>{let e=le();return{customPaths:e.customPaths??f.customPaths,customDirs:e.customDirs??f.customDirs,customFiles:e.customFiles??f.customFiles,protectedPaths:e.protectedPaths??f.protectedPaths,dockerMode:e.dockerMode??f.dockerMode,logfile:e.logfile??f.logfile,rebuild:e.rebuild??f.rebuild}},h=(e=[])=>{let n=L(),s=ce(e);return{...n,...s}},ae=()=>{let e=L();return[...e.customPaths,...e.customDirs,...e.customFiles].filter(s=>typeof s=="string").map(s=>s.trim()).filter(s=>s.length>0)},j=()=>{let e=process.env.TORCH_DRY_RUN==="1",n=0,s=L(),l=ae(),t=s.protectedPaths,p=[...new Set([...K,...H,...Y])],N=[...new Set(l)],w=p.filter(u=>!t.some(R=>u===R||u.startsWith(R+"/"))),O=N.filter(u=>!t.some(R=>u===R||u.startsWith(R+"/"))),A=u=>{if(m.existsSync(u)){o(`${e?"Would remove":"Removing"} ${u}...`,"step");try{e||m.rmSync(u,{recursive:!0,force:!0}),o(`${u} ${e?"marked for removal (dry-run)":"removed"}`,"success"),n++}catch{o(`Failed to remove ${u}`,"fail")}}};o("Scanning for build artifacts and cache directories...","step"),w.forEach(A),O.length>0&&(o("Deleting user defined custom directories and files","step"),O.forEach(A));let I=p.length-w.length+(N.length-O.length);return I>0&&o(`Skipped ${I} protected path(s) from torchrc.json`,"info"),n===0?(o("No build artifacts or cache directories found (project already clean)","info"),!1):(o(`Removed ${n} build/cache directories`,"success"),!0)},G=()=>{let e=process.env.TORCH_DRY_RUN==="1",n=!1;return a("npm")&&(e||c("npm cache clean --force"))&&(o(e?"Dry-run: would clean npm cache":"npm cache cleaned","success"),n=!0),a("yarn")&&(e||c("yarn cache clean"))&&(o(e?"Dry-run: would clean yarn cache":"yarn cache cleaned","success"),n=!0),a("pnpm")&&(e||c("pnpm store prune"))&&(o(e?"Dry-run: would clean pnpm store":"pnpm store cleaned","success"),n=!0),n||o("No package manager caches cleaned (tools not available)","info"),n};function W(){return _.existsSync("Dockerfile")||_.existsSync("docker-compose.yml")||_.existsSync("docker-compose.yaml")}function X(){if(h().dockerMode===!1)return o("Docker mode disabled in torchrc.json - skipping Docker operations","info"),"NO_DOCKER";let n=process.env.TORCH_DRY_RUN==="1";return W()?(o("Stopping Docker services and removing all resources...","info"),a("docker")?c("docker info",{silent:!0})?c("docker compose ps",{silent:!0})?n?(o("Dry-run: would run 'docker compose down --rmi all --volumes'","info"),"OK"):c("docker compose down --rmi all --volumes")?(o("Docker services stopped and resources cleaned","success"),"OK"):(o("Docker cleanup encountered issues","warn"),o("Continuing with the rest of the script...","info"),"DOCKER_FAIL"):(o("No Docker Compose services found - skipping Docker cleanup","warn"),o("This is normal if no services were previously running","info"),"DOCKER_FAIL"):(o("Docker daemon is not running - skipping Docker cleanup","warn"),o("You may need to start Docker manually and run cleanup later","info"),"NO_DOCKER"):(o("Docker is not installed - skipping Docker cleanup","warn"),"NO_DOCKER")):(o("No Docker configuration found - skipping Docker operations","info"),"NO_DOCKER")}function J(){let e=h();if(e.dockerMode===!1)return!1;if(e.rebuild===!1)return o("Rebuild disabled in torchrc.json - skipping Docker rebuild","info"),!1;let n=process.env.TORCH_DRY_RUN==="1";return W()?a("docker")?c("docker info",{silent:!0})?(o("Building Docker resources (this may take a while...)...","step"),console.log(` ${i.YELLOW("\u23F3 Please be patient - pulling fresh images and building...")}`),n?(o("Dry-run: would run 'docker-compose build --pull --no-cache'","info"),!0):c("docker-compose build --pull --no-cache")?!0:(o("Docker build encountered issues - check torch-it.log for details","fail"),!1)):(o("Docker daemon is not running - skipping Docker rebuild","warn"),o("Start Docker manually and run 'docker-compose build --pull --no-cache' later","info"),!1):(o("Docker is not installed - skipping Docker rebuild","warn"),!1):!1}function q(){if(h().dockerMode===!1)return!1;let n=process.env.TORCH_DRY_RUN==="1";return o("Starting Docker services in detached mode...","step"),n?(o("Dry-run: would run 'docker compose up -d'","info"),!0):c("docker compose up -d")?!0:(o("Failed to start Docker services - check torch-it.log for details","fail"),!1)}var E=k(require("fs"));var V=()=>{let e=process.env.TORCH_DRY_RUN==="1",n=!1;return o("Detecting package manager and installing dependencies...","step"),E.existsSync("pnpm-lock.yaml")&&a("pnpm")?(o("Using pnpm (detected pnpm-lock.yaml)...","step"),e||c("pnpm install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with pnpm`,"success"),n=!0):o("pnpm install failed","fail")):E.existsSync("yarn.lock")&&a("yarn")?(o("Using yarn (detected yarn.lock)...","step"),e||c("yarn install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with yarn`,"success"),n=!0):o("yarn install failed","fail")):E.existsSync("package-lock.json")&&a("npm")?(o("Using npm (detected package-lock.json)...","step"),e||c("npm install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with npm`,"success"),n=!0):o("npm install failed","fail")):a("npm")?(o("Using npm (fallback)...","info"),e||c("npm install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with npm`,"success"),n=!0):o("npm install failed","fail")):a("yarn")?(o("Using yarn (fallback)...","info"),e||c("yarn install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with yarn`,"success"),n=!0):o("yarn install failed","")):a("pnpm")?(o("Using pnpm (fallback)...","info"),e||c("pnpm install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with pnpm`,"success"),n=!0):o("pnpm install failed","fail")):o("No package manager found (npm/yarn/pnpm). Please install dependencies manually.","fail"),n};var z=e=>{let n="",s="",l="";e.dockerClean==="NO_DOCKER"?n=`${r.DOCKER} No Docker containers found`:e.dockerClean==="DOCKER_FAIL"&&(n=`${r.FAIL} Failed to remove Docker containers`),e.dockerClean==="OK"&&(e.dockerRebuild?s=`${r.DOCKER} Docker containers rebuilt from scratch`:s=`${r.FAIL} Failed to rebuild Docker containers`,e.dockerLaunch&&e.dockerRebuild?l=`${r.ROCKET} Services running in detached mode`:l=`${r.FAIL} Failed to start Docker containers`);let t=e.buildAndCacheClean&&e.packageManagerClean?`${r.CLEAN} All build artifacts & caches removed`:`${r.FAIL} Build artifacts or cache directories not found`,p=e.dependencyInstall?`${r.BOX} Dependencies freshly installed`:`${r.FAIL} Failed to install dependencies`;console.log(""),D(["\u{1F525} PROJECT SUCCESSFULLY TORCHED! \u{1F525}","",`${t}`,`${p}`,`${n}`,`${s}`,`${l}`,"",e.logfile===!1?`${r.CLIPBOARD} Logging to torch-it.log is disabled; set "logfile": true in torchrc.json to enable it`:`${r.CLIPBOARD} Check torch-it.log for detailed logs`])};var Q=()=>{o(`
15
+ `;console.log(e),x(e)}function V(){console.log(""),w([` ${i.PHOENIX} RISING FROM THE ASHES ${i.PHOENIX}`],f.PURPLE)}function J(e){let n=new RegExp("\x1B\\[[0-9;]*m","g");return e.replace(n,"").length}function w(e,n=f.GREEN){let t=Math.max(56,...e.map(a=>J(a))),c=n("\u2550".repeat(t));console.log(n("\u2554"+c+"\u2557")),e.forEach(a=>{if(x(a),a.trim()==="")console.log(n("\u2551"+" ".repeat(t)+"\u2551"));else{let h=t-J(a);console.log(n("\u2551"+a+" ".repeat(h)+"\u2551"))}}),console.log(n("\u255A"+c+"\u255D"))}var N=require("child_process"),Q=D(require("os"));function d(e,n={}){try{return(0,N.execSync)(e,{stdio:n.silent?"pipe":"inherit"}),!0}catch{return n.silent||o(`Command failed: ${e}`,"fail"),!1}}function l(e){try{return Q.platform()==="win32"?(0,N.execSync)(`where ${e}`,{stdio:"ignore"}):(0,N.execSync)(`command -v ${e}`,{stdio:"ignore"}),!0}catch{return!1}}var m=D(require("fs")),Z=D(require("path"));var A=["node_modules","dist","build",".svelte-kit",".svelte",".next",".nuxt","out",".output",".vercel",".netlify",".astro",".angular",".angular/cache",".solid",".docusaurus",".vite",".cache",".parcel-cache",".webpack",".rollup.cache",".rpt2_cache",".swc",".eslintcache",".stylelintcache",".sass-cache",".tmp","tmp","temp","coverage",".nyc_output","storybook-static",".storybook-out",".turbo",".rush",".firebase",".serverless","android/.gradle","android/build","android/app/build","ios/Pods","ios/build",".expo",".expo-shared","lib","es","cjs","umd",".remix",".qwik",".nitro",".wrangler",".amplify",".sst",".babel-cache",".cache-loader","jspm_packages",".typings"],P=["*.log","*.tgz","*.tar.gz","tsconfig.tsbuildinfo"],F=[".pnpm-store",".pnpm-debug.log",".yarn/cache",".yarn/unplugged",".yarn/install-state.gz",".yarn/build-state.yml",".npm","node_modules/.cache",".yalc",".lerna",".nx/cache",".vite/deps",".turbo","tsconfig.tsbuildinfo",".hardhat",".foundry",".anchor"],U=[];var y={customPaths:[],customDirs:[],customFiles:[],protectedPaths:[],dockerMode:!0,logfile:!1,rebuild:!0};var Re=e=>{let n={};for(let t of e){if(!t.startsWith("--"))continue;let[c,a]=t.slice(2).split("=",2);if(!(!c||!a))try{let h=JSON.parse(a);n[c]=h}catch{a==="true"?n[c]=!0:a==="false"?n[c]=!1:n[c]=a}}return n},be=()=>{let e="torchrc.json";if(!m.existsSync(e))return{};try{return JSON.parse(m.readFileSync(e,"utf8"))}catch{return o("Invalid torchrc.json (must be valid JSON) - skipping custom config","warn"),{}}},I=()=>{let e=be();return{customPaths:e.customPaths??y.customPaths,customDirs:e.customDirs??y.customDirs,customFiles:e.customFiles??y.customFiles,protectedPaths:e.protectedPaths??y.protectedPaths,dockerMode:e.dockerMode??y.dockerMode,logfile:e.logfile??y.logfile,rebuild:e.rebuild??y.rebuild}};var T=(e=[])=>{let n=I(),t=Re(e);return{...n,...t}},G=()=>{let e=I();return[...e.customPaths,...e.customDirs,...e.customFiles].filter(t=>typeof t=="string").map(t=>t.trim()).filter(t=>t.length>0)},ee=()=>{let e=process.env.TORCH_DRY_RUN==="1",n=0,t=I(),c=G(),a=t.protectedPaths,h=[...new Set([...A,...F,...U])],B=[...new Set(c)],v=[...P],L=h.filter(r=>!a.some(u=>r===u||r.startsWith(u+"/"))),R=B.filter(r=>!a.some(u=>r===u||r.startsWith(u+"/"))),b=r=>{if(m.existsSync(r)){o(`${e?"Would remove":"Removing"} ${r}...`,"step");try{e||m.rmSync(r,{recursive:!0,force:!0}),o(`${r} ${e?"marked for removal (dry-run)":"removed"}`,"success"),n++}catch{o(`Failed to remove ${r}`,"fail")}}},O=()=>{for(let r of v)if(r.includes("*"))try{let C=m.readdirSync(".",{withFileTypes:!0}).filter($=>$.name.match(r.replace("*",".*"))).map($=>$.name);for(let $ of C){let k=Z.join(".",$);if(m.existsSync(k)&&m.statSync(k).isFile()&&!a.some(Y=>k===Y||k.startsWith(Y+"/"))){o(`${e?"Would remove":"Removing"} ${k}...`,"step");try{e||m.unlinkSync(k),o(`${k} ${e?"marked for removal (dry-run)":"removed"}`,"success"),n++}catch{o(`Failed to remove ${k}`,"fail")}}}}catch(C){o(`Failed to process pattern ${r}: ${C}`,"warn")}else m.existsSync(r)&&b(r)};o("Scanning for build artifacts and cache directories...","step"),L.forEach(b),o("Scanning for log files and temporary files...","step"),O(),R.length>0&&(o("Deleting user defined custom directories and files","step"),R.forEach(b));let s=h.length-L.length+(B.length-R.length);return s>0&&o(`Skipped ${s} protected path(s) from torchrc.json`,"info"),n===0?(o("No build artifacts or cache directories found (project already clean)","info"),!1):(o(`Removed ${n} build/cache directories`,"success"),!0)},oe=()=>{let e=process.env.TORCH_DRY_RUN==="1",n=!1;return l("npm")&&(e||d("npm cache clean --force"))&&(o(e?"Dry-run: would clean npm cache":"npm cache cleaned","success"),n=!0),l("yarn")&&(e||d("yarn cache clean"))&&(o(e?"Dry-run: would clean yarn cache":"yarn cache cleaned","success"),n=!0),l("pnpm")&&(e||d("pnpm store prune"))&&(o(e?"Dry-run: would clean pnpm store":"pnpm store cleaned","success"),n=!0),n||o("No package manager caches cleaned (tools not available)","info"),n};function ne(){return j.existsSync("Dockerfile")||j.existsSync("docker-compose.yml")||j.existsSync("docker-compose.yaml")}function te(){if(T().dockerMode===!1)return o("Docker mode disabled in torchrc.json - skipping Docker operations","info"),"NO_DOCKER";let n=process.env.TORCH_DRY_RUN==="1";return ne()?(o("Stopping Docker services and removing all resources...","info"),l("docker")?d("docker info",{silent:!0})?d("docker compose ps",{silent:!0})?n?(o("Dry-run: would run 'docker compose down --rmi all --volumes'","info"),"OK"):d("docker compose down --rmi all --volumes")?(o("Docker services stopped and resources cleaned","success"),"OK"):(o("Docker cleanup encountered issues","warn"),o("Continuing with the rest of the script...","info"),"DOCKER_FAIL"):(o("No Docker Compose services found - skipping Docker cleanup","warn"),o("This is normal if no services were previously running","info"),"DOCKER_FAIL"):(o("Docker daemon is not running - skipping Docker cleanup","warn"),o("You may need to start Docker manually and run cleanup later","info"),"NO_DOCKER"):(o("Docker is not installed - skipping Docker cleanup","warn"),"NO_DOCKER")):(o("No Docker configuration found - skipping Docker operations","info"),"NO_DOCKER")}function se(){let e=T();if(e.dockerMode===!1)return!1;if(e.rebuild===!1)return o("Rebuild disabled in torchrc.json - skipping Docker rebuild","info"),!1;let n=process.env.TORCH_DRY_RUN==="1";return ne()?l("docker")?d("docker info",{silent:!0})?(o("Building Docker resources (this may take a while...)...","step"),console.log(` ${f.YELLOW("\u23F3 Please be patient - pulling fresh images and building...")}`),n?(o("Dry-run: would run 'docker-compose build --pull --no-cache'","info"),!0):d("docker-compose build --pull --no-cache")?!0:(o("Docker build encountered issues - check torch-it.log for details","fail"),!1)):(o("Docker daemon is not running - skipping Docker rebuild","warn"),o("Start Docker manually and run 'docker-compose build --pull --no-cache' later","info"),!1):(o("Docker is not installed - skipping Docker rebuild","warn"),!1):!1}function re(){if(T().dockerMode===!1)return!1;let n=process.env.TORCH_DRY_RUN==="1";return o("Starting Docker services in detached mode...","step"),n?(o("Dry-run: would run 'docker compose up -d'","info"),!0):d("docker compose up -d")?!0:(o("Failed to start Docker services - check torch-it.log for details","fail"),!1)}var M=D(require("fs"));var ie=()=>{let e=process.env.TORCH_DRY_RUN==="1",n=!1;return o("Detecting package manager and installing dependencies...","step"),M.existsSync("pnpm-lock.yaml")&&l("pnpm")?(o("Using pnpm (detected pnpm-lock.yaml)...","step"),e||d("pnpm install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with pnpm`,"success"),n=!0):o("pnpm install failed","fail")):M.existsSync("yarn.lock")&&l("yarn")?(o("Using yarn (detected yarn.lock)...","step"),e||d("yarn install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with yarn`,"success"),n=!0):o("yarn install failed","fail")):M.existsSync("package-lock.json")&&l("npm")?(o("Using npm (detected package-lock.json)...","step"),e||d("npm install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with npm`,"success"),n=!0):o("npm install failed","fail")):l("npm")?(o("Using npm (fallback)...","info"),e||d("npm install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with npm`,"success"),n=!0):o("npm install failed","fail")):l("yarn")?(o("Using yarn (fallback)...","info"),e||d("yarn install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with yarn`,"success"),n=!0):o("yarn install failed","")):l("pnpm")?(o("Using pnpm (fallback)...","info"),e||d("pnpm install")?(o(`Dependencies ${e?"would be installed":"installed successfully"} with pnpm`,"success"),n=!0):o("pnpm install failed","fail")):o("No package manager found (npm/yarn/pnpm). Please install dependencies manually.","fail"),n};var ce=e=>{let n="",t="",c="";e.dockerClean==="NO_DOCKER"?n=`${i.DOCKER} No Docker containers found`:e.dockerClean==="DOCKER_FAIL"&&(n=`${i.FAIL} Failed to remove Docker containers`),e.dockerClean==="OK"&&(e.dockerRebuild?t=`${i.DOCKER} Docker containers rebuilt from scratch`:t=`${i.FAIL} Failed to rebuild Docker containers`,e.dockerLaunch&&e.dockerRebuild?c=`${i.ROCKET} Services running in detached mode`:c=`${i.FAIL} Failed to start Docker containers`);let a=e.buildAndCacheClean&&e.packageManagerClean?`${i.CLEAN} All build artifacts & caches removed`:`${i.FAIL} Build artifacts or cache directories not found`,h=e.dependencyInstall?`${i.BOX} Dependencies freshly installed`:`${i.FAIL} Failed to install dependencies`;console.log(""),w(["\u{1F525} PROJECT SUCCESSFULLY TORCHED! \u{1F525}","",`${a}`,`${h}`,`${n}`,`${t}`,`${c}`,"",e.logfile===!1?`${i.CLIPBOARD} Logging to torch-it.log is disabled; set "logfile": true in torchrc.json to enable it`:`${i.CLIPBOARD} Check torch-it.log for detailed logs`])};var ae=()=>{o(`
16
16
  \u{1F525} Torch It - Project Environment Reset Tool
17
17
 
18
18
  USAGE:
@@ -20,6 +20,8 @@ USAGE:
20
20
 
21
21
  OPTIONS:
22
22
  --help Show this help message and exit
23
+ --version, -v Show version information and exit
24
+ --config Show current configuration and exit
23
25
  --test Run in dry-run mode (preview changes without executing)
24
26
  --dockerMode=<bool> Enable/disable Docker operations (default: true)
25
27
  --rebuild=<bool> Enable/disable rebuild operations (default: true)
@@ -29,6 +31,8 @@ OPTIONS:
29
31
 
30
32
  EXAMPLES:
31
33
  torch-it # Run with default settings
34
+ torch-it --version # Show version information
35
+ torch-it --config # Show current configuration
32
36
  torch-it --test # Preview what would be done
33
37
  torch-it --rebuild=false # Clean only, don't rebuild
34
38
  torch-it --dockerMode=false # Skip Docker operations
@@ -47,4 +51,12 @@ CONFIGURATION:
47
51
  }
48
52
 
49
53
  For more information, visit: https://github.com/piyook/torch-it
50
- `.trim(),"info")};var $=process.argv.slice(2);$.includes("--help")&&(Q(),process.exit(0));var Z=$.includes("--test");Z&&(process.env.TORCH_DRY_RUN="1");var C=h($.filter(e=>e!=="--test"&&e!=="--help"));P(C.logfile);C.logfile&&x();U();Z&&o("Running in --test dry-run mode (no files or services will be changed)","warn");var d={dockerClean:"NO_DOCKER",buildAndCacheClean:!1,packageManagerClean:!1,dependencyInstall:!1,dockerRebuild:!1,dockerLaunch:!1,logfile:C.logfile};o(`${r.CLEAN} DOCKER CLEANUP`,"step");d.dockerClean=X();o(`${r.CLEAN} BUILD ARTIFACTS & CACHE CLEANUP`,"step");d.buildAndCacheClean=j();o("Cleaning package manager caches...","step");d.packageManagerClean=G();C.rebuild!==!1?(M(),o(`${r.BUILD} DEPENDENCY INSTALLATION`,"step"),d.dependencyInstall=V()):(o("Rebuild disabled - skipping dependency installation","info"),d.dependencyInstall=!1);d.dockerClean!=="NO_DOCKER"&&C.rebuild!==!1?(o(`${r.BUILD} DOCKER REBUILD`,"step"),d.dockerRebuild=J()):d.dockerClean!=="NO_DOCKER"&&C.rebuild===!1&&(o("Rebuild disabled - skipping Docker rebuild","info"),d.dockerRebuild=!1);d.dockerRebuild&&(d.dockerLaunch=q(),o(`${r.ROCKET} LAUNCH`,"step"));z(d);
54
+ `.trim(),"info")};var p=D(require("fs"));var le=()=>{let e=I(),n=G(),t=e.protectedPaths;o("=".repeat(60),"info"),o("TORCH-IT CONFIGURATION","info"),o("=".repeat(60),"info"),o(`
55
+ BASIC SETTINGS:`,"info"),o(` Docker Mode: ${e.dockerMode}`,"info"),o(` Rebuild: ${e.rebuild}`,"info"),o(` Logfile: ${e.logfile}`,"info"),o(`
56
+ PACKAGE MANAGER DETECTION:`,"info");let c=[];p.existsSync("package-lock.json")&&l("npm")?c.push("npm (package-lock.json)"):l("npm")&&c.push("npm (fallback)"),p.existsSync("yarn.lock")&&l("yarn")?c.push("yarn (yarn.lock)"):l("yarn")&&c.push("yarn (fallback)"),p.existsSync("pnpm-lock.yaml")&&l("pnpm")?c.push("pnpm (pnpm-lock.yaml)"):l("pnpm")&&c.push("pnpm (fallback)"),c.length>0?c.forEach(s=>o(` ${s}`,"info")):o(" No package manager detected","warn"),o(`
57
+ DOCKER DETECTION:`,"info");let h=["Dockerfile","docker-compose.yml","docker-compose.yaml"].filter(s=>p.existsSync(s));h.length>0?h.forEach(s=>o(` ${s}`,"info")):o(" No Docker configuration found","info"),o(`
58
+ FILES/DIRECTORIES THAT WILL BE DELETED:`,"info");let v=[...new Set([...A,...F,...U,...P])].filter(s=>!t.some(r=>s===r||s.startsWith(r+"/"))),L=n.filter(s=>!t.some(r=>s===r||s.startsWith(r+"/"))),R=v.filter(s=>!s.includes("*")&&p.existsSync(s)),b=v.filter(s=>s.includes("*")),O=L.filter(s=>p.existsSync(s));R.length>0&&(o(" Default targets:","info"),R.forEach(s=>{let r=p.statSync(s).isDirectory()?"DIR":"FILE";o(` ${s} (${r})`,"info")})),b.length>0&&(o(" Glob patterns:","info"),b.forEach(s=>{try{let r=p.readdirSync(".",{withFileTypes:!0}).filter(u=>u.name.match(s.replace("*",".*"))).map(u=>u.name);r.length>0?(o(` ${s} (matches ${r.length} file${r.length===1?"":"s"}):`,"info"),r.forEach(u=>{o(` ${u} (FILE)`,"info")})):o(` ${s} (no matches)`,"info")}catch(r){o(` ${s} (error: ${r})`,"warn")}})),O.length>0&&(o(" Custom targets:","info"),O.forEach(s=>{let r=p.statSync(s).isDirectory()?"DIR":"FILE";o(` ${s} (${r})`,"info")})),R.length===0&&b.length===0&&O.length===0&&o(" No targets found (nothing to delete)","info"),t.length>0?(o(`
59
+ PROTECTED PATHS (will NOT be deleted):`,"info"),t.forEach(s=>{let r=p.existsSync(s),u=r&&p.statSync(s).isDirectory()?"DIR":"FILE",C=r?`(${u})`:"(not found)";o(` ${s} ${C}`,"info")})):o(`
60
+ PROTECTED PATHS: None`,"info"),n.length>0&&(o(`
61
+ CUSTOM PATHS FROM torchrc.json:`,"info"),n.forEach(s=>{let r=p.existsSync(s),u=r&&p.statSync(s).isDirectory()?"DIR":"FILE",C=r?`(${u})`:"(not found)";o(` ${s} ${C}`,"info")})),o(`
62
+ `+"=".repeat(60),"info"),o("Use 'torch-it --help' for available options","info"),o("=".repeat(60),"info")};var S=process.argv.slice(2);S.includes("--help")&&(ae(),process.exit(0));if(S.includes("--version")||S.includes("-v")){let e=fe();o(`torch-it v${e.version}`,"info"),process.exit(0)}S.includes("--config")&&(le(),process.exit(0));var de=S.includes("--test");de&&(process.env.TORCH_DRY_RUN="1");var _=T(S.filter(e=>e!=="--test"&&e!=="--help"&&e!=="--version"&&e!=="-v"&&e!=="--config"));X(_.logfile);_.logfile&&q();z();de&&o("Running in --test dry-run mode (no files or services will be changed)","warn");var g={dockerClean:"NO_DOCKER",buildAndCacheClean:!1,packageManagerClean:!1,dependencyInstall:!1,dockerRebuild:!1,dockerLaunch:!1,logfile:_.logfile};o(`${i.CLEAN} DOCKER CLEANUP`,"step");g.dockerClean=te();o(`${i.CLEAN} BUILD ARTIFACTS & CACHE CLEANUP`,"step");g.buildAndCacheClean=ee();o("Cleaning package manager caches...","step");g.packageManagerClean=oe();_.rebuild!==!1?(V(),o(`${i.BUILD} DEPENDENCY INSTALLATION`,"step"),g.dependencyInstall=ie()):(o("Rebuild disabled - skipping dependency installation","info"),g.dependencyInstall=!1);g.dockerClean!=="NO_DOCKER"&&_.rebuild!==!1?(o(`${i.BUILD} DOCKER REBUILD`,"step"),g.dockerRebuild=se()):g.dockerClean!=="NO_DOCKER"&&_.rebuild===!1&&(o("Rebuild disabled - skipping Docker rebuild","info"),g.dockerRebuild=!1);g.dockerRebuild&&(g.dockerLaunch=re(),o(`${i.ROCKET} LAUNCH`,"step"));ce(g);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "torch-it",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "CLI to reset, clean, and rebuild Node.js project environments.",
5
5
  "keywords": [
6
6
  "cleanup",