fix(tools): adjust create language block helper script (#62090)

This commit is contained in:
Tom
2025-09-09 09:32:10 -05:00
committed by GitHub
parent ce9f1dd99a
commit bd2167c176
3 changed files with 29 additions and 3 deletions
@@ -54,7 +54,7 @@ async function createLanguageBlock(
const superblockFilename = (
superBlockToFilename as Record<SuperBlocks, string>
)[superBlock];
void updateSimpleSuperblockStructure(block, { order: 0 }, superblockFilename);
void updateSimpleSuperblockStructure(block, {}, superblockFilename);
// TODO: remove once we stop relying on markdown in the client.
await createIntroMD(superBlock, block, title);
}
@@ -70,6 +70,26 @@ describe('updateSimpleSuperblockStructure', () => {
}
);
});
it('should insert the block into the blocks array at the end when no order is given', async () => {
const existingBlocks = ['block1', 'block2'];
const superblockFilename = 'test-superblock';
const newBlock = 'block3';
mockGetSuperblockStructure.mockReturnValue({
blocks: existingBlocks
});
await updateSimpleSuperblockStructure(newBlock, {}, superblockFilename);
expect(mockGetSuperblockStructure).toHaveBeenCalledWith(superblockFilename);
expect(mockWriteSuperblockStructure).toHaveBeenCalledWith(
superblockFilename,
{
blocks: ['block1', 'block2', 'block3']
}
);
});
});
describe('updateChapterModuleSuperblockStructure', () => {
@@ -8,14 +8,20 @@ import { insertInto } from './utils';
export async function updateSimpleSuperblockStructure(
block: string,
position: { order: number },
position: { order?: number },
superblockFilename: string
) {
const existing = getSuperblockStructure(superblockFilename) as {
blocks: string[];
};
const order =
typeof position.order === 'number'
? position.order
: existing.blocks.length;
const updated = {
blocks: insertInto(existing.blocks, position.order, block)
blocks: insertInto(existing.blocks, order, block)
};
await writeSuperblockStructure(superblockFilename, updated);
}