Repository: FHIR/sushi
Pull request #1556 (2025-01-21 19:20:40)

place fsh-index.json in the data folder
**Description:**
This PR puts the fsh-index.json not in fsh-generated but in fsh-generated/data. This way, it is possible to allow the IG Publisher to consider this an additional data folder, and use this in rendering. This was originally requested and discussed in Zulip here:[#ig publishing requirements > sushi index file location @ 💬](https://chat.fhir.org/#narrow/channel/196008-ig-publishing-requirements/topic/sushi.20index.20file.20location/near/491302989)

**Testing Instructions:**
When running sushi, the fsh-index.json should be in fsh-generated/data

cmoesel: This looks good, @costateixeira! I tested it manually (in addition to the unit tests) and it works as expected. I also checked to see if we document this in FSH School, and I don't think we do, so I don't think there is any need to update documentation.

That said, could you please edit this PR's description to describe the changes you made and why you made them? Please also include a link to [this zulip thread]([#ig publishing requirements > sushi index file location @ 💬](https://chat.fhir.org/#narrow/channel/196008-ig-publishing-requirements/topic/sushi.20index.20file.20location/near/491302989)) in the description so it's clear that we discussed this in the community.

Thanks for contributing this!
costateixeira: @cmoesel can you please see if it is ok?
cmoesel: Perfect. Thank you!

Patch:
diff --git a/src/utils/Processing.ts b/src/utils/Processing.ts
index e774878..1124521 100644
--- a/src/utils/Processing.ts
+++ b/src/utils/Processing.ts
@@ -632,8 +632,11 @@ export function writeFSHIndex(
   // write txt with nice formatting
   textIndex.unshift(['Output File', 'Name', 'Type', 'FSH File', 'Lines']);
   fs.outputFileSync(path.join(outDir, 'fsh-generated', 'fsh-index.txt'), table(textIndex));
-  // write json for machine usage
-  fs.outputJsonSync(path.join(outDir, 'fsh-generated', 'fsh-index.json'), jsonIndex, { spaces: 2 });
+  // write json for machine usage. Use the fsh-generated/data folder for the template to pick it up. Ensure the folder exists
+  fs.ensureDirSync(path.join(outDir, 'fsh-generated', 'data'));
+  fs.outputJsonSync(path.join(outDir, 'fsh-generated', 'data', 'fsh-index.json'), jsonIndex, {
+    spaces: 2
+  });
 }
 
 export function writePreprocessedFSH(outDir: string, inDir: string, tank: FSHTank) {


Test patch:
diff --git a/test/utils/Processing.test.ts b/test/utils/Processing.test.ts
index eb4b108..0d1d024 100644
--- a/test/utils/Processing.test.ts
+++ b/test/utils/Processing.test.ts
@@ -1675,7 +1675,7 @@ describe('Processing', () => {
     it('should create text and json index files that contain each resource in the package', () => {
       writeFSHIndex(tempIGPubRoot, outPackage, fshRoot, []);
       const textIndex = path.join(tempIGPubRoot, 'fsh-generated', 'fsh-index.txt');
-      const jsonIndex = path.join(tempIGPubRoot, 'fsh-generated', 'fsh-index.json');
+      const jsonIndex = path.join(tempIGPubRoot, 'fsh-generated', 'data', 'fsh-index.json');
       expect(fs.existsSync(textIndex)).toBeTrue();
       expect(fs.existsSync(jsonIndex)).toBeTrue();
 
@@ -1734,7 +1734,7 @@ describe('Processing', () => {
     it('should sort the list of resources by output file name', () => {
       writeFSHIndex(tempIGPubRoot, outPackage, fshRoot, []);
       const textIndex = path.join(tempIGPubRoot, 'fsh-generated', 'fsh-index.txt');
-      const jsonIndex = path.join(tempIGPubRoot, 'fsh-generated', 'fsh-index.json');
+      const jsonIndex = path.join(tempIGPubRoot, 'fsh-generated', 'data', 'fsh-index.json');
       expect(fs.existsSync(textIndex)).toBeTrue();
       expect(fs.existsSync(jsonIndex)).toBeTrue();
 
@@ -1757,7 +1757,7 @@ describe('Processing', () => {
     it('should not include a resource in the package if it is in the list of resources to skip', () => {
       writeFSHIndex(tempIGPubRoot, outPackage, fshRoot, ['StructureDefinition-my-extension.json']);
       const textIndex = path.join(tempIGPubRoot, 'fsh-generated', 'fsh-index.txt');
-      const jsonIndex = path.join(tempIGPubRoot, 'fsh-generated', 'fsh-index.json');
+      const jsonIndex = path.join(tempIGPubRoot, 'fsh-generated', 'data', 'fsh-index.json');
       expect(fs.existsSync(textIndex)).toBeTrue();
       expect(fs.existsSync(jsonIndex)).toBeTrue();