Skip to content

Commit

Permalink
feat: add basic nvue support
Browse files Browse the repository at this point in the history
  • Loading branch information
KeJunMao committed Nov 9, 2023
1 parent 5d823ae commit 67de5bd
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 74 deletions.
23 changes: 23 additions & 0 deletions fixtures/input/nvue.nvue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<div>
<h1>
{{ greeting }}</h1>
<button @click="incrementCounter">Click me!</button>
<p>Counter: {{ counter }}</p>
<web-view src="https://uni-helper.js.org"
/>
</div>
</template>

<script setup>
// Define reactive data and props
import { ref } from '@vue/reactivity';

const greeting = ref('Hello, Vue 3!' + 1);
let counter = ref(0)

// Define a function
const incrementCounter = () => {
counter.value++;
};
</script>
1 change: 1 addition & 0 deletions fixtures/output/json/nvue.nvue
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// unchanged
25 changes: 25 additions & 0 deletions fixtures/output/uni/nvue.nvue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script setup>
// Define reactive data and props
import { ref } from 'vue'

const greeting = ref(`Hello, Vue 3!${1}`)
const counter = ref(0)

// Define a function
function incrementCounter() {
counter.value++
}
</script>

<template>
<div>
<h1>
{{ greeting }}
</h1>
<button @click="incrementCounter">
Click me!
</button>
<p>Counter: {{ counter }}</p>
<web-view src="https://uni-helper.js.org" />
</div>
</template>
94 changes: 24 additions & 70 deletions src/config/uni.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,32 @@
import { GLOB_VUE } from '@antfu/eslint-config'
import type { ConfigItem, OptionsOverrides } from '@antfu/eslint-config'
import type { ConfigItem, OptionsHasTypeScript, OptionsOverrides, OptionsStylistic } from '@antfu/eslint-config'
import { pluginVue, vue } from '@antfu/eslint-config'
import { GLOB_UNI } from '../globs'

export function uni(options: OptionsOverrides = {}): ConfigItem[] {
export function uni(options: OptionsHasTypeScript & OptionsOverrides & OptionsStylistic = {}): ConfigItem[] {
const {
overrides = {},
} = options
const vueConfig = vue({ ...options })

const setup = vueConfig.find(v => v.name === 'antfu:vue:setup')!
const rules = vueConfig.find(v => v.name === 'antfu:vue:rules')!

setup.name = 'uni:vue:setup'
setup.plugins = {
vue: pluginVue,
}
rules.name = 'uni:vue:rules'
rules.files = [GLOB_UNI]
rules.rules = {
...rules.rules,
'vue/component-name-in-template-casing': ['error', 'kebab-case', {
registeredComponentsOnly: false,
}],
...overrides,
}

return [
{
files: [GLOB_VUE],
name: 'uni:vue:rules',
rules: {
'vue/component-name-in-template-casing': ['error', 'PascalCase', {
registeredComponentsOnly: false,
ignores: [
// 视图
'view',
'scroll-view',
'swiper',
'match-media',
'movable-area',
'movable-view',
'cover-view',
'cover-image',
// 基础
'icon',
'text',
'rich-text',
'progress',
// 表单
'editor',
'picker',
'picker-view',
'slider',
// 路由
'navigator',
// 媒体
'animation-view',
'camera',
'image',
'live-player',
'live-pusher',
// 地图
'map',
// 画布
// webview
'web-view',
// TODO: 广告
'ad',
'ad-rewarded-video',
'ad-fullscreen-video',
'ad-interstitial',
'ad-draw',
'ad-content-page',
// 云数据库
'unicloud-db',
// 页面配置
'page-meta',
'navigation-bar',
'custom-tab-bar',
// nvue 组件
'barcode',
'list',
'cell',
'recycle-list',
'waterfall',
'refresh',
// 小程序组件
'official-account',
'open-data',
],
}],
...overrides,
},
},
setup,
rules,
]
}
1 change: 1 addition & 0 deletions src/globs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const GLOB_UNI = '**/*.?([un])vue'
19 changes: 16 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ export function uniHelper(options: OptionsConfig & ConfigItem = {}, ...userConfi
uni: enableUni = true,
uniJson = true,
overrides = {},
typescript: enableTypeScript = isPackageExists('typescript'),
} = options

const stylisticOptions = options.stylistic === false
? false
: typeof options.stylistic === 'object'
? options.stylistic
: {}
if (stylisticOptions && !('jsx' in stylisticOptions))
stylisticOptions.jsx = options.jsx ?? true

const ignoreManifestJSON = isPackageExists('@uni-helper/vite-plugin-uni-manifest') || uniJson === false
const ignorePagesJSON = isPackageExists('@uni-helper/vite-plugin-uni-pages') || uniJson === false
options.ignores = options.ignores || []
Expand All @@ -39,14 +48,18 @@ export function uniHelper(options: OptionsConfig & ConfigItem = {}, ...userConfi
userConfigs.unshift(sortThemeJson())

if (enableUni) {
// force enable vue
options.vue = true
// force disable vue
options.vue = false
userConfigs.unshift(uni({
overrides: overrides.uni,
typescript: !!enableTypeScript,
stylistic: stylisticOptions,
}))
}

return antfu(options, ...userConfigs)
const config = antfu(options, ...userConfigs)

return config
}

export default uniHelper
1 change: 0 additions & 1 deletion test/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export default uni(

await execa('npx', ['eslint', '.', '--fix'], {
cwd: target,
stdio: 'pipe',
})

const files = await fg('**/*', {
Expand Down

0 comments on commit 67de5bd

Please sign in to comment.