|
1 | 1 | #!/usr/bin/env node |
2 | 2 | import { Command } from "commander"; |
3 | 3 | import { execFile } from "node:child_process"; |
4 | | -import { openAsBlob } from "node:fs"; |
| 4 | +import { openAsBlob, readFileSync, realpathSync } from "node:fs"; |
5 | 5 | import { createServer } from "node:http"; |
6 | 6 | import { appendFile, writeFile, mkdir, readFile } from "node:fs/promises"; |
7 | 7 | import { dirname } from "node:path"; |
| 8 | +import { fileURLToPath } from "node:url"; |
8 | 9 | import { ApiClient, delay } from "./core/client.js"; |
9 | 10 | import { |
10 | 11 | clearProfileToken, |
@@ -58,7 +59,9 @@ import { |
58 | 59 | validateLimit, |
59 | 60 | } from "./core/validators.js"; |
60 | 61 |
|
61 | | -const version = "0.1.0"; |
| 62 | +const version = JSON.parse( |
| 63 | + readFileSync(new URL("../package.json", import.meta.url), "utf8"), |
| 64 | +).version as string; |
62 | 65 |
|
63 | 66 | type Handler<T extends unknown[] = unknown[]> = (...args: T) => Promise<void>; |
64 | 67 |
|
@@ -3016,6 +3019,18 @@ function agentCommands(): Record<string, any> { |
3016 | 3019 | return out; |
3017 | 3020 | } |
3018 | 3021 |
|
3019 | | -if (import.meta.url === `file://${process.argv[1]}`) { |
| 3022 | +function isMainModule(): boolean { |
| 3023 | + if (!process.argv[1]) return false; |
| 3024 | + try { |
| 3025 | + return ( |
| 3026 | + realpathSync(fileURLToPath(import.meta.url)) === |
| 3027 | + realpathSync(process.argv[1]) |
| 3028 | + ); |
| 3029 | + } catch { |
| 3030 | + return false; |
| 3031 | + } |
| 3032 | +} |
| 3033 | + |
| 3034 | +if (isMainModule()) { |
3020 | 3035 | await buildProgram().parseAsync(process.argv); |
3021 | 3036 | } |
0 commit comments