@cldmv/fix-headers 1.1.0 → 1.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 +1 -0
- package/package.json +1 -1
- package/src/cli.mjs +14 -3
- package/src/core/fix-headers.mjs +1 -0
- package/src/detect/project.mjs +26 -1
- package/src/detectors/json.mjs +76 -0
- package/src/detectors/node.mjs +1 -1
package/README.md
CHANGED
|
@@ -100,6 +100,7 @@ Important options:
|
|
|
100
100
|
- `marker?: string | null`
|
|
101
101
|
- `authorName?: string`
|
|
102
102
|
- `authorEmail?: string`
|
|
103
|
+
- `company?: string` - appends to `@Author` as `Name <Company>`
|
|
103
104
|
- `forceAuthorUpdate?: boolean` - force update `@Author`/`@Email` to detected or overridden current values
|
|
104
105
|
- `useGpgSignerAuthor?: boolean` - use signed-commit UID (`%GS`) for detected `@Author` (includes signer comment when present)
|
|
105
106
|
- `companyName?: string` (default: `Catalyzed Motivation Inc.`)
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { readFile } from "node:fs/promises";
|
|
16
|
+
import { realpathSync } from "node:fs";
|
|
16
17
|
import { isAbsolute, join } from "node:path";
|
|
17
|
-
import { pathToFileURL } from "node:url";
|
|
18
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
18
19
|
import fixHeaders from "./fix-header.mjs";
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -22,7 +23,7 @@ import fixHeaders from "./fix-header.mjs";
|
|
|
22
23
|
* @module fix-headers/cli
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
|
-
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 --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 <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`;
|
|
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 --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`;
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Converts CLI flag token to camelCase key.
|
|
@@ -62,6 +63,7 @@ export function parseCliArgs(argv) {
|
|
|
62
63
|
marker: "marker",
|
|
63
64
|
"author-name": "authorName",
|
|
64
65
|
"author-email": "authorEmail",
|
|
66
|
+
company: "company",
|
|
65
67
|
"company-name": "companyName",
|
|
66
68
|
"copyright-start-year": "copyrightStartYear",
|
|
67
69
|
config: "config"
|
|
@@ -293,7 +295,16 @@ export async function runCli(argv, deps = {}) {
|
|
|
293
295
|
* @returns {boolean} Whether the entrypoint branch was executed.
|
|
294
296
|
*/
|
|
295
297
|
export function runCliAsMain(argv = process.argv, moduleUrl = import.meta.url, executor = runCli) {
|
|
296
|
-
|
|
298
|
+
let isMain = false;
|
|
299
|
+
if (argv[1]) {
|
|
300
|
+
try {
|
|
301
|
+
const argvRealPath = realpathSync(argv[1]);
|
|
302
|
+
const moduleRealPath = realpathSync(fileURLToPath(moduleUrl));
|
|
303
|
+
isMain = argvRealPath === moduleRealPath;
|
|
304
|
+
} catch {
|
|
305
|
+
isMain = moduleUrl === pathToFileURL(argv[1]).href;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
297
308
|
if (!isMain) {
|
|
298
309
|
return false;
|
|
299
310
|
}
|
package/src/core/fix-headers.mjs
CHANGED
package/src/detect/project.mjs
CHANGED
|
@@ -73,6 +73,29 @@ async function findClosestDetectorMatch(startPath, detectors, preferredExtension
|
|
|
73
73
|
return closest;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Appends company suffix to author display name when requested.
|
|
78
|
+
* @param {string} authorName - Base author name.
|
|
79
|
+
* @param {string | undefined} company - Optional company suffix value.
|
|
80
|
+
* @returns {string} Formatted author name.
|
|
81
|
+
*/
|
|
82
|
+
function formatAuthorNameWithCompany(authorName, company) {
|
|
83
|
+
if (typeof company !== "string") {
|
|
84
|
+
return authorName;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const trimmedCompany = company.trim();
|
|
88
|
+
if (trimmedCompany.length === 0) {
|
|
89
|
+
return authorName;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (/<[^>]+>/.test(authorName)) {
|
|
93
|
+
return authorName;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return `${authorName} <${trimmedCompany}>`;
|
|
97
|
+
}
|
|
98
|
+
|
|
76
99
|
/**
|
|
77
100
|
* Detects project root and language by scanning known marker files.
|
|
78
101
|
* @param {string} cwd - Starting working directory.
|
|
@@ -126,6 +149,7 @@ export async function detectProjectFromMarkers(cwd, options = {}) {
|
|
|
126
149
|
* useGpgSignerAuthor?: boolean,
|
|
127
150
|
* authorName?: string,
|
|
128
151
|
* authorEmail?: string,
|
|
152
|
+
* company?: string,
|
|
129
153
|
* companyName?: string,
|
|
130
154
|
* copyrightStartYear?: number
|
|
131
155
|
* }} [options={}] - Detection options and overrides.
|
|
@@ -151,13 +175,14 @@ export async function resolveProjectMetadata(options = {}) {
|
|
|
151
175
|
useGpgSignerAuthor: options.useGpgSignerAuthor === true
|
|
152
176
|
});
|
|
153
177
|
const currentYear = new Date().getFullYear();
|
|
178
|
+
const baseAuthorName = options.authorName || gitAuthor.authorName || "Unknown Author";
|
|
154
179
|
|
|
155
180
|
return {
|
|
156
181
|
projectName: options.projectName || detected.projectName,
|
|
157
182
|
language: options.language || detected.language,
|
|
158
183
|
projectRoot: options.projectRoot || detected.rootDir,
|
|
159
184
|
marker: options.marker === undefined ? detected.marker : options.marker,
|
|
160
|
-
authorName: options.
|
|
185
|
+
authorName: formatAuthorNameWithCompany(baseAuthorName, options.company),
|
|
161
186
|
authorEmail: options.authorEmail || gitAuthor.authorEmail || "unknown@example.com",
|
|
162
187
|
companyName: options.companyName || DEFAULT_COMPANY_NAME,
|
|
163
188
|
copyrightStartYear: Number.isInteger(options.copyrightStartYear) ? Number(options.copyrightStartYear) : currentYear
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Project: @cldmv/fix-headers
|
|
3
|
+
* @Filename: /src/detectors/json.mjs
|
|
4
|
+
* @Date: 2026-03-01 20:00:00 -08:00 (1772433600)
|
|
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-01 20:00:00 -08:00 (1772433600)
|
|
10
|
+
* -----
|
|
11
|
+
* @Copyright: Copyright (c) 2026-2026 Catalyzed Motivation Inc. All rights reserved.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { extname } from "node:path";
|
|
15
|
+
import { findNearestMarker } from "./shared.mjs";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @fileoverview JSON-family detector implementation.
|
|
19
|
+
* @module fix-headers/detectors/json
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const markers = ["package.json"];
|
|
23
|
+
const extensions = [".jsonv", ".jsonc", ".json5"];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Parses project name from package marker content.
|
|
27
|
+
* @param {string} markerContent - Marker file content.
|
|
28
|
+
* @param {string} rootDirName - Fallback root directory name.
|
|
29
|
+
* @returns {string} Project name.
|
|
30
|
+
*/
|
|
31
|
+
function parseJsonProjectName(markerContent, rootDirName) {
|
|
32
|
+
try {
|
|
33
|
+
const parsed = JSON.parse(markerContent);
|
|
34
|
+
if (typeof parsed.name === "string" && parsed.name.trim().length > 0) {
|
|
35
|
+
return parsed.name.trim();
|
|
36
|
+
}
|
|
37
|
+
return rootDirName;
|
|
38
|
+
} catch {
|
|
39
|
+
return rootDirName;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resolves comment syntax for JSON-family file extensions.
|
|
45
|
+
* @param {string} filePath - File path.
|
|
46
|
+
* @returns {{kind: "block", blockStart: string, blockLinePrefix: string, blockEnd: string} | null} Syntax descriptor.
|
|
47
|
+
*/
|
|
48
|
+
function resolveJsonCommentSyntax(filePath) {
|
|
49
|
+
const extension = extname(filePath).toLowerCase();
|
|
50
|
+
if (extensions.includes(extension)) {
|
|
51
|
+
return {
|
|
52
|
+
kind: "block",
|
|
53
|
+
blockStart: "/**",
|
|
54
|
+
blockLinePrefix: " *\t",
|
|
55
|
+
blockEnd: " */"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const detector = {
|
|
62
|
+
id: "json",
|
|
63
|
+
priority: 95,
|
|
64
|
+
markers,
|
|
65
|
+
extensions,
|
|
66
|
+
enabledByDefault: true,
|
|
67
|
+
findNearestConfig(startPath) {
|
|
68
|
+
return findNearestMarker(startPath, markers);
|
|
69
|
+
},
|
|
70
|
+
parseProjectName(_marker, markerContent, rootDirName) {
|
|
71
|
+
return parseJsonProjectName(markerContent, rootDirName);
|
|
72
|
+
},
|
|
73
|
+
resolveCommentSyntax(filePath) {
|
|
74
|
+
return resolveJsonCommentSyntax(filePath);
|
|
75
|
+
}
|
|
76
|
+
};
|
package/src/detectors/node.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import { findNearestMarker } from "./shared.mjs";
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
const markers = ["package.json"];
|
|
23
|
-
const extensions = [".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx"
|
|
23
|
+
const extensions = [".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx"];
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Parses Node project name from package marker content.
|