import type { Plugin } from 'vite'
import colors from 'picocolors'
import pkg from '../../package.json'
import { configUniPlugin } from './uni'
import { configImportPlugin } from './unplugin'
import { configUnocssPlugin } from './unocss'

export function createVitePlugins(viteEnv: ViteEnv) {
    const { VITE_GLOB_APP_NAME, VITE_GLOB_APP_DESCRIPTION, VITE_GLOB_API_URL, VITE_GLOB_API_URL_PREFIX } = viteEnv

    // 以红色字体输出信息
    console.log()
    console.log(colors.red(`APP 版本: v${pkg.version}`))
    console.log(colors.red(`APP 名称: ${VITE_GLOB_APP_NAME}`))
    console.log(colors.red(`APP 描述: ${VITE_GLOB_APP_DESCRIPTION}`))
    console.log(colors.red(`API Doc: ${VITE_GLOB_API_URL}${VITE_GLOB_API_URL_PREFIX}/doc.html`))
    console.log()

    // plugins
    const vitePlugins: (Plugin | Plugin[])[] = []

    // unocss
    vitePlugins.push(configUnocssPlugin())

    // unplugin-auto-import
    // unplugin-vue-components
    vitePlugins.push(configImportPlugin())

    // uni-app
    vitePlugins.push(configUniPlugin())

    return vitePlugins
}
