Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ jobs:
- run: npm install
- run: npm run check:spelling

test-reorg-docs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: scripts/reorg-docs
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with: { node-version-file: .nvmrc }
- run: npm install
- run: npm run build
- run: npm test -- --runInBand

block-pr-from-main-branch:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 1 addition & 2 deletions scripts/reorg-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
"start": "node dist/cli.js"
},
"dependencies": {
"js-yaml": "^4.1.0"
"js-yaml": "^5.0.0"
},
"devDependencies": {
"@types/jest": "^30.0.0",
"@types/js-yaml": "^4.0.9",
"@types/mdast": "^4.0.4",
"@types/node": "^24.10.0",
"jest": "^30.0.0",
Expand Down
12 changes: 6 additions & 6 deletions scripts/reorg-docs/src/FileMover.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import yaml from 'js-yaml';
import { dump, load } from 'js-yaml';
import type { FileSystem } from './types.js';
import { LinkFixer } from './LinkFixer.js';
import { FileWalker } from './FileWalker.js';
Expand Down Expand Up @@ -93,7 +93,7 @@ export class FileMover {
const matches = content.match(/^---\n([\s\S]*?)\n---/);
if (!matches) return false; // No front matter

const frontMatter = yaml.load(matches[1]) as FrontMatter;
const frontMatter = load(matches[1]) as FrontMatter;
return Boolean(frontMatter?.children?.length);
} catch (error) {
if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') {
Expand All @@ -112,7 +112,7 @@ export class FileMover {
const matches = content.match(/^---\n([\s\S]*?)\n---/);
if (!matches) return []; // No front matter

const frontMatter = yaml.load(matches[1]) as FrontMatter;
const frontMatter = load(matches[1]) as FrontMatter;
return frontMatter?.children?.map(child => child.url) ?? [];
} catch (error) {
if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') {
Expand Down Expand Up @@ -218,7 +218,7 @@ export class FileMover {
const matches = content.match(/^---\n([\s\S]*?)\n---/);
if (!matches) return content;

const frontMatter = yaml.load(matches[1]) as FrontMatter;
const frontMatter = load(matches[1]) as FrontMatter;
const orderedFrontMatter: Record<string, any> = {};

// Track if we've added the aliases field
Expand Down Expand Up @@ -246,7 +246,7 @@ export class FileMover {
orderedFrontMatter.aliases = [alias];
}

const newFrontMatter = yaml.dump(orderedFrontMatter, {
const newFrontMatter = dump(orderedFrontMatter, {
flowLevel: 1 // Force flow style (array syntax) for arrays
});
return content.replace(matches[0], `---\n${newFrontMatter}---`);
Expand All @@ -265,4 +265,4 @@ export class FileMover {
const oldBase = path.basename(oldPath, '.md');
return path.join(relPath, oldBase);
}
}
}
4 changes: 2 additions & 2 deletions scripts/reorg-docs/tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Integration tests with real docs', () => {

it('leaves _index.md where it is (sanity check)', async () => {
const rootIndex = await _readFile('_index.md');
expect(rootIndex).toContain('title: Docs');
expect(rootIndex).toMatch(/^---\n[\s\S]*?\n---/);
});


Expand Down Expand Up @@ -253,4 +253,4 @@ async function copyDirectory(src: string, dest: string): Promise<void> {
await fs.copyFile(srcPath, destPath);
}
}
}
}