Skip to content

Commit 044aa02

Browse files
committed
refactor(@maz-ui/node): add utility to print banner (useful for CLI)
1 parent 0cf1d39 commit 044aa02

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

packages/node/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
},
4949
"dependencies": {
5050
"colorette": "^2.0.20",
51-
"consola": "^3.4.2"
51+
"consola": "^3.4.2",
52+
"figlet": "^1.9.3"
5253
},
5354
"devDependencies": {
5455
"unbuild": "^3.6.1"

packages/node/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
export * from './execPromise.js'
2-
export * from './logger.js'
1+
export * from './execPromise'
2+
export * from './logger'
3+
export * from './printBanner'

packages/node/src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function createLogger(options?: LoggerOptions) {
3636
fatal: (message: InputLogObject | any, ...args: any[]) => consola.fatal(message, ...args),
3737
ready: (message: InputLogObject | any, ...args: any[]) => consola.ready(message, ...args),
3838
silent: (message: InputLogObject | any, ...args: any[]) => consola.silent(message, ...args),
39-
divider: () => console.log('-'.repeat(process.stdout.columns ?? 20)),
39+
divider: (character: string = '=') => console.log(character.repeat(process.stdout.columns ?? 20)),
4040
eot: () => console.log(),
4141
brand: (message: string) => console.log(blueBright(message)),
4242
clear: () => console.clear(),

packages/node/src/printBanner.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { FigletOptions } from 'figlet/node'
2+
import figlet from 'figlet'
3+
import { logger } from './logger'
4+
5+
export function printBanner({
6+
name,
7+
version,
8+
options,
9+
}: {
10+
name: string
11+
version?: string
12+
options?: FigletOptions & {
13+
clear?: boolean
14+
}
15+
}) {
16+
options = {
17+
horizontalLayout: 'full',
18+
font: 'ANSI Shadow',
19+
clear: true,
20+
...options,
21+
}
22+
if (options.clear)
23+
process.stdout.write('\x1B[2J')
24+
25+
const banner = figlet.textSync(name, options)
26+
logger.brand(banner)
27+
28+
if (version) {
29+
logger.brand(version)
30+
logger.eot()
31+
}
32+
33+
logger.divider()
34+
logger.eot()
35+
}

0 commit comments

Comments
 (0)