UNPKG

track-dev-time

Version:

CLI tool to track your coding sessions with start, pause and stop commands. Outputs session data to a JSON file.

207 lines (171 loc) â€ĸ 6.58 kB
//@ts-nocheck import readline from "readline"; import fs from "fs"; import path from "path"; import { execSync } from "child_process"; import { META_PATH } from "../utils/constants.js"; import { detectPackageManager } from "../utils/concurrently.js"; export const uninstallTrackDevTime = (basePath = process.cwd()) => { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.question( "âš ī¸ This will remove all track-dev-time related files. Continue? (y/n): ", (answer) => { rl.close(); const confirm = answer.trim().toLowerCase(); if (confirm !== "y" && confirm !== "yes") { console.log("❌ Uninstall aborted."); return; } console.log("\n🧹 Uninstalling track-dev-time..."); removeTrackingFolder(basePath); cleanGitignore(basePath); cleanPackageJson(basePath); removeConcurrentlyIfInstalledByCli(basePath); console.log("\n✅ Uninstall complete! You can now run:"); console.log(" npm uninstall track-dev-time"); console.log( "\nâ„šī¸ If you no longer use 'concurrently' in your project, you can remove it:" ); console.log(" npm uninstall concurrently\n"); } ); }; const removeTrackingFolder = (basePath) => { const trackingFolderPath = path.resolve(basePath, ".track-dev-time"); if (fs.existsSync(trackingFolderPath)) { fs.rmSync(trackingFolderPath, { recursive: true, force: true }); console.log("âœ”ī¸ Removed .track-dev-time folder"); } }; const cleanGitignore = (basePath) => { const gitignorePath = path.resolve(basePath, ".gitignore"); if (fs.existsSync(gitignorePath)) { const content = fs.readFileSync(gitignorePath, "utf-8"); const updated = content .split("\n") .filter((line) => !line.includes(".track-dev-time/")) .join("\n"); fs.writeFileSync(gitignorePath, updated); console.log("âœ”ī¸ Cleaned .gitignore"); } }; const cleanPackageJson = (basePath) => { const pkgJsonPath = path.resolve(basePath, "package.json"); if (fs.existsSync(pkgJsonPath)) { const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")); if (pkg.trackDevTimeBackupDevScript) { pkg.scripts.dev = pkg.trackDevTimeBackupDevScript; delete pkg.trackDevTimeBackupDevScript; fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2), "utf-8"); console.log("✅ 'dev' script restored to original"); } else { console.log("â„šī¸ No backup found, nothing to restore"); } } }; const removeConcurrentlyIfInstalledByCli = (basePath) => { const metaPath = path.resolve(basePath, META_PATH); if (!fs.existsSync(metaPath)) return; const meta = JSON.parse(fs.readFileSync(metaPath, "utf-8")); if (!meta.concurrentlyInstalledByCli) return; const pkgManager = detectPackageManager(); const uninstallCmd = { npm: "npm uninstall concurrently", yarn: "yarn remove concurrently", pnpm: "pnpm remove concurrently", }[pkgManager]; console.log(`\n🔧 Removing 'concurrently' using ${pkgManager}...`); try { execSync(uninstallCmd, { stdio: "inherit" }); console.log("✅ 'concurrently' uninstalled"); } catch (err) { console.error("❌ Failed to uninstall 'concurrently':", err); } }; // //@ts-nocheck // import readline from "readline"; // import fs from "fs"; // import path from "path"; // import { META_PATH } from "../utils/constants.js"; // export const uninstallTrackDevTime = () => { // const rl = readline.createInterface({ // input: process.stdin, // output: process.stdout, // }); // rl.question( // "âš ī¸ This will remove all track-dev-time related files. Continue? (y/n): ", // (answer) => { // rl.close(); // const confirm = answer.trim().toLowerCase(); // if (confirm !== "y" && confirm !== "yes") { // console.log("❌ Uninstall aborted."); // return; // } // console.log("\n🧹 Uninstalling track-dev-time..."); // removeTrackingFolder(); // cleanGitignore(); // cleanPackageJson(); // removeConcurrentlyIfInstalledByCli(); // console.log("\n✅ Uninstall complete! You can now run:"); // console.log(" npm uninstall track-dev-time"); // console.log( // "\nâ„šī¸ If you no longer use 'concurrently' in your project, you can remove it:" // ); // console.log(" npm uninstall concurrently\n"); // } // ); // }; // const removeTrackingFolder = () => { // const trackingFolderPath = path.resolve(".track-dev-time"); // if (fs.existsSync(trackingFolderPath)) { // fs.rmSync(trackingFolderPath, { recursive: true, force: true }); // console.log("âœ”ī¸ Removed .track-dev-time folder"); // } // }; // const cleanGitignore = () => { // const gitignorePath = path.resolve(".gitignore"); // if (fs.existsSync(gitignorePath)) { // const content = fs.readFileSync(gitignorePath, "utf-8"); // const updated = content // .split("\n") // .filter((line) => !line.includes(".track-dev-time/")) // .join("\n"); // fs.writeFileSync(gitignorePath, updated); // console.log("âœ”ī¸ Cleaned .gitignore"); // } // }; // const cleanPackageJson = () => { // const pkgJsonPath = path.resolve("package.json"); // if (fs.existsSync(pkgJsonPath)) { // const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8")); // if (pkg.trackDevTimeBackupDevScript) { // pkg.scripts.dev = pkg.trackDevTimeBackupDevScript; // delete pkg.trackDevTimeBackupDevScript; // fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2), "utf-8"); // console.log("✅ 'dev' script restored to original"); // } else { // console.log("â„šī¸ No backup found, nothing to restore"); // } // } // }; // const removeConcurrentlyIfInstalledByCli = () => { // if (!fs.existsSync(META_PATH)) return; // const meta = JSON.parse(fs.readFileSync(META_PATH, "utf-8")); // if (!meta.concurrentlyInstalledByCli) return; // const pkgManager = detectPackageManager(); // const uninstallCmd = { // npm: "npm uninstall concurrently", // yarn: "yarn remove concurrently", // pnpm: "pnpm remove concurrently", // }[pkgManager]; // console.log(`\n🔧 Removing 'concurrently' using ${pkgManager}...`); // try { // execSync(uninstallCmd, { stdio: "inherit" }); // console.log("✅ 'concurrently' uninstalled"); // } catch (err) { // console.error("❌ Failed to uninstall 'concurrently':", err); // } // };