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// TODO: show ascii logo only in `--help` and `--version` commands
42export function printCliIntro(initialDir: string, showLogo: boolean = false): void {
43 const packageJson = loadPackageJson(initialDir);
44 if (packageJson) {
45 if (showLogo) {
46 const text = asciiToLines(textAscii, { padding: 1 });
47 for (const line of text.lines) {
48 console.log(colors.cyan(line));
49 }
50 }
51 console.log(colors.gray(`${packageJson.name} v${packageJson.version}`));
52 }
53 console.log('');
54}