Repository navigation
Expand file tree
/
Copy pathsloc.js
More file actions
123 lines (103 loc) · 2.56 KB
/
Copy pathsloc.js
File metadata and controls
123 lines (103 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* @author Ben Siebert <ben@mctzock.de>
* @copyright (c) 2018-2022 Ben Siebert. All rights reserved.
*/
const old_console_log = console.log;
if (process.argv.includes("--codeup-stats-only-lines-raw")) {
console.log = (...args) => {};
console.warn = (...args) => {};
console.error = (...args) => {};
}
const fs = require("fs");
const path = require("path");
const byteSize = require("byte-size");
let paths = getAllPaths(".", []);
const disallowed = [
".turbo",
".git",
".idea",
".ico",
".jpg",
".png",
".docusaurus",
".ttf",
".afdesign",
"LICENSE",
".lock",
"package-lock.json",
".log",
"node_modules",
".next",
"dist",
"build",
".codeup_app_stats.json",
"privacy.tsx",
"imprint.tsx",
".react-email",
".pdf",
".docx",
".tmp",
"script.base.js",
];
// filter disallowed files
paths = paths.filter((p) => {
let allowed = true;
disallowed.forEach((d) => {
if (p.toLowerCase().includes(d.toLowerCase())) {
allowed = false;
}
});
return allowed;
});
let lines = 0;
let size = 0;
let filesWithLines = [];
for (let i = 0; i < paths.length; i++) {
let fLines = getFileLines(paths[i]);
filesWithLines.push({
path: paths[i],
lines: fLines,
});
lines += fLines;
}
if (process.argv.includes("-v")) {
console.log(JSON.stringify(paths, null, 2));
}
console.warn("\u001b[31mProject Statistics\u001b[0m");
console.table({
"Total Lines": lines,
"Total Files": paths.length,
"Total Size": byteSize(size).value + " " + byteSize(size).unit,
"Total Characters": size,
});
console.log("\n");
console.warn("\u001b[31mBigest Files\u001b[0m");
filesWithLines.sort((a, b) => b.lines - a.lines);
filesWithLines.slice(0, 10).forEach((f, i) => {
console.log(i + 1 + ". " + f.path + ": " + f.lines);
});
if (process.argv.includes("--list-all")) {
filesWithLines.slice(10, filesWithLines.length).forEach((f, i) => {
console.log(i + 11 + ". " + f.path + ": " + f.lines);
});
}
if (process.argv.includes("--codeup-stats-only-lines-raw")) {
old_console_log(lines);
}
function getAllPaths(dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function (file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllPaths(dirPath + "/" + file, arrayOfFiles);
} else {
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file));
}
});
return arrayOfFiles;
}
function getFileLines(p) {
let file = fs.readFileSync(p, "utf8");
size += file.toString().length;
return file.toString().split("\n").length;
}