forked from electron/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategories.js
More file actions
executable file
·40 lines (34 loc) · 1.04 KB
/
Copy pathcategories.js
File metadata and controls
executable file
·40 lines (34 loc) · 1.04 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
const fs = require('fs');
const path = require('path');
const slugify = require('slugify');
const apps = require('../lib/raw-app-list')();
console.log('Generating a list of categories with counts...');
const countArrayValues = function (arr, nameLabel, countLabel) {
var counts = {};
nameLabel = nameLabel || 'value';
countLabel = countLabel || 'count';
arr.forEach(function (value) {
if (typeof value !== 'string') return;
counts[value] ? counts[value]++ : (counts[value] = 1);
});
return Object.keys(counts)
.map(function (key) {
var obj = {};
obj[nameLabel] = key;
obj[countLabel] = counts[key];
return obj;
})
.sort(function (a, b) {
return b[countLabel] - a[countLabel];
});
};
const categories = countArrayValues(
apps.map((app) => app.category),
'name',
)
.map((category) => Object.assign(category, { slug: slugify(category.name) }))
.sort((a, b) => b.count - a.count);
fs.writeFileSync(
path.join(__dirname, '../meta/categories.json'),
JSON.stringify(categories, null, 2),
);