uncomment-cli 2.2.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 +101 -0
- package/bin/uncomment +0 -0
- package/index.js +37 -0
- package/install.js +142 -0
- package/package.json +44 -0
package/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# uncomment-cli
|
2
|
+
|
3
|
+
[](https://badge.fury.io/js/uncomment-cli)
|
4
|
+
[](https://github.com/Goldziher/uncomment/blob/main/LICENSE)
|
5
|
+
|
6
|
+
A blazing fast Rust-based command-line tool that removes comments from your source code. Perfect for cleaning up AI-generated code that comes with excessive explanations.
|
7
|
+
|
8
|
+
## Why Use This?
|
9
|
+
|
10
|
+
- 🚀 **Lightning Fast** - Built in Rust for maximum performance
|
11
|
+
- 🎯 **100% Accurate** - Never accidentally removes code that looks like comments
|
12
|
+
- 🛡️ **Safe by Default** - Preview changes before applying them
|
13
|
+
- 🌍 **Multi-language** - Supports 12+ programming languages
|
14
|
+
- 🔧 **Zero Dependencies** - Downloads a self-contained binary
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
```bash
|
19
|
+
npm install -g uncomment-cli
|
20
|
+
```
|
21
|
+
|
22
|
+
The installer will automatically download the appropriate pre-compiled Rust binary for your platform (Windows, macOS, or Linux).
|
23
|
+
|
24
|
+
## Quick Start
|
25
|
+
|
26
|
+
Remove comments from a single file:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
uncomment main.py
|
30
|
+
```
|
31
|
+
|
32
|
+
Preview changes without modifying files:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
uncomment --dry-run src/
|
36
|
+
```
|
37
|
+
|
38
|
+
Process all Python files in a directory:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
uncomment "src/**/*.py"
|
42
|
+
```
|
43
|
+
|
44
|
+
## Key Features
|
45
|
+
|
46
|
+
### Smart Comment Detection
|
47
|
+
|
48
|
+
Unlike simple regex-based tools, `uncomment` understands your code's structure:
|
49
|
+
|
50
|
+
```python
|
51
|
+
# This comment will be removed
|
52
|
+
code = "# But this won't - it's in a string!"
|
53
|
+
```
|
54
|
+
|
55
|
+
### Preserves Important Comments
|
56
|
+
|
57
|
+
Keeps what matters:
|
58
|
+
|
59
|
+
- `TODO` and `FIXME` comments (configurable)
|
60
|
+
- License headers and copyright notices
|
61
|
+
- Linting directives (`eslint-disable`, `@ts-ignore`, etc.)
|
62
|
+
- Documentation strings and JSDoc comments (configurable)
|
63
|
+
|
64
|
+
### Supported Languages
|
65
|
+
|
66
|
+
Python, JavaScript, TypeScript, Rust, Go, Java, C/C++, Ruby, YAML, Terraform/HCL, Makefile, and more!
|
67
|
+
|
68
|
+
## Common Use Cases
|
69
|
+
|
70
|
+
**Clean up AI-generated code:**
|
71
|
+
|
72
|
+
```bash
|
73
|
+
uncomment generated_code.js
|
74
|
+
```
|
75
|
+
|
76
|
+
**Remove all comments including TODOs:**
|
77
|
+
|
78
|
+
```bash
|
79
|
+
uncomment --remove-todo --remove-fixme src/
|
80
|
+
```
|
81
|
+
|
82
|
+
**Remove documentation comments:**
|
83
|
+
|
84
|
+
```bash
|
85
|
+
uncomment --remove-doc api.ts
|
86
|
+
```
|
87
|
+
|
88
|
+
**Use multiple threads for large codebases:**
|
89
|
+
|
90
|
+
```bash
|
91
|
+
uncomment --threads 8 entire_project/
|
92
|
+
```
|
93
|
+
|
94
|
+
## Documentation
|
95
|
+
|
96
|
+
For detailed documentation, advanced options, and examples, visit:
|
97
|
+
[https://github.com/Goldziher/uncomment](https://github.com/Goldziher/uncomment)
|
98
|
+
|
99
|
+
## License
|
100
|
+
|
101
|
+
MIT - see [LICENSE](https://github.com/Goldziher/uncomment/blob/main/LICENSE) for details.
|
package/bin/uncomment
ADDED
Binary file
|
package/index.js
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
const { Binary } = require("binary-install");
|
2
|
+
const os = require("os");
|
3
|
+
const { version } = require("./package.json");
|
4
|
+
|
5
|
+
function getPlatform() {
|
6
|
+
const type = os.type();
|
7
|
+
const arch = os.arch();
|
8
|
+
|
9
|
+
if (type === "Windows_NT") {
|
10
|
+
return arch === "x64" ? "x86_64-pc-windows-msvc" : "i686-pc-windows-msvc";
|
11
|
+
}
|
12
|
+
|
13
|
+
if (type === "Linux") {
|
14
|
+
if (arch === "x64") return "x86_64-unknown-linux-gnu";
|
15
|
+
if (arch === "arm64") return "aarch64-unknown-linux-gnu";
|
16
|
+
return "x86_64-unknown-linux-gnu"; // fallback
|
17
|
+
}
|
18
|
+
|
19
|
+
if (type === "Darwin") {
|
20
|
+
if (arch === "x64") return "x86_64-apple-darwin";
|
21
|
+
if (arch === "arm64") return "aarch64-apple-darwin";
|
22
|
+
return "x86_64-apple-darwin"; // fallback
|
23
|
+
}
|
24
|
+
|
25
|
+
throw new Error(`Unsupported platform: ${type} ${arch}`);
|
26
|
+
}
|
27
|
+
|
28
|
+
function getBinaryUrl() {
|
29
|
+
const platform = getPlatform();
|
30
|
+
const ext = os.type() === "Windows_NT" ? ".exe" : "";
|
31
|
+
const baseUrl = `https://github.com/Goldziher/uncomment/releases/download/v${version}`;
|
32
|
+
return `${baseUrl}/uncomment-${platform}${ext}`;
|
33
|
+
}
|
34
|
+
|
35
|
+
const binary = new Binary("uncomment", getBinaryUrl());
|
36
|
+
|
37
|
+
module.exports = binary;
|
package/install.js
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
const https = require("https");
|
2
|
+
const http = require("http");
|
3
|
+
const fs = require("fs");
|
4
|
+
const path = require("path");
|
5
|
+
const os = require("os");
|
6
|
+
const tar = require("tar");
|
7
|
+
const { version } = require("./package.json");
|
8
|
+
|
9
|
+
function getPlatform() {
|
10
|
+
const type = os.type();
|
11
|
+
const arch = os.arch();
|
12
|
+
|
13
|
+
if (type === "Windows_NT") {
|
14
|
+
return arch === "x64" ? "x86_64-pc-windows-msvc" : "i686-pc-windows-msvc";
|
15
|
+
}
|
16
|
+
|
17
|
+
if (type === "Linux") {
|
18
|
+
if (arch === "x64") return "x86_64-unknown-linux-gnu";
|
19
|
+
if (arch === "arm64") return "aarch64-unknown-linux-gnu";
|
20
|
+
return "x86_64-unknown-linux-gnu"; // fallback
|
21
|
+
}
|
22
|
+
|
23
|
+
if (type === "Darwin") {
|
24
|
+
if (arch === "x64") return "x86_64-apple-darwin";
|
25
|
+
if (arch === "arm64") return "aarch64-apple-darwin";
|
26
|
+
return "x86_64-apple-darwin"; // fallback
|
27
|
+
}
|
28
|
+
|
29
|
+
throw new Error(`Unsupported platform: ${type} ${arch}`);
|
30
|
+
}
|
31
|
+
|
32
|
+
function getBinaryUrl() {
|
33
|
+
const platform = getPlatform();
|
34
|
+
const baseUrl = `https://github.com/Goldziher/uncomment/releases/download/v${version}`;
|
35
|
+
return `${baseUrl}/uncomment-${platform}-v${version}.tar.gz`;
|
36
|
+
}
|
37
|
+
|
38
|
+
function downloadWithRedirects(url, dest, maxRedirects = 5) {
|
39
|
+
return new Promise((resolve, reject) => {
|
40
|
+
if (maxRedirects <= 0) {
|
41
|
+
return reject(new Error("Too many redirects"));
|
42
|
+
}
|
43
|
+
|
44
|
+
const urlObj = new URL(url);
|
45
|
+
const client = urlObj.protocol === "https:" ? https : http;
|
46
|
+
|
47
|
+
const req = client.get(
|
48
|
+
url,
|
49
|
+
{
|
50
|
+
headers: {
|
51
|
+
"User-Agent": "uncomment-npm-wrapper",
|
52
|
+
},
|
53
|
+
},
|
54
|
+
(res) => {
|
55
|
+
// Handle redirects
|
56
|
+
if (
|
57
|
+
res.statusCode >= 300 &&
|
58
|
+
res.statusCode < 400 &&
|
59
|
+
res.headers.location
|
60
|
+
) {
|
61
|
+
return downloadWithRedirects(
|
62
|
+
res.headers.location,
|
63
|
+
dest,
|
64
|
+
maxRedirects - 1,
|
65
|
+
)
|
66
|
+
.then(resolve)
|
67
|
+
.catch(reject);
|
68
|
+
}
|
69
|
+
|
70
|
+
if (res.statusCode !== 200) {
|
71
|
+
return reject(
|
72
|
+
new Error(`HTTP ${res.statusCode}: ${res.statusMessage}`),
|
73
|
+
);
|
74
|
+
}
|
75
|
+
|
76
|
+
const file = fs.createWriteStream(dest);
|
77
|
+
res.pipe(file);
|
78
|
+
|
79
|
+
file.on("finish", () => {
|
80
|
+
file.close();
|
81
|
+
resolve();
|
82
|
+
});
|
83
|
+
|
84
|
+
file.on("error", (err) => {
|
85
|
+
fs.unlink(dest, () => {}); // Delete partial file
|
86
|
+
reject(err);
|
87
|
+
});
|
88
|
+
},
|
89
|
+
);
|
90
|
+
|
91
|
+
req.on("error", reject);
|
92
|
+
req.setTimeout(30000, () => {
|
93
|
+
req.destroy();
|
94
|
+
reject(new Error("Download timeout"));
|
95
|
+
});
|
96
|
+
});
|
97
|
+
}
|
98
|
+
|
99
|
+
async function installBinary() {
|
100
|
+
try {
|
101
|
+
const url = getBinaryUrl();
|
102
|
+
const binDir = path.join(__dirname, "bin");
|
103
|
+
const tarPath = path.join(binDir, "uncomment.tar.gz");
|
104
|
+
const binaryName =
|
105
|
+
os.type() === "Windows_NT" ? "uncomment.exe" : "uncomment";
|
106
|
+
|
107
|
+
// Ensure bin directory exists
|
108
|
+
if (!fs.existsSync(binDir)) {
|
109
|
+
fs.mkdirSync(binDir, { recursive: true });
|
110
|
+
}
|
111
|
+
|
112
|
+
console.log(`Downloading uncomment binary from ${url}...`);
|
113
|
+
|
114
|
+
// Download the tar.gz file
|
115
|
+
await downloadWithRedirects(url, tarPath);
|
116
|
+
|
117
|
+
console.log("Extracting binary...");
|
118
|
+
|
119
|
+
// Extract the binary from tar.gz
|
120
|
+
await tar.extract({
|
121
|
+
file: tarPath,
|
122
|
+
cwd: binDir,
|
123
|
+
filter: (path) => path.endsWith(binaryName),
|
124
|
+
});
|
125
|
+
|
126
|
+
// Clean up tar file
|
127
|
+
fs.unlinkSync(tarPath);
|
128
|
+
|
129
|
+
// Make binary executable on Unix systems
|
130
|
+
if (os.type() !== "Windows_NT") {
|
131
|
+
const binaryPath = path.join(binDir, binaryName);
|
132
|
+
fs.chmodSync(binaryPath, 0o755);
|
133
|
+
}
|
134
|
+
|
135
|
+
console.log("uncomment binary installed successfully!");
|
136
|
+
} catch (error) {
|
137
|
+
console.error("Error installing uncomment binary:", error.message);
|
138
|
+
process.exit(1);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
installBinary();
|
package/package.json
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
{
|
2
|
+
"name": "uncomment-cli",
|
3
|
+
"version": "2.2.0",
|
4
|
+
"description": "A fast Rust-based CLI tool for removing comments from source code",
|
5
|
+
"main": "index.js",
|
6
|
+
"bin": {
|
7
|
+
"uncomment": "bin/uncomment"
|
8
|
+
},
|
9
|
+
"scripts": {
|
10
|
+
"postinstall": "node install.js"
|
11
|
+
},
|
12
|
+
"keywords": [
|
13
|
+
"comments",
|
14
|
+
"cli",
|
15
|
+
"rust",
|
16
|
+
"remove-comments",
|
17
|
+
"code-cleanup",
|
18
|
+
"ai-generated-code",
|
19
|
+
"formatting",
|
20
|
+
"uncomment",
|
21
|
+
"clean-code"
|
22
|
+
],
|
23
|
+
"author": "Na'aman Hirschfeld",
|
24
|
+
"license": "MIT",
|
25
|
+
"repository": {
|
26
|
+
"type": "git",
|
27
|
+
"url": "https://github.com/Goldziher/uncomment.git"
|
28
|
+
},
|
29
|
+
"homepage": "https://github.com/Goldziher/uncomment#readme",
|
30
|
+
"bugs": {
|
31
|
+
"url": "https://github.com/Goldziher/uncomment/issues"
|
32
|
+
},
|
33
|
+
"dependencies": {
|
34
|
+
"tar": "^6.0.0"
|
35
|
+
},
|
36
|
+
"files": [
|
37
|
+
"index.js",
|
38
|
+
"install.js",
|
39
|
+
"bin/"
|
40
|
+
],
|
41
|
+
"engines": {
|
42
|
+
"node": ">=14"
|
43
|
+
}
|
44
|
+
}
|