rmshii 1.0.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/index.js +118 -0
- package/package.json +25 -0
package/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { program } = require('commander');
|
|
6
|
+
const strip = require('strip-comments');
|
|
7
|
+
const emojiRegex = require('emoji-regex');
|
|
8
|
+
const packageJson = require('./package.json');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
program
|
|
12
|
+
.name('rmshii')
|
|
13
|
+
.description('A CLI tool to clean AI-generated code by removing comments and emojis.')
|
|
14
|
+
.version(packageJson.version)
|
|
15
|
+
.argument('[target]', 'Target directory or file to clean (defaults to current directory)')
|
|
16
|
+
.option('-c, --comments', 'Remove code comments (single and multi-line)')
|
|
17
|
+
.option('-e, --emoji', 'Remove all emojis')
|
|
18
|
+
.option('-a, --all', 'Remove both comments and emojis')
|
|
19
|
+
.addHelpText('after', `
|
|
20
|
+
|
|
21
|
+
Example usage:
|
|
22
|
+
$ npx rmshii -c # Clean comments in the current folder
|
|
23
|
+
$ npx rmshii -e src/ # Clean emojis only in the 'src' folder
|
|
24
|
+
$ npx rmshii -a app.js # Clean everything in 'app.js' specifically
|
|
25
|
+
`)
|
|
26
|
+
.showHelpAfterError()
|
|
27
|
+
.parse(process.argv);
|
|
28
|
+
|
|
29
|
+
const options = program.opts();
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const removeComments = options.all || options.comments;
|
|
33
|
+
const removeEmojis = options.all || options.emoji;
|
|
34
|
+
|
|
35
|
+
if (!removeComments && !removeEmojis) {
|
|
36
|
+
console.log('Please specify what to remove: -c (comments), -e (emojis), or -a (all)');
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
const EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx', '.py', '.html', '.css', '.json'];
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
function processFile(filePath) {
|
|
45
|
+
let content = fs.readFileSync(filePath, 'utf8');
|
|
46
|
+
let changed = false;
|
|
47
|
+
|
|
48
|
+
if (removeComments) {
|
|
49
|
+
const strippedContent = strip(content);
|
|
50
|
+
if (content !== strippedContent) {
|
|
51
|
+
content = strippedContent;
|
|
52
|
+
changed = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (removeEmojis) {
|
|
57
|
+
const regex = emojiRegex();
|
|
58
|
+
const noEmojiContent = content.replace(regex, '');
|
|
59
|
+
if (content !== noEmojiContent) {
|
|
60
|
+
content = noEmojiContent;
|
|
61
|
+
changed = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (changed) {
|
|
66
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
67
|
+
console.log(`Cleaned: ${filePath}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
function walkDir(dir) {
|
|
73
|
+
const files = fs.readdirSync(dir);
|
|
74
|
+
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
const fullPath = path.join(dir, file);
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
if (file === 'node_modules' || file.startsWith('.')) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
84
|
+
walkDir(fullPath);
|
|
85
|
+
} else {
|
|
86
|
+
if (EXTENSIONS.includes(path.extname(fullPath))) {
|
|
87
|
+
processFile(fullPath);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
const targetArg = program.args[0] || '.';
|
|
95
|
+
const targetPath = path.resolve(process.cwd(), targetArg);
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if (!fs.existsSync(targetPath)) {
|
|
99
|
+
console.error(` Error: The path "${targetArg}" does not exist.`);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const stats = fs.statSync(targetPath);
|
|
104
|
+
|
|
105
|
+
if (stats.isDirectory()) {
|
|
106
|
+
console.log(` Scanning directory: ${targetPath}...`);
|
|
107
|
+
walkDir(targetPath);
|
|
108
|
+
} else if (stats.isFile()) {
|
|
109
|
+
console.log(` Scanning file: ${targetPath}...`);
|
|
110
|
+
|
|
111
|
+
if (EXTENSIONS.includes(path.extname(targetPath))) {
|
|
112
|
+
processFile(targetPath);
|
|
113
|
+
} else {
|
|
114
|
+
console.log(` Skipped: "${targetArg}" is not a supported file type.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
console.log(' Cleanup complete!');
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rmshii",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Remove comments and emojis from your code.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"rmshii": "index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"cli",
|
|
14
|
+
"clean",
|
|
15
|
+
"comments",
|
|
16
|
+
"emoji"
|
|
17
|
+
],
|
|
18
|
+
"author": "Gatling",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"commander": "^14.0.3",
|
|
22
|
+
"emoji-regex": "^10.6.0",
|
|
23
|
+
"strip-comments": "^2.0.1"
|
|
24
|
+
}
|
|
25
|
+
}
|