@civicactions/cmsds-open-data-components 4.0.8-alpha.1 → 4.0.8-alpha.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civicactions/cmsds-open-data-components",
3
- "version": "4.0.8-alpha.1",
3
+ "version": "4.0.8-alpha.2",
4
4
  "description": "Components for the open data catalog frontend using CMS Design System",
5
5
  "main": "dist/main.js",
6
6
  "source": "src/index.ts",
@@ -241,7 +241,7 @@ function generateUsageRow(name, usages, category) {
241
241
  const githubUrl = `https://github.com/GetDKAN/cmsds-open-data-components/tree/main/${githubPath}`;
242
242
  const nameLink = `[${name}](${githubUrl})`;
243
243
 
244
- return `| ${nameLink} | ${category} | ${count} | ${fileList} |`;
244
+ return `| ${nameLink} | ${count} | ${fileList} |`;
245
245
  }
246
246
 
247
247
  /**
@@ -400,26 +400,48 @@ function addCategoryBreakdown(lines, categorized) {
400
400
  }
401
401
 
402
402
  /**
403
- * Add detailed usage table section
403
+ * Add detailed usage table section grouped by category
404
404
  */
405
405
  function addUsageTable(lines, usageMap) {
406
406
  lines.push('## Component Usage Details');
407
407
  lines.push('');
408
- lines.push('| Component | Type | Usage Count | Used In |');
409
- lines.push('|-----------|------|-------------|---------|');
410
408
 
411
- // Sort by usage count (descending)
412
- const sortedComponents = Array.from(usageMap.entries())
413
- .sort((a, b) => b[1].length - a[1].length);
414
-
415
- sortedComponents.forEach(([name, usages]) => {
409
+ // Categorize all components
410
+ const categorized = new Map();
411
+ usageMap.forEach((usages, name) => {
416
412
  const category = categorizeComponent(name);
417
- lines.push(generateUsageRow(name, usages, category));
413
+ if (!categorized.has(category)) {
414
+ categorized.set(category, []);
415
+ }
416
+ categorized.get(category).push({ name, usages });
418
417
  });
419
418
 
420
- lines.push('');
421
- lines.push('---');
422
- lines.push('');
419
+ // Generate a table for each category
420
+ const categories = ['Component', 'Template', 'Hook', 'Context', 'Service', 'Utility'];
421
+ categories.forEach(category => {
422
+ const items = categorized.get(category);
423
+ if (!items || items.length === 0) return;
424
+
425
+ // Sort by usage count within category
426
+ items.sort((a, b) => b.usages.length - a.usages.length);
427
+
428
+ // Category header
429
+ lines.push(`### ${category}s`);
430
+ lines.push('');
431
+
432
+ // Table header
433
+ lines.push('| Component | Count | Used In |');
434
+ lines.push('|-----------|-------|---------|');
435
+
436
+ // Table rows
437
+ items.forEach(({ name, usages }) => {
438
+ lines.push(generateUsageRow(name, usages, category));
439
+ });
440
+
441
+ lines.push('');
442
+ lines.push('---');
443
+ lines.push('');
444
+ });
423
445
  }
424
446
 
425
447
  /**
package/scripts/README.md DELETED
@@ -1,264 +0,0 @@
1
- # Scripts Documentation
2
-
3
- This directory contains utility scripts for managing and analyzing the cmsds-open-data-components library.
4
-
5
- ## Component Inventory Generator
6
-
7
- This script automatically generates a comprehensive markdown inventory report for the cmsds-open-data-components library.
8
-
9
- ## Usage
10
-
11
- Run the script using npm:
12
-
13
- ```bash
14
- npm run generate:inventory
15
- ```
16
-
17
- Or run it directly:
18
-
19
- ```bash
20
- node scripts/generate-inventory.cjs
21
- ```
22
-
23
- ## Output
24
-
25
- The script generates `COMPONENTS_INVENTORY.md` in the root directory containing:
26
-
27
- - **Inventory Table**: Complete list of all components, services, templates, hooks, contexts, utilities, types, and assets
28
- - **Public Export Status**: Indicates which items are publicly exported vs internal-only
29
- - **Storybook Status**: Shows which items have Storybook stories for visual documentation
30
- - **Unit Test Status**: Shows which items have unit test coverage
31
- - **Quality Metrics**: Summary statistics for documentation and testing coverage
32
- - **Export Summary**: Count of public vs internal items by category
33
-
34
- ## What It Scans
35
-
36
- The script automatically scans the following directories:
37
-
38
- - `src/components/` - React components
39
- - `src/templates/` - Page-level templates
40
- - `src/services/` - API service hooks
41
- - `src/utilities/` - Utility functions
42
- - `src/types/` - TypeScript type definitions
43
- - `src/assets/` - Static assets and data files
44
-
45
- It also automatically detects:
46
- - **Hooks**: Directories or files starting with `use` (e.g., `useScrollToTop`)
47
- - **Contexts**: Files ending with `Context` that contain `createContext()` calls
48
-
49
- ## How It Works
50
-
51
- 1. **Reads `src/index.ts`** to determine which items are publicly exported
52
- 2. **Scans each directory** for subdirectories and files
53
- 3. **Dynamically discovers hooks and contexts** by naming patterns and file content
54
- 4. **Checks for `.stories.*` files** to determine Storybook coverage
55
- 5. **Checks for `.test.*` and `.spec.*` files** to determine unit test coverage
56
- 6. **Calculates statistics** for overall project quality metrics
57
- 7. **Generates markdown** with formatted tables and summaries
58
-
59
- ## Maintenance
60
-
61
- The script is designed to automatically adapt to changes in the codebase:
62
-
63
- - New components/templates/services/hooks/contexts are automatically discovered
64
- - Public export status updates when `src/index.ts` changes
65
- - Story and test status updates as files are added/removed
66
- - Statistics recalculate automatically
67
-
68
- No manual updates needed when adding or removing hooks and contexts!
69
-
70
- ### Hook and Context Detection
71
-
72
- **Hooks** are detected by:
73
- - Directory names starting with `use` (e.g., `src/components/useScrollToTop/`)
74
- - File names starting with `use` (e.g., `useAddLoginLink.ts`)
75
-
76
- **Contexts** are detected by:
77
- - File names ending with `Context` (e.g., `HeaderContext.tsx`)
78
- - File must contain a `createContext()` call
79
- - Export name is extracted from `export default` or `export const` statements
80
-
81
- The scanner automatically excludes test and story files to prevent false positives.
82
-
83
- ### Known Special Cases
84
-
85
- The script handles several special cases:
86
-
87
- - **DatasetAdditionalInformation**: Exports `buildRows` function
88
- - **DatasetTableTab**: Exported as `DatasetTable`
89
- - **Datatable**: Exported as `DataTable` (case difference)
90
- - **frequencyMap**: Commented out in exports
91
- - **aca.ts**: Exports `acaToParams` function
92
-
93
- To add new special cases, update the scanning functions in `generate-inventory.cjs`.
94
-
95
- ## File Structure
96
-
97
- ```
98
- scripts/
99
- generate-inventory.cjs # Component inventory script
100
- generate-inventory.test.js # Tests for inventory script
101
- generate-usage-report.cjs # Component usage report script
102
- generate-usage-report.test.js # Tests for usage report script
103
- README.md # This file
104
-
105
- COMPONENTS_INVENTORY.md # Generated inventory (root directory)
106
- COMPONENT_USAGE_REPORT.md # Generated usage report (root directory, when run in dependent projects)
107
- SAMPLE_COMPONENT_USAGE_REPORT.md # Sample usage report (root directory, when run locally)
108
- ```
109
-
110
- ---
111
-
112
- # Component Usage Report Generator
113
-
114
- This script analyzes projects that use cmsds-open-data-components as a dependency and generates a comprehensive report showing which components are being used and where.
115
-
116
- ## Usage
117
-
118
- ### In Projects Using cmsds-open-data-components
119
-
120
- From a project that has `@civicactions/cmsds-open-data-components` as a dependency:
121
-
122
- ```bash
123
- npx generate-usage-report
124
- ```
125
-
126
- Or add to your project's scripts in `package.json`:
127
- ```json
128
- {
129
- "scripts": {
130
- "usage-report": "generate-usage-report"
131
- }
132
- }
133
- ```
134
-
135
- Then run:
136
- ```bash
137
- npm run usage-report
138
- ```
139
-
140
- ### In the Library Repository
141
-
142
- Run the script directly in this repository to generate a sample report:
143
-
144
- ```bash
145
- npm run generate:usage-report
146
- ```
147
-
148
- Or run it directly:
149
-
150
- ```bash
151
- node scripts/generate-usage-report.cjs
152
- ```
153
-
154
- When run in the library repository, it generates a sample report (`SAMPLE_COMPONENT_USAGE_REPORT.md`) by analyzing Storybook files.
155
-
156
- ## Output
157
-
158
- The script generates a markdown report containing:
159
-
160
- - **Library Version**: Version of cmsds-open-data-components being analyzed
161
- - **Summary Statistics**: Total unique components, import statements, and files analyzed
162
- - **Category Breakdown**: Components grouped by type (Component, Template, Hook, Context, Service, Utility)
163
- - **Component Usage Details**: Table showing each component with:
164
- - Component name (linked to GitHub repository)
165
- - Category/type
166
- - Number of times imported
167
- - List of files where it's used
168
-
169
- ## What It Scans
170
-
171
- The script scans the following directories in your project:
172
-
173
- - `src/` - Main source directory
174
- - `app/` - Next.js app directory
175
- - `pages/` - Next.js pages directory
176
- - `components/` - Components directory
177
- - `templates/` - Templates directory
178
-
179
- It searches for these file types:
180
- - `.js`, `.jsx` - JavaScript/React files
181
- - `.ts`, `.tsx` - TypeScript/React files
182
-
183
- The script automatically excludes:
184
- - `node_modules/` - Dependencies
185
- - `dist/`, `build/` - Build output directories
186
- - `.next/`, `.cache/` - Framework cache directories
187
-
188
- ## How It Works
189
-
190
- 1. **Detects execution context**: Determines if running in the library repo or a dependent project
191
- 2. **Scans project files**: Recursively searches for JavaScript/TypeScript files
192
- 3. **Parses imports**: Uses regex to find imports from `@civicactions/cmsds-open-data-components`
193
- 4. **Tracks usage**: Records each component, where it's imported, and at what line number
194
- 5. **Categorizes components**: Automatically categorizes by naming patterns:
195
- - Hooks: Names starting with `use`
196
- - Contexts: Names ending with `Context`
197
- - Templates: From `templates/` directory
198
- - Services: From `services/` directory
199
- - Utilities: From `utilities/` directory
200
- - Components: Everything else
201
- 6. **Generates report**: Creates formatted markdown with statistics and detailed usage tables
202
- 7. **Adds GitHub links**: Links each component name to its source in the GitHub repository
203
-
204
- ## Component Categories
205
-
206
- Components are automatically categorized based on naming conventions and source location:
207
-
208
- - **Hook**: Components starting with `use` (e.g., `useScrollToTop`, `useDatastore`)
209
- - **Context**: Components ending with `Context` (e.g., `ACAContext`)
210
- - **Template**: Components from the `templates/` directory
211
- - **Service**: Components from the `services/` directory
212
- - **Utility**: Components from the `utilities/` directory
213
- - **Component**: All other React components
214
-
215
- ## Sample vs Real Reports
216
-
217
- **In the library repository**: Generates `SAMPLE_COMPONENT_USAGE_REPORT.md` by analyzing how components are used in Storybook files. This serves as an example of the report format.
218
-
219
- **In dependent projects**: Generates `COMPONENT_USAGE_REPORT.md` by analyzing actual component usage throughout the project's codebase.
220
-
221
- ## Requirements
222
-
223
- - Node.js v14 or higher
224
- - No additional dependencies required (uses Node.js built-in `fs` and `path` modules)
225
-
226
- ## Troubleshooting
227
-
228
- **Error: "require is not defined"**
229
- - The script uses `.cjs` extension to work with the ES module package type
230
- - Make sure the file is named `generate-usage-report.cjs` (not `.js`)
231
-
232
- **No components found in scan**
233
- - Verify that `@civicactions/cmsds-open-data-components` is installed as a dependency
234
- - Check that your import statements use the full package name
235
- - Ensure source files are in scanned directories (`src/`, `app/`, `pages/`, `components/`, `templates/`)
236
-
237
- **Missing some component usages**
238
- - The script only detects standard ES6 import syntax
239
- - Dynamic imports (e.g., `import()`) are not currently detected
240
- - Ensure imports use the package name: `from '@civicactions/cmsds-open-data-components'`
241
-
242
- ---
243
-
244
- ## File Structure
245
-
246
- ## Requirements
247
-
248
- - Node.js v14 or higher
249
- - No additional dependencies required (uses Node.js built-in `fs` and `path` modules)
250
-
251
- ## Troubleshooting
252
-
253
- **Error: "require is not defined"**
254
- - The script uses `.cjs` extension to work with the ES module package type
255
- - Make sure the file is named `generate-inventory.cjs` (not `.js`)
256
-
257
- **Missing components in output**
258
- - Ensure new components follow the standard directory structure
259
- - Component directories should be in `src/components/`
260
- - Each component should have an `index.tsx` or similar entry file
261
-
262
- **Incorrect public export status**
263
- - Check if the component is exported in `src/index.ts`
264
- - For special export names, add them to the scanning logic in the script