@adithya-naik/cmd-tracker 1.0.0 β†’ 1.0.3

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.
@@ -8,14 +8,14 @@
8
8
  * β†’ Any unexpected file system errors
9
9
  */
10
10
 
11
- const fs = require("fs");
12
- const path = require("path");
13
- const { initStorage } = require("../utils/storage");
14
- const { isInitialized } = require("../utils/validator");
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+ const { initStorage } = require('../utils/storage');
14
+ const { isInitialized } = require('../utils/validator');
15
15
 
16
16
  function initCommand() {
17
17
 
18
- console.log("πŸš€ Initializing cmd-tracker in your project...\n");
18
+ console.log('πŸš€ Initializing cmd-tracker in your project...\n');
19
19
 
20
20
  try {
21
21
 
@@ -25,9 +25,9 @@ function initCommand() {
25
25
  * but still continue in case files are corrupted
26
26
  */
27
27
  if (isInitialized()) {
28
- console.log("⚠️ cmd-tracker is already initialized in this project!");
29
- console.log("πŸ’‘ Your existing commands are safe");
30
- console.log("πŸ’‘ Running init again will not delete your saved commands\n");
28
+ console.log('⚠️ cmd-tracker is already initialized in this project!');
29
+ console.log('πŸ’‘ Your existing commands are safe');
30
+ console.log('πŸ’‘ Running init again will not delete your saved commands\n');
31
31
  }
32
32
 
33
33
  /*
@@ -41,15 +41,15 @@ function initCommand() {
41
41
  */
42
42
  updateGitignore();
43
43
 
44
- console.log("\nβœ… cmd-tracker initialized successfully!");
45
- console.log("πŸ“ Created .tracker/commands.json in your project");
46
- console.log("\n🎯 You can now use:");
47
- console.log(" tracker list β†’ see all saved commands");
48
- console.log(" tracker stats β†’ see command statistics");
49
- console.log(" tracker search β†’ search your commands");
50
- console.log(" tracker export β†’ export your commands");
51
- console.log("\nπŸ’‘ Start using your terminal normally");
52
- console.log(" Commands will be saved automatically!\n");
44
+ console.log('\nβœ… cmd-tracker initialized successfully!');
45
+ console.log('πŸ“ Created .tracker/commands.json in your project');
46
+ console.log('\n🎯 You can now use:');
47
+ console.log(' tracker list β†’ see all saved commands');
48
+ console.log(' tracker stats β†’ see command statistics');
49
+ console.log(' tracker search β†’ search your commands');
50
+ console.log(' tracker export β†’ export your commands');
51
+ console.log('\nπŸ’‘ Start using your terminal normally');
52
+ console.log(' Commands will be saved automatically!\n');
53
53
 
54
54
  } catch (error) {
55
55
 
@@ -60,83 +60,83 @@ function initCommand() {
60
60
  * This happens when user doesn't have write access
61
61
  * to the current folder
62
62
  */
63
- if (error.code === "EACCES") {
64
- console.error("❌ Permission denied!");
65
- console.error("πŸ’‘ Try running with admin permissions");
66
- console.error("πŸ’‘ Or check folder write permissions\n");
63
+ if (error.code === 'EACCES') {
64
+ console.error('❌ Permission denied!');
65
+ console.error('πŸ’‘ Try running with admin permissions');
66
+ console.error('πŸ’‘ Or check folder write permissions\n');
67
67
  return;
68
68
  }
69
69
 
70
70
  /*
71
71
  * Handle no space left on disk
72
72
  */
73
- if (error.code === "ENOSPC") {
74
- console.error("❌ No space left on disk!");
75
- console.error("πŸ’‘ Free up some disk space and try again\n");
73
+ if (error.code === 'ENOSPC') {
74
+ console.error('❌ No space left on disk!');
75
+ console.error('πŸ’‘ Free up some disk space and try again\n');
76
76
  return;
77
77
  }
78
78
 
79
79
  /*
80
80
  * Any other unexpected error
81
81
  */
82
- console.error("❌ Failed to initialize cmd-tracker");
82
+ console.error('❌ Failed to initialize cmd-tracker');
83
83
  console.error(`Error: ${error.message}\n`);
84
84
  }
85
85
  }
86
86
 
87
87
  function updateGitignore() {
88
88
 
89
- const gitignorePath = path.join(process.cwd(), ".gitignore");
89
+ const gitignorePath = path.join(process.cwd(), '.gitignore');
90
90
  /*
91
91
  * Added tracker-export files to gitignore too
92
92
  * Users should not push their exported files to GitHub
93
93
  * These are personal revision files β€” local only
94
94
  */
95
- const trackerEntry = "\n# cmd-tracker personal data\n.tracker/\ntracker-export.json\ntracker-export.csv\n";
95
+ const trackerEntry = '\n# cmd-tracker personal data\n.tracker/\ntracker-export.json\ntracker-export.csv\n';
96
96
 
97
97
  try {
98
98
 
99
99
  if (fs.existsSync(gitignorePath)) {
100
- const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8");
100
+ const gitignoreContent = fs.readFileSync(gitignorePath, 'utf-8');
101
101
 
102
102
  /*
103
103
  * Check each entry separately
104
104
  * So we can add missing entries without touching existing ones
105
105
  */
106
- let entriesToAdd = "";
106
+ let entriesToAdd = '';
107
107
 
108
- if (!gitignoreContent.includes(".tracker/")) {
109
- entriesToAdd += ".tracker/\n";
108
+ if (!gitignoreContent.includes('.tracker/')) {
109
+ entriesToAdd += '.tracker/\n';
110
110
  }
111
111
 
112
- if (!gitignoreContent.includes("tracker-export.json")) {
113
- entriesToAdd += "tracker-export.json\n";
112
+ if (!gitignoreContent.includes('tracker-export.json')) {
113
+ entriesToAdd += 'tracker-export.json\n';
114
114
  }
115
115
 
116
- if (!gitignoreContent.includes("tracker-export.csv")) {
117
- entriesToAdd += "tracker-export.csv\n";
116
+ if (!gitignoreContent.includes('tracker-export.csv')) {
117
+ entriesToAdd += 'tracker-export.csv\n';
118
118
  }
119
119
 
120
120
  /*
121
121
  * Only write if there's something new to add
122
122
  */
123
- if (entriesToAdd === "") {
124
- console.log("βœ… .gitignore already up to date");
123
+ if (entriesToAdd === '') {
124
+ console.log('βœ… .gitignore already up to date');
125
125
  return;
126
126
  }
127
127
 
128
128
  fs.appendFileSync(
129
129
  gitignorePath,
130
- "\n# cmd-tracker personal data\n" + entriesToAdd
130
+ '\n# cmd-tracker personal data\n' + entriesToAdd
131
131
  );
132
- console.log("βœ… Updated .gitignore with cmd-tracker entries");
132
+ console.log('βœ… Updated .gitignore with cmd-tracker entries');
133
133
 
134
134
  fs.appendFileSync(gitignorePath, trackerEntry);
135
- console.log("βœ… Added .tracker/ to your .gitignore");
135
+ console.log('βœ… Added .tracker/ to your .gitignore');
136
136
 
137
137
  } else {
138
138
  fs.writeFileSync(gitignorePath, trackerEntry);
139
- console.log("βœ… Created .gitignore with .tracker/ entry");
139
+ console.log('βœ… Created .gitignore with .tracker/ entry');
140
140
  }
141
141
 
142
142
  } catch (error) {
@@ -145,8 +145,8 @@ function updateGitignore() {
145
145
  * .gitignore update failed β€” not critical
146
146
  * tracker still works, just warn the user
147
147
  */
148
- console.log("⚠️ Could not update .gitignore automatically");
149
- console.log("πŸ’‘ Manually add .tracker/ to your .gitignore\n");
148
+ console.log('⚠️ Could not update .gitignore automatically');
149
+ console.log('πŸ’‘ Manually add .tracker/ to your .gitignore\n');
150
150
  }
151
151
  }
152
152
 
@@ -5,13 +5,13 @@
5
5
  * Now with proper error handling using validator.js
6
6
  */
7
7
 
8
- const { readCommands } = require("../utils/storage");
8
+ const { readCommands } = require('../utils/storage');
9
9
  const {
10
10
  isInitialized,
11
11
  showInitError,
12
12
  isValidCategory,
13
13
  showCategoryError
14
- } = require("../utils/validator");
14
+ } = require('../utils/validator');
15
15
 
16
16
  function listCommand(category) {
17
17
 
@@ -46,8 +46,8 @@ function listCommand(category) {
46
46
  const data = readCommands();
47
47
  let totalCommands = 0;
48
48
 
49
- console.log("\nπŸ“Ÿ CMD-TRACKER β€” Your Command History\n");
50
- console.log("─".repeat(50));
49
+ console.log('\nπŸ“Ÿ CMD-TRACKER β€” Your Command History\n');
50
+ console.log('─'.repeat(50));
51
51
 
52
52
  for (const [cat, commands] of Object.entries(data)) {
53
53
  if (commands.length === 0) continue;
@@ -56,13 +56,13 @@ function listCommand(category) {
56
56
  }
57
57
 
58
58
  if (totalCommands === 0) {
59
- console.log("\nπŸ“­ No commands saved yet!");
60
- console.log("πŸ’‘ Use: tracker save \"your command\"");
61
- console.log("πŸ’‘ Or run commands normally if shell hook is set up\n");
59
+ console.log('\nπŸ“­ No commands saved yet!');
60
+ console.log('πŸ’‘ Use: tracker save "your command"');
61
+ console.log('πŸ’‘ Or run commands normally if shell hook is set up\n');
62
62
  return;
63
63
  }
64
64
 
65
- console.log("─".repeat(50));
65
+ console.log('─'.repeat(50));
66
66
  console.log(`\nβœ… Total: ${totalCommands} commands saved\n`);
67
67
 
68
68
  } catch (error) {
@@ -70,38 +70,48 @@ function listCommand(category) {
70
70
  * Something went wrong reading the file
71
71
  * Show clear error instead of crashing
72
72
  */
73
- console.log("\n❌ Error reading commands");
74
- console.log(`πŸ’‘ Try running tracker init again\n`);
73
+ console.log('\n❌ Error reading commands');
74
+ console.log('πŸ’‘ Try running tracker init again\n');
75
75
  }
76
76
  }
77
77
 
78
78
  function displayCategory(categoryName, commands) {
79
79
 
80
80
  const icons = {
81
- git: "πŸ”€",
82
- npm: "πŸ“¦",
83
- docker: "🐳",
84
- linux: "🐧",
85
- node: "🟒",
86
- angular: "πŸ”΄",
87
- python: "🐍",
88
- others: "πŸ“Œ"
81
+ git: 'πŸ”€',
82
+ npm: 'πŸ“¦',
83
+ docker: '🐳',
84
+ linux: '🐧',
85
+ node: '🟒',
86
+ angular: 'πŸ”΄',
87
+ python: '🐍',
88
+ go: 'πŸ”·',
89
+ java: 'β˜•',
90
+ rust: 'πŸ¦€',
91
+ dotnet: 'πŸ”·',
92
+ kubernetes: '☸️',
93
+ database: 'πŸ—„οΈ',
94
+ cloud: '☁️',
95
+ packagemanagers: 'πŸ“₯',
96
+ testing: 'πŸ§ͺ',
97
+ ai: 'πŸ€–',
98
+ others: 'πŸ“Œ'
89
99
  };
90
100
 
91
- const icon = icons[categoryName] || "πŸ“Œ";
101
+ const icon = icons[categoryName] || 'πŸ“Œ';
92
102
 
93
103
  console.log(`\n${icon} ${categoryName.toUpperCase()} (${commands.length})`);
94
- console.log("─".repeat(30));
104
+ console.log('─'.repeat(30));
95
105
 
96
106
  if (commands.length === 0) {
97
- console.log(" πŸ“­ No commands saved yet");
107
+ console.log(' πŸ“­ No commands saved yet');
98
108
  return;
99
109
  }
100
110
 
101
111
  commands.forEach((item, index) => {
102
112
  const date = new Date(item.time).toLocaleDateString();
103
- console.log(` ${String(index + 1).padStart(2, " ")}. ${item.command} (${date})`);
113
+ console.log(` ${String(index + 1).padStart(2, ' ')}. ${item.command} (${date})`);
104
114
  });
105
115
  }
106
116
 
107
- module.exports = { listCommand };
117
+ module.exports = { listCommand };
@@ -13,8 +13,8 @@
13
13
  * We NEVER want it to interrupt user's workflow
14
14
  */
15
15
 
16
- const { saveCommand } = require("../utils/storage");
17
- const { isInitialized } = require("../utils/validator");
16
+ const { saveCommand } = require('../utils/storage');
17
+ const { isInitialized } = require('../utils/validator');
18
18
 
19
19
  function saveCommandAction(command) {
20
20
 
@@ -10,12 +10,12 @@
10
10
  * Returns matching commands with their category
11
11
  */
12
12
 
13
- const { readCommands } = require("../utils/storage");
13
+ const { readCommands } = require('../utils/storage');
14
14
  const {
15
15
  isInitialized,
16
16
  showInitError,
17
17
  isValidQuery
18
- } = require("../utils/validator");
18
+ } = require('../utils/validator');
19
19
 
20
20
  /*
21
21
  * searchCommand() β€” main function
@@ -37,8 +37,8 @@ function searchCommand(query) {
37
37
  * Validate query
38
38
  */
39
39
  if (!isValidQuery(query)) {
40
- console.log("\n❌ Please provide a search query");
41
- console.log("πŸ’‘ Usage: tracker search \"git\"\n");
40
+ console.log('\n❌ Please provide a search query');
41
+ console.log('πŸ’‘ Usage: tracker search "git"\n');
42
42
  return;
43
43
  }
44
44
 
@@ -65,32 +65,32 @@ function searchCommand(query) {
65
65
  }
66
66
 
67
67
  console.log(`\nπŸ” Search results for: "${query}"`);
68
- console.log("─".repeat(50));
68
+ console.log('─'.repeat(50));
69
69
 
70
- results.forEach((item, index) => {
70
+ results.forEach((item, index) => {
71
71
 
72
- const date = new Date(item.time).toLocaleDateString();
72
+ const date = new Date(item.time).toLocaleDateString();
73
73
 
74
- /*
74
+ /*
75
75
  * Highlight the search term in results
76
76
  * Replace matched part with uppercase version
77
77
  * So user can easily spot what matched
78
78
  */
79
- const highlighted = item.command.replace(
80
- new RegExp(searchTerm, "gi"),
81
- (match) => `[${match.toUpperCase()}]`
82
- );
79
+ const highlighted = item.command.replace(
80
+ new RegExp(searchTerm, 'gi'),
81
+ (match) => `[${match.toUpperCase()}]`
82
+ );
83
83
 
84
- console.log(`\n ${index + 1}. ${highlighted}`);
85
- console.log(` πŸ“ Category: ${item.category} πŸ“… ${date}`);
86
- });
84
+ console.log(`\n ${index + 1}. ${highlighted}`);
85
+ console.log(` πŸ“ Category: ${item.category} πŸ“… ${date}`);
86
+ });
87
87
 
88
- console.log("\n" + "─".repeat(50));
88
+ console.log('\n' + '─'.repeat(50));
89
89
  console.log(`βœ… Found ${results.length} matching command(s)\n`);
90
90
 
91
91
  } catch (error) {
92
- console.log("\n❌ Error searching commands");
93
- console.log("πŸ’‘ Try running tracker init again\n");
92
+ console.log('\n❌ Error searching commands');
93
+ console.log('πŸ’‘ Try running tracker init again\n');
94
94
  }
95
95
  }
96
96
 
@@ -10,8 +10,8 @@
10
10
  * β†’ Most used category
11
11
  */
12
12
 
13
- const { readCommands } = require("../utils/storage");
14
- const { isInitialized, showInitError } = require("../utils/validator");
13
+ const { readCommands } = require('../utils/storage');
14
+ const { isInitialized, showInitError } = require('../utils/validator');
15
15
 
16
16
  function statsCommand() {
17
17
 
@@ -23,7 +23,7 @@ function statsCommand() {
23
23
  try {
24
24
  const data = readCommands();
25
25
 
26
- /*
26
+ /*
27
27
  * Calculate total commands across all categories
28
28
  * Object.values() β†’ gets all arrays from data object
29
29
  * .reduce() β†’ adds up all lengths
@@ -33,87 +33,97 @@ function statsCommand() {
33
33
  * β†’ values β†’ [[1,2], [1]]
34
34
  * β†’ reduce β†’ 2 + 1 = 3
35
35
  */
36
- const total = Object.values(data).reduce(
37
- (sum, commands) => sum + commands.length, 0
38
- );
36
+ const total = Object.values(data).reduce(
37
+ (sum, commands) => sum + commands.length, 0
38
+ );
39
39
 
40
40
  if (total === 0) {
41
- console.log("\nπŸ“­ No commands saved yet!");
42
- console.log("πŸ’‘ Use: tracker save \"your command\"\n");
41
+ console.log('\nπŸ“­ No commands saved yet!');
42
+ console.log('πŸ’‘ Use: tracker save "your command"\n');
43
43
  return;
44
44
  }
45
45
 
46
- console.log("\nπŸ“Š CMD-TRACKER β€” Statistics\n");
47
- console.log("─".repeat(50));
46
+ console.log('\nπŸ“Š CMD-TRACKER β€” Statistics\n');
47
+ console.log('─'.repeat(50));
48
48
 
49
- /*
49
+ /*
50
50
  * Category icons β€” same as list.js for consistency
51
51
  */
52
- const icons = {
53
- git: "πŸ”€",
54
- npm: "πŸ“¦",
55
- docker: "🐳",
56
- linux: "🐧",
57
- node: "🟒",
58
- angular: "πŸ”΄",
59
- python: "🐍",
60
- others: "πŸ“Œ"
61
- };
62
-
63
- /*
52
+ const icons = {
53
+ git: 'πŸ”€',
54
+ npm: 'πŸ“¦',
55
+ docker: '🐳',
56
+ linux: '🐧',
57
+ node: '🟒',
58
+ angular: 'πŸ”΄',
59
+ python: '🐍',
60
+ go: 'πŸ”·',
61
+ java: 'β˜•',
62
+ rust: 'πŸ¦€',
63
+ dotnet: 'πŸ”·',
64
+ kubernetes: '☸️',
65
+ database: 'πŸ—„οΈ',
66
+ cloud: '☁️',
67
+ packageManagers: 'πŸ“₯',
68
+ testing: 'πŸ§ͺ',
69
+ ai: 'πŸ€–',
70
+ others: 'πŸ“Œ'
71
+ };
72
+
73
+ /*
64
74
  * Track which category has most commands
65
75
  */
66
- let topCategory = "";
67
- let topCount = 0;
76
+ let topCategory = '';
77
+ let topCount = 0;
68
78
 
69
- /*
79
+ /*
70
80
  * Loop through each category and show stats
71
81
  */
72
- for (const [category, commands] of Object.entries(data)) {
82
+ for (const [category, commands] of Object.entries(data)) {
73
83
 
74
- /*
84
+ /*
75
85
  * Skip empty categories
76
86
  */
77
- if (commands.length === 0) continue;
87
+ if (commands.length === 0) continue;
78
88
 
79
- /*
89
+ /*
80
90
  * Calculate percentage
81
91
  * Math.round() β†’ rounds to nearest whole number
82
92
  * 2.7 β†’ 3, 2.3 β†’ 2
83
93
  */
84
- const percentage = Math.round((commands.length / total) * 100);
94
+ const percentage = Math.round((commands.length / total) * 100);
85
95
 
86
- /*
96
+ /*
87
97
  * Build a simple visual bar
88
98
  * "β–ˆ".repeat(percentage/5) β†’ each block = 5%
89
99
  * So 50% β†’ 10 blocks, 100% β†’ 20 blocks
90
100
  */
91
- const bar = "β–ˆ".repeat(Math.round(percentage / 5));
101
+ const bar = 'β–ˆ'.repeat(Math.round(percentage / 5));
92
102
 
93
- const icon = icons[category] || "πŸ“Œ";
103
+ const icon = icons[category] || 'πŸ“Œ';
94
104
 
95
- console.log(
96
- `\n${icon} ${category.toUpperCase().padEnd(10)} ` +
105
+ console.log(
106
+ `\n${icon} ${category.toUpperCase().padEnd(10)} ` +
97
107
  `${String(commands.length).padStart(3)} commands ` +
98
108
  `${String(percentage).padStart(3)}% ${bar}`
99
- );
109
+ );
100
110
 
101
- /*
111
+ /*
102
112
  * Track top category
103
113
  */
104
- if (commands.length > topCount) {
105
- topCount = commands.length;
106
- topCategory = category;
114
+ if (commands.length > topCount) {
115
+ topCount = commands.length;
116
+ topCategory = category;
117
+ }
107
118
  }
108
- }
109
119
 
110
- console.log("\n" + "─".repeat(50));
120
+ console.log('\n' + '─'.repeat(50));
111
121
  console.log(`πŸ“¦ Total commands : ${total}`);
112
122
  console.log(`πŸ† Most used : ${topCategory} (${topCount} commands)\n`);
113
123
 
114
124
  } catch (error) {
115
- console.log("\n❌ Error reading statistics");
116
- console.log("πŸ’‘ Try running tracker init again\n");
125
+ console.log('\n❌ Error reading statistics');
126
+ console.log('πŸ’‘ Try running tracker init again\n');
117
127
  }
118
128
  }
119
129
 
package/src/index.js CHANGED
@@ -8,8 +8,8 @@
8
8
  * use them programmatically in their own code
9
9
  */
10
10
 
11
- const { saveCommand, readCommands, initStorage } = require("./utils/storage");
12
- const { categorize } = require("./utils/categorizer");
11
+ const { saveCommand, readCommands, initStorage } = require('./utils/storage');
12
+ const { categorize } = require('./utils/categorizer');
13
13
 
14
14
  module.exports = {
15
15
  saveCommand,