-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
138 lines (128 loc) · 3.74 KB
/
index.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// @ts-check
const path = require('path');
const fs = require('fs');
const table = require('markdown-table');
const markdownMagic = require('markdown-magic');
const npmtotal = require('npmtotal');
const { 'npm-stats': key } = require('./package.json');
const badgeStats = require('./stats.json');
if (!key) {
throw new Error('Please add `npm-stats` to your package.json');
}
(async () => {
const stats = await npmtotal(key, {
startDate: '2012-12-12',
exclude: [
'eslint-plugin-babel',
'precise-commits',
'typescript-eslint',
'eslint-config-babel',
'eslint-plugin-codelyzer',
'typescript-pro-library-project',
'@jameshenry/nx-project-graph',
'@jameshenry/eslint-plugin-angular-template',
'@jameshenry/eslint-plugin-codelyzer',
'@jameshenry/angular-template-parser',
'@jameshenry/eslint-builder',
'angular-eslint',
'nx-print-affected',
/**
* Whilst I am at the time of writing the lead maintainer of lerna on behalf of Nrwl,
* I do not want to include the lerna stats as I did not create the project, nor work
* on it at all for most of its existence.
*/
'lerna',
'@lerna/project',
'@lerna/publish',
'@lerna/command',
'@lerna/package-graph',
'@lerna/bootstrap',
'@lerna/changed',
'@lerna/add',
'@lerna/collect-updates',
'@lerna/list',
'@lerna/run',
'@lerna/create',
'@lerna/exec',
'@lerna/import',
'@lerna/clean',
'@lerna/version',
'@lerna/package',
'@lerna/link',
'@lerna/diff',
'@lerna/init',
'@lerna/child-process',
'@lerna/filter-options',
'@lerna/conventional-commits',
'@lerna/validation-error',
'@lerna/filter-packages',
'@lerna/npm-publish',
'@lerna/npm-dist-tag',
'@lerna/npm-install',
'@lerna/symlink-dependencies',
'@lerna/describe-ref',
'@lerna/npm-run-script',
'@lerna/symlink-binary',
'@lerna/rimraf-dir',
'@lerna/run-lifecycle',
'@lerna/cli',
'@lerna/create-symlink',
'@lerna/listable',
'@lerna/resolve-symlink',
'@lerna/has-npm-version',
'@lerna/prompt',
'@lerna/check-working-tree',
'@lerna/write-log-file',
'@lerna/log-packed',
'@lerna/get-npm-exec-opts',
'@lerna/output',
'@lerna/global-options',
'@lerna/npm-conf',
'@lerna/pack-directory',
'@lerna/timer',
'@lerna/get-packed',
'@lerna/github-client',
'@lerna/pulse-till-done',
'@lerna/prerelease-id-from-version',
'@lerna/query-graph',
'@lerna/run-topologically',
'@lerna/otplease',
'@lerna/collect-uncommitted',
'@lerna/gitlab-client',
'@lerna/info',
'@lerna/profiler',
'@lerna/batch-packages',
'@lerna/run-parallel-batches',
'@lerna/temp-write',
'@lerna/collect-packages',
'@lerna/git-utils',
'@lerna/fs-utils',
'@lerna/has-dependency-installed',
'@lerna/match-package-name',
'@lerna/map-to-registry',
],
});
const sortedStats = stats.stats.map((package) => {
const [name, count] = package;
return [`[${name}](https://www.npmjs.com/package/${name})`, count];
});
badgeStats.message = `${stats.sum} Downloads`;
await fs.writeFileSync('./stats.json', JSON.stringify(badgeStats, null, 2));
generate(sortedStats, stats.sum);
})();
function generate(data, sum) {
const config = {
transforms: {
PACKAGES() {
return table([
['Name', 'Downloads'],
...data,
['**Sum**', `**${sum}**`],
]);
},
},
};
markdownMagic(path.join(__dirname, 'README.md'), config, (d) => {
console.log(`Updated total downloads - ${sum}`);
});
}