An open API service indexing awesome lists of open source software.

https://github.com/unplugin/unplugin-printer

✨ Print beautiful info in the terminal
https://github.com/unplugin/unplugin-printer

Last synced: 7 months ago
JSON representation

✨ Print beautiful info in the terminal

Awesome Lists containing this project

README

          

# unplugin-printer


unplugin-printer



## Install

```bash
npm i unplugin-printer
```

## Features

- User-friendly options

- Customizable styles

- Supports async functions

## Options

`unplugin-printer` uses [kolorist](https://github.com/marvinhagemeister/kolorist) and [boxen](https://github.com/sindresorhus/boxen) to customize the text color and style of the output. You can refer to the documentation to explore the available options in detail.

```ts
import type * as kolorist from 'kolorist'

import type { Options as BoxenOptions } from 'boxen'

type Kolorist = typeof kolorist

type MessageValue = BoxenOptions & { text: string }

type Message = string | MessageValue | ((kolorist: Kolorist) => string | MessageValue | Promise)

interface Options {
info: Message[]
}
```

## Usage

```ts
// vite.config.ts

import Printer from 'unplugin-printer/vite'

export default defineConfig({
plugins: [
Printer({
info: [
// 1. use string value
'Hello World',

// 2. use object to customize the style
{ text: 'Hello World', padding: 1, margin: 1, borderColor: 'green' },

// 3. use function to customize the text color and style
(kolorist) => {
return {
text: kolorist.yellow('Hello World'),
padding: 1,
margin: 1,
}
},

// 4. use with async function
async (kolorist) => {
const text = await fetch('https://api.github.com/repos/unplugin/unplugin-printer')
.then(res => res.json())
.then(res => res.description)

return {
text: kolorist.yellow(text),
padding: 1,
margin: 1,
}
},
]
}),
],
})
```

Vite

```ts
// vite.config.ts
import Printer from 'unplugin-printer/vite'

export default defineConfig({
plugins: [
Printer({ /* options */ }),
],
})
```


Webpack

```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-printer/webpack')({ /* options */ })
]
}
```


Nuxt

```ts
// nuxt.config.js
export default defineNuxtConfig({
modules: [
['unplugin-printer/nuxt', { /* options */ }],
],
})
```

> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)


Vue CLI

```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-printer/webpack')({ /* options */ }),
],
},
}
```


## License

MIT License © 2023-PRESENT [webfansplz](./LICENSE)