Skip to content

Commit

Permalink
fix: unocss render
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Feb 1, 2024
1 parent 6a417f5 commit f4d4cb4
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 24 deletions.
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,12 @@ async function init() {
}

// Render Plugins
result.pluginList?.forEach((plugin) => {
render(`plugin/${plugin}`)
})
result.pluginList?.forEach(plugin => render(`plugin/${plugin}`))

// Render Models
result.modelList?.forEach((model) => {
render(`model/${model}`)
})
result.modelList?.forEach(model => render(`model/${model}`))
if (needUnocss && !result.modelList?.includes('unocss'))
render('model/unocss')

// Render UI
const UI = {
Expand Down
2 changes: 1 addition & 1 deletion src/question/plugin/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ModelType } from '../type'
export const configList: ModelType[] = [
{
title: rgb(236, 112, 99)('vite-plugin-uni-components'),
value: 'improt',
value: 'import',
description: '按需自动引入组件',
},
{
Expand Down
14 changes: 9 additions & 5 deletions template/UI/ano/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function getData({ oldData }) {
const autoImportUniUiPlugin = {
name: 'ano-ui',
const autoImportAnoUiPlugin = {
id: 'ano-ui',
importer: `import { AnoResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'`,
initializer: `Components({
dts: true,
Expand All @@ -10,8 +10,12 @@ export default function getData({ oldData }) {

return {
...oldData,
plugins: oldData.plugins.flatMap(plugin =>
plugin.id === 'uni' ? [autoImportUniUiPlugin, plugin] : plugin,
),
plugins: oldData.plugins.some(plugin => plugin.id === 'autoImport')
? oldData.plugins.flatMap(plugin =>
plugin.id === 'autoImport' ? [{ id: plugin.id, importer: plugin.importer }, autoImportAnoUiPlugin] : plugin,
)
: oldData.plugins.flatMap(plugin =>
plugin.id === 'uni' ? [autoImportAnoUiPlugin, plugin] : plugin,
),
}
}
12 changes: 8 additions & 4 deletions template/UI/uni/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function getData({ oldData }) {
const autoImportUniUiPlugin = {
name: 'uni-ui',
id: 'uni-ui',
importer: `import { UniUIResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'`,
initializer: `Components({
dts: true,
Expand All @@ -10,8 +10,12 @@ export default function getData({ oldData }) {

return {
...oldData,
plugins: oldData.plugins.flatMap(plugin =>
plugin.id === 'uni' ? [autoImportUniUiPlugin, plugin] : plugin,
),
plugins: oldData.plugins.some(plugin => plugin.id === 'autoImport')
? oldData.plugins.flatMap(plugin =>
plugin.id === 'autoImport' ? [{ id: plugin.id, importer: plugin.importer }, autoImportUniUiPlugin] : plugin,
)
: oldData.plugins.flatMap(plugin =>
plugin.id === 'uni' ? [autoImportUniUiPlugin, plugin] : plugin,
),
}
}
2 changes: 1 addition & 1 deletion template/model/unocss/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function getData({ oldData }) {
const UnoCSSPlugin = {
name: 'UnoCSS',
id: 'UnoCSS',
importer: 'import UnoCSS from \'unocss/vite\'',
initializer: 'UnoCSS()',
}
Expand Down
2 changes: 1 addition & 1 deletion template/plugin/filePlatform/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function getData({ oldData }) {
const platformPlugin = {
name: 'platform',
id: 'platform',
importer: `import UniPlatform from '@uni-helper/vite-plugin-uni-platform'`,
initializer: `// https://github.com/uni-helper/vite-plugin-uni-platform
UniPlatform()`,
Expand Down
5 changes: 4 additions & 1 deletion template/plugin/import/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export default function getData({ oldData }) {
const autoImportPlugin = {
name: 'autoImport',
id: 'autoImport',
importer: `import Components from '@uni-helper/vite-plugin-uni-components'`,
initializer: `Components({
dts: true,
})`,
}

return {
Expand Down
2 changes: 1 addition & 1 deletion template/plugin/layouts/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function getData({ oldData }) {
const layoutsPlugin = {
name: 'layouts',
id: 'layouts',
importer: `import UniLayouts from '@uni-helper/vite-plugin-uni-layouts'`,
initializer: `// https://github.com/uni-helper/vite-plugin-uni-layouts
UniLayouts()`,
Expand Down
2 changes: 1 addition & 1 deletion template/plugin/manifest/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function getData({ oldData }) {
const manifestPlugin = {
name: 'manifest',
id: 'manifest',
importer: `import UniManifest from '@uni-helper/vite-plugin-uni-manifest'`,
initializer: `// https://github.com/uni-helper/vite-plugin-uni-manifest
UniManifest()`,
Expand Down
2 changes: 1 addition & 1 deletion template/plugin/middleware/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function getData({ oldData }) {
const middlewarePlugin = {
name: 'middleware',
id: 'middleware',
importer: `import UniMiddleware from '@uni-helper/vite-plugin-uni-middleware'`,
initializer: `// https://github.com/uni-helper/vite-plugin-uni-middleware
UniMiddleware()`,
Expand Down
2 changes: 1 addition & 1 deletion template/plugin/pages/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function getData({ oldData }) {
const pagesPlugin = {
name: 'pages',
id: 'pages',
importer: `import UniPages from '@uni-helper/vite-plugin-uni-pages'`,
initializer: `// https://github.com/uni-helper/vite-plugin-uni-pages
UniPages()`,
Expand Down
2 changes: 1 addition & 1 deletion template/plugin/platformModifier/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function getData({ oldData }) {
const platformModifierPlugin = {
name: 'platformModifier',
id: 'platformModifier',
importer: `import UniPlatformModifier from '@uni-helper/vite-plugin-uni-platform-modifier'`,
initializer: `// https://github.com/uni-helper/vite-plugin-uni-platform-modifier
UniPlatformModifier()`,
Expand Down

0 comments on commit f4d4cb4

Please sign in to comment.