fork of hey-api/openapi-ts because I need some additional things
1import colors from 'ansi-colors';
2
3import { loadPackageJson } from './tsConfig';
4
5const textAscii = `
6888 | e 888~-_ 888
7888___| e88~~8e Y88b / d8b 888 \\ 888
8888 | d888 88b Y888/ /Y88b 888 | 888
9888 | 8888__888 Y8/ / Y88b 888 / 888
10888 | Y888 , Y /____Y88b 888_-~ 888
11888 | "88___/ / / Y88b 888 888
12 _/
13`;
14
15const asciiToLines = (
16 ascii: string,
17 options?: {
18 padding?: number;
19 },
20) => {
21 const lines: Array<string> = [];
22 const padding = Array.from<string>({ length: options?.padding ?? 0 }).fill('');
23 lines.push(...padding);
24 let maxLineLength = 0;
25 let line = '';
26 for (const char of ascii) {
27 if (char === '\n') {
28 if (line) {
29 lines.push(line);
30 maxLineLength = Math.max(maxLineLength, line.length);
31 line = '';
32 }
33 } else {
34 line += char;
35 }
36 }
37 lines.push(...padding);
38 return { lines, maxLineLength };
39};
40
41/**
42 * Checks the current environment based on the HEYAPI_CODEGEN_ENV environment variable.
43 */
44export function isEnvironment(value: 'development'): boolean {
45 return process.env.HEYAPI_CODEGEN_ENV === value;
46}
47
48// TODO: show ascii logo only in `--help` and `--version` commands
49export function printCliIntro(initialDir: string, showLogo: boolean = false): void {
50 const packageJson = loadPackageJson(initialDir);
51 if (packageJson) {
52 if (showLogo) {
53 const text = asciiToLines(textAscii, { padding: 1 });
54 for (const line of text.lines) {
55 console.log(colors.cyan(line));
56 }
57 }
58 const versionString = isEnvironment('development')
59 ? '[DEVELOPMENT]'
60 : `v${packageJson.version}`;
61 console.log(colors.gray(`${packageJson.name} ${versionString}`));
62 }
63 console.log('');
64}