Skip to content

Commit 89b10a3

Browse files
committed
fix: resolve CI failures in cross-platform testing and Windows builds
- Fix Windows TypeScript compilation errors by adding proper type annotations to api-server.ts - Add missing .js extensions to ESM imports in cli.ts and commands/index.ts - Fix cross-platform test CLI flag from --format json to --json - Add JSON output support to index command for proper CI testing - Add json option to IndexCliOptions interface - Implement generateIndexFilesJson function for structured JSON output Resolves cross-platform CI test failures and Windows build issues. All platforms now properly detect filesystem capabilities and execute tests.
1 parent f88a487 commit 89b10a3

File tree

8 files changed

+91
-15
lines changed

8 files changed

+91
-15
lines changed

.github/workflows/cross-platform-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ jobs:
174174
175175
# Test basic file operations
176176
echo "Testing file listing..."
177-
node ../../dist/cli.js index --format json . || echo "Index command failed"
177+
node ../../dist/cli.js index --json . || echo "Index command failed"
178178
179179
# Test file moving with different path styles
180180
if [ "${{ runner.os }}" = "Windows" ]; then
@@ -201,8 +201,8 @@ jobs:
201201
echo "✅ Case-sensitive files coexist"
202202
203203
# Test CLI handles case-sensitive files correctly
204-
node ../../dist/cli.js index --format json . | grep -i "lowercase.md"
205-
node ../../dist/cli.js index --format json . | grep -i "UPPERCASE.md"
204+
node ../../dist/cli.js index --json . | grep -i "lowercase.md"
205+
node ../../dist/cli.js index --json . | grep -i "UPPERCASE.md"
206206
else
207207
echo "❌ Expected case-sensitive files not found"
208208
ls -la

src/api-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async function handleRequest(
124124

125125
// Handle auto-generated API routes
126126
const autoRoute = autoGeneratedApiRoutes.find(
127-
(route) => route.method === method && route.path === path
127+
(route: { method: string; path: string; handler: (req: http.IncomingMessage, res: http.ServerResponse, markmv: ReturnType<typeof createMarkMv>) => Promise<void> }) => route.method === method && route.path === path
128128
);
129129

130130
if (autoRoute) {
@@ -134,7 +134,7 @@ async function handleRequest(
134134
}
135135

136136
// Route not found
137-
const availableRoutes = ['GET /health', ...getApiRoutePaths().map((p) => `POST ${p}`)];
137+
const availableRoutes = ['GET /health', ...getApiRoutePaths().map((p: string) => `POST ${p}`)];
138138
const errorResponse = createErrorResponse(
139139
404,
140140
'NotFound',

src/cli.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env node
22

33
import { Command } from 'commander';
4-
import { convertCommand } from './commands/convert';
5-
import { indexCommand } from './commands/index';
6-
import { joinCommand } from './commands/join';
7-
import { mergeCommand } from './commands/merge';
8-
import { moveCommand } from './commands/move';
9-
import { splitCommand } from './commands/split';
4+
import { convertCommand } from './commands/convert.js';
5+
import { indexCommand } from './commands/index.js';
6+
import { joinCommand } from './commands/join.js';
7+
import { mergeCommand } from './commands/merge.js';
8+
import { moveCommand } from './commands/move.js';
9+
import { splitCommand } from './commands/split.js';
1010

1111
const program = new Command();
1212

src/commands/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join } from 'node:path';
22
import { beforeEach, describe, expect, it, vi } from 'vitest';
3-
import { FileUtils } from '../utils/file-utils';
4-
import { indexCommand } from './index';
3+
import { FileUtils } from '../utils/file-utils.js';
4+
import { indexCommand } from './index.js';
55

66
// Mock FileUtils
77
vi.mock('../utils/file-utils');

src/commands/index.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { existsSync, statSync } from 'node:fs';
22
import { join, relative, resolve } from 'node:path';
33
import { glob } from 'glob';
4-
import { FileUtils } from '../utils/file-utils';
4+
import { FileUtils } from '../utils/file-utils.js';
55

66
// Test PR creation with trailing spaces on main branch
77

@@ -99,6 +99,7 @@ interface IndexCliOptions {
9999
template?: string;
100100
dryRun?: boolean;
101101
verbose?: boolean;
102+
json?: boolean;
102103
maxDepth?: number;
103104
noTraverseUp?: boolean;
104105
boundary?: string;
@@ -145,7 +146,65 @@ export async function indexCommand(
145146
...(cliOptions.boundary && { boundary: cliOptions.boundary }),
146147
};
147148

148-
return generateIndexFiles(options, directory || '.');
149+
if (cliOptions.json) {
150+
return generateIndexFilesJson(options, directory || '.');
151+
} else {
152+
return generateIndexFiles(options, directory || '.');
153+
}
154+
}
155+
156+
/** Generate index files for markdown documentation (JSON output) */
157+
async function generateIndexFilesJson(options: IndexOptions, directory: string): Promise<void> {
158+
const targetDir = resolve(directory);
159+
160+
if (!existsSync(targetDir)) {
161+
throw new Error(`Directory not found: ${targetDir}`);
162+
}
163+
164+
if (!statSync(targetDir).isDirectory()) {
165+
throw new Error(`Path is not a directory: ${targetDir}`);
166+
}
167+
168+
try {
169+
// Discover markdown files
170+
const files = await discoverMarkdownFiles(targetDir, options);
171+
172+
// Organize files based on strategy
173+
const organizedFiles = organizeFiles(files, options);
174+
175+
// Convert to JSON output
176+
const jsonOutput = {
177+
directory: targetDir,
178+
options: {
179+
type: options.type,
180+
strategy: options.strategy,
181+
location: options.location,
182+
},
183+
totalFiles: files.length,
184+
organizedFiles: Object.fromEntries(
185+
Array.from(organizedFiles.entries()).map(([key, groupFiles]) => [
186+
key,
187+
groupFiles.map(file => ({
188+
path: file.path,
189+
relativePath: file.relativePath,
190+
title: file.metadata.title || file.relativePath,
191+
}))
192+
])
193+
),
194+
files: files.map(file => ({
195+
path: file.path,
196+
relativePath: file.relativePath,
197+
title: file.metadata.title || file.relativePath,
198+
}))
199+
};
200+
201+
console.log(JSON.stringify(jsonOutput, null, 2));
202+
} catch (error) {
203+
if (error instanceof Error) {
204+
throw new Error(`Failed to generate index: ${error.message}`);
205+
}
206+
throw error;
207+
}
149208
}
150209

151210
/** Generate index files for markdown documentation */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uppercase content

test-data/cross-platform/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
generated: true
3+
generator: markmv-index
4+
type: links
5+
strategy: directory
6+
updated: 2025-06-15T23:00:53.921Z
7+
---
8+
9+
# Documentation Index
10+
11+
## Root
12+
13+
- [lowercase](lowercase.md)
14+
- [UPPERCASE](UPPERCASE.md)
15+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lowercase content

0 commit comments

Comments
 (0)