Skip to content

Commit 684a13d

Browse files
committed
workflow: add script 'downloads-count'
1 parent 9461790 commit 684a13d

File tree

3 files changed

+92
-4
lines changed

3 files changed

+92
-4
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"test-unit": "vitest run",
5656
"coverage": "vitest run --coverage",
5757
"doc": "vitepress dev --open /README",
58+
"downloads-count": "esno ./scripts/downloads-count.mts",
5859
"build": "vite build",
5960
"release": "esno ./scripts/release.mts",
6061
"lint": "eslint \"**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,vue,json,md,html,css,scss,sass}\" --ignore-pattern stats.html",
@@ -88,6 +89,7 @@
8889
"@vitest/ui": "^1.5.0",
8990
"@vue/compiler-sfc": "^3.4.24",
9091
"@vue/test-utils": "^2.4.5",
92+
"axios": "^1.6.8",
9193
"case-police": "^0.6.1",
9294
"cross-spawn": "^7.0.3",
9395
"del": "^7.1.0",

pnpm-lock.yaml

Lines changed: 78 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/downloads-count.mts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import axios from 'axios'
2+
import { name } from '../package.json'
3+
4+
const initialPublishDate = '2020-07-15'
5+
const currentDate = new Date().toISOString().split('T')[0]
6+
const url = `https://api.npmjs.org/downloads/range/${initialPublishDate}:${currentDate}/${name}`
7+
8+
axios.get(url).then((response) => {
9+
const data = response.data
10+
const totalDownloads = data.downloads.reduce((acc: number, day: any) => acc + day.downloads, 0)
11+
console.log(`Total npm downloads for ${name}: ${totalDownloads}`)
12+
})

0 commit comments

Comments
 (0)