@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.
- package/README.md +157 -0
- package/index.cjs +39 -0
- package/index.mjs +7 -0
- package/package.json +56 -0
- package/src/cli.mjs +216 -0
- package/src/constants.mjs +15 -0
- package/src/core/file-discovery.mjs +133 -0
- package/src/core/fix-headers.mjs +210 -0
- package/src/detect/project.mjs +175 -0
- package/src/detectors/css.mjs +54 -0
- package/src/detectors/go.mjs +52 -0
- package/src/detectors/html.mjs +54 -0
- package/src/detectors/index.mjs +160 -0
- package/src/detectors/node.mjs +63 -0
- package/src/detectors/php.mjs +53 -0
- package/src/detectors/python.mjs +48 -0
- package/src/detectors/rust.mjs +49 -0
- package/src/detectors/shared.mjs +32 -0
- package/src/fix-header.mjs +30 -0
- package/src/header/parser.mjs +76 -0
- package/src/header/syntax.mjs +54 -0
- package/src/header/template.mjs +44 -0
- package/src/utils/fs.mjs +125 -0
- package/src/utils/git.mjs +97 -0
- package/src/utils/time.mjs +31 -0
- package/types/index.d.mts +2 -0
- package/types/src/cli.d.mts +44 -0
- package/types/src/constants.d.mts +7 -0
- package/types/src/core/file-discovery.d.mts +22 -0
- package/types/src/core/fix-headers.d.mts +86 -0
- package/types/src/detect/project.d.mts +81 -0
- package/types/src/detectors/css.d.mts +25 -0
- package/types/src/detectors/go.d.mts +25 -0
- package/types/src/detectors/html.d.mts +25 -0
- package/types/src/detectors/index.d.mts +66 -0
- package/types/src/detectors/node.d.mts +25 -0
- package/types/src/detectors/php.d.mts +25 -0
- package/types/src/detectors/python.d.mts +23 -0
- package/types/src/detectors/rust.d.mts +25 -0
- package/types/src/detectors/shared.d.mts +14 -0
- package/types/src/fix-header.d.mts +12 -0
- package/types/src/header/parser.d.mts +43 -0
- package/types/src/header/syntax.d.mts +44 -0
- package/types/src/header/template.d.mts +52 -0
- package/types/src/utils/fs.d.mts +50 -0
- package/types/src/utils/git.d.mts +40 -0
- package/types/src/utils/time.d.mts +19 -0
package/src/utils/fs.mjs
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { access, readdir, readFile, stat } from "node:fs/promises";
|
|
2
|
+
import { constants as fsConstants } from "node:fs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview Filesystem helpers for project discovery and recursive scanning.
|
|
7
|
+
* @module fix-headers/utils/fs
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Checks whether a file exists and is readable.
|
|
12
|
+
* @param {string} filePath - Absolute or relative path.
|
|
13
|
+
* @returns {Promise<boolean>} True when the path exists.
|
|
14
|
+
*/
|
|
15
|
+
export async function pathExists(filePath) {
|
|
16
|
+
try {
|
|
17
|
+
await access(filePath, fsConstants.F_OK);
|
|
18
|
+
return true;
|
|
19
|
+
} catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Finds a marker file by traversing upward from a directory.
|
|
26
|
+
* @param {string} startDir - Starting directory.
|
|
27
|
+
* @param {string[]} markerFiles - Candidate marker file names.
|
|
28
|
+
* @returns {Promise<{root: string, marker: string} | null>} First match with root path.
|
|
29
|
+
*/
|
|
30
|
+
export async function findProjectRoot(startDir, markerFiles) {
|
|
31
|
+
let currentDir = resolve(startDir);
|
|
32
|
+
|
|
33
|
+
while (true) {
|
|
34
|
+
for (const marker of markerFiles) {
|
|
35
|
+
const markerPath = join(currentDir, marker);
|
|
36
|
+
if (await pathExists(markerPath)) {
|
|
37
|
+
return { root: currentDir, marker };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const parent = dirname(currentDir);
|
|
42
|
+
if (parent === currentDir) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
currentDir = parent;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Reads UTF-8 file content if it exists.
|
|
52
|
+
* @param {string} filePath - File path.
|
|
53
|
+
* @returns {Promise<string | null>} File content or null when missing.
|
|
54
|
+
*/
|
|
55
|
+
export async function readTextIfExists(filePath) {
|
|
56
|
+
if (!(await pathExists(filePath))) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return readFile(filePath, "utf8");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Recursively discovers files matching allowed extensions.
|
|
65
|
+
* @param {string} dirPath - Root directory to scan.
|
|
66
|
+
* @param {{
|
|
67
|
+
* allowedExtensions: Set<string>,
|
|
68
|
+
* ignoreFolders: Set<string>,
|
|
69
|
+
* shouldSkipDirectory?: (directoryPath: string, directoryName: string) => boolean
|
|
70
|
+
* }} options - Scan options.
|
|
71
|
+
* @returns {Promise<string[]>} Matching file paths.
|
|
72
|
+
*/
|
|
73
|
+
export async function walkFiles(dirPath, options) {
|
|
74
|
+
const files = [];
|
|
75
|
+
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
76
|
+
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
const fullPath = join(dirPath, entry.name);
|
|
79
|
+
|
|
80
|
+
if (entry.isDirectory() && options.ignoreFolders.has(entry.name)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (entry.isDirectory() && options.shouldSkipDirectory?.(fullPath, entry.name) === true) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (entry.isDirectory()) {
|
|
89
|
+
const nested = await walkFiles(fullPath, options);
|
|
90
|
+
files.push(...nested);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!entry.isFile()) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const extensionStart = entry.name.lastIndexOf(".");
|
|
99
|
+
if (extensionStart === -1) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const extension = entry.name.slice(extensionStart).toLowerCase();
|
|
104
|
+
if (options.allowedExtensions.has(extension)) {
|
|
105
|
+
files.push(fullPath);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return files;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Gets creation-like and modified timestamps from filesystem stats.
|
|
114
|
+
* @param {string} filePath - Absolute file path.
|
|
115
|
+
* @returns {Promise<{createdAt: Date, updatedAt: Date}>} Date pair.
|
|
116
|
+
*/
|
|
117
|
+
export async function readFileDates(filePath) {
|
|
118
|
+
const fileStats = await stat(filePath);
|
|
119
|
+
const createdAt = fileStats.birthtimeMs > 0 ? fileStats.birthtime : fileStats.mtime;
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
createdAt,
|
|
123
|
+
updatedAt: fileStats.mtime
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
|
|
4
|
+
const execFileAsync = promisify(execFile);
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview Git helpers for author identity and file history metadata.
|
|
8
|
+
* @module fix-headers/utils/git
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Runs a git command and returns trimmed stdout.
|
|
13
|
+
* @param {string} cwd - Working directory.
|
|
14
|
+
* @param {string[]} args - Git command arguments.
|
|
15
|
+
* @returns {Promise<string | null>} Trimmed stdout or null on failure.
|
|
16
|
+
*/
|
|
17
|
+
export async function runGit(cwd, args) {
|
|
18
|
+
try {
|
|
19
|
+
const { stdout } = await execFileAsync("git", args, { cwd });
|
|
20
|
+
const value = stdout.trim();
|
|
21
|
+
return value.length > 0 ? value : null;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Detects git author name and email from config or commit history.
|
|
29
|
+
* @param {string} cwd - Project directory.
|
|
30
|
+
* @returns {Promise<{authorName: string | null, authorEmail: string | null}>} Author information.
|
|
31
|
+
*/
|
|
32
|
+
export async function detectGitAuthor(cwd) {
|
|
33
|
+
let authorName = await runGit(cwd, ["config", "--get", "user.name"]);
|
|
34
|
+
let authorEmail = await runGit(cwd, ["config", "--get", "user.email"]);
|
|
35
|
+
|
|
36
|
+
if (!authorName || !authorEmail) {
|
|
37
|
+
const fallback = await runGit(cwd, ["log", "-1", "--format=%an|%ae"]);
|
|
38
|
+
if (fallback) {
|
|
39
|
+
const [fallbackName, fallbackEmail] = fallback.split("|");
|
|
40
|
+
authorName = authorName || fallbackName || null;
|
|
41
|
+
authorEmail = authorEmail || fallbackEmail || null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { authorName, authorEmail };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Gets a file's first commit date from git history.
|
|
50
|
+
* @param {string} cwd - Project directory.
|
|
51
|
+
* @param {string} filePath - Relative file path.
|
|
52
|
+
* @returns {Promise<{date: string, timestamp: number} | null>} Git creation date payload.
|
|
53
|
+
*/
|
|
54
|
+
export async function getGitCreationDate(cwd, filePath) {
|
|
55
|
+
const output = await runGit(cwd, ["log", "--follow", "--format=%aI|%at", "--reverse", "--", filePath]);
|
|
56
|
+
if (!output) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const firstLine = output.split("\n")[0];
|
|
61
|
+
const [date, timestampText] = firstLine.split("|");
|
|
62
|
+
if (!date || !timestampText) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const timestamp = Number.parseInt(timestampText, 10);
|
|
67
|
+
if (Number.isNaN(timestamp)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return { date, timestamp };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Gets a file's latest commit date from git history.
|
|
76
|
+
* @param {string} cwd - Project directory.
|
|
77
|
+
* @param {string} filePath - Relative file path.
|
|
78
|
+
* @returns {Promise<{date: string, timestamp: number} | null>} Git last-modified payload.
|
|
79
|
+
*/
|
|
80
|
+
export async function getGitLastModifiedDate(cwd, filePath) {
|
|
81
|
+
const output = await runGit(cwd, ["log", "-1", "--format=%aI|%at", "--", filePath]);
|
|
82
|
+
if (!output) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const [date, timestampText] = output.split("|");
|
|
87
|
+
if (!date || !timestampText) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const timestamp = Number.parseInt(timestampText, 10);
|
|
92
|
+
if (Number.isNaN(timestamp)) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { date, timestamp };
|
|
97
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Date/time helpers used for header timestamp formatting.
|
|
3
|
+
* @module fix-headers/utils/time
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Formats a date as `YYYY-MM-DD HH:mm:ss ±HH:MM`.
|
|
8
|
+
* @param {Date} date - Input date.
|
|
9
|
+
* @returns {string} Formatted date string.
|
|
10
|
+
*/
|
|
11
|
+
export function formatDateWithTimezone(date) {
|
|
12
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
13
|
+
const tzOffset = -date.getTimezoneOffset();
|
|
14
|
+
const sign = tzOffset >= 0 ? "+" : "-";
|
|
15
|
+
const tzHours = pad(Math.floor(Math.abs(tzOffset) / 60));
|
|
16
|
+
const tzMinutes = pad(Math.abs(tzOffset) % 60);
|
|
17
|
+
|
|
18
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())} ${sign}${tzHours}:${tzMinutes}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns a formatted date and unix timestamp.
|
|
23
|
+
* @param {Date} [date=new Date()] - Date value to format.
|
|
24
|
+
* @returns {{ date: string, timestamp: number }} Formatted datetime payload.
|
|
25
|
+
*/
|
|
26
|
+
export function toDatePayload(date = new Date()) {
|
|
27
|
+
return {
|
|
28
|
+
date: formatDateWithTimezone(date),
|
|
29
|
+
timestamp: Math.floor(date.getTime() / 1000)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Parses CLI arguments into fixHeaders options and control flags.
|
|
4
|
+
* @param {string[]} argv - Process argument vector without node/script items.
|
|
5
|
+
* @returns {{
|
|
6
|
+
* options: Record<string, unknown>,
|
|
7
|
+
* help: boolean,
|
|
8
|
+
* json: boolean
|
|
9
|
+
* }} Parsed CLI payload.
|
|
10
|
+
*/
|
|
11
|
+
export function parseCliArgs(argv: string[]): {
|
|
12
|
+
options: Record<string, unknown>;
|
|
13
|
+
help: boolean;
|
|
14
|
+
json: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Loads extra options from a JSON config file.
|
|
18
|
+
* @param {Record<string, unknown>} options - Current options object.
|
|
19
|
+
* @returns {Promise<Record<string, unknown>>} Merged options object.
|
|
20
|
+
*/
|
|
21
|
+
export function applyConfigFile(options: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
22
|
+
/**
|
|
23
|
+
* Executes CLI flow and returns process-like exit code.
|
|
24
|
+
* @param {string[]} argv - CLI arguments.
|
|
25
|
+
* @param {{
|
|
26
|
+
* runner?: (options: Record<string, unknown>) => Promise<unknown>,
|
|
27
|
+
* stdout?: (message: string) => void,
|
|
28
|
+
* stderr?: (message: string) => void
|
|
29
|
+
* }} [deps={}] - Dependency overrides for tests.
|
|
30
|
+
* @returns {Promise<number>} Exit code.
|
|
31
|
+
*/
|
|
32
|
+
export function runCli(argv: string[], deps?: {
|
|
33
|
+
runner?: (options: Record<string, unknown>) => Promise<unknown>;
|
|
34
|
+
stdout?: (message: string) => void;
|
|
35
|
+
stderr?: (message: string) => void;
|
|
36
|
+
}): Promise<number>;
|
|
37
|
+
/**
|
|
38
|
+
* Executes CLI flow when the module is the process entrypoint.
|
|
39
|
+
* @param {string[]} [argv=process.argv] - Process argument vector.
|
|
40
|
+
* @param {string} [moduleUrl=import.meta.url] - Current module URL.
|
|
41
|
+
* @param {(args: string[]) => Promise<number>} [executor=runCli] - CLI executor.
|
|
42
|
+
* @returns {boolean} Whether the entrypoint branch was executed.
|
|
43
|
+
*/
|
|
44
|
+
export function runCliAsMain(argv?: string[], moduleUrl?: string, executor?: (args: string[]) => Promise<number>): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** @type {string} */
|
|
2
|
+
export const DEFAULT_COMPANY_NAME: string;
|
|
3
|
+
/** @type {number} */
|
|
4
|
+
export const DEFAULT_MAX_HEADER_SCAN_LINES: number;
|
|
5
|
+
/** @type {Set<string>} */
|
|
6
|
+
export const DEFAULT_IGNORE_FOLDERS: Set<string>;
|
|
7
|
+
export { DETECTOR_PROFILES, getAllowedExtensions, getEnabledDetectors } from "./detectors/index.mjs";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discovers source files for processing.
|
|
3
|
+
* @param {{
|
|
4
|
+
* projectRoot: string,
|
|
5
|
+
* language?: string,
|
|
6
|
+
* includeExtensions?: string[],
|
|
7
|
+
* enabledDetectors?: string[],
|
|
8
|
+
* disabledDetectors?: string[],
|
|
9
|
+
* includeFolders?: string[],
|
|
10
|
+
* excludeFolders?: string[]
|
|
11
|
+
* }} options - File discovery options.
|
|
12
|
+
* @returns {Promise<string[]>} Absolute file paths.
|
|
13
|
+
*/
|
|
14
|
+
export function discoverFiles(options: {
|
|
15
|
+
projectRoot: string;
|
|
16
|
+
language?: string;
|
|
17
|
+
includeExtensions?: string[];
|
|
18
|
+
enabledDetectors?: string[];
|
|
19
|
+
disabledDetectors?: string[];
|
|
20
|
+
includeFolders?: string[];
|
|
21
|
+
excludeFolders?: string[];
|
|
22
|
+
}): Promise<string[]>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main header-fixing engine with auto-detection and override support.
|
|
3
|
+
* @module fix-headers/core/fix-headers
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Fixes headers in a project using auto-detected metadata unless overridden.
|
|
7
|
+
* @param {{
|
|
8
|
+
* cwd?: string,
|
|
9
|
+
* input?: string,
|
|
10
|
+
* dryRun?: boolean,
|
|
11
|
+
* configFile?: string,
|
|
12
|
+
* enabledDetectors?: string[],
|
|
13
|
+
* disabledDetectors?: string[],
|
|
14
|
+
* detectorSyntaxOverrides?: Record<string, { linePrefix?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }>,
|
|
15
|
+
* includeFolders?: string[],
|
|
16
|
+
* excludeFolders?: string[],
|
|
17
|
+
* includeExtensions?: string[],
|
|
18
|
+
* projectName?: string,
|
|
19
|
+
* language?: string,
|
|
20
|
+
* projectRoot?: string,
|
|
21
|
+
* marker?: string | null,
|
|
22
|
+
* authorName?: string,
|
|
23
|
+
* authorEmail?: string,
|
|
24
|
+
* companyName?: string,
|
|
25
|
+
* copyrightStartYear?: number
|
|
26
|
+
* }} [options={}] - Runtime options.
|
|
27
|
+
* @returns {Promise<{
|
|
28
|
+
* metadata: {
|
|
29
|
+
* projectName: string,
|
|
30
|
+
* language: string,
|
|
31
|
+
* projectRoot: string,
|
|
32
|
+
* marker: string | null,
|
|
33
|
+
* authorName: string,
|
|
34
|
+
* authorEmail: string,
|
|
35
|
+
* companyName: string,
|
|
36
|
+
* copyrightStartYear: number
|
|
37
|
+
* },
|
|
38
|
+
* filesScanned: number,
|
|
39
|
+
* filesUpdated: number,
|
|
40
|
+
* dryRun: boolean,
|
|
41
|
+
* changes: Array<{file: string, changed: boolean}>
|
|
42
|
+
* }>} Process report.
|
|
43
|
+
*/
|
|
44
|
+
export function fixHeaders(options?: {
|
|
45
|
+
cwd?: string;
|
|
46
|
+
input?: string;
|
|
47
|
+
dryRun?: boolean;
|
|
48
|
+
configFile?: string;
|
|
49
|
+
enabledDetectors?: string[];
|
|
50
|
+
disabledDetectors?: string[];
|
|
51
|
+
detectorSyntaxOverrides?: Record<string, {
|
|
52
|
+
linePrefix?: string;
|
|
53
|
+
blockStart?: string;
|
|
54
|
+
blockLinePrefix?: string;
|
|
55
|
+
blockEnd?: string;
|
|
56
|
+
}>;
|
|
57
|
+
includeFolders?: string[];
|
|
58
|
+
excludeFolders?: string[];
|
|
59
|
+
includeExtensions?: string[];
|
|
60
|
+
projectName?: string;
|
|
61
|
+
language?: string;
|
|
62
|
+
projectRoot?: string;
|
|
63
|
+
marker?: string | null;
|
|
64
|
+
authorName?: string;
|
|
65
|
+
authorEmail?: string;
|
|
66
|
+
companyName?: string;
|
|
67
|
+
copyrightStartYear?: number;
|
|
68
|
+
}): Promise<{
|
|
69
|
+
metadata: {
|
|
70
|
+
projectName: string;
|
|
71
|
+
language: string;
|
|
72
|
+
projectRoot: string;
|
|
73
|
+
marker: string | null;
|
|
74
|
+
authorName: string;
|
|
75
|
+
authorEmail: string;
|
|
76
|
+
companyName: string;
|
|
77
|
+
copyrightStartYear: number;
|
|
78
|
+
};
|
|
79
|
+
filesScanned: number;
|
|
80
|
+
filesUpdated: number;
|
|
81
|
+
dryRun: boolean;
|
|
82
|
+
changes: Array<{
|
|
83
|
+
file: string;
|
|
84
|
+
changed: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
}>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects project root and language by scanning known marker files.
|
|
3
|
+
* @param {string} cwd - Starting working directory.
|
|
4
|
+
* @param {{ detectors?: { id: string, extensions: string[], priority?: number, findNearestConfig: (path: string) => Promise<{ root: string, marker: string } | null>, parseProjectName: (marker: string, content: string, rootDirName: string) => string }[], enabledDetectors?: string[], disabledDetectors?: string[], preferredExtension?: string }} [options={}] - Detection options.
|
|
5
|
+
* @returns {Promise<{
|
|
6
|
+
* language: string,
|
|
7
|
+
* rootDir: string,
|
|
8
|
+
* marker: string | null,
|
|
9
|
+
* projectName: string
|
|
10
|
+
* }>} Detection result.
|
|
11
|
+
*/
|
|
12
|
+
export function detectProjectFromMarkers(cwd: string, options?: {
|
|
13
|
+
detectors?: {
|
|
14
|
+
id: string;
|
|
15
|
+
extensions: string[];
|
|
16
|
+
priority?: number;
|
|
17
|
+
findNearestConfig: (path: string) => Promise<{
|
|
18
|
+
root: string;
|
|
19
|
+
marker: string;
|
|
20
|
+
} | null>;
|
|
21
|
+
parseProjectName: (marker: string, content: string, rootDirName: string) => string;
|
|
22
|
+
}[];
|
|
23
|
+
enabledDetectors?: string[];
|
|
24
|
+
disabledDetectors?: string[];
|
|
25
|
+
preferredExtension?: string;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
language: string;
|
|
28
|
+
rootDir: string;
|
|
29
|
+
marker: string | null;
|
|
30
|
+
projectName: string;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Resolves project metadata with override support for every auto-detected field.
|
|
34
|
+
* @param {{
|
|
35
|
+
* cwd?: string,
|
|
36
|
+
* targetFilePath?: string,
|
|
37
|
+
* enabledDetectors?: string[],
|
|
38
|
+
* disabledDetectors?: string[],
|
|
39
|
+
* projectName?: string,
|
|
40
|
+
* language?: string,
|
|
41
|
+
* projectRoot?: string,
|
|
42
|
+
* marker?: string | null,
|
|
43
|
+
* authorName?: string,
|
|
44
|
+
* authorEmail?: string,
|
|
45
|
+
* companyName?: string,
|
|
46
|
+
* copyrightStartYear?: number
|
|
47
|
+
* }} [options={}] - Detection options and overrides.
|
|
48
|
+
* @returns {Promise<{
|
|
49
|
+
* projectName: string,
|
|
50
|
+
* language: string,
|
|
51
|
+
* projectRoot: string,
|
|
52
|
+
* marker: string | null,
|
|
53
|
+
* authorName: string,
|
|
54
|
+
* authorEmail: string,
|
|
55
|
+
* companyName: string,
|
|
56
|
+
* copyrightStartYear: number
|
|
57
|
+
* }>} Final metadata.
|
|
58
|
+
*/
|
|
59
|
+
export function resolveProjectMetadata(options?: {
|
|
60
|
+
cwd?: string;
|
|
61
|
+
targetFilePath?: string;
|
|
62
|
+
enabledDetectors?: string[];
|
|
63
|
+
disabledDetectors?: string[];
|
|
64
|
+
projectName?: string;
|
|
65
|
+
language?: string;
|
|
66
|
+
projectRoot?: string;
|
|
67
|
+
marker?: string | null;
|
|
68
|
+
authorName?: string;
|
|
69
|
+
authorEmail?: string;
|
|
70
|
+
companyName?: string;
|
|
71
|
+
copyrightStartYear?: number;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
projectName: string;
|
|
74
|
+
language: string;
|
|
75
|
+
projectRoot: string;
|
|
76
|
+
marker: string | null;
|
|
77
|
+
authorName: string;
|
|
78
|
+
authorEmail: string;
|
|
79
|
+
companyName: string;
|
|
80
|
+
copyrightStartYear: number;
|
|
81
|
+
}>;
|
|
@@ -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): string;
|
|
12
|
+
export function resolveCommentSyntax(filePath: any): {
|
|
13
|
+
kind: "block";
|
|
14
|
+
blockStart: string;
|
|
15
|
+
blockLinePrefix: string;
|
|
16
|
+
blockEnd: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @fileoverview CSS detector implementation.
|
|
21
|
+
* @module fix-headers/detectors/css
|
|
22
|
+
*/
|
|
23
|
+
declare const markers: string[];
|
|
24
|
+
declare const extensions: string[];
|
|
25
|
+
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 Go detector implementation.
|
|
21
|
+
* @module fix-headers/detectors/go
|
|
22
|
+
*/
|
|
23
|
+
declare const markers: string[];
|
|
24
|
+
declare const extensions: string[];
|
|
25
|
+
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): string;
|
|
12
|
+
export function resolveCommentSyntax(filePath: any): {
|
|
13
|
+
kind: "html";
|
|
14
|
+
blockStart: string;
|
|
15
|
+
blockLinePrefix: string;
|
|
16
|
+
blockEnd: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @fileoverview HTML detector implementation.
|
|
21
|
+
* @module fix-headers/detectors/html
|
|
22
|
+
*/
|
|
23
|
+
declare const markers: string[];
|
|
24
|
+
declare const extensions: string[];
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets enabled detector profiles based on include/exclude options.
|
|
3
|
+
* @param {{ enabledDetectors?: string[], disabledDetectors?: string[] }} [options={}] - Runtime options.
|
|
4
|
+
* @returns {typeof DETECTOR_PROFILES} Enabled detector list.
|
|
5
|
+
*/
|
|
6
|
+
export function getEnabledDetectors(options?: {
|
|
7
|
+
enabledDetectors?: string[];
|
|
8
|
+
disabledDetectors?: string[];
|
|
9
|
+
}): typeof DETECTOR_PROFILES;
|
|
10
|
+
/**
|
|
11
|
+
* Gets allowed file extensions for enabled detectors.
|
|
12
|
+
* @param {{ enabledDetectors?: string[], disabledDetectors?: string[], includeExtensions?: string[] }} [options={}] - Runtime options.
|
|
13
|
+
* @returns {Set<string>} Allowed extensions.
|
|
14
|
+
*/
|
|
15
|
+
export function getAllowedExtensions(options?: {
|
|
16
|
+
enabledDetectors?: string[];
|
|
17
|
+
disabledDetectors?: string[];
|
|
18
|
+
includeExtensions?: string[];
|
|
19
|
+
}): Set<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Gets a detector by id.
|
|
22
|
+
* @param {string} id - Detector id.
|
|
23
|
+
* @returns {typeof DETECTOR_PROFILES[number] | undefined} Detector.
|
|
24
|
+
*/
|
|
25
|
+
export function getDetectorById(id: string): (typeof DETECTOR_PROFILES)[number] | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves comment syntax for a file path using detector-specific templates.
|
|
28
|
+
* @param {string} filePath - File path.
|
|
29
|
+
* @param {{ language?: string, enabledDetectors?: string[], disabledDetectors?: string[], detectorSyntaxOverrides?: Record<string, { linePrefix?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string }> }} [options={}] - Runtime options.
|
|
30
|
+
* @returns {{kind: "block" | "line" | "html", linePrefix?: string, blockStart?: string, blockLinePrefix?: string, blockEnd?: string}} Syntax descriptor.
|
|
31
|
+
*/
|
|
32
|
+
export function getCommentSyntaxForFile(filePath: string, options?: {
|
|
33
|
+
language?: string;
|
|
34
|
+
enabledDetectors?: string[];
|
|
35
|
+
disabledDetectors?: string[];
|
|
36
|
+
detectorSyntaxOverrides?: Record<string, {
|
|
37
|
+
linePrefix?: string;
|
|
38
|
+
blockStart?: string;
|
|
39
|
+
blockLinePrefix?: string;
|
|
40
|
+
blockEnd?: string;
|
|
41
|
+
}>;
|
|
42
|
+
}): {
|
|
43
|
+
kind: "block" | "line" | "html";
|
|
44
|
+
linePrefix?: string;
|
|
45
|
+
blockStart?: string;
|
|
46
|
+
blockLinePrefix?: string;
|
|
47
|
+
blockEnd?: string;
|
|
48
|
+
};
|
|
49
|
+
export const DETECTOR_PROFILES: {
|
|
50
|
+
id: string;
|
|
51
|
+
markers: string[];
|
|
52
|
+
extensions: string[];
|
|
53
|
+
enabledByDefault: boolean;
|
|
54
|
+
findNearestConfig: (startPath: string) => Promise<{
|
|
55
|
+
root: string;
|
|
56
|
+
marker: string;
|
|
57
|
+
} | null>;
|
|
58
|
+
parseProjectName: (marker: string, markerContent: string, rootDirName: string) => string;
|
|
59
|
+
resolveCommentSyntax: (filePath: string) => {
|
|
60
|
+
kind: "block" | "line" | "html";
|
|
61
|
+
linePrefix?: string;
|
|
62
|
+
blockStart?: string;
|
|
63
|
+
blockLinePrefix?: string;
|
|
64
|
+
blockEnd?: string;
|
|
65
|
+
} | null;
|
|
66
|
+
}[];
|
|
@@ -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): string;
|
|
12
|
+
export function resolveCommentSyntax(filePath: any): {
|
|
13
|
+
kind: "block";
|
|
14
|
+
blockStart: string;
|
|
15
|
+
blockLinePrefix: string;
|
|
16
|
+
blockEnd: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @fileoverview Node.js detector implementation.
|
|
21
|
+
* @module fix-headers/detectors/node
|
|
22
|
+
*/
|
|
23
|
+
declare const markers: string[];
|
|
24
|
+
declare const extensions: string[];
|
|
25
|
+
export {};
|