linguist-js
Advanced tools
Comparing version 1.6.1 to 1.7.0
@@ -16,2 +16,3 @@ "use strict"; | ||
.option('-f|--files|--full [bool]', 'List every file parsed', false) | ||
.option('-c|--categories <categories...>', 'Language categories to include in output') | ||
.option('-s|--summary [bool]', 'Show output in a human-readable format', false) | ||
@@ -29,2 +30,3 @@ .option('-q|--quick [bool]', 'Skip checking of gitattributes/gitignore files (alias for -{A|I|H|S}=false)', false) | ||
const args = commander_1.program.opts(); | ||
// Normalise arguments | ||
for (const arg in args) { | ||
@@ -37,14 +39,24 @@ if (typeof args[arg] !== 'string') | ||
} | ||
if (args.analyze) { | ||
// Run Linguist | ||
if (args.analyze) | ||
(async () => { | ||
var _a; | ||
var _a, _b; | ||
const root = args.analyze === true ? '.' : args.analyze; | ||
// Normalise array arguments | ||
if ((_a = args.ignore) === null || _a === void 0 ? void 0 : _a[0].match(/(?<!\\)[:;|]/)) | ||
args.ignore = args.ignore[0].split(/(?<!\\)[:;|]/); | ||
if (((_b = args.categories) === null || _b === void 0 ? void 0 : _b.length) === 1) | ||
args.categories = args.categories[0].split(','); | ||
// Fetch language data | ||
const { count, languages, results } = await index_1.default(root, args); | ||
// Make file paths relative | ||
for (const [file, lang] of Object.entries(results)) { | ||
const relFile = file.replace(path_1.default.resolve(root).replace(/\\/g, '/'), '.'); | ||
results[relFile] = lang; | ||
delete results[file]; | ||
} | ||
// Print output | ||
if (args.summary) { | ||
const { data, markup, programming, prose, total: { bytes: totalBytes } } = languages; | ||
const languageData = { data, markup, programming, prose }; | ||
const languageValues = Object.values(languageData).reduce((obj, val) => Object.assign(obj, val)); | ||
const sortedEntries = Object.entries(languageValues).sort((a, b) => a[1] < b[1] ? +1 : -1); | ||
const sortedEntries = Object.entries(languages.all).map(([lang, data]) => [lang, data.bytes]).sort((a, b) => a[1] < b[1] ? +1 : -1); | ||
const totalBytes = languages.total.bytes; | ||
console.log(`Languages summary:`); | ||
@@ -58,13 +70,6 @@ for (const [lang, bytes] of sortedEntries) { | ||
else { | ||
const relResults = {}; | ||
for (const [file, lang] of Object.entries(results)) { | ||
const relFile = file.replace(path_1.default.resolve(root).replace(/\\/g, '/'), '.'); | ||
relResults[relFile] = lang; | ||
} | ||
const languageData = languages; | ||
delete languageData.all; | ||
console.log(args.files ? { results: relResults, count, languages: languageData } : { count, languages: languageData }); | ||
languages.all = {}; | ||
console.log(args.files ? { results, count, languages } : { count, languages }); | ||
} | ||
})(); | ||
} | ||
else { | ||
@@ -71,0 +76,0 @@ console.log(`Welcome to linguist-js, the JavaScript port of GitHub's language analyzer.`); |
@@ -55,4 +55,4 @@ "use strict"; | ||
module.exports = async function analyse(root = '.', opts = {}) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var _h, _j, _k; | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var _j, _k, _l; | ||
const langData = await loadFile('languages.yml').then(js_yaml_1.default.load); | ||
@@ -181,3 +181,3 @@ const vendorData = await loadFile('vendor.yml').then(js_yaml_1.default.load); | ||
// Skip binary files | ||
if (!opts.keepBinary && (binary_extensions_1.default.some(ext => file.endsWith(ext)) || await isbinaryfile_1.isBinaryFile(file))) { | ||
if (!opts.keepBinary && (binary_extensions_1.default.some(ext => file.endsWith('.' + ext)) || await isbinaryfile_1.isBinaryFile(file))) { | ||
continue; | ||
@@ -225,2 +225,17 @@ } | ||
} | ||
// Skip specified categories | ||
if ((_e = opts.categories) === null || _e === void 0 ? void 0 : _e.length) { | ||
const categories = ['data', 'markup', 'programming', 'prose']; | ||
const hiddenCategories = categories.filter(cat => !opts.categories.includes(cat)); | ||
for (const [file, lang] of Object.entries(finalResults)) { | ||
if (!hiddenCategories.some(cat => lang && langData[lang].type === cat)) | ||
continue; | ||
delete finalResults[file]; | ||
if (lang) | ||
delete languages.all[lang]; | ||
} | ||
for (const category of hiddenCategories) { | ||
languages[category] = {}; | ||
} | ||
} | ||
// Load language bytes size | ||
@@ -234,3 +249,3 @@ for (const [file, lang] of Object.entries(finalResults)) { | ||
const ext = path_1.posix.extname(file); | ||
(_e = (_h = languages.unknown)[ext]) !== null && _e !== void 0 ? _e : (_h[ext] = 0); | ||
(_f = (_j = languages.unknown)[ext]) !== null && _f !== void 0 ? _f : (_j[ext] = 0); | ||
languages.unknown[ext] += fileSize; | ||
@@ -242,5 +257,5 @@ languages.total.unknownBytes += fileSize; | ||
const { type } = langData[lang]; | ||
(_f = (_j = languages.all)[lang]) !== null && _f !== void 0 ? _f : (_j[lang] = { type, bytes: 0, color: langData[lang].color }); | ||
(_g = (_k = languages.all)[lang]) !== null && _g !== void 0 ? _g : (_k[lang] = { type, bytes: 0, color: langData[lang].color }); | ||
languages.all[lang].bytes += fileSize; | ||
(_g = (_k = languages[type])[lang]) !== null && _g !== void 0 ? _g : (_k[lang] = 0); | ||
(_h = (_l = languages[type])[lang]) !== null && _h !== void 0 ? _h : (_l[lang] = 0); | ||
languages[type][lang] += fileSize; | ||
@@ -247,0 +262,0 @@ languages.total.bytes += fileSize; |
@@ -8,2 +8,4 @@ import { LanguageType } from "./schema"; | ||
export interface Options { | ||
ignore?: string[]; | ||
categories?: LanguageType[]; | ||
keepVendored?: boolean; | ||
@@ -16,3 +18,2 @@ keepBinary?: boolean; | ||
checkShebang?: boolean; | ||
ignore?: string[]; | ||
} | ||
@@ -19,0 +20,0 @@ export interface LanguagesData { |
{ | ||
"name": "linguist-js", | ||
"version": "1.6.1", | ||
"version": "1.7.0", | ||
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -87,2 +87,5 @@ [![Latest version](https://img.shields.io/github/v/release/Nixinova/Linguist?label=latest%20version&style=flat-square)](https://github.com/Nixinova/Linguist/releases) | ||
A list of file path globs to explicitly ignore. | ||
- `categories` (string array): | ||
A list of programming language categories that should be included in the results. | ||
Defaults to `['data', 'markup', 'programming', 'prose']`. | ||
- `quick` (boolean): | ||
@@ -116,7 +119,9 @@ Whether to skip the checking of `.gitattributes` and `.gitignore` files for manual language classifications (defaults to `false`). | ||
Analyse multiple folders using the syntax `"{folder1,folder2,...}"`. | ||
- `--ignore` (optional): | ||
A list of file path globs to ignore. | ||
- `--ignore <paths...>` (optional): | ||
A list of space-delimited file path globs to ignore. | ||
- `--files` (optional): | ||
Whether to print a full list of all files analysed. | ||
Does nothing when `--summary` is specified. | ||
- `--categories <categories...>` (optional): | ||
A list of space-delimited categories that should be displayed in the output. | ||
- `--summary` (optional): | ||
@@ -123,0 +128,0 @@ Output language data in a human-readable manner instead of JSON. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27662
422
146