-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
executable file
·147 lines (136 loc) · 3.53 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
139
140
141
142
143
144
145
146
147
const path = require('path')
const fs = require('fs')
const _ = require('lodash')
const table = require('markdown-table')
const markdownMagic = require('markdown-magic')
const npmtotal = require('npmtotal')
const pkg = require('./package.json')
const badgeStats = require('./stats.json')
const key = pkg['npm-stats']
if (!key) {
throw new Error('Please add `npm-stats` to your package.json'); // eslint-disable-line
}
const exclude = [
'fung-shway',
'@vendia/serverless-express',
'testing-lerna-usage',
'testing-lerna-one',
'testing-lerna-two',
'@serverless/sdk',
'micro-api-client',
'@middy',
'proto-jojo',
'serviceful',
'@middy/core',
'@middy/error-logger',
'@middy/http-partial-response',
'@middy/http-content-negotiation',
'@middy/input-output-logger',
'@middy/s3-key-normalizer',
'vue-cli-plugin-netlify-lambda',
'@middy/function-shield',
'@netlify/git-utils',
'@netlify/run-utils',
'@netlify/functions-utils',
'@middy/ssm',
'@middy/secrets-manager',
'@middy/validator',
'netlify-lambda',
'@middy/cache',
'@middy/http-error-handler',
'@netlify/rules-proxy',
'netlify-redirector',
'netlify-cms',
'netlify-cli-logo',
'@netlify/open-api',
'gotrue-js',
'gocommerce-js',
'netlify-lm-plugin',
'@netlify/cli-utils',
'netlify-setup-heuristics',
'@serverless/emulator',
'netlify',
'@netlify/zip-it-and-ship-it',
'netlify-identity-widget',
'middy',
'netlify-redirect-parser',
'@netlify/config',
'user-events',
'@middy/http-urlencode-path-parser',
'@middy/http-urlencode-body-parser',
'@middy/do-not-wait-for-empty-event-loop',
'@middy/http-multipart-body-parser',
'@middy/http-cors',
'@middy/http-header-normalizer',
'@middy/http-json-body-parser',
'@middy/http-event-normalizer',
'@middy/http-response-serializer',
'@middy/warmup',
'@netlify/cache-utils',
'@middy/http-security-headers',
'@middy/db-manager',
'phenomic-serverless',
'@serverless/sdk',
'@serverless/aws',
'@netlify/parse-domain',
'@netlify/plugin-sitemap',
'@netlify/sitemap-plugin',
'@serverless/ui-components',
'@serverless/fdk',
'netlify-dev-plugin',
'npm-post-install-example',
'netlifys_api_definition'
]
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
function generateMarkdownTable(tableRows, sum) {
const total = numberWithCommas(sum)
const config = {
transforms: {
PACKAGES() {
return table([
['Name', 'Downloads'],
['**Total**', `**${total}**`],
...tableRows,
['**Total**', `**${total}**`],
])
}
}
}
markdownMagic(path.join(__dirname, 'README.md'), config, d => {
console.log(`Updated total downloads ${sum}`)
})
}
(async () => {
console.log(`Running npmtotal(${key}), This can take some time`)
const stats = await npmtotal(key, {
exclude: exclude
})
const sortedStats = _.reverse(
_.sortBy(stats.stats, [
function(o) {
return o[1]
}
])
).filter((d) => {
const [name, count] = d
if (count === 0) {
return false
}
if (name.match(/^@middy/)) {
return false
}
return true
}).map((d) => {
const [name, count] = d
return [
`[${name}](https://www.npmjs.com/package/${name})`,
numberWithCommas(count)
]
})
// '@serverless', '@netlify', 'netlify-', '@middy'
badgeStats.message = `${numberWithCommas(stats.sum)} Downloads`
await fs.writeFileSync('./stats.json', JSON.stringify(badgeStats, null, 2))
generateMarkdownTable(sortedStats, stats.sum)
})()