@cldmv/fix-headers 1.3.12 → 2.1.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/LICENSE +202 -0
- package/README.md +354 -25
- package/bin/fix-headers.mjs +64 -0
- package/dist/index.cjs +28 -0
- package/dist/index.mjs +15 -0
- package/package.json +39 -19
- package/types/src/cli.d.mts +20 -2
- package/types/src/config/load.d.mts +36 -0
- package/types/src/constants.d.mts +15 -23
- package/types/src/core/file-discovery.d.mts +17 -5
- package/types/src/core/fix-headers.d.mts +61 -4
- package/types/src/core/ignore-rules.d.mts +38 -0
- package/types/src/detect/project.d.mts +64 -15
- package/types/src/detectors/css.d.mts +0 -8
- package/types/src/detectors/go.d.mts +0 -8
- package/types/src/detectors/html.d.mts +0 -8
- package/types/src/detectors/index.d.mts +31 -8
- package/types/src/detectors/json.d.mts +0 -8
- package/types/src/detectors/node.d.mts +0 -8
- package/types/src/detectors/php.d.mts +0 -8
- package/types/src/detectors/python.d.mts +0 -8
- package/types/src/detectors/rust.d.mts +0 -8
- package/types/src/detectors/yaml.d.mts +0 -8
- package/types/src/drivers/go.d.mts +2 -0
- package/types/src/drivers/index.d.mts +154 -0
- package/types/src/drivers/node.d.mts +2 -0
- package/types/src/drivers/php.d.mts +2 -0
- package/types/src/drivers/python.d.mts +2 -0
- package/types/src/drivers/rust.d.mts +2 -0
- package/types/src/drivers/shared.d.mts +78 -0
- package/types/src/header/dates.d.mts +108 -0
- package/types/src/header/fields.d.mts +48 -0
- package/types/src/header/parser.d.mts +6 -2
- package/types/src/header/syntax.d.mts +8 -3
- package/types/src/header/template.d.mts +7 -4
- package/types/src/utils/diff.d.mts +53 -0
- package/types/src/utils/fs.d.mts +10 -3
- package/types/src/utils/git.d.mts +27 -0
- package/types/src/utils/time.d.mts +55 -0
- package/index.cjs +0 -39
- package/index.mjs +0 -20
- package/src/cli.mjs +0 -323
- package/src/constants.mjs +0 -50
- package/src/core/file-discovery.mjs +0 -213
- package/src/core/fix-headers.mjs +0 -413
- package/src/detect/project.mjs +0 -190
- package/src/detectors/css.mjs +0 -67
- package/src/detectors/go.mjs +0 -65
- package/src/detectors/html.mjs +0 -67
- package/src/detectors/index.mjs +0 -187
- package/src/detectors/json.mjs +0 -76
- package/src/detectors/node.mjs +0 -90
- package/src/detectors/php.mjs +0 -66
- package/src/detectors/python.mjs +0 -75
- package/src/detectors/rust.mjs +0 -62
- package/src/detectors/shared.mjs +0 -45
- package/src/detectors/yaml.mjs +0 -79
- package/src/fix-header.mjs +0 -30
- package/src/header/parser.mjs +0 -145
- package/src/header/syntax.mjs +0 -69
- package/src/header/template.mjs +0 -65
- package/src/utils/fs.mjs +0 -138
- package/src/utils/git.mjs +0 -135
- package/src/utils/time.mjs +0 -44
- package/types/src/detectors/shared.d.mts +0 -14
|
@@ -20,6 +20,30 @@
|
|
|
20
20
|
* @returns {string} Formatted date string.
|
|
21
21
|
*/
|
|
22
22
|
export function formatDateWithTimezone(date: Date): string;
|
|
23
|
+
/**
|
|
24
|
+
* Renders datetime parts in the space form (`YYYY-MM-DD HH:mm:ss ±HH:MM`), keeping their offset.
|
|
25
|
+
* @param {DateParts} parts - Datetime parts.
|
|
26
|
+
* @returns {string} Formatted date string.
|
|
27
|
+
*/
|
|
28
|
+
export function formatSpaceDate(parts: DateParts): string;
|
|
29
|
+
/**
|
|
30
|
+
* Validates an IANA time zone name with Intl (`new Intl.DateTimeFormat` throws a RangeError for a
|
|
31
|
+
* zone it does not know).
|
|
32
|
+
* @param {unknown} timeZone - Zone name to validate, such as `America/Los_Angeles` or `UTC`.
|
|
33
|
+
* @returns {string} The zone name.
|
|
34
|
+
* @throws {Error} When the value is not a string, or Intl does not know the zone.
|
|
35
|
+
*/
|
|
36
|
+
export function assertTimeZone(timeZone: unknown): string;
|
|
37
|
+
/**
|
|
38
|
+
* Expresses an instant in a zone: its wall-clock parts there and the zone's UTC offset at that
|
|
39
|
+
* instant (DST included), read from Intl's time zone data rather than a fixed table. The offset is
|
|
40
|
+
* the difference between that wall-clock time and the instant, so a historical offset that is not
|
|
41
|
+
* a whole number of minutes (local mean time) comes back fractional.
|
|
42
|
+
* @param {number} timestamp - Unix timestamp in seconds.
|
|
43
|
+
* @param {string} timeZone - IANA zone name.
|
|
44
|
+
* @returns {DateParts} Wall-clock parts and offset in the zone.
|
|
45
|
+
*/
|
|
46
|
+
export function toZonedDateParts(timestamp: number, timeZone: string): DateParts;
|
|
23
47
|
/**
|
|
24
48
|
* Returns a formatted date and unix timestamp.
|
|
25
49
|
* @param {Date} [date=new Date()] - Date value to format.
|
|
@@ -29,3 +53,34 @@ export function toDatePayload(date?: Date): {
|
|
|
29
53
|
date: string;
|
|
30
54
|
timestamp: number;
|
|
31
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Parses a header datetime string into its wall-clock parts, UTC offset, and unix timestamp.
|
|
58
|
+
* Calendar-invalid values (month 13, February 30, hour 24, ...) are rejected rather than rolled over.
|
|
59
|
+
* @param {string} text - Datetime text as written in a header.
|
|
60
|
+
* @returns {{ year: number, month: number, day: number, hour: number, minute: number, second: number, offsetMinutes: number, timestamp: number } | null} Parsed datetime, or null when unrecognised.
|
|
61
|
+
*/
|
|
62
|
+
export function parseHeaderDate(text: string): {
|
|
63
|
+
year: number;
|
|
64
|
+
month: number;
|
|
65
|
+
day: number;
|
|
66
|
+
hour: number;
|
|
67
|
+
minute: number;
|
|
68
|
+
second: number;
|
|
69
|
+
offsetMinutes: number;
|
|
70
|
+
timestamp: number;
|
|
71
|
+
} | null;
|
|
72
|
+
/**
|
|
73
|
+
* Renders parsed datetime parts in the git `%aI` form (`YYYY-MM-DDTHH:mm:ss±HH:MM`), keeping the original offset.
|
|
74
|
+
* @param {DateParts} parts - Parsed datetime parts.
|
|
75
|
+
* @returns {string} ISO 8601 datetime text.
|
|
76
|
+
*/
|
|
77
|
+
export function formatIsoDate(parts: DateParts): string;
|
|
78
|
+
export type DateParts = {
|
|
79
|
+
year: number;
|
|
80
|
+
month: number;
|
|
81
|
+
day: number;
|
|
82
|
+
hour: number;
|
|
83
|
+
minute: number;
|
|
84
|
+
second: number;
|
|
85
|
+
offsetMinutes: number;
|
|
86
|
+
};
|
package/index.cjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @Project: @cldmv/fix-headers
|
|
3
|
-
* @Filename: /index.cjs
|
|
4
|
-
* @Date: 2026-03-01 13:29:45 -08:00 (1772400585)
|
|
5
|
-
* @Author: Nate Corcoran <CLDMV>
|
|
6
|
-
* @Email: <Shinrai@users.noreply.github.com>
|
|
7
|
-
* -----
|
|
8
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
9
|
-
* @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
|
|
10
|
-
* -----
|
|
11
|
-
* @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @fileoverview CJS shim for consuming the ESM-based fix-headers module.
|
|
16
|
-
* @module fix-headers/cjs-shim
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
"use strict";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Loads the ESM module implementation.
|
|
23
|
-
* @returns {Promise<import("./index.mjs")>} Loaded ESM module.
|
|
24
|
-
*/
|
|
25
|
-
function loadEsmModule() {
|
|
26
|
-
return import("./index.mjs");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Runs header normalization with auto-detection and override options.
|
|
31
|
-
* @param {Record<string, unknown>} [options] - Runtime options.
|
|
32
|
-
* @returns {Promise<unknown>} Header update report.
|
|
33
|
-
*/
|
|
34
|
-
async function fixHeaders(options) {
|
|
35
|
-
const mod = await loadEsmModule();
|
|
36
|
-
return mod.default(options);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = fixHeaders;
|
package/index.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @Project: @cldmv/fix-headers
|
|
3
|
-
* @Filename: /index.mjs
|
|
4
|
-
* @Date: 2026-03-01T17:59:32-08:00 (1772416772)
|
|
5
|
-
* @Author: Nate Corcoran <CLDMV>
|
|
6
|
-
* @Email: <Shinrai@users.noreply.github.com>
|
|
7
|
-
* -----
|
|
8
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
9
|
-
* @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
|
|
10
|
-
* -----
|
|
11
|
-
* @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @fileoverview ESM shim for the fix-headers package API.
|
|
16
|
-
* @module fix-headers/esm-shim
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
export * from "./src/fix-header.mjs";
|
|
20
|
-
export { default } from "./src/fix-header.mjs";
|
package/src/cli.mjs
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* @Project: @cldmv/fix-headers
|
|
4
|
-
* @Filename: /src/cli.mjs
|
|
5
|
-
* @Date: 2026-03-01T17:59:32-08:00 (1772416772)
|
|
6
|
-
* @Author: Nate Corcoran <CLDMV>
|
|
7
|
-
* @Email: <Shinrai@users.noreply.github.com>
|
|
8
|
-
* -----
|
|
9
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
10
|
-
* @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
|
|
11
|
-
* -----
|
|
12
|
-
* @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { readFile } from "node:fs/promises";
|
|
16
|
-
import { realpathSync } from "node:fs";
|
|
17
|
-
import { isAbsolute, join } from "node:path";
|
|
18
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
19
|
-
import fixHeaders from "./fix-header.mjs";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @fileoverview CLI entry point for running fix-headers from terminal commands.
|
|
23
|
-
* @module fix-headers/cli
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const HELP_TEXT = `fix-headers CLI\n\nUsage:\n fix-headers [options]\n\nOptions:\n -h, --help Show help\n --dry-run Compute changes without writing files\n --json Print JSON output\n --verbose Print updated file paths in summary mode\n --sample-output Show previous/new header sample for changed files\n --force-author-update Always update @Author/@Email to detected/current values\n --force-last-modified-author-update Always update @Last modified by to detected/current values\n --use-gpg-signer-author Use signed-commit UID (%GS) for detected @Author\n --cwd <path> Working directory for project detection\n --input <path> Single file or folder input\n --include-folder <path> Include folder (repeatable)\n --exclude-folder <path> Exclude folder name/path (repeatable)\n --include-extension <ext> Include extension (repeatable)\n --enable-detector <id> Enable only specific detector (repeatable)\n --disable-detector <id> Disable detector by id (repeatable)\n --project-name <name> Override project name\n --language <id> Override language id\n --project-root <path> Override project root\n --marker <name|null> Override marker filename\n --author-name <name> Override author name\n --author-email <email> Override author email\n --company <name> Append company suffix to @Author (Name <Company>)\n --company-name <name> Override company name\n --copyright-start-year <year> Override copyright start year\n --config <path> Load JSON options file\n\nExamples:\n fix-headers --dry-run --include-folder src\n fix-headers --project-name @scope/pkg --company-name "Catalyzed Motivation Inc."\n`;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Converts CLI flag token to camelCase key.
|
|
30
|
-
* @param {string} token - CLI token without leading dashes.
|
|
31
|
-
* @returns {string} CamelCase key.
|
|
32
|
-
*/
|
|
33
|
-
function toCamelCase(token) {
|
|
34
|
-
return token.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Parses CLI arguments into fixHeaders options and control flags.
|
|
39
|
-
* @param {string[]} argv - Process argument vector without node/script items.
|
|
40
|
-
* @returns {{
|
|
41
|
-
* options: Record<string, unknown>,
|
|
42
|
-
* help: boolean,
|
|
43
|
-
* json: boolean
|
|
44
|
-
* }} Parsed CLI payload.
|
|
45
|
-
*/
|
|
46
|
-
export function parseCliArgs(argv) {
|
|
47
|
-
/** @type {Record<string, unknown>} */
|
|
48
|
-
const options = {};
|
|
49
|
-
const control = { help: false, json: false };
|
|
50
|
-
const multiMap = {
|
|
51
|
-
"include-folder": "includeFolders",
|
|
52
|
-
"exclude-folder": "excludeFolders",
|
|
53
|
-
"include-extension": "includeExtensions",
|
|
54
|
-
"enable-detector": "enabledDetectors",
|
|
55
|
-
"disable-detector": "disabledDetectors"
|
|
56
|
-
};
|
|
57
|
-
const scalarMap = {
|
|
58
|
-
cwd: "cwd",
|
|
59
|
-
input: "input",
|
|
60
|
-
"project-name": "projectName",
|
|
61
|
-
language: "language",
|
|
62
|
-
"project-root": "projectRoot",
|
|
63
|
-
marker: "marker",
|
|
64
|
-
"author-name": "authorName",
|
|
65
|
-
"author-email": "authorEmail",
|
|
66
|
-
company: "company",
|
|
67
|
-
"company-name": "companyName",
|
|
68
|
-
"copyright-start-year": "copyrightStartYear",
|
|
69
|
-
config: "config"
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
73
|
-
const arg = argv[index];
|
|
74
|
-
if (arg === "-h" || arg === "--help") {
|
|
75
|
-
control.help = true;
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (arg === "--json") {
|
|
79
|
-
control.json = true;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (arg === "--verbose") {
|
|
83
|
-
options.verbose = true;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (arg === "--dry-run") {
|
|
87
|
-
options.dryRun = true;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (arg === "--sample-output") {
|
|
91
|
-
options.sampleOutput = true;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (arg === "--force-author-update") {
|
|
95
|
-
options.forceAuthorUpdate = true;
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (arg === "--force-last-modified-author-update") {
|
|
99
|
-
options.forceLastModifiedAuthorUpdate = true;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (arg === "--use-gpg-signer-author") {
|
|
103
|
-
options.useGpgSignerAuthor = true;
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (!arg.startsWith("--")) {
|
|
107
|
-
throw new Error(`Unexpected argument: ${arg}`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const flag = arg.slice(2);
|
|
111
|
-
if (multiMap[flag]) {
|
|
112
|
-
const value = argv[index + 1];
|
|
113
|
-
if (!value || value.startsWith("--")) {
|
|
114
|
-
throw new Error(`Missing value for --${flag}`);
|
|
115
|
-
}
|
|
116
|
-
index += 1;
|
|
117
|
-
const key = multiMap[flag];
|
|
118
|
-
const list = Array.isArray(options[key]) ? options[key] : [];
|
|
119
|
-
options[key] = Array.from(new Set([...list, value]));
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (scalarMap[flag]) {
|
|
124
|
-
const value = argv[index + 1];
|
|
125
|
-
if (!value || value.startsWith("--")) {
|
|
126
|
-
throw new Error(`Missing value for --${flag}`);
|
|
127
|
-
}
|
|
128
|
-
index += 1;
|
|
129
|
-
const key = scalarMap[flag];
|
|
130
|
-
if (key === "copyrightStartYear") {
|
|
131
|
-
options[key] = Number.parseInt(value, 10);
|
|
132
|
-
if (Number.isNaN(options[key])) {
|
|
133
|
-
throw new Error(`Invalid number for --${flag}: ${value}`);
|
|
134
|
-
}
|
|
135
|
-
} else if (key === "marker" && value === "null") {
|
|
136
|
-
options[key] = null;
|
|
137
|
-
} else {
|
|
138
|
-
options[key] = value;
|
|
139
|
-
}
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const camelKey = toCamelCase(flag);
|
|
144
|
-
const value = argv[index + 1];
|
|
145
|
-
if (!value || value.startsWith("--")) {
|
|
146
|
-
throw new Error(`Unknown or malformed flag: --${flag}`);
|
|
147
|
-
}
|
|
148
|
-
index += 1;
|
|
149
|
-
options[camelKey] = value;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return {
|
|
153
|
-
options,
|
|
154
|
-
help: control.help,
|
|
155
|
-
json: control.json
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Loads extra options from a JSON config file.
|
|
161
|
-
* @param {Record<string, unknown>} options - Current options object.
|
|
162
|
-
* @returns {Promise<Record<string, unknown>>} Merged options object.
|
|
163
|
-
*/
|
|
164
|
-
export async function applyConfigFile(options) {
|
|
165
|
-
if (typeof options.config !== "string" || options.config.trim().length === 0) {
|
|
166
|
-
return options;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const baseDir = typeof options.cwd === "string" && options.cwd.length > 0 ? options.cwd : process.cwd();
|
|
170
|
-
const configPath = isAbsolute(options.config) ? options.config : join(baseDir, options.config);
|
|
171
|
-
const raw = await readFile(configPath, "utf8");
|
|
172
|
-
const parsed = JSON.parse(raw);
|
|
173
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
174
|
-
throw new Error("Config file must contain a JSON object");
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const merged = { ...parsed, ...options };
|
|
178
|
-
delete merged.config;
|
|
179
|
-
/** @type {Record<string, unknown>} */
|
|
180
|
-
const output = merged;
|
|
181
|
-
return output;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Prints per-file previous/new header samples when available.
|
|
186
|
-
* @param {(message: string) => void} stdout - Standard output writer.
|
|
187
|
-
* @param {unknown} result - Runner result object.
|
|
188
|
-
* @returns {void}
|
|
189
|
-
*/
|
|
190
|
-
function printSampleOutput(stdout, result) {
|
|
191
|
-
if (!result || typeof result !== "object") {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const report =
|
|
196
|
-
/** @type {{changes?: Array<{file?: string, changed?: boolean, sample?: { previousValue?: string | null, newValue?: string, detectedValues?: Record<string, unknown> }}>}} */ (
|
|
197
|
-
result
|
|
198
|
-
);
|
|
199
|
-
const changes = Array.isArray(report.changes) ? report.changes : [];
|
|
200
|
-
for (const change of changes) {
|
|
201
|
-
if (!change || change.changed !== true || !change.sample || typeof change.sample.newValue !== "string") {
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
stdout(`sample: ${change.file || "<unknown-file>"}`);
|
|
206
|
-
stdout("previous:");
|
|
207
|
-
stdout(change.sample.previousValue === null ? "(none)" : String(change.sample.previousValue));
|
|
208
|
-
stdout("new:");
|
|
209
|
-
stdout(change.sample.newValue);
|
|
210
|
-
if (change.sample.detectedValues && typeof change.sample.detectedValues === "object") {
|
|
211
|
-
stdout("detected-values:");
|
|
212
|
-
stdout(JSON.stringify(change.sample.detectedValues, null, 2));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Prints changed file paths from result payload.
|
|
219
|
-
* @param {(message: string) => void} stdout - Standard output writer.
|
|
220
|
-
* @param {unknown} result - Runner result object.
|
|
221
|
-
* @returns {void}
|
|
222
|
-
*/
|
|
223
|
-
function printChangedFiles(stdout, result) {
|
|
224
|
-
if (!result || typeof result !== "object") {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const report = /** @type {{changes?: Array<{file?: string, changed?: boolean}>}} */ (result);
|
|
229
|
-
const changes = Array.isArray(report.changes) ? report.changes : [];
|
|
230
|
-
const updatedFiles = changes.filter((change) => change && change.changed === true).map((change) => change.file || "<unknown-file>");
|
|
231
|
-
for (const file of updatedFiles) {
|
|
232
|
-
stdout(`updated: ${file}`);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Executes CLI flow and returns process-like exit code.
|
|
238
|
-
* @param {string[]} argv - CLI arguments.
|
|
239
|
-
* @param {{
|
|
240
|
-
* runner?: (options: Record<string, unknown>) => Promise<unknown>,
|
|
241
|
-
* stdout?: (message: string) => void,
|
|
242
|
-
* stderr?: (message: string) => void
|
|
243
|
-
* }} [deps={}] - Dependency overrides for tests.
|
|
244
|
-
* @returns {Promise<number>} Exit code.
|
|
245
|
-
*/
|
|
246
|
-
export async function runCli(argv, deps = {}) {
|
|
247
|
-
const runner = deps.runner || fixHeaders;
|
|
248
|
-
const stdout = deps.stdout || console.log;
|
|
249
|
-
const stderr = deps.stderr || console.error;
|
|
250
|
-
|
|
251
|
-
try {
|
|
252
|
-
const parsed = parseCliArgs(argv);
|
|
253
|
-
if (parsed.help) {
|
|
254
|
-
stdout(HELP_TEXT);
|
|
255
|
-
return 0;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const finalOptions = await applyConfigFile(parsed.options);
|
|
259
|
-
const result = await runner(finalOptions);
|
|
260
|
-
|
|
261
|
-
if (parsed.json) {
|
|
262
|
-
stdout(JSON.stringify(result, null, 2));
|
|
263
|
-
return 0;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (result && typeof result === "object") {
|
|
267
|
-
const report = /** @type {{filesScanned?: number, filesUpdated?: number, dryRun?: boolean}} */ (result);
|
|
268
|
-
stdout(
|
|
269
|
-
`fix-headers complete: scanned=${report.filesScanned ?? 0}, updated=${report.filesUpdated ?? 0}, dryRun=${report.dryRun === true}`
|
|
270
|
-
);
|
|
271
|
-
if (finalOptions.verbose === true) {
|
|
272
|
-
printChangedFiles(stdout, result);
|
|
273
|
-
}
|
|
274
|
-
if (finalOptions.sampleOutput === true) {
|
|
275
|
-
printSampleOutput(stdout, result);
|
|
276
|
-
}
|
|
277
|
-
} else {
|
|
278
|
-
if (finalOptions.verbose === true) {
|
|
279
|
-
printChangedFiles(stdout, result);
|
|
280
|
-
}
|
|
281
|
-
if (finalOptions.sampleOutput === true) {
|
|
282
|
-
printSampleOutput(stdout, result);
|
|
283
|
-
}
|
|
284
|
-
stdout("fix-headers complete");
|
|
285
|
-
}
|
|
286
|
-
return 0;
|
|
287
|
-
} catch (error) {
|
|
288
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
289
|
-
stderr(`fix-headers failed: ${message}`);
|
|
290
|
-
return 1;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Executes CLI flow when the module is the process entrypoint.
|
|
296
|
-
* @param {string[]} [argv=process.argv] - Process argument vector.
|
|
297
|
-
* @param {string} [moduleUrl=import.meta.url] - Current module URL.
|
|
298
|
-
* @param {(args: string[]) => Promise<number>} [executor=runCli] - CLI executor.
|
|
299
|
-
* @returns {boolean} Whether the entrypoint branch was executed.
|
|
300
|
-
*/
|
|
301
|
-
export function runCliAsMain(argv = process.argv, moduleUrl = import.meta.url, executor = runCli) {
|
|
302
|
-
let isMain = false;
|
|
303
|
-
if (argv[1]) {
|
|
304
|
-
try {
|
|
305
|
-
const argvRealPath = realpathSync(argv[1]);
|
|
306
|
-
const moduleRealPath = realpathSync(fileURLToPath(moduleUrl));
|
|
307
|
-
isMain = argvRealPath === moduleRealPath;
|
|
308
|
-
} catch {
|
|
309
|
-
isMain = moduleUrl === pathToFileURL(argv[1]).href;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
if (!isMain) {
|
|
313
|
-
return false;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
executor(argv.slice(2)).then((code) => {
|
|
317
|
-
process.exitCode = code;
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
return true;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
runCliAsMain();
|
package/src/constants.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @Project: @cldmv/fix-headers
|
|
3
|
-
* @Filename: /src/constants.mjs
|
|
4
|
-
* @Date: 2026-03-01T17:59:32-08:00 (1772416772)
|
|
5
|
-
* @Author: Nate Corcoran <CLDMV>
|
|
6
|
-
* @Email: <Shinrai@users.noreply.github.com>
|
|
7
|
-
* -----
|
|
8
|
-
* @Last modified by: Nate Corcoran <CLDMV> (Shinrai@users.noreply.github.com)
|
|
9
|
-
* @Last modified time: 2026-03-01T17:59:32-08:00 (1772416772)
|
|
10
|
-
* -----
|
|
11
|
-
* @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @fileoverview Shared constants for project/language detection and header defaults.
|
|
16
|
-
* @module fix-headers/constants
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
export { DETECTOR_PROFILES, getAllowedExtensions, getEnabledDetectors } from "./detectors/index.mjs";
|
|
20
|
-
|
|
21
|
-
/** @type {string} */
|
|
22
|
-
export const DEFAULT_COMPANY_NAME = "Catalyzed Motivation Inc.";
|
|
23
|
-
|
|
24
|
-
/** Header must sit near the top of the file, but a metadata block can legitimately
|
|
25
|
-
* run long; cap the scan generously so a long block's closing `*/` is still seen.
|
|
26
|
-
* @type {number} */
|
|
27
|
-
export const DEFAULT_MAX_HEADER_SCAN_LINES = 200;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Folders skipped at ANY depth — vendored / VCS directories that are never source and can
|
|
31
|
-
* legitimately nest (hoisted `node_modules`, submodule `.git`).
|
|
32
|
-
* @type {Set<string>}
|
|
33
|
-
*/
|
|
34
|
-
export const ALWAYS_IGNORE_FOLDERS = new Set([".git", "node_modules"]);
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Folders skipped ONLY at the project root — build / cache output directories. Anchored to
|
|
38
|
-
* the root so a nested SOURCE directory that happens to share the name (e.g. `tools/build`,
|
|
39
|
-
* `packages/x/dist`-style source) is still processed; only the top-level `/build`, `/dist`,
|
|
40
|
-
* `/coverage`, … are ignored.
|
|
41
|
-
* @type {Set<string>}
|
|
42
|
-
*/
|
|
43
|
-
export const ROOT_IGNORE_FOLDERS = new Set(["dist", "build", "coverage", "tmp", ".next", ".turbo"]);
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Backward-compatible union of {@link ALWAYS_IGNORE_FOLDERS} and {@link ROOT_IGNORE_FOLDERS}.
|
|
47
|
-
* Discovery applies the two sets with different scoping; prefer the specific sets.
|
|
48
|
-
* @type {Set<string>}
|
|
49
|
-
*/
|
|
50
|
-
export const DEFAULT_IGNORE_FOLDERS = new Set([...ALWAYS_IGNORE_FOLDERS, ...ROOT_IGNORE_FOLDERS]);
|