linguist-js 2.5.5 → 2.5.6
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/dist/cli.d.ts +1 -1
- package/dist/cli.js +107 -107
- package/dist/helpers/convert-pcre.js +38 -38
- package/dist/helpers/load-data.js +31 -30
- package/dist/helpers/read-file.js +23 -23
- package/dist/helpers/walk-tree.js +64 -64
- package/dist/index.d.ts +4 -4
- package/dist/index.js +375 -375
- package/dist/schema.d.ts +37 -37
- package/dist/schema.js +2 -2
- package/dist/types.d.ts +47 -47
- package/dist/types.js +2 -2
- package/ext/heuristics.yml +804 -791
- package/package.json +4 -4
package/dist/cli.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/cli.js
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const VERSION = require('../package.json').version;
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const index_1 = __importDefault(require("./index"));
|
|
9
|
-
const colouredMsg = ([r, g, b], msg) => `\u001B[${38};2;${r};${g};${b}m${msg}${'\u001b[0m'}`;
|
|
10
|
-
const hexToRgb = (hex) => [parseInt(hex.slice(1, 3), 16), parseInt(hex.slice(3, 5), 16), parseInt(hex.slice(5, 7), 16)];
|
|
11
|
-
commander_1.program
|
|
12
|
-
.name('linguist')
|
|
13
|
-
.usage('--analyze [<folder>] [<options...>]')
|
|
14
|
-
.option('-a|--analyze|--analyse [folders...]', 'Analyse the languages of all files in a folder')
|
|
15
|
-
.option('-i|--ignoredFiles <files...>', `A list of file path globs to ignore`)
|
|
16
|
-
.option('-l|--ignoredLanguages <languages...>', `A list of languages to ignore`)
|
|
17
|
-
.option('-c|--categories <categories...>', 'Language categories to include in output')
|
|
18
|
-
.option('-C|--childLanguages [bool]', 'Display child languages instead of their parents', false)
|
|
19
|
-
.option('-j|--json [bool]', 'Display the output as JSON', false)
|
|
20
|
-
.option('-t|--tree <traversal>', 'Which part of the output JSON to display (dot-delimited)')
|
|
21
|
-
.option('-q|--quick [bool]', 'Skip complex language analysis (alias for -{A|I|H|S}=false)', false)
|
|
22
|
-
.option('-o|--offline [bool]', 'Use packaged data files instead of fetching latest from GitHub', false)
|
|
23
|
-
.option('-V|--keepVendored [bool]', 'Prevent skipping over vendored/generated files', false)
|
|
24
|
-
.option('-B|--keepBinary [bool]', 'Prevent skipping over binary files', false)
|
|
25
|
-
.option('-r|--relativePaths [bool]', 'Convert absolute file paths to relative', false)
|
|
26
|
-
.option('-A|--checkAttributes [bool]', 'Force the checking of gitattributes files', true)
|
|
27
|
-
.option('-I|--checkIgnored [bool]', 'Force the checking of gitignore files', true)
|
|
28
|
-
.option('-H|--checkHeuristics [bool]', 'Apply heuristics to ambiguous languages', true)
|
|
29
|
-
.option('-S|--checkShebang [bool]', 'Check shebang lines for explicit classification', true)
|
|
30
|
-
.option('-M|--checkModeline [bool]', 'Check modelines for explicit classification', true)
|
|
31
|
-
.helpOption(`-h|--help`, 'Display this help message')
|
|
32
|
-
.version(VERSION, '-v|--version', 'Display the installed version of linguist-js');
|
|
33
|
-
commander_1.program.parse(process.argv);
|
|
34
|
-
const args = commander_1.program.opts();
|
|
35
|
-
// Normalise arguments
|
|
36
|
-
for (const arg in args) {
|
|
37
|
-
const normalise = (val) => {
|
|
38
|
-
if (typeof val !== 'string')
|
|
39
|
-
return val;
|
|
40
|
-
val = val.replace(/^=/, '');
|
|
41
|
-
if (val.match(/true$|false$/))
|
|
42
|
-
val = val === 'true';
|
|
43
|
-
return val;
|
|
44
|
-
};
|
|
45
|
-
if (Array.isArray(args[arg]))
|
|
46
|
-
args[arg] = args[arg].map(normalise);
|
|
47
|
-
else
|
|
48
|
-
args[arg] = normalise(args[arg]);
|
|
49
|
-
}
|
|
50
|
-
// Run Linguist
|
|
51
|
-
if (args.analyze)
|
|
52
|
-
(async () => {
|
|
53
|
-
// Fetch language data
|
|
54
|
-
const root = args.analyze === true ? '.' : args.analyze;
|
|
55
|
-
const data = await (0, index_1.default)(root, args);
|
|
56
|
-
const { files, languages, unknown } = data;
|
|
57
|
-
// Print output
|
|
58
|
-
if (!args.json) {
|
|
59
|
-
const sortedEntries = Object.entries(languages.results).sort((a, b) => a[1].bytes < b[1].bytes ? +1 : -1);
|
|
60
|
-
const totalBytes = languages.bytes;
|
|
61
|
-
console.log(`\n Analysed ${files.bytes.toLocaleString()} B from ${files.count} files with linguist-js`);
|
|
62
|
-
console.log(`\n Language analysis results:`);
|
|
63
|
-
let count = 0;
|
|
64
|
-
if (sortedEntries.length === 0)
|
|
65
|
-
console.log(` None`);
|
|
66
|
-
// List parsed results
|
|
67
|
-
for (const [lang, { bytes, color }] of sortedEntries) {
|
|
68
|
-
const fmtd = {
|
|
69
|
-
index: (++count).toString().padStart(2, ' '),
|
|
70
|
-
lang: lang.padEnd(24, ' '),
|
|
71
|
-
percent: (bytes / (totalBytes || 1) * 100).toFixed(2).padStart(5, ' '),
|
|
72
|
-
bytes: bytes.toLocaleString().padStart(10, ' '),
|
|
73
|
-
icon: colouredMsg(hexToRgb(color !== null && color !== void 0 ? color : '#ededed'), '\u2588'),
|
|
74
|
-
};
|
|
75
|
-
console.log(` ${fmtd.index}. ${fmtd.icon} ${fmtd.lang} ${fmtd.percent}% ${fmtd.bytes} B`);
|
|
76
|
-
}
|
|
77
|
-
console.log(` Total: ${totalBytes.toLocaleString()} B`);
|
|
78
|
-
// List unknown files/extensions
|
|
79
|
-
if (unknown.bytes > 0) {
|
|
80
|
-
console.log(`\n Unknown files and extensions:`);
|
|
81
|
-
for (const [name, bytes] of Object.entries(unknown.filenames)) {
|
|
82
|
-
console.log(` '${name}': ${bytes.toLocaleString()} B`);
|
|
83
|
-
}
|
|
84
|
-
for (const [ext, bytes] of Object.entries(unknown.extensions)) {
|
|
85
|
-
console.log(` '*${ext}': ${bytes.toLocaleString()} B`);
|
|
86
|
-
}
|
|
87
|
-
console.log(` Total: ${unknown.bytes.toLocaleString()} B`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (args.tree) {
|
|
91
|
-
const treeParts = args.tree.split('.');
|
|
92
|
-
let nestedData = data;
|
|
93
|
-
for (const part of treeParts) {
|
|
94
|
-
if (!nestedData[part])
|
|
95
|
-
throw Error(`TraversalError: Key '${part}' cannot be found on output object.`);
|
|
96
|
-
nestedData = nestedData[part];
|
|
97
|
-
}
|
|
98
|
-
console.log(nestedData);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
console.dir(data, { depth: null });
|
|
102
|
-
}
|
|
103
|
-
})();
|
|
104
|
-
else {
|
|
105
|
-
console.log(`Welcome to linguist-js, a JavaScript port of GitHub's language analyzer.`);
|
|
106
|
-
console.log(`Type 'linguist --help' for a list of commands.`);
|
|
107
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const VERSION = require('../package.json').version;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const index_1 = __importDefault(require("./index"));
|
|
9
|
+
const colouredMsg = ([r, g, b], msg) => `\u001B[${38};2;${r};${g};${b}m${msg}${'\u001b[0m'}`;
|
|
10
|
+
const hexToRgb = (hex) => [parseInt(hex.slice(1, 3), 16), parseInt(hex.slice(3, 5), 16), parseInt(hex.slice(5, 7), 16)];
|
|
11
|
+
commander_1.program
|
|
12
|
+
.name('linguist')
|
|
13
|
+
.usage('--analyze [<folder>] [<options...>]')
|
|
14
|
+
.option('-a|--analyze|--analyse [folders...]', 'Analyse the languages of all files in a folder')
|
|
15
|
+
.option('-i|--ignoredFiles <files...>', `A list of file path globs to ignore`)
|
|
16
|
+
.option('-l|--ignoredLanguages <languages...>', `A list of languages to ignore`)
|
|
17
|
+
.option('-c|--categories <categories...>', 'Language categories to include in output')
|
|
18
|
+
.option('-C|--childLanguages [bool]', 'Display child languages instead of their parents', false)
|
|
19
|
+
.option('-j|--json [bool]', 'Display the output as JSON', false)
|
|
20
|
+
.option('-t|--tree <traversal>', 'Which part of the output JSON to display (dot-delimited)')
|
|
21
|
+
.option('-q|--quick [bool]', 'Skip complex language analysis (alias for -{A|I|H|S}=false)', false)
|
|
22
|
+
.option('-o|--offline [bool]', 'Use packaged data files instead of fetching latest from GitHub', false)
|
|
23
|
+
.option('-V|--keepVendored [bool]', 'Prevent skipping over vendored/generated files', false)
|
|
24
|
+
.option('-B|--keepBinary [bool]', 'Prevent skipping over binary files', false)
|
|
25
|
+
.option('-r|--relativePaths [bool]', 'Convert absolute file paths to relative', false)
|
|
26
|
+
.option('-A|--checkAttributes [bool]', 'Force the checking of gitattributes files', true)
|
|
27
|
+
.option('-I|--checkIgnored [bool]', 'Force the checking of gitignore files', true)
|
|
28
|
+
.option('-H|--checkHeuristics [bool]', 'Apply heuristics to ambiguous languages', true)
|
|
29
|
+
.option('-S|--checkShebang [bool]', 'Check shebang lines for explicit classification', true)
|
|
30
|
+
.option('-M|--checkModeline [bool]', 'Check modelines for explicit classification', true)
|
|
31
|
+
.helpOption(`-h|--help`, 'Display this help message')
|
|
32
|
+
.version(VERSION, '-v|--version', 'Display the installed version of linguist-js');
|
|
33
|
+
commander_1.program.parse(process.argv);
|
|
34
|
+
const args = commander_1.program.opts();
|
|
35
|
+
// Normalise arguments
|
|
36
|
+
for (const arg in args) {
|
|
37
|
+
const normalise = (val) => {
|
|
38
|
+
if (typeof val !== 'string')
|
|
39
|
+
return val;
|
|
40
|
+
val = val.replace(/^=/, '');
|
|
41
|
+
if (val.match(/true$|false$/))
|
|
42
|
+
val = val === 'true';
|
|
43
|
+
return val;
|
|
44
|
+
};
|
|
45
|
+
if (Array.isArray(args[arg]))
|
|
46
|
+
args[arg] = args[arg].map(normalise);
|
|
47
|
+
else
|
|
48
|
+
args[arg] = normalise(args[arg]);
|
|
49
|
+
}
|
|
50
|
+
// Run Linguist
|
|
51
|
+
if (args.analyze)
|
|
52
|
+
(async () => {
|
|
53
|
+
// Fetch language data
|
|
54
|
+
const root = args.analyze === true ? '.' : args.analyze;
|
|
55
|
+
const data = await (0, index_1.default)(root, args);
|
|
56
|
+
const { files, languages, unknown } = data;
|
|
57
|
+
// Print output
|
|
58
|
+
if (!args.json) {
|
|
59
|
+
const sortedEntries = Object.entries(languages.results).sort((a, b) => a[1].bytes < b[1].bytes ? +1 : -1);
|
|
60
|
+
const totalBytes = languages.bytes;
|
|
61
|
+
console.log(`\n Analysed ${files.bytes.toLocaleString()} B from ${files.count} files with linguist-js`);
|
|
62
|
+
console.log(`\n Language analysis results:`);
|
|
63
|
+
let count = 0;
|
|
64
|
+
if (sortedEntries.length === 0)
|
|
65
|
+
console.log(` None`);
|
|
66
|
+
// List parsed results
|
|
67
|
+
for (const [lang, { bytes, color }] of sortedEntries) {
|
|
68
|
+
const fmtd = {
|
|
69
|
+
index: (++count).toString().padStart(2, ' '),
|
|
70
|
+
lang: lang.padEnd(24, ' '),
|
|
71
|
+
percent: (bytes / (totalBytes || 1) * 100).toFixed(2).padStart(5, ' '),
|
|
72
|
+
bytes: bytes.toLocaleString().padStart(10, ' '),
|
|
73
|
+
icon: colouredMsg(hexToRgb(color !== null && color !== void 0 ? color : '#ededed'), '\u2588'),
|
|
74
|
+
};
|
|
75
|
+
console.log(` ${fmtd.index}. ${fmtd.icon} ${fmtd.lang} ${fmtd.percent}% ${fmtd.bytes} B`);
|
|
76
|
+
}
|
|
77
|
+
console.log(` Total: ${totalBytes.toLocaleString()} B`);
|
|
78
|
+
// List unknown files/extensions
|
|
79
|
+
if (unknown.bytes > 0) {
|
|
80
|
+
console.log(`\n Unknown files and extensions:`);
|
|
81
|
+
for (const [name, bytes] of Object.entries(unknown.filenames)) {
|
|
82
|
+
console.log(` '${name}': ${bytes.toLocaleString()} B`);
|
|
83
|
+
}
|
|
84
|
+
for (const [ext, bytes] of Object.entries(unknown.extensions)) {
|
|
85
|
+
console.log(` '*${ext}': ${bytes.toLocaleString()} B`);
|
|
86
|
+
}
|
|
87
|
+
console.log(` Total: ${unknown.bytes.toLocaleString()} B`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (args.tree) {
|
|
91
|
+
const treeParts = args.tree.split('.');
|
|
92
|
+
let nestedData = data;
|
|
93
|
+
for (const part of treeParts) {
|
|
94
|
+
if (!nestedData[part])
|
|
95
|
+
throw Error(`TraversalError: Key '${part}' cannot be found on output object.`);
|
|
96
|
+
nestedData = nestedData[part];
|
|
97
|
+
}
|
|
98
|
+
console.log(nestedData);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
console.dir(data, { depth: null });
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
else {
|
|
105
|
+
console.log(`Welcome to linguist-js, a JavaScript port of GitHub's language analyzer.`);
|
|
106
|
+
console.log(`Type 'linguist --help' for a list of commands.`);
|
|
107
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/** Convert a PCRE regex into JS. */
|
|
4
|
-
function pcre(regex) {
|
|
5
|
-
let finalRegex = regex;
|
|
6
|
-
const replace = (search, replace) => finalRegex = finalRegex.replace(search, replace);
|
|
7
|
-
const finalFlags = new Set();
|
|
8
|
-
// Convert inline flag declarations
|
|
9
|
-
const inlineMatches = regex.matchAll(/\?(-)?([a-z]):/g);
|
|
10
|
-
const startMatches = regex.matchAll(/\(\?(-)?([a-z]+)\)/g);
|
|
11
|
-
for (const [match, isNegative, flags] of [...inlineMatches, ...startMatches]) {
|
|
12
|
-
replace(match, '');
|
|
13
|
-
const func = (flag) => isNegative ? finalFlags.delete(flag) : finalFlags.add(flag);
|
|
14
|
-
[...flags].forEach(func);
|
|
15
|
-
}
|
|
16
|
-
// Remove PCRE-only syntax
|
|
17
|
-
replace(/([*+]){2}/g, '$1');
|
|
18
|
-
replace(/\(\?>/g, '(?:');
|
|
19
|
-
// Remove start/end-of-file markers
|
|
20
|
-
if (/\\[AZ]/.test(finalRegex)) {
|
|
21
|
-
replace(/\\A/g, '^');
|
|
22
|
-
replace(/\\Z/g, '$');
|
|
23
|
-
finalFlags.delete('m');
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
finalFlags.add('m');
|
|
27
|
-
}
|
|
28
|
-
// Reformat free-spacing mode
|
|
29
|
-
if (finalFlags.has('x')) {
|
|
30
|
-
finalFlags.delete('x');
|
|
31
|
-
replace(/#.+/g, '');
|
|
32
|
-
replace(/^\s+|\s+$|\n/gm, '');
|
|
33
|
-
replace(/\s+/g, ' ');
|
|
34
|
-
}
|
|
35
|
-
// Return final regex
|
|
36
|
-
return RegExp(finalRegex, [...finalFlags].join(''));
|
|
37
|
-
}
|
|
38
|
-
exports.default = pcre;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/** Convert a PCRE regex into JS. */
|
|
4
|
+
function pcre(regex) {
|
|
5
|
+
let finalRegex = regex;
|
|
6
|
+
const replace = (search, replace) => finalRegex = finalRegex.replace(search, replace);
|
|
7
|
+
const finalFlags = new Set();
|
|
8
|
+
// Convert inline flag declarations
|
|
9
|
+
const inlineMatches = regex.matchAll(/\?(-)?([a-z]):/g);
|
|
10
|
+
const startMatches = regex.matchAll(/\(\?(-)?([a-z]+)\)/g);
|
|
11
|
+
for (const [match, isNegative, flags] of [...inlineMatches, ...startMatches]) {
|
|
12
|
+
replace(match, '');
|
|
13
|
+
const func = (flag) => isNegative ? finalFlags.delete(flag) : finalFlags.add(flag);
|
|
14
|
+
[...flags].forEach(func);
|
|
15
|
+
}
|
|
16
|
+
// Remove PCRE-only syntax
|
|
17
|
+
replace(/([*+]){2}/g, '$1');
|
|
18
|
+
replace(/\(\?>/g, '(?:');
|
|
19
|
+
// Remove start/end-of-file markers
|
|
20
|
+
if (/\\[AZ]/.test(finalRegex)) {
|
|
21
|
+
replace(/\\A/g, '^');
|
|
22
|
+
replace(/\\Z/g, '$');
|
|
23
|
+
finalFlags.delete('m');
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
finalFlags.add('m');
|
|
27
|
+
}
|
|
28
|
+
// Reformat free-spacing mode
|
|
29
|
+
if (finalFlags.has('x')) {
|
|
30
|
+
finalFlags.delete('x');
|
|
31
|
+
replace(/#.+/g, '');
|
|
32
|
+
replace(/^\s+|\s+$|\n/gm, '');
|
|
33
|
+
replace(/\s+/g, ' ');
|
|
34
|
+
}
|
|
35
|
+
// Return final regex
|
|
36
|
+
return RegExp(finalRegex, [...finalFlags].join(''));
|
|
37
|
+
}
|
|
38
|
+
exports.default = pcre;
|
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
9
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
10
|
-
const cache = new node_cache_1.default({});
|
|
11
|
-
async function loadWebFile(file) {
|
|
12
|
-
// Return cache if it exists
|
|
13
|
-
const cachedContent = cache.get(file);
|
|
14
|
-
if (cachedContent)
|
|
15
|
-
return cachedContent;
|
|
16
|
-
// Otherwise cache the request
|
|
17
|
-
const dataUrl = (file) => `https://raw.githubusercontent.com/github/linguist/HEAD/lib/linguist/${file}`;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
9
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
10
|
+
const cache = new node_cache_1.default({});
|
|
11
|
+
async function loadWebFile(file) {
|
|
12
|
+
// Return cache if it exists
|
|
13
|
+
const cachedContent = cache.get(file);
|
|
14
|
+
if (cachedContent)
|
|
15
|
+
return cachedContent;
|
|
16
|
+
// Otherwise cache the request
|
|
17
|
+
const dataUrl = (file) => `https://raw.githubusercontent.com/github/linguist/HEAD/lib/linguist/${file}`;
|
|
18
|
+
// Load file content, falling back to the local file if the request fails
|
|
19
|
+
const fileContent = await (0, cross_fetch_1.default)(dataUrl(file)).then(data => data.text()).catch(async () => await loadLocalFile(file));
|
|
20
|
+
cache.set(file, fileContent);
|
|
21
|
+
return fileContent;
|
|
22
|
+
}
|
|
23
|
+
async function loadLocalFile(file) {
|
|
24
|
+
const filePath = path_1.default.resolve(__dirname, '../../ext', file);
|
|
25
|
+
return fs_1.default.promises.readFile(filePath).then(buffer => buffer.toString());
|
|
26
|
+
}
|
|
27
|
+
/** Load a data file from github-linguist. */
|
|
28
|
+
async function loadFile(file, offline = false) {
|
|
29
|
+
return offline ? loadLocalFile(file) : loadWebFile(file);
|
|
30
|
+
}
|
|
31
|
+
exports.default = loadFile;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
/**
|
|
8
|
-
* Read part of a file on disc.
|
|
9
|
-
* @throws 'EPERM' if the file is not readable.
|
|
10
|
-
*/
|
|
11
|
-
async function readFile(filename, onlyFirstLine = false) {
|
|
12
|
-
const chunkSize = 100;
|
|
13
|
-
const stream = fs_1.default.createReadStream(filename, { highWaterMark: chunkSize });
|
|
14
|
-
let content = '';
|
|
15
|
-
for await (const data of stream) { // may throw
|
|
16
|
-
content += data.toString();
|
|
17
|
-
if (onlyFirstLine && content.includes('\n')) {
|
|
18
|
-
return content.split(/\r?\n/)[0];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return content;
|
|
22
|
-
}
|
|
23
|
-
exports.default = readFile;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
/**
|
|
8
|
+
* Read part of a file on disc.
|
|
9
|
+
* @throws 'EPERM' if the file is not readable.
|
|
10
|
+
*/
|
|
11
|
+
async function readFile(filename, onlyFirstLine = false) {
|
|
12
|
+
const chunkSize = 100;
|
|
13
|
+
const stream = fs_1.default.createReadStream(filename, { highWaterMark: chunkSize });
|
|
14
|
+
let content = '';
|
|
15
|
+
for await (const data of stream) { // may throw
|
|
16
|
+
content += data.toString();
|
|
17
|
+
if (onlyFirstLine && content.includes('\n')) {
|
|
18
|
+
return content.split(/\r?\n/)[0];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return content;
|
|
22
|
+
}
|
|
23
|
+
exports.default = readFile;
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
let allFiles;
|
|
9
|
-
let allFolders;
|
|
10
|
-
/** Generate list of files in a directory. */
|
|
11
|
-
function walk(init, root, folders, gitignores, regexIgnores) {
|
|
12
|
-
// Initialise files and folders lists
|
|
13
|
-
if (init) {
|
|
14
|
-
allFiles = new Set();
|
|
15
|
-
allFolders = new Set();
|
|
16
|
-
}
|
|
17
|
-
// Walk tree of a folder
|
|
18
|
-
if (folders.length === 1) {
|
|
19
|
-
const folder = folders[0];
|
|
20
|
-
// Get list of files and folders inside this folder
|
|
21
|
-
const files = fs_1.default.readdirSync(folder).map(file => {
|
|
22
|
-
// Create path relative to root
|
|
23
|
-
const base = path_1.default.resolve(folder, file).replace(/\\/g, '/').replace(root, '.');
|
|
24
|
-
// Add trailing slash to mark directories
|
|
25
|
-
const isDir = fs_1.default.lstatSync(path_1.default.resolve(root, base)).isDirectory();
|
|
26
|
-
return isDir ? `${base}/` : base;
|
|
27
|
-
});
|
|
28
|
-
// Loop through files and folders
|
|
29
|
-
for (const file of files) {
|
|
30
|
-
// Create absolute path for disc operations
|
|
31
|
-
const path = path_1.default.resolve(root, file).replace(/\\/g, '/');
|
|
32
|
-
// Skip if nonexistant or ignored
|
|
33
|
-
const nonExistant = !fs_1.default.existsSync(path);
|
|
34
|
-
const isGitIgnored = gitignores.test(file.replace('./', '')).ignored;
|
|
35
|
-
const isRegexIgnored = regexIgnores.find(match => file.replace('./', '').match(match));
|
|
36
|
-
if (nonExistant || isGitIgnored || isRegexIgnored)
|
|
37
|
-
continue;
|
|
38
|
-
// Add absolute folder path to list
|
|
39
|
-
allFolders.add(path_1.default.resolve(folder).replace(/\\/g, '/'));
|
|
40
|
-
// Check if this is a folder or file
|
|
41
|
-
if (file.endsWith('/')) {
|
|
42
|
-
// Recurse into subfolders
|
|
43
|
-
allFolders.add(path);
|
|
44
|
-
walk(false, root, [path], gitignores, regexIgnores);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
// Add relative file path to list
|
|
48
|
-
allFiles.add(path);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
// Recurse into all folders
|
|
53
|
-
else {
|
|
54
|
-
for (const path of folders) {
|
|
55
|
-
walk(false, root, [path], gitignores, regexIgnores);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// Return absolute files and folders lists
|
|
59
|
-
return {
|
|
60
|
-
files: [...allFiles].map(file => file.replace(/^\./, root)),
|
|
61
|
-
folders: [...allFolders],
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
exports.default = walk;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
let allFiles;
|
|
9
|
+
let allFolders;
|
|
10
|
+
/** Generate list of files in a directory. */
|
|
11
|
+
function walk(init, root, folders, gitignores, regexIgnores) {
|
|
12
|
+
// Initialise files and folders lists
|
|
13
|
+
if (init) {
|
|
14
|
+
allFiles = new Set();
|
|
15
|
+
allFolders = new Set();
|
|
16
|
+
}
|
|
17
|
+
// Walk tree of a folder
|
|
18
|
+
if (folders.length === 1) {
|
|
19
|
+
const folder = folders[0];
|
|
20
|
+
// Get list of files and folders inside this folder
|
|
21
|
+
const files = fs_1.default.readdirSync(folder).map(file => {
|
|
22
|
+
// Create path relative to root
|
|
23
|
+
const base = path_1.default.resolve(folder, file).replace(/\\/g, '/').replace(root, '.');
|
|
24
|
+
// Add trailing slash to mark directories
|
|
25
|
+
const isDir = fs_1.default.lstatSync(path_1.default.resolve(root, base)).isDirectory();
|
|
26
|
+
return isDir ? `${base}/` : base;
|
|
27
|
+
});
|
|
28
|
+
// Loop through files and folders
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
// Create absolute path for disc operations
|
|
31
|
+
const path = path_1.default.resolve(root, file).replace(/\\/g, '/');
|
|
32
|
+
// Skip if nonexistant or ignored
|
|
33
|
+
const nonExistant = !fs_1.default.existsSync(path);
|
|
34
|
+
const isGitIgnored = gitignores.test(file.replace('./', '')).ignored;
|
|
35
|
+
const isRegexIgnored = regexIgnores.find(match => file.replace('./', '').match(match));
|
|
36
|
+
if (nonExistant || isGitIgnored || isRegexIgnored)
|
|
37
|
+
continue;
|
|
38
|
+
// Add absolute folder path to list
|
|
39
|
+
allFolders.add(path_1.default.resolve(folder).replace(/\\/g, '/'));
|
|
40
|
+
// Check if this is a folder or file
|
|
41
|
+
if (file.endsWith('/')) {
|
|
42
|
+
// Recurse into subfolders
|
|
43
|
+
allFolders.add(path);
|
|
44
|
+
walk(false, root, [path], gitignores, regexIgnores);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Add relative file path to list
|
|
48
|
+
allFiles.add(path);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Recurse into all folders
|
|
53
|
+
else {
|
|
54
|
+
for (const path of folders) {
|
|
55
|
+
walk(false, root, [path], gitignores, regexIgnores);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Return absolute files and folders lists
|
|
59
|
+
return {
|
|
60
|
+
files: [...allFiles].map(file => file.replace(/^\./, root)),
|
|
61
|
+
folders: [...allFolders],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
exports.default = walk;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as T from './types';
|
|
2
|
-
declare function analyse(path?: string, opts?: T.Options): Promise<T.Results>;
|
|
3
|
-
declare function analyse(paths?: string[], opts?: T.Options): Promise<T.Results>;
|
|
4
|
-
export = analyse;
|
|
1
|
+
import * as T from './types';
|
|
2
|
+
declare function analyse(path?: string, opts?: T.Options): Promise<T.Results>;
|
|
3
|
+
declare function analyse(paths?: string[], opts?: T.Options): Promise<T.Results>;
|
|
4
|
+
export = analyse;
|