()
| 134 | } |
| 135 | |
| 136 | function main() { |
| 137 | |
| 138 | const program = new Command(); |
| 139 | |
| 140 | // Version from package.json |
| 141 | const packageJson = JSON.parse( |
| 142 | fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf-8') |
| 143 | ); |
| 144 | |
| 145 | // Make the version trivial to reach. commander's `.version()` (below) wires up |
| 146 | // `--version` and `-V`; intercept the spellings it can't — lowercase `-v` and |
| 147 | // single-dash `-version` — before any parsing. (commander's version short flag |
| 148 | // is the capital `-V`, and its parser rejects a multi-character single-dash |
| 149 | // flag.) The bare `codegraph version` subcommand is registered further down so |
| 150 | // the affordance also shows up in `codegraph --help`. |
| 151 | const firstArg = process.argv[2]; |
| 152 | if (firstArg === '-v' || firstArg === '-version') { |
| 153 | console.log(packageJson.version); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | // ============================================================================= |
| 158 | // ANSI Color Helpers (avoid chalk ESM issues) |
| 159 | // ============================================================================= |
| 160 | |
| 161 | // `--color` / `--no-color` are global and position-independent — they were |
| 162 | // already read by ansiColorsEnabled() at module load, so strip them before |
| 163 | // commander parses (a subcommand would otherwise reject the unknown flag). |
| 164 | process.argv = process.argv.filter((a) => a !== '--color' && a !== '--no-color'); |
| 165 | |
| 166 | const colors = COLORS_ENABLED |
| 167 | ? { |
| 168 | reset: '\x1b[0m', |
| 169 | bold: '\x1b[1m', |
| 170 | dim: '\x1b[2m', |
| 171 | red: '\x1b[31m', |
| 172 | green: '\x1b[32m', |
| 173 | yellow: '\x1b[33m', |
| 174 | blue: '\x1b[34m', |
| 175 | cyan: '\x1b[36m', |
| 176 | white: '\x1b[37m', |
| 177 | gray: '\x1b[90m', |
| 178 | } |
| 179 | : { |
| 180 | reset: '', |
| 181 | bold: '', |
| 182 | dim: '', |
| 183 | red: '', |
| 184 | green: '', |
| 185 | yellow: '', |
| 186 | blue: '', |
| 187 | cyan: '', |
| 188 | white: '', |
| 189 | gray: '', |
| 190 | }; |
| 191 | |
| 192 | const chalk = { |
| 193 | bold: (s: string) => `${colors.bold}${s}${colors.reset}`, |
no test coverage detected