Skip to content

Commit a2ad43d

Browse files
committed
Add direct excel->file store conversion
1 parent a9c58b0 commit a2ad43d

8 files changed

Lines changed: 774 additions & 5 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ clean:: # Clean-up project resources (main) @Operations
2626
config:: _install-dependencies version # Configure development environment (main) @Configuration
2727
(cd docs && make install)
2828

29+
internal-config:
30+
npm run parse --workspace=@supplier-config/excel-parser -- \
31+
"$(PWD)/specifications.xlsx" --output-dir "$(PWD)/artifacts/config-store" --pretty
32+
2933
# ==============================================================================
3034

3135
${VERBOSE}.SILENT: \

packages/excel-parser/README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,25 @@ npm run parse -- config.xlsx -o output.json
2929
# Parse with pretty formatting and save to file
3030
npm run parse -- config.xlsx --pretty --output output.json
3131

32+
# Parse and write a file-store-compatible directory of JSON files
33+
npm run parse -- config.xlsx --output-dir ./config-store
34+
35+
# Pretty-print each JSON file in the generated config store
36+
npm run parse -- config.xlsx --output-dir ./config-store --pretty
37+
3238
# Show help
3339
npm run parse -- --help
3440
```
3541

3642
**Options:**
3743

3844
- `-o, --output <file>` - Write output to a file instead of stdout
45+
- `-d, --output-dir <directory>` - Write one JSON file per record into a directory compatible with `@supplier-config/file-store`
3946
- `-p, --pretty` - Pretty-print the JSON output
4047
- `-h, --help` - Show help message
4148

49+
`--output` and `--output-dir` are mutually exclusive.
50+
4251
**Output format:**
4352

4453
The JSON output contains the following top-level keys:
@@ -50,6 +59,21 @@ The JSON output contains the following top-level keys:
5059
- `allocations` - Record of SupplierAllocation objects keyed by ID
5160
- `supplierPacks` - Record of SupplierPack objects keyed by ID
5261

62+
#### Parse Excel to a file-store directory
63+
64+
When `--output-dir` is used, the parser writes one JSON file per record using the directory names expected by the file-store package:
65+
66+
- `volume-group/`
67+
- `letter-variant/`
68+
- `pack-specification/`
69+
- `supplier/`
70+
- `supplier-allocation/`
71+
- `supplier-pack/`
72+
73+
Each file is written as a file-store-safe filename derived from the record id. Lowercase letters, digits, and hyphens are kept readable where possible, while characters that could cause path or casing issues are percent-encoded. `@supplier-config/file-store` decodes that filename back to the original id when loading records.
74+
75+
To keep the generated store in sync with the Excel source, the writer recreates those managed entity directories on each run before writing the latest records. Unrelated files in the output root are left untouched.
76+
5377
#### Generate Template
5478

5579
Generate a template Excel file with the correct sheet structure and column headers:
@@ -86,7 +110,10 @@ The template includes the following sheets with proper column headers:
86110
#### Parsing an Excel file
87111

88112
```typescript
89-
import { parseExcelFile } from "@nhs-notify/excel-parser";
113+
import {
114+
parseExcelFile,
115+
writeParseResultToConfigStore,
116+
} from "@supplier-config/excel-parser";
90117

91118
const result = parseExcelFile("./specifications.xlsx");
92119

@@ -96,12 +123,16 @@ console.log(result.volumeGroups); // Record<string, VolumeGroup>
96123
console.log(result.suppliers); // Record<string, Supplier>
97124
console.log(result.allocations); // Record<string, SupplierAllocation>
98125
console.log(result.supplierPacks); // Record<string, SupplierPack>
126+
127+
await writeParseResultToConfigStore(result, "./config-store", {
128+
pretty: true,
129+
});
99130
```
100131

101132
### Generating a template Excel file
102133

103134
```typescript
104-
import { generateTemplateExcel } from "@nhs-notify/excel-parser";
135+
import { generateTemplateExcel } from "@supplier-config/excel-parser";
105136

106137
// Generate a new template (fails if file exists)
107138
generateTemplateExcel("./specifications.template.xlsx");

0 commit comments

Comments
 (0)