linguist-js 2.1.4 → 2.2.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/dist/cli.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const VERSION = require('../package.json').version;
7
7
  const commander_1 = require("commander");
8
8
  const index_1 = __importDefault(require("./index"));
9
+ const walk_tree_1 = __importDefault(require("./helpers/walk-tree"));
9
10
  const colouredMsg = ([r, g, b], msg) => `\u001B[${38};2;${r};${g};${b}m${msg}${'\u001b[0m'}`;
10
11
  const hexToRgb = (hex) => [parseInt(hex.slice(1, 3), 16), parseInt(hex.slice(3, 5), 16), parseInt(hex.slice(5, 7), 16)];
11
12
  commander_1.program
@@ -21,6 +22,7 @@ commander_1.program
21
22
  .option('-q|--quick [bool]', 'Skip complex language analysis (alias for -{A|I|H|S}=false)', false)
22
23
  .option('-V|--keepVendored [bool]', 'Prevent skipping over vendored/generated files', false)
23
24
  .option('-B|--keepBinary [bool]', 'Prevent skipping over binary files', false)
25
+ .option('-r|--relativePaths [bool]', 'Convert absolute file paths to relative', false)
24
26
  .option('-A|--checkAttributes [bool]', 'Force the checking of gitattributes files', true)
25
27
  .option('-I|--checkIgnored [bool]', 'Force the checking of gitignore files', true)
26
28
  .option('-H|--checkHeuristics [bool]', 'Apply heuristics to ambiguous languages', true)
@@ -51,16 +53,20 @@ if (args.analyze)
51
53
  const root = args.analyze === true ? '.' : args.analyze;
52
54
  const data = await (0, index_1.default)(root, args);
53
55
  const { files, languages, unknown } = data;
56
+ // Get file count
57
+ let totalFiles = (0, walk_tree_1.default)(root).files.length;
54
58
  // Print output
55
59
  if (!args.json) {
56
60
  const sortedEntries = Object.entries(languages.results).sort((a, b) => a[1].bytes < b[1].bytes ? +1 : -1);
57
61
  const totalBytes = languages.bytes;
58
- console.log(`\n Analysed ${files.bytes.toLocaleString()} B from ${files.count} files with linguist-js`);
62
+ console.log(`\n Analysed ${files.bytes.toLocaleString()} B from ${totalFiles} files (${totalFiles - files.count} ignored) with linguist-js`);
59
63
  console.log(`\n Language analysis results:`);
60
- let i = 0;
64
+ let count = 0;
65
+ if (sortedEntries.length === 0)
66
+ console.log(` None`);
61
67
  for (const [lang, { bytes, color }] of sortedEntries) {
62
68
  const fmtd = {
63
- index: (++i).toString().padStart(2, ' '),
69
+ index: (++count).toString().padStart(2, ' '),
64
70
  lang: lang.padEnd(24, ' '),
65
71
  percent: (bytes / (totalBytes || 1) * 100).toFixed(2).padStart(5, ' '),
66
72
  bytes: bytes.toLocaleString().padStart(10, ' '),
@@ -75,7 +81,7 @@ if (args.analyze)
75
81
  console.log(` '${name}': ${bytes.toLocaleString()} B`);
76
82
  }
77
83
  for (const [ext, bytes] of Object.entries(unknown.extensions)) {
78
- console.log(` '${ext}': ${bytes.toLocaleString()} B`);
84
+ console.log(` '*${ext}': ${bytes.toLocaleString()} B`);
79
85
  }
80
86
  console.log(` Total: ${unknown.bytes.toLocaleString()} B`);
81
87
  }
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const glob_to_regexp_1 = __importDefault(require("glob-to-regexp"));
7
7
  function parseGitGlob(path) {
8
- const globPath = `**/${path}`.replace(/\[:(space|digit):\]/, (_, val) => `\\${val[0]}`);
8
+ const globPath = `**/${path}`.replace(/\\/g, '/').replace(/\[:(space|digit):\]/g, (_, val) => `\\${val[0]}`);
9
9
  return (0, glob_to_regexp_1.default)(globPath, { globstar: true, extended: true });
10
10
  }
11
11
  exports.default = parseGitGlob;
package/dist/index.js CHANGED
@@ -224,6 +224,17 @@ async function analyse(input, opts = {}) {
224
224
  }
225
225
  }
226
226
  }
227
+ // Convert paths to relative
228
+ if (opts.relativePaths) {
229
+ const newMap = {};
230
+ for (const [file, lang] of Object.entries(results.files.results)) {
231
+ let relPath = path_1.default.relative(process.cwd(), file).replace(/\\/g, '/');
232
+ if (!relPath.startsWith('../'))
233
+ relPath = './' + relPath;
234
+ newMap[relPath] = lang;
235
+ }
236
+ results.files.results = newMap;
237
+ }
227
238
  // Load language bytes size
228
239
  for (const [file, lang] of Object.entries(results.files.results)) {
229
240
  if (lang && !langData[lang])
package/dist/types.d.ts CHANGED
@@ -10,6 +10,7 @@ export interface Options {
10
10
  categories?: Category[];
11
11
  keepVendored?: boolean;
12
12
  keepBinary?: boolean;
13
+ relativePaths?: boolean;
13
14
  childLanguages?: boolean;
14
15
  quick?: boolean;
15
16
  checkIgnored?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linguist-js",
3
- "version": "2.1.4",
3
+ "version": "2.2.0",
4
4
  "description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -37,7 +37,7 @@
37
37
  "homepage": "https://github.com/Nixinova/Linguist#readme",
38
38
  "dependencies": {
39
39
  "binary-extensions": "^2.2.0",
40
- "commander": "^8.2.0",
40
+ "commander": "^8.3.0",
41
41
  "cross-fetch": "^3.1.4",
42
42
  "glob-to-regexp": "~0.4.1",
43
43
  "isbinaryfile": "^4.0.8",
@@ -49,6 +49,6 @@
49
49
  "@types/js-yaml": "ts4.4",
50
50
  "@types/node": "ts4.4",
51
51
  "deep-object-diff": "^1.1.0",
52
- "typescript": "~4.4.3"
52
+ "typescript": "~4.5.4"
53
53
  }
54
54
  }
package/readme.md CHANGED
@@ -115,6 +115,8 @@ const { files, languages, unknown } = linguist(folder, options);
115
115
  Whether to keep vendored files (dependencies, etc) (defaults to `false`).
116
116
  - `keepBinary` (boolean):
117
117
  Whether binary files should be included in the output (defaults to `false`).
118
+ - `relativePaths` (boolean):
119
+ Change the absolute file paths in the output to be relative to the current working directory (defaults to `false`).
118
120
  - `checkAttributes` (boolean):
119
121
  Force the checking of `.gitattributes` files (defaults to `true` unless `quick` is set).
120
122
  - `checkIgnored` (boolean):
@@ -155,6 +157,8 @@ linguist --help
155
157
  Whether to include vendored files (auto-generated files, dependencies folder, etc).
156
158
  - `--keepBinary`:
157
159
  Whether binary files should be excluded from the output.
160
+ - `--relativePaths`:
161
+ Change the absolute file paths in the output to be relative to the current working directory.
158
162
  - `--checkAttributes`:
159
163
  Force the checking of `.gitatributes` files (use alongside `--quick` to overwrite).
160
164
  - `--checkIgnored`: