@nuitsukera/refine 1.0.1 → 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.
- package/README.md +370 -370
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,370 +1,370 @@
|
|
|
1
|
-
# refine
|
|
2
|
-
|
|
3
|
-
Remove comments from JavaScript, TypeScript, JSX, TSX, Vue, HTML, CSS/SCSS/LESS and more — with parallel processing, watch mode, `.refineignore` support and JSON reports.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
### Local (per-project)
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
# bun
|
|
13
|
-
bun add -D @nuitsukera/refine
|
|
14
|
-
|
|
15
|
-
# npm
|
|
16
|
-
npm install --save-dev @nuitsukera/refine
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
After installing, run the setup wizard once:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
# bun
|
|
23
|
-
bunx refine init
|
|
24
|
-
|
|
25
|
-
# npm
|
|
26
|
-
npx refine init
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
A `refine.json` is created in the project root (or merged into your existing `config.json` if you prefer). A post-install tip is shown automatically if no config is found.
|
|
30
|
-
|
|
31
|
-
### Global
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
# bun
|
|
35
|
-
bun install -g @nuitsukera/refine
|
|
36
|
-
|
|
37
|
-
# npm
|
|
38
|
-
npm install -g @nuitsukera/refine
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Once installed globally you can call `refine` from any directory. A default global config is automatically created on install:
|
|
42
|
-
|
|
43
|
-
- **Linux / Mac:** `~/.config/refine/refine.json`
|
|
44
|
-
- **Windows:** `%APPDATA%\refine\refine.json`
|
|
45
|
-
|
|
46
|
-
Edit that file to customise the default behavior for all projects.
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
## Quick start
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
# 1. Create config in your project root (interactive)
|
|
54
|
-
refine init
|
|
55
|
-
|
|
56
|
-
# 2. Run (auto-detects refine.json)
|
|
57
|
-
refine
|
|
58
|
-
|
|
59
|
-
# 3. Dry run — preview what would change, no files modified
|
|
60
|
-
refine --dry-run
|
|
61
|
-
|
|
62
|
-
# 4. Watch mode — reprocess on every file change
|
|
63
|
-
refine --watch
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
## Console output
|
|
69
|
-
|
|
70
|
-
Every run prints a per-file report of exactly what was removed and on which line:
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
refine ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
74
|
-
|
|
75
|
-
ℹ Scanning files...
|
|
76
|
-
✓ Found 2 files to process
|
|
77
|
-
|
|
78
|
-
Processing Files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
79
|
-
|
|
80
|
-
ℹ Total files to process: 2
|
|
81
|
-
|
|
82
|
-
src/utils/helper.ts ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
83
|
-
|
|
84
|
-
✖ 4 comments removed
|
|
85
|
-
|
|
86
|
-
1 │ - /** @file helper.ts — utility functions
|
|
87
|
-
15 │ - // internal state
|
|
88
|
-
42 │ - // TODO: cleanup later
|
|
89
|
-
88 │ - /* legacy fallback */
|
|
90
|
-
|
|
91
|
-
src/components/Button.tsx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
92
|
-
|
|
93
|
-
✖ 2 comments removed
|
|
94
|
-
|
|
95
|
-
3 │ - // @deprecated
|
|
96
|
-
27 │ - /* unused */
|
|
97
|
-
|
|
98
|
-
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
99
|
-
|
|
100
|
-
Results ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
101
|
-
|
|
102
|
-
Files Processed 2 · Files Skipped 0 · Comments Removed 6 · Comments Preserved 0 · Processing Time 12ms
|
|
103
|
-
|
|
104
|
-
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
105
|
-
✓ Done!
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
In `--dry-run` mode each file is tagged `[dry run]` and nothing is written to disk:
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
src/utils/helper.ts ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
112
|
-
|
|
113
|
-
✖ 4 comments removed [dry run]
|
|
114
|
-
|
|
115
|
-
1 │ - /** @file helper.ts — utility functions
|
|
116
|
-
15 │ - // internal state
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
## Config file auto-detection
|
|
122
|
-
|
|
123
|
-
When no `-c` flag is passed, the CLI looks for a config in this order:
|
|
124
|
-
|
|
125
|
-
1. `refine.json` in `process.cwd()`
|
|
126
|
-
2. `.refine.json` in `process.cwd()`
|
|
127
|
-
3. `refine` key inside `config.json` in `process.cwd()`
|
|
128
|
-
4. Global config (`~/.config/refine/refine.json` on Linux/Mac, `%APPDATA%\refine\refine.json` on Windows)
|
|
129
|
-
|
|
130
|
-
If none is found, built-in defaults are used and a hint to run `refine init` is shown.
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## `init` command
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
# Default: creates refine.json in the current directory
|
|
138
|
-
refine init
|
|
139
|
-
|
|
140
|
-
# Custom filename
|
|
141
|
-
refine init --output my-config.json
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
If the target config file already exists, `refine init` exits with a warning:
|
|
145
|
-
|
|
146
|
-
```
|
|
147
|
-
⚠ Config file already exists: refine.json
|
|
148
|
-
Delete it first or use --output to specify a different path.
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
If **`config.json`** already exists in the project root and you run `init` without `--output`, an interactive prompt asks:
|
|
152
|
-
|
|
153
|
-
```
|
|
154
|
-
⚠ A config.json already exists in this directory.
|
|
155
|
-
|
|
156
|
-
How would you like to add refine config?
|
|
157
|
-
[1] Merge into existing config.json (adds "refine" key, keeps everything else)
|
|
158
|
-
[2] Create a separate refine.json file
|
|
159
|
-
[3] Use a custom filename
|
|
160
|
-
Choice (1-3):
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
**Option 1** — the CLI reads `config.json` transparently via the `"refine"` key:
|
|
164
|
-
|
|
165
|
-
```json
|
|
166
|
-
{
|
|
167
|
-
"someOtherTool": {},
|
|
168
|
-
"refine": {
|
|
169
|
-
"targetDirectory": "./src",
|
|
170
|
-
"removeJSDoc": false
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
```bash
|
|
176
|
-
refine -c config.json
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
## CLI options
|
|
182
|
-
|
|
183
|
-
```
|
|
184
|
-
Usage: refine [options] [command]
|
|
185
|
-
|
|
186
|
-
Options:
|
|
187
|
-
-c, --config <path> Path to config file (auto-detected if not specified)
|
|
188
|
-
-d, --directory <path> Target directory to process
|
|
189
|
-
-o, --output <path> Output directory (overwrites originals if omitted)
|
|
190
|
-
-e, --extensions <list> Comma-separated extensions to process (e.g. .js,.ts,.vue)
|
|
191
|
-
--concurrency <n> Number of parallel workers (default: 8)
|
|
192
|
-
--report <path> Write a JSON report to the specified file
|
|
193
|
-
--watch Watch target directory and re-process on changes
|
|
194
|
-
--dry-run Run without making changes
|
|
195
|
-
-v, --verbose Verbose output (includes per-file line counts)
|
|
196
|
-
--remove-jsdoc Remove JSDoc comments
|
|
197
|
-
--keep-todo Keep TODO comments
|
|
198
|
-
--keep-fixme Keep FIXME comments
|
|
199
|
-
--keep-note Keep NOTE comments
|
|
200
|
-
-V, --version Output the version number
|
|
201
|
-
-h, --help Display help for command
|
|
202
|
-
|
|
203
|
-
Commands:
|
|
204
|
-
init [options] Create the refine config in the current project directory
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
## `.refineignore`
|
|
210
|
-
|
|
211
|
-
Place a `.refineignore` file in your target directory to exclude paths using gitignore-style patterns:
|
|
212
|
-
|
|
213
|
-
```gitignore
|
|
214
|
-
# Ignore generated files
|
|
215
|
-
dist/
|
|
216
|
-
build/
|
|
217
|
-
**/*.min.js
|
|
218
|
-
|
|
219
|
-
# Ignore a specific folder
|
|
220
|
-
src/vendor/
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
The file name can be customised via the `ignoreFile` config field.
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## Watch mode
|
|
228
|
-
|
|
229
|
-
```bash
|
|
230
|
-
refine --watch
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
Watches the target directory recursively. Any change to a matching file triggers a debounced (500 ms) re-run. Press `Ctrl+C` to stop.
|
|
234
|
-
|
|
235
|
-
Combine with other flags:
|
|
236
|
-
|
|
237
|
-
```bash
|
|
238
|
-
refine --watch --dry-run --verbose
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
---
|
|
242
|
-
|
|
243
|
-
## JSON report
|
|
244
|
-
|
|
245
|
-
```bash
|
|
246
|
-
refine --report report.json
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
After processing, a report is written to `report.json`:
|
|
250
|
-
|
|
251
|
-
```json
|
|
252
|
-
{
|
|
253
|
-
"timestamp": "2025-01-01T00:00:00.000Z",
|
|
254
|
-
"config": { ... },
|
|
255
|
-
"stats": {
|
|
256
|
-
"filesProcessed": 42,
|
|
257
|
-
"filesSkipped": 3,
|
|
258
|
-
"commentsRemoved": 187,
|
|
259
|
-
"commentsPreserved": 12,
|
|
260
|
-
"filesWithErrors": [],
|
|
261
|
-
"processingTime": 340
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
---
|
|
267
|
-
|
|
268
|
-
## Configuration reference
|
|
269
|
-
|
|
270
|
-
| Field | Type | Default | Description |
|
|
271
|
-
|--------------------|------------|---------------------------------------------------------------------------------|----------------------------------------------------|
|
|
272
|
-
| `targetDirectory` | `string` | `"./src"` | Directory to scan for files |
|
|
273
|
-
| `outputDirectory` | `string?` | `undefined` | Output directory (overwrites originals if omitted) |
|
|
274
|
-
| `fileExtensions` | `string[]` | `[".js",".mjs",".cjs",".ts",".jsx",".tsx",".vue",".svelte",".astro",".html",".htm",".jsonc"]` | File extensions to process |
|
|
275
|
-
| `excludeFiles` | `string[]` | `["*.config.js","*.config.ts"]` | File glob patterns to exclude |
|
|
276
|
-
| `excludeDirs` | `string[]` | `["node_modules","dist","build",".git"]` | Directories to exclude |
|
|
277
|
-
| `ignoreFile` | `string?` | `".refineignore"` | Gitignore-style ignore file inside target dir |
|
|
278
|
-
| `preserveComments` | `string[]` | `["// @ts-expect-error","// @ts-ignore","/// <reference","#!/usr/bin/env node","// biome-ignore","/* webpackIgnore:","/* webpackChunkName:"]` | Exact comment strings to always keep |
|
|
279
|
-
| `preservePatterns` | `string[]` | `["^\\s*//\\s*@ts-","^\\s*///\\s*<reference","^#!/","biome-ignore","webpack[A-Za-z]"]` | Regex patterns for comments to always keep |
|
|
280
|
-
| `removeJSDoc` | `boolean` | `false` | Remove JSDoc blocks (`/** ... */`) |
|
|
281
|
-
| `removeTODO` | `boolean` | `true` | Remove `// TODO:` comments |
|
|
282
|
-
| `removeFIXME` | `boolean` | `true` | Remove `// FIXME:` comments |
|
|
283
|
-
| `removeNOTE` | `boolean` | `true` | Remove `// NOTE:` comments |
|
|
284
|
-
| `dryRun` | `boolean` | `false` | Preview only, no files written |
|
|
285
|
-
| `verbose` | `boolean` | `false` | Detailed log output with per-file line counts |
|
|
286
|
-
| `concurrency` | `number?` | `8` | Number of parallel worker threads |
|
|
287
|
-
| `reportPath` | `string?` | `undefined` | Path to write JSON report after processing |
|
|
288
|
-
|
|
289
|
-
---
|
|
290
|
-
|
|
291
|
-
## Safety Guard
|
|
292
|
-
|
|
293
|
-
refine has a built-in **Safety Guard** layer that runs before any config evaluation. The comments listed below are **always preserved**, regardless of what `refine.json` says — no config option can override them.
|
|
294
|
-
|
|
295
|
-
| Category | What is protected |
|
|
296
|
-
|---|---|
|
|
297
|
-
| **URLs** | Any comment containing `http://` or `https://` |
|
|
298
|
-
| **Biome** | `biome-ignore` |
|
|
299
|
-
| **ESLint** | `eslint-disable`, `eslint-enable`, `eslint-env` |
|
|
300
|
-
| **TypeScript** | `// @ts-*`, `/// <reference ...>` |
|
|
301
|
-
| **Prettier** | `prettier-ignore` |
|
|
302
|
-
| **Stylelint** | `stylelint-disable`, `stylelint-enable` |
|
|
303
|
-
| **Tailwind** | `tailwind-ignore` |
|
|
304
|
-
| **Webpack** | `/* webpackIgnore */`, `/* webpackChunkName */`, etc. |
|
|
305
|
-
| **Vite / Rollup** | `vite-ignore`, `@rollup/` |
|
|
306
|
-
| **Coverage** | `istanbul ignore`, `c8 ignore`, `v8 ignore` |
|
|
307
|
-
| **Node.js** | Shebangs (`#!/`), `"use client"`, `"use server"`, `"use strict"` |
|
|
308
|
-
| **JSX pragmas** | `@jsx`, `@jsxRuntime`, `@jsxImportSource` |
|
|
309
|
-
| **License / Copyright** | Any header containing `license`, `copyright`, `(c)` or `©` |
|
|
310
|
-
| **Source maps** | `sourceMappingURL` |
|
|
311
|
-
| **JetBrains IDEs** | `noinspection` |
|
|
312
|
-
|
|
313
|
-
> This means patterns like `.replace(/\//g, "_")` (regex literals with `/`) and CDN URLs inside strings are also protected from being mis-detected as comment content.
|
|
314
|
-
|
|
315
|
-
---
|
|
316
|
-
|
|
317
|
-
## Supported file types
|
|
318
|
-
|
|
319
|
-
| Extension | Parser |
|
|
320
|
-
|------------------------------------|---------------------------------------|
|
|
321
|
-
| `.js` `.mjs` `.cjs` `.ts` | JavaScript / TypeScript |
|
|
322
|
-
| `.jsx` `.tsx` | JSX / TSX |
|
|
323
|
-
| `.vue` | Vue SFC (template + script + style) |
|
|
324
|
-
| `.svelte` `.astro` | Vue-style (template + script + style) |
|
|
325
|
-
| `.html` `.htm` | HTML (`<!-- -->` + IE conditionals) |
|
|
326
|
-
| `.css` | CSS (`/* */`) |
|
|
327
|
-
| `.scss` `.sass` `.less` | SCSS / SASS / LESS (`/* */` + `//`) |
|
|
328
|
-
| `.jsonc` | JSONC |
|
|
329
|
-
|
|
330
|
-
---
|
|
331
|
-
|
|
332
|
-
## Development scripts
|
|
333
|
-
|
|
334
|
-
| Command | Description |
|
|
335
|
-
|-----------------------|-----------------------------------------------------|
|
|
336
|
-
| `bun start` | Run CLI from source (`src/cli.ts`) |
|
|
337
|
-
| `bun run dev` | Run with file watch (auto-restart on change) |
|
|
338
|
-
| `bun run build` | Compile TypeScript → `dist/` |
|
|
339
|
-
| `bun run rebuild` | Clean `dist/` then compile TypeScript → `dist/` |
|
|
340
|
-
| `bun run watch` | Compile TypeScript in watch mode |
|
|
341
|
-
| `bun run prepare` | Rebuild + generate `refine.json` for development |
|
|
342
|
-
| `bun test` | Run tests |
|
|
343
|
-
| `bun run lint` | Lint `src/` with Biome |
|
|
344
|
-
| `bun run format` | Format `src/` with Biome |
|
|
345
|
-
| `bun run clean` | Remove the `dist/` directory |
|
|
346
|
-
|
|
347
|
-
---
|
|
348
|
-
|
|
349
|
-
## How it works (local vs global)
|
|
350
|
-
|
|
351
|
-
| Install type | How to run | Config location |
|
|
352
|
-
|---------------------------|-------------------------------------|-------------------------------------------------------------------------------------------|
|
|
353
|
-
| Local (`bun add -D`) | `bunx refine` / package.json script | Project root (`process.cwd()`) |
|
|
354
|
-
| Global (`bun install -g`) | `refine` from any terminal | `~/.config/refine/refine.json` (Linux/Mac) · `%APPDATA%\refine\refine.json` (Windows) |
|
|
355
|
-
|
|
356
|
-
Config file paths and all relative paths inside it are resolved against the directory from which `refine` is called (`process.cwd()`), never against the package installation directory.
|
|
357
|
-
|
|
358
|
-
---
|
|
359
|
-
|
|
360
|
-
## Requirements
|
|
361
|
-
|
|
362
|
-
- [Node.js](https://nodejs.org) >= 18.0.0
|
|
363
|
-
- [Bun](https://bun.sh) >= 1.0.0 *(required only for development / building from source)*
|
|
364
|
-
|
|
365
|
-
---
|
|
366
|
-
|
|
367
|
-
## License
|
|
368
|
-
|
|
369
|
-
MIT
|
|
370
|
-
|
|
1
|
+
# refine
|
|
2
|
+
|
|
3
|
+
Remove comments from JavaScript, TypeScript, JSX, TSX, Vue, HTML, CSS/SCSS/LESS and more — with parallel processing, watch mode, `.refineignore` support and JSON reports.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### Local (per-project)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# bun
|
|
13
|
+
bun add -D @nuitsukera/refine
|
|
14
|
+
|
|
15
|
+
# npm
|
|
16
|
+
npm install --save-dev @nuitsukera/refine
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
After installing, run the setup wizard once:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# bun
|
|
23
|
+
bunx refine init
|
|
24
|
+
|
|
25
|
+
# npm
|
|
26
|
+
npx refine init
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
A `refine.json` is created in the project root (or merged into your existing `config.json` if you prefer). A post-install tip is shown automatically if no config is found.
|
|
30
|
+
|
|
31
|
+
### Global
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# bun
|
|
35
|
+
bun install -g @nuitsukera/refine
|
|
36
|
+
|
|
37
|
+
# npm
|
|
38
|
+
npm install -g @nuitsukera/refine
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Once installed globally you can call `refine` from any directory. A default global config is automatically created on install:
|
|
42
|
+
|
|
43
|
+
- **Linux / Mac:** `~/.config/refine/refine.json`
|
|
44
|
+
- **Windows:** `%APPDATA%\refine\refine.json`
|
|
45
|
+
|
|
46
|
+
Edit that file to customise the default behavior for all projects.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# 1. Create config in your project root (interactive)
|
|
54
|
+
refine init
|
|
55
|
+
|
|
56
|
+
# 2. Run (auto-detects refine.json)
|
|
57
|
+
refine
|
|
58
|
+
|
|
59
|
+
# 3. Dry run — preview what would change, no files modified
|
|
60
|
+
refine --dry-run
|
|
61
|
+
|
|
62
|
+
# 4. Watch mode — reprocess on every file change
|
|
63
|
+
refine --watch
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Console output
|
|
69
|
+
|
|
70
|
+
Every run prints a per-file report of exactly what was removed and on which line:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
refine ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
74
|
+
|
|
75
|
+
ℹ Scanning files...
|
|
76
|
+
✓ Found 2 files to process
|
|
77
|
+
|
|
78
|
+
Processing Files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
79
|
+
|
|
80
|
+
ℹ Total files to process: 2
|
|
81
|
+
|
|
82
|
+
src/utils/helper.ts ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
83
|
+
|
|
84
|
+
✖ 4 comments removed
|
|
85
|
+
|
|
86
|
+
1 │ - /** @file helper.ts — utility functions
|
|
87
|
+
15 │ - // internal state
|
|
88
|
+
42 │ - // TODO: cleanup later
|
|
89
|
+
88 │ - /* legacy fallback */
|
|
90
|
+
|
|
91
|
+
src/components/Button.tsx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
92
|
+
|
|
93
|
+
✖ 2 comments removed
|
|
94
|
+
|
|
95
|
+
3 │ - // @deprecated
|
|
96
|
+
27 │ - /* unused */
|
|
97
|
+
|
|
98
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
99
|
+
|
|
100
|
+
Results ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
101
|
+
|
|
102
|
+
Files Processed 2 · Files Skipped 0 · Comments Removed 6 · Comments Preserved 0 · Processing Time 12ms
|
|
103
|
+
|
|
104
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
105
|
+
✓ Done!
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
In `--dry-run` mode each file is tagged `[dry run]` and nothing is written to disk:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
src/utils/helper.ts ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
112
|
+
|
|
113
|
+
✖ 4 comments removed [dry run]
|
|
114
|
+
|
|
115
|
+
1 │ - /** @file helper.ts — utility functions
|
|
116
|
+
15 │ - // internal state
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Config file auto-detection
|
|
122
|
+
|
|
123
|
+
When no `-c` flag is passed, the CLI looks for a config in this order:
|
|
124
|
+
|
|
125
|
+
1. `refine.json` in `process.cwd()`
|
|
126
|
+
2. `.refine.json` in `process.cwd()`
|
|
127
|
+
3. `refine` key inside `config.json` in `process.cwd()`
|
|
128
|
+
4. Global config (`~/.config/refine/refine.json` on Linux/Mac, `%APPDATA%\refine\refine.json` on Windows)
|
|
129
|
+
|
|
130
|
+
If none is found, built-in defaults are used and a hint to run `refine init` is shown.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## `init` command
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# Default: creates refine.json in the current directory
|
|
138
|
+
refine init
|
|
139
|
+
|
|
140
|
+
# Custom filename
|
|
141
|
+
refine init --output my-config.json
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
If the target config file already exists, `refine init` exits with a warning:
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
⚠ Config file already exists: refine.json
|
|
148
|
+
Delete it first or use --output to specify a different path.
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
If **`config.json`** already exists in the project root and you run `init` without `--output`, an interactive prompt asks:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
⚠ A config.json already exists in this directory.
|
|
155
|
+
|
|
156
|
+
How would you like to add refine config?
|
|
157
|
+
[1] Merge into existing config.json (adds "refine" key, keeps everything else)
|
|
158
|
+
[2] Create a separate refine.json file
|
|
159
|
+
[3] Use a custom filename
|
|
160
|
+
Choice (1-3):
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Option 1** — the CLI reads `config.json` transparently via the `"refine"` key:
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"someOtherTool": {},
|
|
168
|
+
"refine": {
|
|
169
|
+
"targetDirectory": "./src",
|
|
170
|
+
"removeJSDoc": false
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
refine -c config.json
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## CLI options
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
Usage: refine [options] [command]
|
|
185
|
+
|
|
186
|
+
Options:
|
|
187
|
+
-c, --config <path> Path to config file (auto-detected if not specified)
|
|
188
|
+
-d, --directory <path> Target directory to process
|
|
189
|
+
-o, --output <path> Output directory (overwrites originals if omitted)
|
|
190
|
+
-e, --extensions <list> Comma-separated extensions to process (e.g. .js,.ts,.vue)
|
|
191
|
+
--concurrency <n> Number of parallel workers (default: 8)
|
|
192
|
+
--report <path> Write a JSON report to the specified file
|
|
193
|
+
--watch Watch target directory and re-process on changes
|
|
194
|
+
--dry-run Run without making changes
|
|
195
|
+
-v, --verbose Verbose output (includes per-file line counts)
|
|
196
|
+
--remove-jsdoc Remove JSDoc comments
|
|
197
|
+
--keep-todo Keep TODO comments
|
|
198
|
+
--keep-fixme Keep FIXME comments
|
|
199
|
+
--keep-note Keep NOTE comments
|
|
200
|
+
-V, --version Output the version number
|
|
201
|
+
-h, --help Display help for command
|
|
202
|
+
|
|
203
|
+
Commands:
|
|
204
|
+
init [options] Create the refine config in the current project directory
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## `.refineignore`
|
|
210
|
+
|
|
211
|
+
Place a `.refineignore` file in your target directory to exclude paths using gitignore-style patterns:
|
|
212
|
+
|
|
213
|
+
```gitignore
|
|
214
|
+
# Ignore generated files
|
|
215
|
+
dist/
|
|
216
|
+
build/
|
|
217
|
+
**/*.min.js
|
|
218
|
+
|
|
219
|
+
# Ignore a specific folder
|
|
220
|
+
src/vendor/
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
The file name can be customised via the `ignoreFile` config field.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Watch mode
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
refine --watch
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Watches the target directory recursively. Any change to a matching file triggers a debounced (500 ms) re-run. Press `Ctrl+C` to stop.
|
|
234
|
+
|
|
235
|
+
Combine with other flags:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
refine --watch --dry-run --verbose
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## JSON report
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
refine --report report.json
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
After processing, a report is written to `report.json`:
|
|
250
|
+
|
|
251
|
+
```json
|
|
252
|
+
{
|
|
253
|
+
"timestamp": "2025-01-01T00:00:00.000Z",
|
|
254
|
+
"config": { ... },
|
|
255
|
+
"stats": {
|
|
256
|
+
"filesProcessed": 42,
|
|
257
|
+
"filesSkipped": 3,
|
|
258
|
+
"commentsRemoved": 187,
|
|
259
|
+
"commentsPreserved": 12,
|
|
260
|
+
"filesWithErrors": [],
|
|
261
|
+
"processingTime": 340
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Configuration reference
|
|
269
|
+
|
|
270
|
+
| Field | Type | Default | Description |
|
|
271
|
+
|--------------------|------------|---------------------------------------------------------------------------------|----------------------------------------------------|
|
|
272
|
+
| `targetDirectory` | `string` | `"./src"` | Directory to scan for files |
|
|
273
|
+
| `outputDirectory` | `string?` | `undefined` | Output directory (overwrites originals if omitted) |
|
|
274
|
+
| `fileExtensions` | `string[]` | `[".js",".mjs",".cjs",".ts",".jsx",".tsx",".vue",".svelte",".astro",".html",".htm",".jsonc"]` | File extensions to process |
|
|
275
|
+
| `excludeFiles` | `string[]` | `["*.config.js","*.config.ts"]` | File glob patterns to exclude |
|
|
276
|
+
| `excludeDirs` | `string[]` | `["node_modules","dist","build",".git"]` | Directories to exclude |
|
|
277
|
+
| `ignoreFile` | `string?` | `".refineignore"` | Gitignore-style ignore file inside target dir |
|
|
278
|
+
| `preserveComments` | `string[]` | `["// @ts-expect-error","// @ts-ignore","/// <reference","#!/usr/bin/env node","// biome-ignore","/* webpackIgnore:","/* webpackChunkName:"]` | Exact comment strings to always keep |
|
|
279
|
+
| `preservePatterns` | `string[]` | `["^\\s*//\\s*@ts-","^\\s*///\\s*<reference","^#!/","biome-ignore","webpack[A-Za-z]"]` | Regex patterns for comments to always keep |
|
|
280
|
+
| `removeJSDoc` | `boolean` | `false` | Remove JSDoc blocks (`/** ... */`) |
|
|
281
|
+
| `removeTODO` | `boolean` | `true` | Remove `// TODO:` comments |
|
|
282
|
+
| `removeFIXME` | `boolean` | `true` | Remove `// FIXME:` comments |
|
|
283
|
+
| `removeNOTE` | `boolean` | `true` | Remove `// NOTE:` comments |
|
|
284
|
+
| `dryRun` | `boolean` | `false` | Preview only, no files written |
|
|
285
|
+
| `verbose` | `boolean` | `false` | Detailed log output with per-file line counts |
|
|
286
|
+
| `concurrency` | `number?` | `8` | Number of parallel worker threads |
|
|
287
|
+
| `reportPath` | `string?` | `undefined` | Path to write JSON report after processing |
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Safety Guard
|
|
292
|
+
|
|
293
|
+
refine has a built-in **Safety Guard** layer that runs before any config evaluation. The comments listed below are **always preserved**, regardless of what `refine.json` says — no config option can override them.
|
|
294
|
+
|
|
295
|
+
| Category | What is protected |
|
|
296
|
+
|---|---|
|
|
297
|
+
| **URLs** | Any comment containing `http://` or `https://` |
|
|
298
|
+
| **Biome** | `biome-ignore` |
|
|
299
|
+
| **ESLint** | `eslint-disable`, `eslint-enable`, `eslint-env` |
|
|
300
|
+
| **TypeScript** | `// @ts-*`, `/// <reference ...>` |
|
|
301
|
+
| **Prettier** | `prettier-ignore` |
|
|
302
|
+
| **Stylelint** | `stylelint-disable`, `stylelint-enable` |
|
|
303
|
+
| **Tailwind** | `tailwind-ignore` |
|
|
304
|
+
| **Webpack** | `/* webpackIgnore */`, `/* webpackChunkName */`, etc. |
|
|
305
|
+
| **Vite / Rollup** | `vite-ignore`, `@rollup/` |
|
|
306
|
+
| **Coverage** | `istanbul ignore`, `c8 ignore`, `v8 ignore` |
|
|
307
|
+
| **Node.js** | Shebangs (`#!/`), `"use client"`, `"use server"`, `"use strict"` |
|
|
308
|
+
| **JSX pragmas** | `@jsx`, `@jsxRuntime`, `@jsxImportSource` |
|
|
309
|
+
| **License / Copyright** | Any header containing `license`, `copyright`, `(c)` or `©` |
|
|
310
|
+
| **Source maps** | `sourceMappingURL` |
|
|
311
|
+
| **JetBrains IDEs** | `noinspection` |
|
|
312
|
+
|
|
313
|
+
> This means patterns like `.replace(/\//g, "_")` (regex literals with `/`) and CDN URLs inside strings are also protected from being mis-detected as comment content.
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Supported file types
|
|
318
|
+
|
|
319
|
+
| Extension | Parser |
|
|
320
|
+
|------------------------------------|---------------------------------------|
|
|
321
|
+
| `.js` `.mjs` `.cjs` `.ts` | JavaScript / TypeScript |
|
|
322
|
+
| `.jsx` `.tsx` | JSX / TSX |
|
|
323
|
+
| `.vue` | Vue SFC (template + script + style) |
|
|
324
|
+
| `.svelte` `.astro` | Vue-style (template + script + style) |
|
|
325
|
+
| `.html` `.htm` | HTML (`<!-- -->` + IE conditionals) |
|
|
326
|
+
| `.css` | CSS (`/* */`) |
|
|
327
|
+
| `.scss` `.sass` `.less` | SCSS / SASS / LESS (`/* */` + `//`) |
|
|
328
|
+
| `.jsonc` | JSONC |
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Development scripts
|
|
333
|
+
|
|
334
|
+
| Command | Description |
|
|
335
|
+
|-----------------------|-----------------------------------------------------|
|
|
336
|
+
| `bun start` | Run CLI from source (`src/cli.ts`) |
|
|
337
|
+
| `bun run dev` | Run with file watch (auto-restart on change) |
|
|
338
|
+
| `bun run build` | Compile TypeScript → `dist/` |
|
|
339
|
+
| `bun run rebuild` | Clean `dist/` then compile TypeScript → `dist/` |
|
|
340
|
+
| `bun run watch` | Compile TypeScript in watch mode |
|
|
341
|
+
| `bun run prepare` | Rebuild + generate `refine.json` for development |
|
|
342
|
+
| `bun test` | Run tests |
|
|
343
|
+
| `bun run lint` | Lint `src/` with Biome |
|
|
344
|
+
| `bun run format` | Format `src/` with Biome |
|
|
345
|
+
| `bun run clean` | Remove the `dist/` directory |
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## How it works (local vs global)
|
|
350
|
+
|
|
351
|
+
| Install type | How to run | Config location |
|
|
352
|
+
|---------------------------|-------------------------------------|-------------------------------------------------------------------------------------------|
|
|
353
|
+
| Local (`bun add -D`) | `bunx refine` / package.json script | Project root (`process.cwd()`) |
|
|
354
|
+
| Global (`bun install -g`) | `refine` from any terminal | `~/.config/refine/refine.json` (Linux/Mac) · `%APPDATA%\refine\refine.json` (Windows) |
|
|
355
|
+
|
|
356
|
+
Config file paths and all relative paths inside it are resolved against the directory from which `refine` is called (`process.cwd()`), never against the package installation directory.
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## Requirements
|
|
361
|
+
|
|
362
|
+
- [Node.js](https://nodejs.org) >= 18.0.0
|
|
363
|
+
- [Bun](https://bun.sh) >= 1.0.0 *(required only for development / building from source)*
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## License
|
|
368
|
+
|
|
369
|
+
MIT
|
|
370
|
+
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
2
|
"name": "@nuitsukera/refine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Remove comments from JavaScript/TypeScript, CSS/SCSS/LESS, HTML, Vue and related files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsc --emitDeclarationOnly && bun build src/cli.ts --target=node --outdir=dist && bun build src/index.ts --target=node --outdir=dist && bun build src/postinstall.ts --target=node --outdir=dist",
|
|
24
|
-
"postinstall": "node dist/postinstall.js",
|
|
24
|
+
"postinstall": "node -e \"const f='dist/postinstall.js';require('fs').existsSync(f)&&require('child_process').execFileSync(process.execPath,[f],{stdio:'inherit'})\"",
|
|
25
25
|
"prepare": "bun run rebuild && bun scripts/create-config.ts",
|
|
26
26
|
"start": "bun src/cli.ts",
|
|
27
27
|
"dev": "bun --watch src/cli.ts",
|