@mxpicture/build-api 0.3.9 → 0.3.10
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.
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { LineCountFile } from "../types/types.code.js";
|
|
2
2
|
import type { LinesOfCodeParams } from "../types/types.package.js";
|
|
3
|
+
export declare const ignoredDirs: string[];
|
|
4
|
+
export declare const ignoredFiles: string[];
|
|
5
|
+
export declare const isIgnored: (path: string) => boolean;
|
|
3
6
|
export declare const runLinesOfCode: (params: LinesOfCodeParams) => Promise<void>;
|
|
4
7
|
export declare const getLineCountFiles: (dir: string) => Promise<LineCountFile[]>;
|
|
5
8
|
export declare const getLineCountFile: (filePath: string) => Promise<LineCountFile>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.lines.d.ts","sourceRoot":"","sources":["../../src/code/code.lines.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,eAAO,MAAM,cAAc,GAAU,QAAQ,iBAAiB,kBAsB7D,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,KAAK,MAAM,KACV,OAAO,CAAC,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"code.lines.d.ts","sourceRoot":"","sources":["../../src/code/code.lines.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,eAAO,MAAM,WAAW,EAAE,MAAM,EAM/B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,MAAM,EAAiB,CAAC;AAEnD,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,OAWxC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,QAAQ,iBAAiB,kBAsB7D,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,KAAK,MAAM,KACV,OAAO,CAAC,aAAa,EAAE,CAczB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,UAAU,MAAM,KACf,OAAO,CAAC,aAAa,CAMvB,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,KAAK,MAAM,EACX,mBAAmB,OAAO,KACzB,MAgBF,CAAC"}
|
package/dist/code/code.lines.js
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { join, sep } from "node:path";
|
|
3
|
+
export const ignoredDirs = [
|
|
4
|
+
"node_modules",
|
|
5
|
+
"__tests__",
|
|
6
|
+
"__test__",
|
|
7
|
+
"tests",
|
|
8
|
+
"dist",
|
|
9
|
+
];
|
|
10
|
+
export const ignoredFiles = ["index.ts"];
|
|
11
|
+
export const isIgnored = (path) => {
|
|
12
|
+
if (path.endsWith(".d.ts"))
|
|
13
|
+
return true;
|
|
14
|
+
if (!path.endsWith(".ts"))
|
|
15
|
+
return true;
|
|
16
|
+
const parts = path.split(sep);
|
|
17
|
+
if (parts.length === 0)
|
|
18
|
+
return false;
|
|
19
|
+
for (const ignoredDir of ignoredDirs)
|
|
20
|
+
if (parts.includes(ignoredDir))
|
|
21
|
+
return true;
|
|
22
|
+
return ignoredFiles.includes(parts.pop());
|
|
23
|
+
};
|
|
3
24
|
export const runLinesOfCode = async (params) => {
|
|
4
25
|
const files = await getLineCountFiles(params.repoRoot);
|
|
5
26
|
files.sort((a, b) => b.count - a.count);
|
|
@@ -21,16 +42,15 @@ export const runLinesOfCode = async (params) => {
|
|
|
21
42
|
};
|
|
22
43
|
export const getLineCountFiles = async (dir) => {
|
|
23
44
|
const entries = await readdir(dir, { recursive: true, withFileTypes: true });
|
|
24
|
-
const filePaths =
|
|
25
|
-
|
|
26
|
-
entry.
|
|
27
|
-
|
|
28
|
-
entry.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.map((entry) => join(entry.parentPath, entry.name));
|
|
45
|
+
const filePaths = [];
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
if (!entry.isFile())
|
|
48
|
+
continue;
|
|
49
|
+
const path = join(entry.parentPath, entry.name);
|
|
50
|
+
if (isIgnored(path))
|
|
51
|
+
continue;
|
|
52
|
+
filePaths.push(path);
|
|
53
|
+
}
|
|
34
54
|
return await Promise.all(filePaths.map((filePath) => getLineCountFile(filePath)));
|
|
35
55
|
};
|
|
36
56
|
export const getLineCountFile = async (filePath) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.lines.js","sourceRoot":"","sources":["../../src/code/code.lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"code.lines.js","sourceRoot":"","sources":["../../src/code/code.lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,CAAC,MAAM,WAAW,GAAa;IACnC,cAAc;IACd,WAAW;IACX,UAAU;IACV,OAAO;IACP,MAAM;CACP,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAa,CAAC,UAAU,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAW,EAAE;IACjD,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEvC,MAAM,KAAK,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AAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAW,EACX,gBAA0B,EAClB,EAAE;IACV,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,OAAO;QACP,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;YAC7B,mCAAmC;YACnC,IAAI,gBAAgB,EAAE,CAAC;gBACrB,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBAC1D,IAAI,YAAY,KAAK,EAAE;oBAAE,SAAS;YACpC,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import { readdir, readFile } from \"node:fs/promises\";\nimport type { LineCountFile } from \"../types/types.code.js\";\nimport type { LinesOfCodeParams } from \"../types/types.package.js\";\nimport { join, sep } from \"node:path\";\n\nexport const ignoredDirs: string[] = [\n \"node_modules\",\n \"__tests__\",\n \"__test__\",\n \"tests\",\n \"dist\",\n];\n\nexport const ignoredFiles: string[] = [\"index.ts\"];\n\nexport const isIgnored = (path: string): boolean => {\n if (path.endsWith(\".d.ts\")) return true;\n if (!path.endsWith(\".ts\")) return true;\n\n const parts = path.split(sep);\n if (parts.length === 0) return false;\n\n for (const ignoredDir of ignoredDirs)\n if (parts.includes(ignoredDir)) return true;\n\n return ignoredFiles.includes(parts.pop()!);\n};\n\nexport const runLinesOfCode = async (params: LinesOfCodeParams) => {\n const files = await getLineCountFiles(params.repoRoot);\n\n files.sort((a, b) => b.count - a.count);\n\n let topCount: number = 0;\n let allCount: number = 0;\n const outputs: string[] = [];\n\n for (let i = 0; i < files.length; i++) {\n if (!params.top || i < params.top) {\n outputs.push(`${files[i].count} ${files[i].path}`);\n topCount += files[i].count;\n }\n allCount += files[i].count;\n }\n\n if (params.top) console.log(`Top ${params.top} lines: ${topCount}`);\n console.log(`All lines: ${allCount}`);\n console.log();\n\n outputs.forEach((output) => console.log(output));\n};\n\nexport const getLineCountFiles = async (\n dir: string,\n): Promise<LineCountFile[]> => {\n const entries = await readdir(dir, { recursive: true, withFileTypes: true });\n const filePaths: string[] = [];\n\n for (const entry of entries) {\n if (!entry.isFile()) continue;\n const path = join(entry.parentPath, entry.name);\n if (isIgnored(path)) continue;\n filePaths.push(path);\n }\n\n return await Promise.all(\n filePaths.map((filePath) => getLineCountFile(filePath)),\n );\n};\n\nexport const getLineCountFile = async (\n filePath: string,\n): Promise<LineCountFile> => {\n const content = await readFile(filePath, \"utf-8\");\n return {\n path: filePath,\n count: countNewlines(content, true) + 1,\n };\n};\n\nexport const countNewlines = (\n str: string,\n ignoreEmptyLines?: boolean,\n): number => {\n let count = 0;\n\n for (let i = 0; i < str.length; i++) {\n // '\\n'\n if (str.charCodeAt(i) === 10) {\n // 2 in sequence --> count only one\n if (ignoreEmptyLines) {\n const lastCharCode = i > 0 ? str.charCodeAt(i - 1) : null;\n if (lastCharCode === 10) continue;\n }\n count++;\n }\n }\n\n return count;\n};\n"]}
|