Skip to content

Commit

Permalink
Add color key to entries in languages.all
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Aug 3, 2021
1 parent 8fa0410 commit 270951b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.4
*2021-08-03*
- Added an nullable `color` key to each entry in `languages.all`.

## 1.4.3
*2021-08-01*
- Changed outputted file paths to always be absolute regardless of input.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linguist-js",
"version": "1.4.3",
"version": "1.4.4",
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.",
"main": "dist/index.js",
"bin": {
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ Running Linguist on this folder will return the following JSON:
},
"languages": {
"all": {
"JavaScript": { "type": "programming", "bytes": 1000 },
"TypeScript": { "type": "programming", "bytes": 2000 },
"Markdown": { "type": "prose", "bytes": 3000 }
"JavaScript": { "type": "programming", "bytes": 1000, "color": "#f1e05a" },
"TypeScript": { "type": "programming", "bytes": 2000, "color": "#2b7489" },
"Markdown": { "type": "prose", "bytes": 3000, "color": "#083fa1" }
},
"programming": { "JavaScript": 1000, "TypeScript": 2000 },
"markup": {},
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ export = async function analyse(root = '.', opts: T.Options = {}) {
}
// Add language and bytes data to corresponding section
const { type } = langData[lang];
languages.all[lang] ??= { type, bytes: 0 };
languages.all[lang] ??= { type, bytes: 0, color: langData[lang].color };
languages.all[lang].bytes += fileSize;
languages[type][lang] ??= 0;
languages[type][lang] += fileSize;
languages.total.bytes += fileSize;
}
// Load unique language count
languages.total.unique = Object.values({ ...languages.programming, ...languages.markup, ...languages.data, ...languages.prose }).length;
languages.total.unique = Object.values(languages.all).length;
// Return
return { count: Object.keys(finalResults).length, results: finalResults, languages };
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface LanguagesData {
all: Record<LanguageName, {
bytes: Bytes
type: LanguageType
color?: `#${string}`
}>
data: Record<LanguageName, Bytes>
markup: Record<LanguageName, Bytes>
Expand Down
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function test() {
const assert = (a, b, msg) => console.assert(a === b, msg, a, b);
const getResults = obj => Object.entries(obj.results).flat().join(',');
console.log('Results:', actual);
console.log('TOML data:', actual.languages.all['TOML'])
assert(getResults(expected), getResults(actual), 'Results');
assert(expected.count, actual.count, 'Total count');
assert(expected.languages.programming.JavaScript, actual.languages.programming.JavaScript, 'JavaScript count');
Expand Down

0 comments on commit 270951b

Please sign in to comment.