Skip to content

Commit b747e10

Browse files
committed
chore(docs): add adoption metrics generation and service
- Introduced `AdoptionService` to fetch and cache public adoption metrics from npm, jsDelivr, and GitHub. - Added `adoption.ts` task to generate adoption metrics and save them to `static/adoption.json`. - Implemented utility functions for parsing adoption data from various sources. - Updated `package.json` scripts to include a new `generate:adoption` command. - Enhanced documentation to reflect the new adoption metrics functionality. Signed-off-by: Cory Rylan <crylan@nvidia.com>
1 parent 1cda122 commit b747e10

23 files changed

Lines changed: 2222 additions & 74 deletions

projects/internals/metadata/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Node.js scripts that parse the monorepo and generate static JSON metadata files:
2626
- **`lighthouse.ts`** - Collects performance metrics (bundled via Git LFS)
2727
- **`wireit.ts`** - Generates build dependency graph visualization data
2828
- **`releases.ts`** - Parses git history to extract package release information
29+
- **`adoption.ts`** - Refreshes public npm, jsDelivr, and GitHub adoption metrics
2930

3031
### 2. Services (`src/services/`)
3132

@@ -37,6 +38,7 @@ Runtime services that provide cached access to generated metadata with fallback
3738
- **`TestsService`** - Exposes test coverage and results
3839
- **`ReleasesService`** - Returns release history
3940
- **`WireitService`** - Exposes build graph data
41+
- **`AdoptionService`** - Returns the public adoption metrics snapshot
4042

4143
Services use a **dual-loading pattern**: first attempting to load from local `static/*.json` files, then falling back to fetching from public CDN if unavailable.
4244

@@ -83,3 +85,6 @@ The metadata scripts generate common metadata about projects in the repo. This i
8385
- `pnpm run generate:examples`: runs the examples metadata script gathering all the source examples from the packages.
8486
- `pnpm run generate:wireit`: runs the wireit script that gathers all metadata details about the CI build and wireit dependencies.
8587

88+
## Manual/scheduled tasks
89+
90+
- `pnpm run generate:adoption`: refreshes the public adoption metrics snapshot from npm, jsDelivr, and GitHub public APIs. This task is not part of normal CI because it uses live public network data.

projects/internals/metadata/package.json

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
"private": true,
55
"version": "0.0.0",
66
"scripts": {
7-
"dev": "node --experimental-strip-types ./src/metadata.ts",
7+
"dev": "node ./src/metadata.ts",
88
"ci": "wireit",
99
"build": "wireit",
1010
"generate:api": "wireit",
1111
"generate:tests": "wireit",
1212
"generate:examples": "wireit",
13+
"generate:adoption": "wireit",
1314
"generate:lighthouse": "wireit",
1415
"generate:wireit": "wireit",
1516
"generate:releases": "wireit",
@@ -28,6 +29,10 @@
2829
"types": "./dist/index.d.ts",
2930
"default": "./dist/index.js"
3031
},
32+
"./services/adoption.service.js": {
33+
"types": "./dist/services/adoption.service.d.ts",
34+
"default": "./dist/src/services/adoption.service.js"
35+
},
3136
"./services/api.service.js": {
3237
"types": "./dist/services/api.service.d.ts",
3338
"default": "./dist/src/services/api.service.js"
@@ -65,6 +70,7 @@
6570
"files": [
6671
"src/**",
6772
"!src/**/*.test.ts",
73+
"static/adoption.json",
6874
"static/lighthouse.json",
6975
"static/releases.json",
7076
"static/tests.json",
@@ -85,7 +91,7 @@
8591
]
8692
},
8793
"generate:api": {
88-
"command": "node --experimental-strip-types ./src/tasks/api.ts",
94+
"command": "node ./src/tasks/api.ts",
8995
"files": [
9096
"./src/tasks/api.ts",
9197
"./src/tasks/api.utils.ts",
@@ -143,7 +149,7 @@
143149
]
144150
},
145151
"generate:projects": {
146-
"command": "node --experimental-strip-types ./src/tasks/projects.ts",
152+
"command": "node ./src/tasks/projects.ts",
147153
"files": [
148154
"./src/tasks/projects.ts",
149155
"./src/tasks/projects.utils.ts",
@@ -177,7 +183,7 @@
177183
]
178184
},
179185
"generate:tests": {
180-
"command": "node --experimental-strip-types ./src/tasks/tests.ts",
186+
"command": "node ./src/tasks/tests.ts",
181187
"files": [
182188
"./src/tasks/tests.ts",
183189
"./src/tasks/tests.utils.ts",
@@ -272,7 +278,7 @@
272278
]
273279
},
274280
"generate:examples": {
275-
"command": "node --experimental-strip-types ./src/tasks/examples.ts",
281+
"command": "node ./src/tasks/examples.ts",
276282
"clean": false,
277283
"files": [
278284
"./src/tasks/examples.ts",
@@ -321,8 +327,20 @@
321327
}
322328
]
323329
},
330+
"generate:adoption": {
331+
"command": "node ./src/tasks/adoption.ts",
332+
"clean": false,
333+
"files": [
334+
"src/tasks/adoption.ts",
335+
"src/tasks/adoption.utils.ts",
336+
"../../*/package.json"
337+
],
338+
"output": [
339+
"static/adoption.json"
340+
]
341+
},
324342
"generate:lighthouse": {
325-
"command": "node --experimental-strip-types ./src/tasks/lighthouse.ts",
343+
"command": "node ./src/tasks/lighthouse.ts",
326344
"clean": false,
327345
"files": [
328346
"src/tasks/lighthouse.ts",
@@ -336,7 +354,7 @@
336354
]
337355
},
338356
"generate:wireit": {
339-
"command": "node --experimental-strip-types ./src/tasks/wireit.ts",
357+
"command": "node ./src/tasks/wireit.ts",
340358
"clean": false,
341359
"files": [
342360
"src/tasks/wireit.ts",
@@ -348,7 +366,7 @@
348366
"dependencies": []
349367
},
350368
"generate:releases": {
351-
"command": "node --experimental-strip-types ./src/tasks/releases.ts",
369+
"command": "node ./src/tasks/releases.ts",
352370
"clean": false,
353371
"files": [
354372
"src/tasks/releases.ts",

projects/internals/metadata/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
export { ExamplesService } from './services/examples.service.js';
5+
export * from './services/adoption.service.js';
56
export * from './services/api.service.js';
67
export * from './services/tests.service.js';
78
export * from './services/wireit.service.js';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { describe, expect, it } from 'vitest';
5+
import { AdoptionService } from './adoption.service.js';
6+
7+
describe('AdoptionService', () => {
8+
it('should return the adoption data', async () => {
9+
const adoption = await AdoptionService.getData();
10+
11+
expect(adoption.created).toBeDefined();
12+
expect(adoption.packages.length).toBeGreaterThan(0);
13+
expect(adoption.totals.packages).toBe(adoption.packages.length);
14+
expect(adoption.github.repository).toBe('NVIDIA/elements');
15+
expect(await AdoptionService.getData()).toBe(adoption);
16+
});
17+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import type { AdoptionSummary } from '../types.js';
5+
6+
export class AdoptionService {
7+
static #adoption: AdoptionSummary = {
8+
created: '',
9+
period: '',
10+
sources: {
11+
npmDownloads: '',
12+
npmRegistry: '',
13+
jsdelivr: '',
14+
github: ''
15+
},
16+
totals: {
17+
packages: 0,
18+
publishedPackages: 0,
19+
unavailablePackages: 0,
20+
npmDownloads: 0,
21+
cdnRequests: 0
22+
},
23+
packages: [],
24+
github: {
25+
repository: '',
26+
stars: 0,
27+
forks: 0,
28+
subscribers: 0,
29+
contributors: 0,
30+
releases: 0,
31+
stargazers: [],
32+
errors: []
33+
}
34+
};
35+
36+
static async getData(): Promise<AdoptionSummary> {
37+
if (AdoptionService.#adoption.created === '') {
38+
AdoptionService.#adoption = (await import('../../static/adoption.json', { with: { type: 'json' } }))
39+
.default as AdoptionSummary;
40+
}
41+
42+
return AdoptionService.#adoption;
43+
}
44+
}

projects/internals/metadata/src/services/releases.service.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('ReleasesService', () => {
1010
expect(releases).toBeDefined();
1111
expect(releases.created).toBeDefined();
1212
expect(releases.data).toBeDefined();
13-
expect(releases.data.length).toBeGreaterThan(0);
13+
expect(releases.data.length).toBeGreaterThan(1);
14+
expect(releases.data.some(release => release.name === '@nvidia-elements/core-v2.0.2')).toBe(true);
1415
});
1516
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { writeFileSync } from 'node:fs';
5+
import { getAdoptionData } from './adoption.utils.ts';
6+
7+
const adoption = await getAdoptionData();
8+
9+
writeFileSync('./static/adoption.json', JSON.stringify(adoption, null, 2));
10+
11+
console.log('✅ Adoption metrics generated successfully.');

0 commit comments

Comments
 (0)