@cldmv/fix-headers 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.
Files changed (47) hide show
  1. package/README.md +157 -0
  2. package/index.cjs +39 -0
  3. package/index.mjs +7 -0
  4. package/package.json +56 -0
  5. package/src/cli.mjs +216 -0
  6. package/src/constants.mjs +15 -0
  7. package/src/core/file-discovery.mjs +133 -0
  8. package/src/core/fix-headers.mjs +210 -0
  9. package/src/detect/project.mjs +175 -0
  10. package/src/detectors/css.mjs +54 -0
  11. package/src/detectors/go.mjs +52 -0
  12. package/src/detectors/html.mjs +54 -0
  13. package/src/detectors/index.mjs +160 -0
  14. package/src/detectors/node.mjs +63 -0
  15. package/src/detectors/php.mjs +53 -0
  16. package/src/detectors/python.mjs +48 -0
  17. package/src/detectors/rust.mjs +49 -0
  18. package/src/detectors/shared.mjs +32 -0
  19. package/src/fix-header.mjs +30 -0
  20. package/src/header/parser.mjs +76 -0
  21. package/src/header/syntax.mjs +54 -0
  22. package/src/header/template.mjs +44 -0
  23. package/src/utils/fs.mjs +125 -0
  24. package/src/utils/git.mjs +97 -0
  25. package/src/utils/time.mjs +31 -0
  26. package/types/index.d.mts +2 -0
  27. package/types/src/cli.d.mts +44 -0
  28. package/types/src/constants.d.mts +7 -0
  29. package/types/src/core/file-discovery.d.mts +22 -0
  30. package/types/src/core/fix-headers.d.mts +86 -0
  31. package/types/src/detect/project.d.mts +81 -0
  32. package/types/src/detectors/css.d.mts +25 -0
  33. package/types/src/detectors/go.d.mts +25 -0
  34. package/types/src/detectors/html.d.mts +25 -0
  35. package/types/src/detectors/index.d.mts +66 -0
  36. package/types/src/detectors/node.d.mts +25 -0
  37. package/types/src/detectors/php.d.mts +25 -0
  38. package/types/src/detectors/python.d.mts +23 -0
  39. package/types/src/detectors/rust.d.mts +25 -0
  40. package/types/src/detectors/shared.d.mts +14 -0
  41. package/types/src/fix-header.d.mts +12 -0
  42. package/types/src/header/parser.d.mts +43 -0
  43. package/types/src/header/syntax.d.mts +44 -0
  44. package/types/src/header/template.d.mts +52 -0
  45. package/types/src/utils/fs.d.mts +50 -0
  46. package/types/src/utils/git.d.mts +40 -0
  47. package/types/src/utils/time.d.mts +19 -0
@@ -0,0 +1,25 @@
1
+ export namespace detector {
2
+ export let id: string;
3
+ export let priority: number;
4
+ export { markers };
5
+ export { extensions };
6
+ export let enabledByDefault: boolean;
7
+ export function findNearestConfig(startPath: any): Promise<{
8
+ root: string;
9
+ marker: string;
10
+ }>;
11
+ export function parseProjectName(_marker: any, markerContent: any, rootDirName: any): any;
12
+ export function resolveCommentSyntax(filePath: any): {
13
+ kind: "block";
14
+ blockStart: string;
15
+ blockLinePrefix: string;
16
+ blockEnd: string;
17
+ };
18
+ }
19
+ /**
20
+ * @fileoverview PHP detector implementation.
21
+ * @module fix-headers/detectors/php
22
+ */
23
+ declare const markers: string[];
24
+ declare const extensions: string[];
25
+ export {};
@@ -0,0 +1,23 @@
1
+ export namespace detector {
2
+ export let id: string;
3
+ export let priority: number;
4
+ export { markers };
5
+ export { extensions };
6
+ export let enabledByDefault: boolean;
7
+ export function findNearestConfig(startPath: any): Promise<{
8
+ root: string;
9
+ marker: string;
10
+ }>;
11
+ export function parseProjectName(_marker: any, markerContent: any, rootDirName: any): string;
12
+ export function resolveCommentSyntax(filePath: any): {
13
+ kind: string;
14
+ linePrefix: string;
15
+ };
16
+ }
17
+ /**
18
+ * @fileoverview Python detector implementation.
19
+ * @module fix-headers/detectors/python
20
+ */
21
+ declare const markers: string[];
22
+ declare const extensions: string[];
23
+ export {};
@@ -0,0 +1,25 @@
1
+ export namespace detector {
2
+ export let id: string;
3
+ export let priority: number;
4
+ export { markers };
5
+ export { extensions };
6
+ export let enabledByDefault: boolean;
7
+ export function findNearestConfig(startPath: any): Promise<{
8
+ root: string;
9
+ marker: string;
10
+ }>;
11
+ export function parseProjectName(_marker: any, markerContent: any, rootDirName: any): any;
12
+ export function resolveCommentSyntax(filePath: any): {
13
+ kind: "block";
14
+ blockStart: string;
15
+ blockLinePrefix: string;
16
+ blockEnd: string;
17
+ };
18
+ }
19
+ /**
20
+ * @fileoverview Rust detector implementation.
21
+ * @module fix-headers/detectors/rust
22
+ */
23
+ declare const markers: string[];
24
+ declare const extensions: string[];
25
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @fileoverview Shared detector helpers for nearest marker search.
3
+ * @module fix-headers/detectors/shared
4
+ */
5
+ /**
6
+ * Finds the closest marker file by walking up parent directories.
7
+ * @param {string} startPath - Starting directory or file path.
8
+ * @param {string[]} markers - Marker filenames to search.
9
+ * @returns {Promise<{root: string, marker: string} | null>} Closest located marker.
10
+ */
11
+ export function findNearestMarker(startPath: string, markers: string[]): Promise<{
12
+ root: string;
13
+ marker: string;
14
+ } | null>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileoverview Public module API exposing a single function for header updates.
3
+ * @module fix-headers
4
+ */
5
+ /**
6
+ * Runs header fix-up using automatic metadata detection and optional overrides.
7
+ * @param {Parameters<typeof fixHeadersCore>[0]} [options] - Runtime options.
8
+ * @returns {ReturnType<typeof fixHeadersCore>} Update report.
9
+ */
10
+ export function fixHeaders(options?: Parameters<typeof fixHeadersCore>[0]): ReturnType<typeof fixHeadersCore>;
11
+ export default fixHeaders;
12
+ import { fixHeaders as fixHeadersCore } from "./core/fix-headers.mjs";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Finds the first top-level project header block in a file.
3
+ * @param {string} content - File content.
4
+ * @param {string} [filePath=""] - File path used for syntax selection.
5
+ * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [syntaxOptions={}] - Syntax resolution options.
6
+ * @returns {{start: number, end: number} | null} Header location.
7
+ */
8
+ export function findProjectHeader(content: string, filePath?: string, syntaxOptions?: {
9
+ language?: string;
10
+ enabledDetectors?: string[];
11
+ disabledDetectors?: string[];
12
+ detectorSyntaxOverrides?: Record<string, {
13
+ linePrefix?: string;
14
+ blockStart?: string;
15
+ blockLinePrefix?: string;
16
+ blockEnd?: string;
17
+ }>;
18
+ }): {
19
+ start: number;
20
+ end: number;
21
+ } | null;
22
+ /**
23
+ * Replaces or inserts a project header block.
24
+ * @param {string} content - Original file content.
25
+ * @param {string} newHeader - Generated header text.
26
+ * @param {string} [filePath=""] - File path used for syntax selection.
27
+ * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [syntaxOptions={}] - Syntax resolution options.
28
+ * @returns {{nextContent: string, changed: boolean}} Updated content result.
29
+ */
30
+ export function replaceOrInsertHeader(content: string, newHeader: string, filePath?: string, syntaxOptions?: {
31
+ language?: string;
32
+ enabledDetectors?: string[];
33
+ disabledDetectors?: string[];
34
+ detectorSyntaxOverrides?: Record<string, {
35
+ linePrefix?: string;
36
+ blockStart?: string;
37
+ blockLinePrefix?: string;
38
+ blockEnd?: string;
39
+ }>;
40
+ }): {
41
+ nextContent: string;
42
+ changed: boolean;
43
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @fileoverview Header comment syntax helpers for mapping file extensions to comment styles.
3
+ * @module fix-headers/header/syntax
4
+ */
5
+ /**
6
+ * @typedef {{
7
+ * kind: "block" | "line" | "html",
8
+ * linePrefix?: string,
9
+ * blockStart?: string,
10
+ * blockLinePrefix?: string,
11
+ * blockEnd?: string
12
+ * }} HeaderSyntax
13
+ */
14
+ /**
15
+ * Resolves comment syntax for a file path based on extension.
16
+ * @param {string} filePath - Absolute or relative file path.
17
+ * @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [options={}] - Syntax resolution options.
18
+ * @returns {HeaderSyntax} Header syntax descriptor.
19
+ */
20
+ export function getHeaderSyntaxForFile(filePath: string, options?: {
21
+ language?: string;
22
+ enabledDetectors?: string[];
23
+ disabledDetectors?: string[];
24
+ detectorSyntaxOverrides?: Record<string, {
25
+ linePrefix?: string;
26
+ blockStart?: string;
27
+ blockLinePrefix?: string;
28
+ blockEnd?: string;
29
+ }>;
30
+ }): HeaderSyntax;
31
+ /**
32
+ * Renders header body lines using a chosen syntax.
33
+ * @param {HeaderSyntax} syntax - Header syntax descriptor.
34
+ * @param {string[]} lines - Header lines without comment wrappers.
35
+ * @returns {string} Formatted header block.
36
+ */
37
+ export function renderHeaderLines(syntax: HeaderSyntax, lines: string[]): string;
38
+ export type HeaderSyntax = {
39
+ kind: "block" | "line" | "html";
40
+ linePrefix?: string;
41
+ blockStart?: string;
42
+ blockLinePrefix?: string;
43
+ blockEnd?: string;
44
+ };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @fileoverview Header template builder used to generate normalized file headers.
3
+ * @module fix-headers/header/template
4
+ */
5
+ /**
6
+ * Builds a normalized header block for a source file.
7
+ * @param {{
8
+ * absoluteFilePath: string,
9
+ * language?: string,
10
+ * syntaxOptions?: { language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> },
11
+ * projectRoot: string,
12
+ * projectName: string,
13
+ * authorName: string,
14
+ * authorEmail: string,
15
+ * createdAt: {date: string, timestamp: number},
16
+ * lastModifiedAt: {date: string, timestamp: number},
17
+ * copyrightStartYear: number,
18
+ * companyName: string,
19
+ * currentYear: number
20
+ * }} data - Header data.
21
+ * @returns {string} Header block text.
22
+ */
23
+ export function buildHeader(data: {
24
+ absoluteFilePath: string;
25
+ language?: string;
26
+ syntaxOptions?: {
27
+ language?: string;
28
+ enabledDetectors?: string[];
29
+ disabledDetectors?: string[];
30
+ detectorSyntaxOverrides?: Record<string, {
31
+ linePrefix?: string;
32
+ blockStart?: string;
33
+ blockLinePrefix?: string;
34
+ blockEnd?: string;
35
+ }>;
36
+ };
37
+ projectRoot: string;
38
+ projectName: string;
39
+ authorName: string;
40
+ authorEmail: string;
41
+ createdAt: {
42
+ date: string;
43
+ timestamp: number;
44
+ };
45
+ lastModifiedAt: {
46
+ date: string;
47
+ timestamp: number;
48
+ };
49
+ copyrightStartYear: number;
50
+ companyName: string;
51
+ currentYear: number;
52
+ }): string;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @fileoverview Filesystem helpers for project discovery and recursive scanning.
3
+ * @module fix-headers/utils/fs
4
+ */
5
+ /**
6
+ * Checks whether a file exists and is readable.
7
+ * @param {string} filePath - Absolute or relative path.
8
+ * @returns {Promise<boolean>} True when the path exists.
9
+ */
10
+ export function pathExists(filePath: string): Promise<boolean>;
11
+ /**
12
+ * Finds a marker file by traversing upward from a directory.
13
+ * @param {string} startDir - Starting directory.
14
+ * @param {string[]} markerFiles - Candidate marker file names.
15
+ * @returns {Promise<{root: string, marker: string} | null>} First match with root path.
16
+ */
17
+ export function findProjectRoot(startDir: string, markerFiles: string[]): Promise<{
18
+ root: string;
19
+ marker: string;
20
+ } | null>;
21
+ /**
22
+ * Reads UTF-8 file content if it exists.
23
+ * @param {string} filePath - File path.
24
+ * @returns {Promise<string | null>} File content or null when missing.
25
+ */
26
+ export function readTextIfExists(filePath: string): Promise<string | null>;
27
+ /**
28
+ * Recursively discovers files matching allowed extensions.
29
+ * @param {string} dirPath - Root directory to scan.
30
+ * @param {{
31
+ * allowedExtensions: Set<string>,
32
+ * ignoreFolders: Set<string>,
33
+ * shouldSkipDirectory?: (directoryPath: string, directoryName: string) => boolean
34
+ * }} options - Scan options.
35
+ * @returns {Promise<string[]>} Matching file paths.
36
+ */
37
+ export function walkFiles(dirPath: string, options: {
38
+ allowedExtensions: Set<string>;
39
+ ignoreFolders: Set<string>;
40
+ shouldSkipDirectory?: (directoryPath: string, directoryName: string) => boolean;
41
+ }): Promise<string[]>;
42
+ /**
43
+ * Gets creation-like and modified timestamps from filesystem stats.
44
+ * @param {string} filePath - Absolute file path.
45
+ * @returns {Promise<{createdAt: Date, updatedAt: Date}>} Date pair.
46
+ */
47
+ export function readFileDates(filePath: string): Promise<{
48
+ createdAt: Date;
49
+ updatedAt: Date;
50
+ }>;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @fileoverview Git helpers for author identity and file history metadata.
3
+ * @module fix-headers/utils/git
4
+ */
5
+ /**
6
+ * Runs a git command and returns trimmed stdout.
7
+ * @param {string} cwd - Working directory.
8
+ * @param {string[]} args - Git command arguments.
9
+ * @returns {Promise<string | null>} Trimmed stdout or null on failure.
10
+ */
11
+ export function runGit(cwd: string, args: string[]): Promise<string | null>;
12
+ /**
13
+ * Detects git author name and email from config or commit history.
14
+ * @param {string} cwd - Project directory.
15
+ * @returns {Promise<{authorName: string | null, authorEmail: string | null}>} Author information.
16
+ */
17
+ export function detectGitAuthor(cwd: string): Promise<{
18
+ authorName: string | null;
19
+ authorEmail: string | null;
20
+ }>;
21
+ /**
22
+ * Gets a file's first commit date from git history.
23
+ * @param {string} cwd - Project directory.
24
+ * @param {string} filePath - Relative file path.
25
+ * @returns {Promise<{date: string, timestamp: number} | null>} Git creation date payload.
26
+ */
27
+ export function getGitCreationDate(cwd: string, filePath: string): Promise<{
28
+ date: string;
29
+ timestamp: number;
30
+ } | null>;
31
+ /**
32
+ * Gets a file's latest commit date from git history.
33
+ * @param {string} cwd - Project directory.
34
+ * @param {string} filePath - Relative file path.
35
+ * @returns {Promise<{date: string, timestamp: number} | null>} Git last-modified payload.
36
+ */
37
+ export function getGitLastModifiedDate(cwd: string, filePath: string): Promise<{
38
+ date: string;
39
+ timestamp: number;
40
+ } | null>;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @fileoverview Date/time helpers used for header timestamp formatting.
3
+ * @module fix-headers/utils/time
4
+ */
5
+ /**
6
+ * Formats a date as `YYYY-MM-DD HH:mm:ss ±HH:MM`.
7
+ * @param {Date} date - Input date.
8
+ * @returns {string} Formatted date string.
9
+ */
10
+ export function formatDateWithTimezone(date: Date): string;
11
+ /**
12
+ * Returns a formatted date and unix timestamp.
13
+ * @param {Date} [date=new Date()] - Date value to format.
14
+ * @returns {{ date: string, timestamp: number }} Formatted datetime payload.
15
+ */
16
+ export function toDatePayload(date?: Date): {
17
+ date: string;
18
+ timestamp: number;
19
+ };