Skip to content

Commit f416823

Browse files
CCM-15146: Fix readme not generating events (#250)
1 parent 2f022dc commit f416823

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

src/cloudevents/tools/generator/docs-generator/generate-docs-cli.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,12 @@ export async function handleCli(args: string[]): Promise<CliResult> {
131131
}
132132
}
133133

134-
// Execute CLI if this module is run directly
135-
// Note: This uses eval to prevent Jest/CommonJS from parsing import.meta
136134
// istanbul ignore next - CLI entry point, difficult to test in Jest
137-
// @ts-ignore
138-
try {
139-
const importMeta = eval('import.meta');
140-
if (importMeta && importMeta.url === `file://${process.argv[1]}`) {
141-
handleCli(process.argv.slice(2)).then((result) => {
142-
process.exit(result.exitCode);
143-
}).catch((err) => {
144-
console.error('Unexpected error:', err);
145-
process.exit(1);
146-
});
147-
}
148-
} catch {
149-
// Intentionally ignoring exception: import.meta not available in CommonJS/Jest environments.
150-
// This is expected when the module is imported rather than executed directly.
151-
if (process.env.DEBUG) {
152-
console.debug('Module loaded in CommonJS/Jest environment (import.meta not available)');
153-
}
135+
if (process.argv[1]?.endsWith('generate-docs-cli.ts')) {
136+
handleCli(process.argv.slice(2)).then((result) => {
137+
process.exit(result.exitCode);
138+
}).catch((err) => {
139+
console.error('Unexpected error:', err);
140+
process.exit(1);
141+
});
154142
}

src/cloudevents/tools/generator/readme-generator/update-readme-cli.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* 2. Render README.md from the index
77
*/
88

9+
import { realpathSync } from "fs";
10+
import { dirname, resolve } from "path";
911
import { handleCli as generateIndexCli } from "./generate-readme-index-cli.ts";
1012
import { handleCli as renderReadmeCli } from "./render-readme-cli.ts";
1113

@@ -59,30 +61,20 @@ export async function handleCli(
5961
}
6062
}
6163

62-
// Execute CLI if this module is run directly
63-
// Note: This uses eval to prevent Jest/CommonJS from parsing import.meta
64+
// Execute CLI if this module is run directly.
6465
// istanbul ignore next - CLI entry point, difficult to test in Jest
65-
// @ts-ignore
66-
try {
67-
const importMeta = eval('import.meta');
68-
if (importMeta && importMeta.url === `file://${process.argv[1]}`) {
69-
// Get the root directory (3 levels up from this file: tools/generator/readme-generator)
70-
const rootDir = new URL("../../../", importMeta.url).pathname;
71-
const args = process.argv.slice(2);
66+
if (process.argv[1]?.endsWith("update-readme-cli.ts")) {
67+
// Derive rootDir from process.argv[1] (3 levels up: tools/generator/readme-generator)
68+
const mainPath = realpathSync(process.argv[1]);
69+
const rootDir = resolve(dirname(mainPath), "../../..");
70+
const args = process.argv.slice(2);
7271

73-
handleCli(args, rootDir)
74-
.then((result) => {
75-
process.exit(result.exitCode);
76-
})
77-
.catch((err) => {
78-
console.error("Unexpected error:", err);
79-
process.exit(1);
80-
});
81-
}
82-
} catch {
83-
// Intentionally ignoring exception: import.meta not available in CommonJS/Jest environments.
84-
// This is expected when the module is imported rather than executed directly.
85-
if (process.env.DEBUG) {
86-
console.debug("Module loaded in CommonJS/Jest environment (import.meta not available)");
87-
}
72+
handleCli(args, rootDir)
73+
.then((result) => {
74+
process.exit(result.exitCode);
75+
})
76+
.catch((err) => {
77+
console.error("Unexpected error:", err);
78+
process.exit(1);
79+
});
8880
}

0 commit comments

Comments
 (0)