@nexub/tokens 3.6.0 → 3.8.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/bin/nexub-usage.mjs +71 -0
- package/package.json +3 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// nexub-usage: counts which @nexub exports your repos import, so the design
|
|
3
|
+
// system's deprecations and codemods follow real usage (roadmap R6).
|
|
4
|
+
//
|
|
5
|
+
// npx -p @nexub/tokens nexub-usage ./apps/web ./apps/admin markdown table
|
|
6
|
+
// npx -p @nexub/tokens nexub-usage . --json JSON
|
|
7
|
+
//
|
|
8
|
+
// ponytail: regex over import statements, not a TS parse. It misses
|
|
9
|
+
// `import * as N` member use and re-exports; switch to the TS API if those matter.
|
|
10
|
+
|
|
11
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
12
|
+
import { join, extname } from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
|
|
15
|
+
const SKIP = new Set(['node_modules', 'dist', 'lib', 'build', '.next', '.expo', '.turbo', '.git', 'coverage']);
|
|
16
|
+
const EXT = new Set(['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs']);
|
|
17
|
+
const IMPORT = /import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*['"](@nexub\/[^'"]+)['"]/g;
|
|
18
|
+
|
|
19
|
+
/** Returns [{ pkg, name }] for every named @nexub import in one source file. */
|
|
20
|
+
export function scanSource(text) {
|
|
21
|
+
const out = [];
|
|
22
|
+
for (const [, names, pkg] of text.matchAll(IMPORT)) {
|
|
23
|
+
for (const raw of names.split(',')) {
|
|
24
|
+
const name = raw.trim().replace(/^type\s+/, '').split(/\s+as\s+/)[0].trim();
|
|
25
|
+
if (name) out.push({ pkg, name });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function* files(dir) {
|
|
32
|
+
for (const entry of readdirSync(dir)) {
|
|
33
|
+
if (SKIP.has(entry)) continue;
|
|
34
|
+
const path = join(dir, entry);
|
|
35
|
+
if (statSync(path).isDirectory()) yield* files(path);
|
|
36
|
+
else if (EXT.has(extname(entry))) yield path;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Tallies imports across repos: one row per pkg + export, with use and repo counts. */
|
|
41
|
+
export function scanRepos(roots) {
|
|
42
|
+
const tally = new Map();
|
|
43
|
+
for (const root of roots) {
|
|
44
|
+
for (const file of files(root)) {
|
|
45
|
+
for (const { pkg, name } of scanSource(readFileSync(file, 'utf8'))) {
|
|
46
|
+
const key = `${pkg} ${name}`;
|
|
47
|
+
const row = tally.get(key) ?? { pkg, name, uses: 0, repos: new Set() };
|
|
48
|
+
row.uses++;
|
|
49
|
+
row.repos.add(root);
|
|
50
|
+
tally.set(key, row);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return [...tally.values()].sort((a, b) => b.uses - a.uses || a.name.localeCompare(b.name));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
58
|
+
const args = process.argv.slice(2);
|
|
59
|
+
const roots = args.filter((a) => !a.startsWith('--'));
|
|
60
|
+
if (!roots.length) {
|
|
61
|
+
console.error('usage: nexub-usage <repo-dir>... [--json]');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const rows = scanRepos(roots);
|
|
65
|
+
if (args.includes('--json')) {
|
|
66
|
+
console.log(JSON.stringify(rows.map((r) => ({ ...r, repos: [...r.repos] })), null, 2));
|
|
67
|
+
} else {
|
|
68
|
+
console.log('| Package | Export | Imports | Repos |\n|---|---|---|---|');
|
|
69
|
+
for (const r of rows) console.log(`| ${r.pkg} | ${r.name} | ${r.uses} | ${r.repos.size} |`);
|
|
70
|
+
}
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexub/tokens",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Design tokens for Nexub Design System — colours, typography, spacing, radii, shadows, and motion as CSS variables, Tailwind presets and React Native objects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"bin": {
|
|
24
|
-
"nexub-migrate": "./bin/nexub-migrate.mjs"
|
|
24
|
+
"nexub-migrate": "./bin/nexub-migrate.mjs",
|
|
25
|
+
"nexub-usage": "./bin/nexub-usage.mjs"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"dist",
|