Skip to content

Commit 261a594

Browse files
committed
Enhance Excel parsing: update constraints structure and add CLI for parsing Excel files
1 parent e1ca80d commit 261a594

10 files changed

Lines changed: 710 additions & 84 deletions

File tree

package-lock.json

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

packages/excel-parser/README.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,80 @@ A package for parsing and generating Excel files for NHS Notify supplier configu
1010

1111
## Usage
1212

13-
### Parsing an Excel file
13+
### CLI Commands
14+
15+
#### Parse Excel to JSON
16+
17+
Parse an Excel file and output the parsed JSON data:
18+
19+
```bash
20+
# Parse and output to stdout
21+
npm run parse -- config.xlsx
22+
23+
# Parse and pretty-print to stdout
24+
npm run parse -- config.xlsx --pretty
25+
26+
# Parse and save to file
27+
npm run parse -- config.xlsx -o output.json
28+
29+
# Parse with pretty formatting and save to file
30+
npm run parse -- config.xlsx --pretty --output output.json
31+
32+
# Show help
33+
npm run parse -- --help
34+
```
35+
36+
**Options:**
37+
38+
- `-o, --output <file>` - Write output to a file instead of stdout
39+
- `-p, --pretty` - Pretty-print the JSON output
40+
- `-h, --help` - Show help message
41+
42+
**Output format:**
43+
44+
The JSON output contains the following top-level keys:
45+
46+
- `packs` - Record of PackSpecification objects keyed by ID
47+
- `variants` - Record of LetterVariant objects keyed by ID
48+
- `volumeGroups` - Record of VolumeGroup objects keyed by ID
49+
- `suppliers` - Record of Supplier objects keyed by ID
50+
- `allocations` - Record of SupplierAllocation objects keyed by ID
51+
- `supplierPacks` - Record of SupplierPack objects keyed by ID
52+
53+
#### Generate Template
54+
55+
Generate a template Excel file with the correct sheet structure and column headers:
56+
57+
```bash
58+
# Generate a new template
59+
npm run template -- output.xlsx
60+
61+
# Overwrite existing template
62+
npm run template -- output.xlsx --force
63+
64+
# Show help
65+
npm run template -- --help
66+
```
67+
68+
**Options:**
69+
70+
- `-f, --force` - Overwrite existing file if it exists
71+
- `-h, --help` - Show help message
72+
73+
**Generated sheets:**
74+
75+
The template includes the following sheets with proper column headers:
76+
77+
- `PackSpecification` - Pack specification definitions
78+
- `LetterVariant` - Letter variant configurations
79+
- `VolumeGroup` - Volume group definitions
80+
- `Supplier` - Supplier information
81+
- `SupplierAllocation` - Supplier allocation percentages
82+
- `SupplierPack` - Supplier-pack mappings
83+
84+
### Programmatic Usage
85+
86+
#### Parsing an Excel file
1487

1588
```typescript
1689
import { parseExcelFile } from "@nhs-notify/excel-parser";

packages/excel-parser/jest.config.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,53 @@
11
import type { Config } from "jest";
22

33
const config: Config = {
4+
preset: "ts-jest",
5+
6+
// Automatically clear mock calls, instances, contexts and results before every test
7+
clearMocks: true,
8+
9+
// Indicates whether the coverage information should be collected while executing the test
10+
collectCoverage: true,
11+
12+
// The directory where Jest should output its coverage files
13+
coverageDirectory: "./.reports/unit/coverage",
14+
15+
// Indicates which provider should be used to instrument code for coverage
16+
coverageProvider: "v8",
17+
18+
coverageThreshold: {
19+
global: {
20+
branches: 100,
21+
functions: 100,
22+
lines: 100,
23+
statements: -10,
24+
},
25+
},
26+
27+
coveragePathIgnorePatterns: ["/__tests__/"],
28+
29+
// Use this configuration option to add custom reporters to Jest
30+
reporters: [
31+
"default",
32+
[
33+
"jest-html-reporter",
34+
{
35+
pageTitle: "Test Report",
36+
outputPath: "./.reports/unit/test-report.html",
37+
includeFailureMsg: true,
38+
},
39+
],
40+
],
41+
442
moduleNameMapper: {
543
"^@supplier-config/excel-parser/(.*)$": "<rootDir>/src/$1",
644
},
7-
preset: "ts-jest",
45+
846
testEnvironment: "node",
947
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
48+
testMatch: ["**/__tests__/**/*.ts", "**/?(*.)+(spec|test).ts"],
49+
moduleFileExtensions: ["ts", "js", "json", "node"],
50+
1051
transform: {
1152
"^.+\\.tsx?$": [
1253
"@swc/jest",

packages/excel-parser/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {
33
"@nhsdigital/nhs-notify-event-schemas-supplier-config": "*",
44
"xlsx": "^0.18.5",
5+
"yargs": "^17.7.2",
56
"zod": "^4.1.12"
67
},
78
"devDependencies": {
@@ -10,7 +11,9 @@
1011
"@tsconfig/node22": "^22.0.2",
1112
"@types/jest": "^29.5.14",
1213
"@types/xlsx": "^0.0.35",
14+
"@types/yargs": "^17.0.33",
1315
"jest": "^29.7.0",
16+
"jest-html-reporter": "^3.10.2",
1417
"jest-mock-extended": "^3.0.7",
1518
"typescript": "^5.9.3"
1619
},
@@ -20,6 +23,8 @@
2023
"build": "tsc",
2124
"lint": "eslint .",
2225
"lint:fix": "eslint . --fix",
26+
"parse": "tsx src/cli-parse.ts",
27+
"template": "tsx src/cli-template.ts",
2328
"test": "jest",
2429
"test:unit": "jest",
2530
"typecheck": "tsc --noEmit"

0 commit comments

Comments
 (0)