@brad-frost-web/eddie-reporter 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -0
- package/dist/cli.d.ts +27 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +152 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/product.d.ts +19 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +120 -0
- package/dist/product.js.map +1 -0
- package/dist/report.d.ts +26 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +42 -0
- package/dist/report.js.map +1 -0
- package/dist/scanner.d.ts +40 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +135 -0
- package/dist/scanner.js.map +1 -0
- package/dist/transport.d.ts +45 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +78 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
- package/templates/eddie-report.yml +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# @brad-frost-web/eddie-reporter
|
|
2
|
+
|
|
3
|
+
> The **Eddie-reporter** — a zero-dependency usage reporter you install on
|
|
4
|
+
> downstream Eddie products. It statically scans a product for Eddie asset
|
|
5
|
+
> usage (components, recipes, page templates, and design tokens) and reports
|
|
6
|
+
> that activity back to **Eddie's Brain**, so adoption and activity of the
|
|
7
|
+
> design system become a living, breathing feedback loop instead of a
|
|
8
|
+
> point-in-time guess.
|
|
9
|
+
|
|
10
|
+
## Why this exists
|
|
11
|
+
|
|
12
|
+
Eddie's Brain already knows **coverage** (what the system offers) and, via the
|
|
13
|
+
adoption scanner, coarse **adoption** (which org repos *declare* an Eddie
|
|
14
|
+
dependency in `package.json`). What it couldn't see was **activity**: _which_
|
|
15
|
+
assets a product actually uses, _how heavily_, and _when it last changed_.
|
|
16
|
+
|
|
17
|
+
The reporter closes that gap. It turns "16 repos depend on Eddie" into "these
|
|
18
|
+
products use `ed-card` 240 times, nobody has touched `ed-r-legacy-banner` in 90
|
|
19
|
+
days, and `ed-p-app-dashboard` is the most-forked template this quarter." That
|
|
20
|
+
signal flows into `.eddie-brain/activity.json` and out through the
|
|
21
|
+
`eddie_get_activity` MCP tool.
|
|
22
|
+
|
|
23
|
+
## Design principles
|
|
24
|
+
|
|
25
|
+
- **Zero dependencies.** Node built-ins only. It installs instantly and adds no
|
|
26
|
+
supply-chain surface to the products it ships to.
|
|
27
|
+
- **Static & read-only.** It reads source text and counts references. It never
|
|
28
|
+
executes the product, never reads runtime/user data, and never mutates the
|
|
29
|
+
host. Reports are deterministic and privacy-friendly.
|
|
30
|
+
- **Never breaks a build.** A failed beacon is logged, not thrown. The CLI exits
|
|
31
|
+
`0` even when delivery fails.
|
|
32
|
+
- **Degrades gracefully.** If there's no network (or you don't want telemetry),
|
|
33
|
+
it writes a local artifact your CI can commit — the brain's org scan or a
|
|
34
|
+
human can pick it up later.
|
|
35
|
+
|
|
36
|
+
## Install & use
|
|
37
|
+
|
|
38
|
+
Run it with no install via `npx`:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx @brad-frost-web/eddie-reporter --event build \
|
|
42
|
+
--endpoint https://ds.bradfrost.com/report
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Or add it as a dev dependency and wire it into a build/postbuild script:
|
|
46
|
+
|
|
47
|
+
```jsonc
|
|
48
|
+
// package.json
|
|
49
|
+
{
|
|
50
|
+
"scripts": {
|
|
51
|
+
"postbuild": "eddie-report --event build"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Set the endpoint once via env so scripts stay clean:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
export EDDIE_REPORT_ENDPOINT="https://ds.bradfrost.com/report"
|
|
60
|
+
export EDDIE_REPORT_TOKEN="…" # optional
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Run it on a schedule
|
|
64
|
+
|
|
65
|
+
The loop is designed to run unattended, on both ends:
|
|
66
|
+
|
|
67
|
+
- **Product side.** Copy [`templates/eddie-report.yml`](./templates/eddie-report.yml)
|
|
68
|
+
to your product's `.github/workflows/` and set the `EDDIE_REPORT_ENDPOINT`
|
|
69
|
+
secret. It beacons **weekly** (`cron`), on every **push** to `main`/`develop`,
|
|
70
|
+
and on demand. Products that deploy elsewhere can use a Netlify/Vercel
|
|
71
|
+
scheduled function, a `postbuild`/`postdeploy` hook, or a plain server cron.
|
|
72
|
+
- **System side.** The hosted `POST /report` endpoint durably captures each
|
|
73
|
+
beacon in a Netlify Blobs store (serverless filesystems are ephemeral). The
|
|
74
|
+
scheduled `eddie-activity` workflow in eddie-design-system then flushes that
|
|
75
|
+
store into `.eddie-brain/activity.json` (`eddie-brain activity flush`),
|
|
76
|
+
refreshes adoption, and opens a PR — so the ledger stays live with zero
|
|
77
|
+
manual steps.
|
|
78
|
+
|
|
79
|
+
## CLI
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
eddie-report [dir] [options]
|
|
83
|
+
|
|
84
|
+
--endpoint <url> Brain ingestion URL (env: EDDIE_REPORT_ENDPOINT)
|
|
85
|
+
--token <token> Bearer token (env: EDDIE_REPORT_TOKEN)
|
|
86
|
+
--event <name> build | deploy | install | ci | dev | manual (default: manual)
|
|
87
|
+
--out <path> Local artifact path (default: .eddie/usage-report.json; '' to skip)
|
|
88
|
+
--dry-run Scan and print, but don't POST or write
|
|
89
|
+
--json Print the full report JSON to stdout
|
|
90
|
+
--quiet Suppress the human summary
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Programmatic API
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { buildReport, sendReport } from '@brad-frost-web/eddie-reporter';
|
|
97
|
+
|
|
98
|
+
const report = buildReport({ dir: process.cwd(), event: 'build' });
|
|
99
|
+
await sendReport(report, { endpoint: process.env.EDDIE_REPORT_ENDPOINT });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## What a report looks like
|
|
103
|
+
|
|
104
|
+
```jsonc
|
|
105
|
+
{
|
|
106
|
+
"schema": "eddie-usage-report/1",
|
|
107
|
+
"reporterVersion": "0.39.0",
|
|
108
|
+
"generatedAt": "2026-07-14T00:00:00.000Z",
|
|
109
|
+
"event": "build",
|
|
110
|
+
"product": {
|
|
111
|
+
"id": "bradfrost.com",
|
|
112
|
+
"repo": "Brad-Frost-Web/bradfrost.com",
|
|
113
|
+
"branch": "main",
|
|
114
|
+
"commit": "a1b2c3d…",
|
|
115
|
+
"environment": "ci"
|
|
116
|
+
},
|
|
117
|
+
"eddie": {
|
|
118
|
+
"declared": { "@brad-frost-web/eddie-web-components": "^0.37.0" },
|
|
119
|
+
"packages": ["design-tokens", "web-components"]
|
|
120
|
+
},
|
|
121
|
+
"usage": {
|
|
122
|
+
"components": { "ed-card": 24, "ed-button": 18 },
|
|
123
|
+
"recipes": { "ed-r-site-header": 1 },
|
|
124
|
+
"pages": { "ed-p-app-dashboard": 1 },
|
|
125
|
+
"tokens": { "--ed-theme-color-content-default": 63 },
|
|
126
|
+
"filesScanned": 210,
|
|
127
|
+
"filesMatched": 47
|
|
128
|
+
},
|
|
129
|
+
"totals": { "distinctComponents": 2, "distinctRecipes": 1, "distinctPages": 1, "distinctTokens": 1, "occurrences": 107 }
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## The bigger picture
|
|
134
|
+
|
|
135
|
+
This reporter is the first leg of a two-way system↔product relationship. See
|
|
136
|
+
[`docs/VISION.md`](./docs/VISION.md) for the full map of where this goes —
|
|
137
|
+
usage-weighted health, deprecation radar, drift nudges, a public adoption
|
|
138
|
+
dashboard, and closing the loop back into governance.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* eddie-report — CLI entry point for the Eddie-reporter.
|
|
4
|
+
*
|
|
5
|
+
* Scans a product for Eddie asset usage and delivers a report to Eddie's Brain
|
|
6
|
+
* (HTTP beacon) and/or a local artifact. Designed to run as an npm script, a
|
|
7
|
+
* postbuild hook, or a CI step. Zero dependencies — argument parsing is hand
|
|
8
|
+
* rolled to keep the install tiny.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* eddie-report [dir] [options]
|
|
12
|
+
*
|
|
13
|
+
* Options:
|
|
14
|
+
* --endpoint <url> Brain ingestion URL (or set EDDIE_REPORT_ENDPOINT).
|
|
15
|
+
* --token <token> Bearer token (or set EDDIE_REPORT_TOKEN).
|
|
16
|
+
* --event <name> build | deploy | install | ci | dev | manual (default: manual).
|
|
17
|
+
* --out <path> Local artifact path (default: .eddie/usage-report.json). '' to skip.
|
|
18
|
+
* --dry-run Scan and print, but don't POST or write.
|
|
19
|
+
* --json Print the full report JSON to stdout.
|
|
20
|
+
* --quiet Suppress the human summary.
|
|
21
|
+
* -h, --help Show help.
|
|
22
|
+
*
|
|
23
|
+
* Exit code is always 0 on a successful scan, even if the beacon fails — a
|
|
24
|
+
* usage report must never break a build. Use --json in CI to inspect delivery.
|
|
25
|
+
*/
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* eddie-report — CLI entry point for the Eddie-reporter.
|
|
4
|
+
*
|
|
5
|
+
* Scans a product for Eddie asset usage and delivers a report to Eddie's Brain
|
|
6
|
+
* (HTTP beacon) and/or a local artifact. Designed to run as an npm script, a
|
|
7
|
+
* postbuild hook, or a CI step. Zero dependencies — argument parsing is hand
|
|
8
|
+
* rolled to keep the install tiny.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* eddie-report [dir] [options]
|
|
12
|
+
*
|
|
13
|
+
* Options:
|
|
14
|
+
* --endpoint <url> Brain ingestion URL (or set EDDIE_REPORT_ENDPOINT).
|
|
15
|
+
* --token <token> Bearer token (or set EDDIE_REPORT_TOKEN).
|
|
16
|
+
* --event <name> build | deploy | install | ci | dev | manual (default: manual).
|
|
17
|
+
* --out <path> Local artifact path (default: .eddie/usage-report.json). '' to skip.
|
|
18
|
+
* --dry-run Scan and print, but don't POST or write.
|
|
19
|
+
* --json Print the full report JSON to stdout.
|
|
20
|
+
* --quiet Suppress the human summary.
|
|
21
|
+
* -h, --help Show help.
|
|
22
|
+
*
|
|
23
|
+
* Exit code is always 0 on a successful scan, even if the beacon fails — a
|
|
24
|
+
* usage report must never break a build. Use --json in CI to inspect delivery.
|
|
25
|
+
*/
|
|
26
|
+
import { buildReport } from './report.js';
|
|
27
|
+
import { sendReport } from './transport.js';
|
|
28
|
+
const VALID_EVENTS = ['build', 'deploy', 'install', 'ci', 'dev', 'manual'];
|
|
29
|
+
function parseArgs(argv) {
|
|
30
|
+
const args = { event: 'manual', dryRun: false, json: false, quiet: false, help: false };
|
|
31
|
+
for (let i = 0; i < argv.length; i++) {
|
|
32
|
+
const a = argv[i];
|
|
33
|
+
switch (a) {
|
|
34
|
+
case '-h':
|
|
35
|
+
case '--help':
|
|
36
|
+
args.help = true;
|
|
37
|
+
break;
|
|
38
|
+
case '--dry-run':
|
|
39
|
+
args.dryRun = true;
|
|
40
|
+
break;
|
|
41
|
+
case '--json':
|
|
42
|
+
args.json = true;
|
|
43
|
+
break;
|
|
44
|
+
case '--quiet':
|
|
45
|
+
args.quiet = true;
|
|
46
|
+
break;
|
|
47
|
+
case '--endpoint':
|
|
48
|
+
args.endpoint = argv[++i];
|
|
49
|
+
break;
|
|
50
|
+
case '--token':
|
|
51
|
+
args.token = argv[++i];
|
|
52
|
+
break;
|
|
53
|
+
case '--out':
|
|
54
|
+
args.out = argv[++i];
|
|
55
|
+
break;
|
|
56
|
+
case '--event': {
|
|
57
|
+
const v = argv[++i];
|
|
58
|
+
if (VALID_EVENTS.includes(v))
|
|
59
|
+
args.event = v;
|
|
60
|
+
else {
|
|
61
|
+
process.stderr.write(`eddie-report: invalid --event "${v}". Valid: ${VALID_EVENTS.join(', ')}\n`);
|
|
62
|
+
process.exit(2);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
default:
|
|
67
|
+
if (a.startsWith('-')) {
|
|
68
|
+
process.stderr.write(`eddie-report: unknown option "${a}". Try --help.\n`);
|
|
69
|
+
process.exit(2);
|
|
70
|
+
}
|
|
71
|
+
args.dir = a; // first positional is the directory
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return args;
|
|
75
|
+
}
|
|
76
|
+
const HELP = `eddie-report — report Eddie asset usage back to Eddie's Brain
|
|
77
|
+
|
|
78
|
+
Usage:
|
|
79
|
+
eddie-report [dir] [options]
|
|
80
|
+
|
|
81
|
+
Options:
|
|
82
|
+
--endpoint <url> Brain ingestion URL (env: EDDIE_REPORT_ENDPOINT)
|
|
83
|
+
--token <token> Bearer token (env: EDDIE_REPORT_TOKEN)
|
|
84
|
+
--event <name> build | deploy | install | ci | dev | manual (default: manual)
|
|
85
|
+
--out <path> Local artifact path (default: .eddie/usage-report.json; '' to skip)
|
|
86
|
+
--dry-run Scan and print, but don't POST or write
|
|
87
|
+
--json Print the full report JSON to stdout
|
|
88
|
+
--quiet Suppress the human summary
|
|
89
|
+
-h, --help Show this help
|
|
90
|
+
|
|
91
|
+
Examples:
|
|
92
|
+
eddie-report --event build --endpoint https://ds.bradfrost.com/report
|
|
93
|
+
eddie-report ./apps/web --dry-run --json
|
|
94
|
+
`;
|
|
95
|
+
/** Render a short human summary of the report + delivery result. */
|
|
96
|
+
function printSummary(report, delivery) {
|
|
97
|
+
const t = report.totals;
|
|
98
|
+
const p = report.product;
|
|
99
|
+
const lines = [
|
|
100
|
+
`\nEddie usage report — ${p.id}${p.branch ? ` (${p.branch})` : ''}`,
|
|
101
|
+
` environment: ${p.environment}${p.commit ? ` · ${p.commit.slice(0, 7)}` : ''}`,
|
|
102
|
+
` eddie deps: ${report.eddie.packages.join(', ') || '—'}`,
|
|
103
|
+
` components: ${t.distinctComponents} distinct`,
|
|
104
|
+
` recipes: ${t.distinctRecipes} distinct`,
|
|
105
|
+
` pages: ${t.distinctPages} distinct`,
|
|
106
|
+
` tokens: ${t.distinctTokens} distinct`,
|
|
107
|
+
` occurrences: ${t.occurrences} across ${report.usage.filesMatched}/${report.usage.filesScanned} files`,
|
|
108
|
+
` delivery: ${delivery}`,
|
|
109
|
+
'',
|
|
110
|
+
];
|
|
111
|
+
process.stdout.write(lines.join('\n'));
|
|
112
|
+
}
|
|
113
|
+
async function main() {
|
|
114
|
+
const args = parseArgs(process.argv.slice(2));
|
|
115
|
+
if (args.help) {
|
|
116
|
+
process.stdout.write(HELP);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const endpoint = args.endpoint ?? process.env.EDDIE_REPORT_ENDPOINT;
|
|
120
|
+
const token = args.token ?? process.env.EDDIE_REPORT_TOKEN;
|
|
121
|
+
const report = buildReport({ dir: args.dir, event: args.event });
|
|
122
|
+
const result = await sendReport(report, {
|
|
123
|
+
endpoint,
|
|
124
|
+
token,
|
|
125
|
+
out: args.out,
|
|
126
|
+
dryRun: args.dryRun,
|
|
127
|
+
});
|
|
128
|
+
let delivery;
|
|
129
|
+
if (result.dryRun) {
|
|
130
|
+
delivery = 'dry run (nothing sent or written)';
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const parts = [];
|
|
134
|
+
if (result.beacon === 'sent')
|
|
135
|
+
parts.push(`beacon → ${endpoint} (${result.beaconStatus})`);
|
|
136
|
+
else if (result.beacon === 'failed')
|
|
137
|
+
parts.push(`beacon failed (${result.beaconError})`);
|
|
138
|
+
if (result.artifact === 'written')
|
|
139
|
+
parts.push(`artifact → ${result.artifactPath}`);
|
|
140
|
+
delivery = parts.join('; ') || 'nothing delivered (no endpoint, artifact skipped)';
|
|
141
|
+
}
|
|
142
|
+
if (args.json)
|
|
143
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
144
|
+
if (!args.quiet && !args.json)
|
|
145
|
+
printSummary(report, delivery);
|
|
146
|
+
}
|
|
147
|
+
main().catch((err) => {
|
|
148
|
+
// Never fail a build over a report. Log and exit clean.
|
|
149
|
+
process.stderr.write(`eddie-report: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
150
|
+
process.exit(0);
|
|
151
|
+
});
|
|
152
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAe5C,MAAM,YAAY,GAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AAE1F,SAAS,SAAS,CAAC,IAAc;IAC/B,MAAM,IAAI,GAAe,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACpG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,C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I,CAAC,cAAc,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;QACnF,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,mDAAmD,CAAC;IACrF,CAAC;IAED,IAAI,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IAC5E,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI;QAAE,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAChE,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,wDAAwD;IACxD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brad-frost-web/eddie-reporter — public programmatic API.
|
|
3
|
+
*
|
|
4
|
+
* The Eddie-reporter is installed on downstream Eddie products. It statically
|
|
5
|
+
* scans a product's source for Eddie asset usage and reports the activity back
|
|
6
|
+
* to Eddie's Brain, turning adoption into a living feedback loop.
|
|
7
|
+
*
|
|
8
|
+
* Typical use is the `eddie-report` CLI (see cli.ts), but the pieces are also
|
|
9
|
+
* exported for programmatic use inside a product's own build tooling.
|
|
10
|
+
*/
|
|
11
|
+
export { scanUsage } from './scanner.js';
|
|
12
|
+
export type { ScanOptions, ScanResult } from './scanner.js';
|
|
13
|
+
export { resolveProductIdentity, resolveEddieDependencies } from './product.js';
|
|
14
|
+
export { buildReport, REPORTER_VERSION } from './report.js';
|
|
15
|
+
export type { BuildReportOptions } from './report.js';
|
|
16
|
+
export { sendReport } from './transport.js';
|
|
17
|
+
export type { SendOptions, SendResult } from './transport.js';
|
|
18
|
+
export { REPORT_SCHEMA } from './types.js';
|
|
19
|
+
export type { UsageReport, UsageBreakdown, ProductIdentity, EddieDependencyInfo, ReportEvent, ReportEnvironment, } from './types.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,YAAY,EACV,WAAW,EACX,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brad-frost-web/eddie-reporter — public programmatic API.
|
|
3
|
+
*
|
|
4
|
+
* The Eddie-reporter is installed on downstream Eddie products. It statically
|
|
5
|
+
* scans a product's source for Eddie asset usage and reports the activity back
|
|
6
|
+
* to Eddie's Brain, turning adoption into a living feedback loop.
|
|
7
|
+
*
|
|
8
|
+
* Typical use is the `eddie-report` CLI (see cli.ts), but the pieces are also
|
|
9
|
+
* exported for programmatic use inside a product's own build tooling.
|
|
10
|
+
*/
|
|
11
|
+
export { scanUsage } from './scanner.js';
|
|
12
|
+
export { resolveProductIdentity, resolveEddieDependencies } from './product.js';
|
|
13
|
+
export { buildReport, REPORTER_VERSION } from './report.js';
|
|
14
|
+
export { sendReport } from './transport.js';
|
|
15
|
+
export { REPORT_SCHEMA } from './types.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG5D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* product — resolve the identity of the product being reported on, without
|
|
3
|
+
* shelling out. We read `package.json` and the `.git` directory directly so
|
|
4
|
+
* the reporter stays dependency-free and side-effect-free (no `git` subprocess
|
|
5
|
+
* to spawn, nothing that could hang a CI job).
|
|
6
|
+
*
|
|
7
|
+
* Everything here is best-effort: any field that can't be resolved is simply
|
|
8
|
+
* omitted. A report with just a directory name for an id is still useful.
|
|
9
|
+
*/
|
|
10
|
+
import type { EddieDependencyInfo, ProductIdentity } from './types.js';
|
|
11
|
+
/** Collect the product's declared Eddie dependencies and short surfaces. */
|
|
12
|
+
export declare function resolveEddieDependencies(dir: string): EddieDependencyInfo;
|
|
13
|
+
/**
|
|
14
|
+
* Resolve a stable product identity. Id precedence: package.json name →
|
|
15
|
+
* git `owner/repo` slug → directory basename. The first stable one wins so a
|
|
16
|
+
* product reports under the same key every run.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveProductIdentity(dir: string): ProductIdentity;
|
|
19
|
+
//# sourceMappingURL=product.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../src/product.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAqB,MAAM,YAAY,CAAC;AAgF1F,4EAA4E;AAC5E,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAazE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAenE"}
|
package/dist/product.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* product — resolve the identity of the product being reported on, without
|
|
3
|
+
* shelling out. We read `package.json` and the `.git` directory directly so
|
|
4
|
+
* the reporter stays dependency-free and side-effect-free (no `git` subprocess
|
|
5
|
+
* to spawn, nothing that could hang a CI job).
|
|
6
|
+
*
|
|
7
|
+
* Everything here is best-effort: any field that can't be resolved is simply
|
|
8
|
+
* omitted. A report with just a directory name for an id is still useful.
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
11
|
+
import { basename, join, resolve } from 'node:path';
|
|
12
|
+
const EDDIE_PKG_PREFIX = '@brad-frost-web/eddie-';
|
|
13
|
+
function readPackageJson(dir) {
|
|
14
|
+
const path = join(dir, 'package.json');
|
|
15
|
+
if (!existsSync(path))
|
|
16
|
+
return null;
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(readFileSync(path, 'utf-8'));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Parse `owner/repo` out of a git remote URL (ssh or https forms). */
|
|
25
|
+
function parseRepoSlug(remoteUrl) {
|
|
26
|
+
const cleaned = remoteUrl.trim().replace(/\.git$/, '');
|
|
27
|
+
// git@github.com:owner/repo | https://github.com/owner/repo | ssh://...
|
|
28
|
+
const m = cleaned.match(/[:/]([^/:]+)\/([^/]+)$/);
|
|
29
|
+
return m ? `${m[1]}/${m[2]}` : undefined;
|
|
30
|
+
}
|
|
31
|
+
/** Read branch + commit + origin remote directly from a `.git` directory. */
|
|
32
|
+
function readGitInfo(dir) {
|
|
33
|
+
const gitDir = join(dir, '.git');
|
|
34
|
+
if (!existsSync(gitDir))
|
|
35
|
+
return {};
|
|
36
|
+
const info = {};
|
|
37
|
+
// HEAD → branch (and commit, when HEAD is detached).
|
|
38
|
+
try {
|
|
39
|
+
const head = readFileSync(join(gitDir, 'HEAD'), 'utf-8').trim();
|
|
40
|
+
const refMatch = head.match(/^ref:\s*(.+)$/);
|
|
41
|
+
if (refMatch) {
|
|
42
|
+
const ref = refMatch[1].trim();
|
|
43
|
+
info.branch = ref.replace(/^refs\/heads\//, '');
|
|
44
|
+
// Resolve the ref to a SHA, trying the loose ref then packed-refs.
|
|
45
|
+
const looseRef = join(gitDir, ref);
|
|
46
|
+
if (existsSync(looseRef)) {
|
|
47
|
+
info.commit = readFileSync(looseRef, 'utf-8').trim();
|
|
48
|
+
}
|
|
49
|
+
else if (existsSync(join(gitDir, 'packed-refs'))) {
|
|
50
|
+
const packed = readFileSync(join(gitDir, 'packed-refs'), 'utf-8');
|
|
51
|
+
const line = packed.split('\n').find((l) => l.endsWith(` ${ref}`));
|
|
52
|
+
if (line)
|
|
53
|
+
info.commit = line.split(' ')[0];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (/^[0-9a-f]{7,40}$/i.test(head)) {
|
|
57
|
+
info.commit = head; // detached HEAD points straight at a SHA
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
/* ignore */
|
|
62
|
+
}
|
|
63
|
+
// origin remote → owner/repo slug.
|
|
64
|
+
try {
|
|
65
|
+
const config = readFileSync(join(gitDir, 'config'), 'utf-8');
|
|
66
|
+
const originBlock = config.split(/\[/).find((b) => b.startsWith('remote "origin"'));
|
|
67
|
+
const urlMatch = originBlock?.match(/url\s*=\s*(.+)/);
|
|
68
|
+
if (urlMatch)
|
|
69
|
+
info.repo = parseRepoSlug(urlMatch[1]);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
/* ignore */
|
|
73
|
+
}
|
|
74
|
+
return info;
|
|
75
|
+
}
|
|
76
|
+
/** True when a well-known CI environment variable is set. */
|
|
77
|
+
function detectEnvironment() {
|
|
78
|
+
const env = process.env;
|
|
79
|
+
if (env.CI === 'true' || env.CI === '1' || env.GITHUB_ACTIONS || env.GITLAB_CI || env.BUILDKITE || env.CIRCLECI) {
|
|
80
|
+
return 'ci';
|
|
81
|
+
}
|
|
82
|
+
// Absence of CI vars means we're most likely on a developer machine.
|
|
83
|
+
return env.CI === undefined ? 'local' : 'unknown';
|
|
84
|
+
}
|
|
85
|
+
/** Collect the product's declared Eddie dependencies and short surfaces. */
|
|
86
|
+
export function resolveEddieDependencies(dir) {
|
|
87
|
+
const pkg = readPackageJson(dir);
|
|
88
|
+
const declared = {};
|
|
89
|
+
if (pkg) {
|
|
90
|
+
const all = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
|
|
91
|
+
for (const [name, version] of Object.entries(all)) {
|
|
92
|
+
if (name.startsWith(EDDIE_PKG_PREFIX))
|
|
93
|
+
declared[name] = version;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const packages = Object.keys(declared)
|
|
97
|
+
.map((n) => n.replace(EDDIE_PKG_PREFIX, ''))
|
|
98
|
+
.sort();
|
|
99
|
+
return { declared, packages };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Resolve a stable product identity. Id precedence: package.json name →
|
|
103
|
+
* git `owner/repo` slug → directory basename. The first stable one wins so a
|
|
104
|
+
* product reports under the same key every run.
|
|
105
|
+
*/
|
|
106
|
+
export function resolveProductIdentity(dir) {
|
|
107
|
+
const absolute = resolve(dir);
|
|
108
|
+
const pkg = readPackageJson(absolute);
|
|
109
|
+
const git = readGitInfo(absolute);
|
|
110
|
+
const id = pkg?.name || git.repo || basename(absolute);
|
|
111
|
+
return {
|
|
112
|
+
id,
|
|
113
|
+
name: pkg?.name,
|
|
114
|
+
repo: git.repo,
|
|
115
|
+
branch: git.branch,
|
|
116
|
+
commit: git.commit,
|
|
117
|
+
environment: detectEnvironment(),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=product.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.js","sourceRoot":"","sources":["../src/product.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpD,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAQlD,SAAS,eAAe,CAAC,GAAW;IAClC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACvC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAgB,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,uEAAuE;AACvE,SAAS,aAAa,CAAC,SAAiB;IACtC,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACvD,4EAA4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,WAAW,CAAC,QAAQ,CAAC,CAAC;IAElC,MAAM,EAAE,GAAG,GAAG,EAAE,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEvD,OAAO;QACL,EAAE;QACF,IAAI,EAAE,GAAG,EAAE,IAAI;QACf,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,WAAW,EAAE,iBAAiB,EAAE;KACjC,CAAC;AACJ,CAAC"}
|
package/dist/report.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* report — assemble a complete UsageReport from a directory scan plus the
|
|
3
|
+
* resolved product identity and declared Eddie dependencies.
|
|
4
|
+
*/
|
|
5
|
+
import { type ScanOptions } from './scanner.js';
|
|
6
|
+
import { type ReportEvent, type UsageReport } from './types.js';
|
|
7
|
+
/** Reporter version, kept in sync with package.json at publish time. */
|
|
8
|
+
export declare const REPORTER_VERSION = "0.39.0";
|
|
9
|
+
export interface BuildReportOptions extends ScanOptions {
|
|
10
|
+
/** Directory to scan and identify. Defaults to cwd. */
|
|
11
|
+
dir?: string;
|
|
12
|
+
/** What triggered the report. Defaults to 'manual'. */
|
|
13
|
+
event?: ReportEvent;
|
|
14
|
+
/**
|
|
15
|
+
* ISO timestamp to stamp the report with. Injectable so builds are
|
|
16
|
+
* reproducible and tests are deterministic. Defaults to now.
|
|
17
|
+
*/
|
|
18
|
+
now?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Scan a product directory and build a JSON-safe UsageReport. Pure aside from
|
|
22
|
+
* the filesystem read done by the scanner — the same directory yields the same
|
|
23
|
+
* report (given a fixed `now`).
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildReport(options?: BuildReportOptions): UsageReport;
|
|
26
|
+
//# sourceMappingURL=report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAiB,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/E,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,WAAW,CAAC;AAEzC,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAMD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,WAAW,CA4BzE"}
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* report — assemble a complete UsageReport from a directory scan plus the
|
|
3
|
+
* resolved product identity and declared Eddie dependencies.
|
|
4
|
+
*/
|
|
5
|
+
import { scanUsage } from './scanner.js';
|
|
6
|
+
import { resolveEddieDependencies, resolveProductIdentity } from './product.js';
|
|
7
|
+
import { REPORT_SCHEMA } from './types.js';
|
|
8
|
+
/** Reporter version, kept in sync with package.json at publish time. */
|
|
9
|
+
export const REPORTER_VERSION = '0.39.0';
|
|
10
|
+
const distinct = (m) => Object.keys(m).length;
|
|
11
|
+
const sum = (m) => Object.values(m).reduce((a, b) => a + b, 0);
|
|
12
|
+
/**
|
|
13
|
+
* Scan a product directory and build a JSON-safe UsageReport. Pure aside from
|
|
14
|
+
* the filesystem read done by the scanner — the same directory yields the same
|
|
15
|
+
* report (given a fixed `now`).
|
|
16
|
+
*/
|
|
17
|
+
export function buildReport(options = {}) {
|
|
18
|
+
const dir = options.dir ?? process.cwd();
|
|
19
|
+
const event = options.event ?? 'manual';
|
|
20
|
+
const generatedAt = options.now ?? new Date().toISOString();
|
|
21
|
+
const usage = scanUsage(dir, options);
|
|
22
|
+
const product = resolveProductIdentity(dir);
|
|
23
|
+
const eddie = resolveEddieDependencies(dir);
|
|
24
|
+
const occurrences = sum(usage.components) + sum(usage.recipes) + sum(usage.pages) + sum(usage.tokens);
|
|
25
|
+
return {
|
|
26
|
+
schema: REPORT_SCHEMA,
|
|
27
|
+
reporterVersion: REPORTER_VERSION,
|
|
28
|
+
generatedAt,
|
|
29
|
+
event,
|
|
30
|
+
product,
|
|
31
|
+
eddie,
|
|
32
|
+
usage,
|
|
33
|
+
totals: {
|
|
34
|
+
distinctComponents: distinct(usage.components),
|
|
35
|
+
distinctRecipes: distinct(usage.recipes),
|
|
36
|
+
distinctPages: distinct(usage.pages),
|
|
37
|
+
distinctTokens: distinct(usage.tokens),
|
|
38
|
+
occurrences,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAoB,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,aAAa,EAAsC,MAAM,YAAY,CAAC;AAE/E,wEAAwE;AACxE,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAczC,MAAM,QAAQ,GAAG,CAAC,CAAyB,EAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9E,MAAM,GAAG,GAAG,CAAC,CAAyB,EAAU,EAAE,CAChD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,C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and read-only. The reporter
|
|
5
|
+
* ships to arbitrary downstream products, so it must install fast, add no
|
|
6
|
+
* supply-chain surface, and never mutate the host. It also never executes the
|
|
7
|
+
* product or reads runtime state — it only reads source text and counts
|
|
8
|
+
* references. That makes reports deterministic, privacy-friendly (no user
|
|
9
|
+
* data, no network egress from the scan itself), and safe to run in CI.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IT COUNTS:
|
|
12
|
+
* - Custom-element tags matching `ed-*`, bucketed by Eddie's taxonomy:
|
|
13
|
+
* ed-r-* → recipes, ed-p-* → pages, everything else ed-* → components.
|
|
14
|
+
* - `--ed-*` custom-property references (token usage).
|
|
15
|
+
* Both are counted by occurrence, across every scanned file.
|
|
16
|
+
*/
|
|
17
|
+
export interface ScanOptions {
|
|
18
|
+
/** Skip files larger than this many bytes (default 2 MiB). Guards against minified bundles. */
|
|
19
|
+
maxFileBytes?: number;
|
|
20
|
+
/** Cap on files walked (default 20000). Guards against pathological trees. */
|
|
21
|
+
maxFiles?: number;
|
|
22
|
+
/** Extra directory names to ignore, merged with the defaults. */
|
|
23
|
+
ignoreDirs?: string[];
|
|
24
|
+
}
|
|
25
|
+
export interface ScanResult {
|
|
26
|
+
components: Record<string, number>;
|
|
27
|
+
recipes: Record<string, number>;
|
|
28
|
+
pages: Record<string, number>;
|
|
29
|
+
tokens: Record<string, number>;
|
|
30
|
+
filesScanned: number;
|
|
31
|
+
filesMatched: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Walk `dir` recursively and count Eddie asset usage. Symlinks are not
|
|
35
|
+
* followed (statSync on the entry, but we skip directory symlinks to avoid
|
|
36
|
+
* cycles). Unreadable files/dirs are skipped silently — a report is
|
|
37
|
+
* best-effort, never a build blocker.
|
|
38
|
+
*/
|
|
39
|
+
export declare function scanUsage(dir: string, options?: ScanOptions): ScanResult;
|
|
40
|
+
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA2BH,MAAM,WAAW,WAAW;IAC1B,+FAA+F;IAC/F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;AAwCD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,UAAU,CAmD5E"}
|
package/dist/scanner.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* scanner — statically detect Eddie asset usage in a product's source tree.
|
|
3
|
+
*
|
|
4
|
+
* DESIGN: zero dependencies (node built-ins only) and read-only. The reporter
|
|
5
|
+
* ships to arbitrary downstream products, so it must install fast, add no
|
|
6
|
+
* supply-chain surface, and never mutate the host. It also never executes the
|
|
7
|
+
* product or reads runtime state — it only reads source text and counts
|
|
8
|
+
* references. That makes reports deterministic, privacy-friendly (no user
|
|
9
|
+
* data, no network egress from the scan itself), and safe to run in CI.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IT COUNTS:
|
|
12
|
+
* - Custom-element tags matching `ed-*`, bucketed by Eddie's taxonomy:
|
|
13
|
+
* ed-r-* → recipes, ed-p-* → pages, everything else ed-* → components.
|
|
14
|
+
* - `--ed-*` custom-property references (token usage).
|
|
15
|
+
* Both are counted by occurrence, across every scanned file.
|
|
16
|
+
*/
|
|
17
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
18
|
+
import { join, extname } from 'node:path';
|
|
19
|
+
/** File extensions worth scanning for Eddie markup and token references. */
|
|
20
|
+
const SCANNED_EXTENSIONS = new Set([
|
|
21
|
+
'.html', '.htm',
|
|
22
|
+
'.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx',
|
|
23
|
+
'.vue', '.svelte', '.astro',
|
|
24
|
+
'.md', '.mdx',
|
|
25
|
+
'.njk', '.liquid', '.hbs', '.handlebars', '.ejs', '.erb', '.php', '.twig',
|
|
26
|
+
'.css', '.scss', '.sass', '.less',
|
|
27
|
+
]);
|
|
28
|
+
/** Directories never worth walking — build output, deps, VCS, caches. */
|
|
29
|
+
const IGNORED_DIRS = new Set([
|
|
30
|
+
'node_modules', '.git', 'dist', 'build', 'out', '.next', '.nuxt', '.output',
|
|
31
|
+
'.svelte-kit', '.astro', 'coverage', '.cache', '.vercel', '.netlify',
|
|
32
|
+
'storybook-static', '.turbo', 'vendor', 'tmp', '.eddie',
|
|
33
|
+
]);
|
|
34
|
+
/** Match an opening Eddie custom-element tag, e.g. `<ed-button`, `<ed-r-site-header`. */
|
|
35
|
+
const TAG_RE = /<(ed-[a-z0-9]+(?:-[a-z0-9]+)*)/gi;
|
|
36
|
+
/** Match an Eddie token reference, e.g. `--ed-theme-color-content-default`. */
|
|
37
|
+
const TOKEN_RE = /(--ed-[a-z0-9]+(?:-[a-z0-9]+)*)/gi;
|
|
38
|
+
function bump(map, key, by) {
|
|
39
|
+
map[key] = (map[key] ?? 0) + by;
|
|
40
|
+
}
|
|
41
|
+
/** Bucket a tag by Eddie's taxonomy prefix and record its occurrences. */
|
|
42
|
+
function recordTag(result, tag, count) {
|
|
43
|
+
const t = tag.toLowerCase();
|
|
44
|
+
if (t.startsWith('ed-r-'))
|
|
45
|
+
bump(result.recipes, t, count);
|
|
46
|
+
else if (t.startsWith('ed-p-'))
|
|
47
|
+
bump(result.pages, t, count);
|
|
48
|
+
else
|
|
49
|
+
bump(result.components, t, count);
|
|
50
|
+
}
|
|
51
|
+
/** Count all Eddie tag + token occurrences in one file's text. */
|
|
52
|
+
function scanText(result, text) {
|
|
53
|
+
let matched = false;
|
|
54
|
+
// Tally tags. We count by tag name so `<ed-button>...<ed-button>` → 2.
|
|
55
|
+
const tagCounts = new Map();
|
|
56
|
+
let m;
|
|
57
|
+
TAG_RE.lastIndex = 0;
|
|
58
|
+
while ((m = TAG_RE.exec(text)) !== null) {
|
|
59
|
+
tagCounts.set(m[1], (tagCounts.get(m[1]) ?? 0) + 1);
|
|
60
|
+
}
|
|
61
|
+
for (const [tag, count] of tagCounts) {
|
|
62
|
+
recordTag(result, tag, count);
|
|
63
|
+
matched = true;
|
|
64
|
+
}
|
|
65
|
+
// Tally token references.
|
|
66
|
+
TOKEN_RE.lastIndex = 0;
|
|
67
|
+
while ((m = TOKEN_RE.exec(text)) !== null) {
|
|
68
|
+
bump(result.tokens, m[1].toLowerCase(), 1);
|
|
69
|
+
matched = true;
|
|
70
|
+
}
|
|
71
|
+
return matched;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Walk `dir` recursively and count Eddie asset usage. Symlinks are not
|
|
75
|
+
* followed (statSync on the entry, but we skip directory symlinks to avoid
|
|
76
|
+
* cycles). Unreadable files/dirs are skipped silently — a report is
|
|
77
|
+
* best-effort, never a build blocker.
|
|
78
|
+
*/
|
|
79
|
+
export function scanUsage(dir, options = {}) {
|
|
80
|
+
const maxFileBytes = options.maxFileBytes ?? 2 * 1024 * 1024;
|
|
81
|
+
const maxFiles = options.maxFiles ?? 20000;
|
|
82
|
+
const ignore = new Set(IGNORED_DIRS);
|
|
83
|
+
for (const d of options.ignoreDirs ?? [])
|
|
84
|
+
ignore.add(d);
|
|
85
|
+
const result = {
|
|
86
|
+
components: {},
|
|
87
|
+
recipes: {},
|
|
88
|
+
pages: {},
|
|
89
|
+
tokens: {},
|
|
90
|
+
filesScanned: 0,
|
|
91
|
+
filesMatched: 0,
|
|
92
|
+
};
|
|
93
|
+
const stack = [dir];
|
|
94
|
+
while (stack.length > 0) {
|
|
95
|
+
if (result.filesScanned >= maxFiles)
|
|
96
|
+
break;
|
|
97
|
+
const current = stack.pop();
|
|
98
|
+
let entries;
|
|
99
|
+
try {
|
|
100
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
for (const entry of entries) {
|
|
106
|
+
const full = join(current, entry.name);
|
|
107
|
+
if (entry.isDirectory()) {
|
|
108
|
+
if (ignore.has(entry.name) || entry.name.startsWith('.'))
|
|
109
|
+
continue;
|
|
110
|
+
stack.push(full);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (!entry.isFile())
|
|
114
|
+
continue;
|
|
115
|
+
if (!SCANNED_EXTENSIONS.has(extname(entry.name).toLowerCase()))
|
|
116
|
+
continue;
|
|
117
|
+
if (result.filesScanned >= maxFiles)
|
|
118
|
+
break;
|
|
119
|
+
try {
|
|
120
|
+
const { size } = statSync(full);
|
|
121
|
+
if (size > maxFileBytes)
|
|
122
|
+
continue;
|
|
123
|
+
result.filesScanned++;
|
|
124
|
+
const text = readFileSync(full, 'utf-8');
|
|
125
|
+
if (scanText(result, text))
|
|
126
|
+
result.filesMatched++;
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAA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,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;oBAAE,SAAS;gBACnE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACjB,SAAS;YACX,CAAC;YACD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;gBAAE,SAAS;YAC9B,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;gBAAE,SAAS;YACzE,IAAI,MAAM,CAAC,YAAY,IAAI,QAAQ;gBAAE,MAAM;YAE3C,IAAI,CAAC;gBACH,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAChC,IAAI,IAAI,GAAG,YAAY;oBAAE,SAAS;gBAClC,MAAM,CAAC,YAAY,EAAE,CAAC;gBACtB,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACzC,IAAI,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;oBAAE,MAAM,CAAC,YAAY,EAAE,CAAC;YACpD,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS;YACX,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transport — deliver a UsageReport back to Eddie's Brain.
|
|
3
|
+
*
|
|
4
|
+
* Two paths, in priority order:
|
|
5
|
+
* 1. HTTP beacon — POST the report JSON to the brain's `/report` ingestion
|
|
6
|
+
* endpoint (the hosted Eddie site). Low-friction, live.
|
|
7
|
+
* 2. Local artifact — write the report to a file the product's CI can commit,
|
|
8
|
+
* or that the brain's org scan / a human can pick up later. This is the
|
|
9
|
+
* durable fallback: it works with no network and no telemetry server, and
|
|
10
|
+
* keeps the reporter useful in air-gapped or privacy-strict setups.
|
|
11
|
+
*
|
|
12
|
+
* The beacon is best-effort: a delivery failure NEVER throws out of the CLI
|
|
13
|
+
* (a usage report must never break someone's build). We always also write the
|
|
14
|
+
* local artifact unless explicitly told not to, so no report is ever lost.
|
|
15
|
+
*/
|
|
16
|
+
import type { UsageReport } from './types.js';
|
|
17
|
+
export interface SendOptions {
|
|
18
|
+
/** Brain ingestion URL, e.g. https://ds.bradfrost.com/report. Omit to skip the beacon. */
|
|
19
|
+
endpoint?: string;
|
|
20
|
+
/** Optional bearer token, sent as `Authorization: Bearer <token>`. */
|
|
21
|
+
token?: string;
|
|
22
|
+
/** Where to write the local artifact. Default `.eddie/usage-report.json`. Pass '' to skip. */
|
|
23
|
+
out?: string;
|
|
24
|
+
/** Don't POST or write — just resolve what would happen. */
|
|
25
|
+
dryRun?: boolean;
|
|
26
|
+
/** Beacon timeout in ms (default 5000). */
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
/** Injectable fetch for testing. Defaults to global fetch. */
|
|
29
|
+
fetchImpl?: typeof fetch;
|
|
30
|
+
}
|
|
31
|
+
export interface SendResult {
|
|
32
|
+
beacon: 'sent' | 'failed' | 'skipped';
|
|
33
|
+
beaconStatus?: number;
|
|
34
|
+
beaconError?: string;
|
|
35
|
+
artifact: 'written' | 'skipped';
|
|
36
|
+
artifactPath?: string;
|
|
37
|
+
dryRun: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Deliver a report. Never throws for a network/beacon failure — the failure is
|
|
41
|
+
* reflected in the returned result. Only a genuinely impossible local write
|
|
42
|
+
* (e.g. an unwritable path) surfaces as a thrown error.
|
|
43
|
+
*/
|
|
44
|
+
export declare function sendReport(report: UsageReport, opts?: SendOptions): Promise<SendResult>;
|
|
45
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,WAAW;IAC1B,0FAA0F;IAC1F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8FAA8F;IAC9F,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;CACjB;AAiCD;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAgCjG"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transport — deliver a UsageReport back to Eddie's Brain.
|
|
3
|
+
*
|
|
4
|
+
* Two paths, in priority order:
|
|
5
|
+
* 1. HTTP beacon — POST the report JSON to the brain's `/report` ingestion
|
|
6
|
+
* endpoint (the hosted Eddie site). Low-friction, live.
|
|
7
|
+
* 2. Local artifact — write the report to a file the product's CI can commit,
|
|
8
|
+
* or that the brain's org scan / a human can pick up later. This is the
|
|
9
|
+
* durable fallback: it works with no network and no telemetry server, and
|
|
10
|
+
* keeps the reporter useful in air-gapped or privacy-strict setups.
|
|
11
|
+
*
|
|
12
|
+
* The beacon is best-effort: a delivery failure NEVER throws out of the CLI
|
|
13
|
+
* (a usage report must never break someone's build). We always also write the
|
|
14
|
+
* local artifact unless explicitly told not to, so no report is ever lost.
|
|
15
|
+
*/
|
|
16
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
17
|
+
import { dirname, resolve } from 'node:path';
|
|
18
|
+
const DEFAULT_OUT = '.eddie/usage-report.json';
|
|
19
|
+
async function postReport(report, opts) {
|
|
20
|
+
const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
|
|
21
|
+
if (!fetchImpl) {
|
|
22
|
+
return { ok: false, error: 'global fetch unavailable (Node 18+ required)' };
|
|
23
|
+
}
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 5000);
|
|
26
|
+
try {
|
|
27
|
+
const res = await fetchImpl(opts.endpoint, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
...(opts.token ? { Authorization: `Bearer ${opts.token}` } : {}),
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify(report),
|
|
34
|
+
signal: controller.signal,
|
|
35
|
+
});
|
|
36
|
+
return { ok: res.ok, status: res.status, error: res.ok ? undefined : `HTTP ${res.status}` };
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Deliver a report. Never throws for a network/beacon failure — the failure is
|
|
47
|
+
* reflected in the returned result. Only a genuinely impossible local write
|
|
48
|
+
* (e.g. an unwritable path) surfaces as a thrown error.
|
|
49
|
+
*/
|
|
50
|
+
export async function sendReport(report, opts = {}) {
|
|
51
|
+
const out = opts.out === '' ? '' : opts.out ?? DEFAULT_OUT;
|
|
52
|
+
if (opts.dryRun) {
|
|
53
|
+
return {
|
|
54
|
+
beacon: opts.endpoint ? 'skipped' : 'skipped',
|
|
55
|
+
artifact: out ? 'skipped' : 'skipped',
|
|
56
|
+
artifactPath: out || undefined,
|
|
57
|
+
dryRun: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const result = { beacon: 'skipped', artifact: 'skipped', dryRun: false };
|
|
61
|
+
// 1. Beacon.
|
|
62
|
+
if (opts.endpoint) {
|
|
63
|
+
const posted = await postReport(report, opts);
|
|
64
|
+
result.beacon = posted.ok ? 'sent' : 'failed';
|
|
65
|
+
result.beaconStatus = posted.status;
|
|
66
|
+
result.beaconError = posted.error;
|
|
67
|
+
}
|
|
68
|
+
// 2. Local artifact — always written (unless suppressed) so no report is lost.
|
|
69
|
+
if (out) {
|
|
70
|
+
const path = resolve(out);
|
|
71
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
72
|
+
writeFileSync(path, JSON.stringify(report, null, 2), 'utf-8');
|
|
73
|
+
result.artifact = 'written';
|
|
74
|
+
result.artifactPath = path;
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2B7C,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAE/C,KAAK,UAAU,UAAU,CACvB,MAAmB,EACnB,IAAiB;IAEjB,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAK,UAAU,CAAC,KAAkC,CAAC;IACnF,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAA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AAG,IAAI,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared shape of an Eddie usage report.
|
|
3
|
+
*
|
|
4
|
+
* This is the wire contract between the Eddie-reporter (client, runs inside a
|
|
5
|
+
* downstream product) and Eddie's Brain (server, ingests into the activity
|
|
6
|
+
* ledger). Keep it small, flat, and JSON-safe — it travels over HTTP, gets
|
|
7
|
+
* committed to git, and is appended to `.eddie-brain/activity.json`.
|
|
8
|
+
*
|
|
9
|
+
* The `schema` field is a version tag so the brain can evolve ingestion
|
|
10
|
+
* without breaking older reporters in the wild. Bump the suffix on a
|
|
11
|
+
* breaking change; add optional fields freely without a bump.
|
|
12
|
+
*/
|
|
13
|
+
export declare const REPORT_SCHEMA: "eddie-usage-report/1";
|
|
14
|
+
/** How the report was triggered. Purely informational — the brain records it. */
|
|
15
|
+
export type ReportEvent = 'build' | 'deploy' | 'install' | 'ci' | 'dev' | 'manual';
|
|
16
|
+
/** Where the report ran. */
|
|
17
|
+
export type ReportEnvironment = 'ci' | 'local' | 'unknown';
|
|
18
|
+
/** Identity of the product that produced the report. */
|
|
19
|
+
export interface ProductIdentity {
|
|
20
|
+
/**
|
|
21
|
+
* Stable identifier, resolved in this order: the product's package.json
|
|
22
|
+
* `name`, else its git `owner/repo` slug, else the scanned directory name.
|
|
23
|
+
* This is the key the brain rolls activity up by, so it must be stable
|
|
24
|
+
* across runs of the same product.
|
|
25
|
+
*/
|
|
26
|
+
id: string;
|
|
27
|
+
/** Human-friendly name (package.json name), when available. */
|
|
28
|
+
name?: string;
|
|
29
|
+
/** `owner/repo` slug parsed from the git origin remote, when available. */
|
|
30
|
+
repo?: string;
|
|
31
|
+
/** Current git branch, when resolvable from `.git`. */
|
|
32
|
+
branch?: string;
|
|
33
|
+
/** Current commit SHA, when resolvable from `.git`. */
|
|
34
|
+
commit?: string;
|
|
35
|
+
/** ci when a CI env var is set, local otherwise. */
|
|
36
|
+
environment: ReportEnvironment;
|
|
37
|
+
}
|
|
38
|
+
/** The Eddie packages a product declares, and their short surfaces. */
|
|
39
|
+
export interface EddieDependencyInfo {
|
|
40
|
+
/** Full package name → declared version range from package.json. */
|
|
41
|
+
declared: Record<string, string>;
|
|
42
|
+
/** Short surfaces in use: tokens, web-components, recipes, icons, charts, pages. */
|
|
43
|
+
packages: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* What Eddie assets the static scan found, and how often. Tag buckets are
|
|
47
|
+
* split by Eddie's taxonomy prefix so the brain can distinguish core-component
|
|
48
|
+
* usage from recipe and page-template usage without re-parsing tags:
|
|
49
|
+
* - components: `ed-*` that are not `ed-r-*` / `ed-p-*`
|
|
50
|
+
* - recipes: `ed-r-*`
|
|
51
|
+
* - pages: `ed-p-*`
|
|
52
|
+
* Values are occurrence counts (how many times the tag/token appears).
|
|
53
|
+
*/
|
|
54
|
+
export interface UsageBreakdown {
|
|
55
|
+
components: Record<string, number>;
|
|
56
|
+
recipes: Record<string, number>;
|
|
57
|
+
pages: Record<string, number>;
|
|
58
|
+
/** `--ed-*` custom-property references → occurrence count. */
|
|
59
|
+
tokens: Record<string, number>;
|
|
60
|
+
/** Source files walked. */
|
|
61
|
+
filesScanned: number;
|
|
62
|
+
/** Source files that contained at least one Eddie asset. */
|
|
63
|
+
filesMatched: number;
|
|
64
|
+
}
|
|
65
|
+
export interface UsageReport {
|
|
66
|
+
schema: typeof REPORT_SCHEMA;
|
|
67
|
+
/** Version of the reporter that produced this report. */
|
|
68
|
+
reporterVersion: string;
|
|
69
|
+
/** ISO timestamp the report was generated. */
|
|
70
|
+
generatedAt: string;
|
|
71
|
+
event: ReportEvent;
|
|
72
|
+
product: ProductIdentity;
|
|
73
|
+
eddie: EddieDependencyInfo;
|
|
74
|
+
usage: UsageBreakdown;
|
|
75
|
+
/** Convenience roll-ups so consumers don't have to recompute from maps. */
|
|
76
|
+
totals: {
|
|
77
|
+
/** Distinct component tags used. */
|
|
78
|
+
distinctComponents: number;
|
|
79
|
+
/** Distinct recipe tags used. */
|
|
80
|
+
distinctRecipes: number;
|
|
81
|
+
/** Distinct page templates used. */
|
|
82
|
+
distinctPages: number;
|
|
83
|
+
/** Distinct tokens referenced. */
|
|
84
|
+
distinctTokens: number;
|
|
85
|
+
/** Total Eddie asset occurrences across all buckets. */
|
|
86
|
+
occurrences: number;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,aAAa,EAAG,sBAA+B,CAAC;AAE7D,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEnF,4BAA4B;AAC5B,MAAM,MAAM,iBAAiB,GAAG,IAAI,GAAG,OAAO,GAAG,SAAS,CAAC;AAE3D,wDAAwD;AACxD,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,EAAE,EAAE,MAAM,CAAC;IACX,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,WAAW,EAAE,iBAAiB,CAAC;CAChC;AAED,uEAAuE;AACvE,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,oFAAoF;IACpF,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,2BAA2B;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,OAAO,aAAa,CAAC;IAC7B,yDAAyD;IACzD,eAAe,EAAE,MAAM,CAAC;IACxB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,eAAe,CAAC;IACzB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,KAAK,EAAE,cAAc,CAAC;IACtB,2EAA2E;IAC3E,MAAM,EAAE;QACN,oCAAoC;QACpC,kBAAkB,EAAE,MAAM,CAAC;QAC3B,iCAAiC;QACjC,eAAe,EAAE,MAAM,CAAC;QACxB,oCAAoC;QACpC,aAAa,EAAE,MAAM,CAAC;QACtB,kCAAkC;QAClC,cAAc,EAAE,MAAM,CAAC;QACvB,wDAAwD;QACxD,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared shape of an Eddie usage report.
|
|
3
|
+
*
|
|
4
|
+
* This is the wire contract between the Eddie-reporter (client, runs inside a
|
|
5
|
+
* downstream product) and Eddie's Brain (server, ingests into the activity
|
|
6
|
+
* ledger). Keep it small, flat, and JSON-safe — it travels over HTTP, gets
|
|
7
|
+
* committed to git, and is appended to `.eddie-brain/activity.json`.
|
|
8
|
+
*
|
|
9
|
+
* The `schema` field is a version tag so the brain can evolve ingestion
|
|
10
|
+
* without breaking older reporters in the wild. Bump the suffix on a
|
|
11
|
+
* breaking change; add optional fields freely without a bump.
|
|
12
|
+
*/
|
|
13
|
+
export const REPORT_SCHEMA = 'eddie-usage-report/1';
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,sBAA+B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brad-frost-web/eddie-reporter",
|
|
3
|
+
"version": "0.40.0",
|
|
4
|
+
"description": "The Eddie-reporter — a zero-dependency usage reporter installed on downstream Eddie products. It statically scans a product for Eddie asset usage (components, recipes, pages, tokens) and reports the activity back to Eddie's Brain, so adoption and activity of the design system can be tracked as a living feedback loop.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"eddie-report": "dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"templates",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"dev": "tsc --watch",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest",
|
|
30
|
+
"report": "node dist/cli.js"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"design-system",
|
|
34
|
+
"adoption",
|
|
35
|
+
"telemetry",
|
|
36
|
+
"usage",
|
|
37
|
+
"eddie",
|
|
38
|
+
"analytics"
|
|
39
|
+
],
|
|
40
|
+
"author": "Brad Frost and Ian Frost",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"vitest": "^3.2.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Eddie usage reporter — drop this into a downstream Eddie product at
|
|
2
|
+
# `.github/workflows/eddie-report.yml`. It reports which Eddie assets the
|
|
3
|
+
# product uses back to Eddie's Brain whenever the default branch changes, and
|
|
4
|
+
# on a weekly cadence, so adoption + activity stay current.
|
|
5
|
+
#
|
|
6
|
+
# Set the repository secret EDDIE_REPORT_ENDPOINT (e.g. https://ds.bradfrost.com/report).
|
|
7
|
+
# Optionally set EDDIE_REPORT_TOKEN if the endpoint requires auth.
|
|
8
|
+
name: Eddie usage report
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [main, develop]
|
|
13
|
+
schedule:
|
|
14
|
+
- cron: '0 6 * * 1' # Mondays 06:00 UTC
|
|
15
|
+
workflow_dispatch:
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
report:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
timeout-minutes: 5
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
- uses: actions/setup-node@v4
|
|
24
|
+
with:
|
|
25
|
+
node-version: 20
|
|
26
|
+
# No install needed — run the reporter straight from npm.
|
|
27
|
+
- name: Report Eddie usage
|
|
28
|
+
env:
|
|
29
|
+
EDDIE_REPORT_ENDPOINT: ${{ secrets.EDDIE_REPORT_ENDPOINT }}
|
|
30
|
+
EDDIE_REPORT_TOKEN: ${{ secrets.EDDIE_REPORT_TOKEN }}
|
|
31
|
+
run: npx --yes @brad-frost-web/eddie-reporter --event ci
|