commentme 1.0.6 โ†’ 1.0.8

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
@@ -1,6 +1,14 @@
1
- # commentme
1
+ # CommentMe ๐Ÿš€
2
2
 
3
- An Open Source CLI tool connected with its own website to manage and store your cluttered-code comments and give the codebase a clean look. Extract comments from your code files, store them in a database, visit commentme platform for UI-friendly seek and restore your comments line-wise later.
3
+ **Declutter your codebase without losing context.**
4
+
5
+ CommentMe is an AI-powered CLI toolkit designed for developers who value clean, readable code. It allows you to "skim" comments out of your source files into a secure vault, keeping your core logic pristine while maintaining a searchable, UI-friendly history on the web.
6
+
7
+ ### Key Capabilities:
8
+ - ๐Ÿงผ **Clean Code, Zero Loss**: Redact comments from files while keeping references for instant restoration.
9
+ - ๐Ÿค– **AI Documentation**: Generate JSDocs and per-function comments automatically with LLMs.
10
+ - ๐Ÿง  **Smart Explainer**: Get instant markdown-formatted architecture explanations for any code file.
11
+ - ๐ŸŒ **Cloud Integration**: Manage and edit your extracted comments through a streamlined web interface.
4
12
 
5
13
  ## Installation
6
14
  ```bash
package/bin/commentme.js CHANGED
@@ -9,6 +9,7 @@ import { deleteComment } from "../deletecoms.js";
9
9
  import { removeCommentsFromFile as skim } from "../skimcoms.js";
10
10
  import { unskimComments as unskim } from "../unskimcoms.js";
11
11
  import { generateCommentsPerFunc, generateCommentsPerClass, generateCommentsPerLine, generateExplanation } from "../generate.js";
12
+ import { sanitizeFile } from "../sanitize.js";
12
13
  // import { connectDB, disconnectDB } from "../config/db.js";
13
14
  import { ensureAuth } from "../auth/authGuard.js";
14
15
  import { logout } from "../auth/logout.js";
@@ -53,6 +54,7 @@ Commands:
53
54
  commentme --unskim <file> Restore comments to a file
54
55
  commentme --generate <file> Generate AI comments and docs for a file
55
56
  commentme --explain <file> Generate a full markdown explanation of a code file
57
+ commentme --sanitize <file> Sanitize file for production (removes noisy comments)
56
58
  commentme --set-key Set your own OpenRouter API key (stored securely)
57
59
  commentme --clear-key Remove your saved API key
58
60
  commentme --logout Log out from your session
@@ -153,6 +155,11 @@ Select generation type:
153
155
  await generateExplanation(args[1]);
154
156
  break;
155
157
 
158
+ case "--sanitize":
159
+ if (!args[1]) throw new Error("Usage: commentme --sanitize <file>");
160
+ await sanitizeFile(args[1]);
161
+ break;
162
+
156
163
  case "--set-key": {
157
164
  console.log("Paste your OpenRouter API key (input is hidden):");
158
165
  const key = await promptPassword("๐Ÿ”‘ API Key: ");
@@ -187,6 +194,7 @@ Commands:
187
194
  commentme --unskim <file>
188
195
  commentme --generate <file>
189
196
  commentme --explain <file>
197
+ commentme --sanitize <file>
190
198
  commentme --set-key
191
199
  commentme --clear-key
192
200
  commentme --logout
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commentme",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "A CLI tool to manage, redact and unredact your comments keeping the codebase clutterfree.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This is a JSDoc block.
3
+ * It should be PRESERVED.
4
+ * @param {string} msg
5
+ */
6
+ function testDoc(msg) {
7
+
8
+
9
+ console.log("This console.log should be PRESERVED.");
10
+
11
+
12
+ const x = 10;
13
+
14
+ /**
15
+ * Another JSDoc.
16
+ * Should be PRESERVED.
17
+ */
18
+ return msg + x;
19
+ }
20
+
21
+ testDoc("Hello");
package/sanitize.js ADDED
@@ -0,0 +1,62 @@
1
+ import * as acorn from "acorn";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import { getCurrentUserId } from "./utils/currentUser.js";
5
+
6
+ /**
7
+ * Sanitizes a file for production by removing:
8
+ * 1. Single-line comments (// ...)
9
+ * 2. Block comments (/* ... * /) EXCEPT JSDocs (/** ... * /)
10
+ *
11
+ * Note: console.log statements are preserved per user request.
12
+ */
13
+ export async function sanitizeFile(filePath) {
14
+ if (!fs.existsSync(filePath)) {
15
+ throw new Error(`File not found: ${filePath}`);
16
+ }
17
+
18
+ // Check authentication
19
+ try {
20
+ getCurrentUserId();
21
+ } catch (e) {
22
+ console.error(e.message);
23
+ return;
24
+ }
25
+
26
+ const code = fs.readFileSync(filePath, "utf8");
27
+ const comments = [];
28
+
29
+ try {
30
+ acorn.parse(code, {
31
+ ecmaVersion: 2020,
32
+ sourceType: "module",
33
+ locations: true,
34
+ onComment: (isBlock, text, start, end) => {
35
+ const isJSDoc = isBlock && text.startsWith("*");
36
+
37
+ // If it's a single-line comment OR a non-JSDoc block comment, mark for removal
38
+ if (!isBlock || !isJSDoc) {
39
+ comments.push({ start, end });
40
+ }
41
+ }
42
+ });
43
+ } catch (e) {
44
+ console.error(`โŒ Error parsing ${filePath}: ${e.message}`);
45
+ console.log("โš ๏ธ Falling back to manual sanitization might be risky. Skipping this file.");
46
+ return;
47
+ }
48
+
49
+ // Sort comments in descending order to avoid offset issues while slicing
50
+ comments.sort((a, b) => b.start - a.start);
51
+
52
+ let result = code;
53
+ for (const comment of comments) {
54
+ result = result.slice(0, comment.start) + result.slice(comment.end);
55
+ }
56
+
57
+ // Optional: Clean up empty lines that only contained comments
58
+ // result = result.replace(/^\s*[\r\n]/gm, "");
59
+
60
+ fs.writeFileSync(filePath, result, "utf8");
61
+ console.log(`โœ… ${filePath} sanitized (comments removed, documentation preserved)`);
62
+ }