|
| 1 | +import type { DefaultTheme } from 'vitepress' |
| 2 | +import { defineConfig } from 'vitepress' |
| 3 | +import { BUNDLED_LANGUAGES } from 'shiki' |
| 4 | +import path from 'path' |
| 5 | +import { fileURLToPath } from 'url' |
| 6 | +import rules from '../../tools/lib/rules' |
| 7 | +import { viteCommonjs, vitePluginRequireResolve } from './vite-plugin' |
| 8 | + |
| 9 | +// Pre-build cjs packages that cannot be bundled well. |
| 10 | +import './build-system/build' |
| 11 | + |
| 12 | +const dirname = path.dirname( |
| 13 | + fileURLToPath( |
| 14 | + // @ts-expect-error -- Cannot change `module` option |
| 15 | + import.meta.url |
| 16 | + ) |
| 17 | +) |
| 18 | + |
| 19 | +// Include `json5` as alias for jsonc |
| 20 | +const jsonc = BUNDLED_LANGUAGES.find((lang) => lang.id === 'jsonc') |
| 21 | +if (jsonc) { |
| 22 | + jsonc.aliases = [...(jsonc.aliases ?? []), 'json5'] |
| 23 | +} |
| 24 | + |
| 25 | +const uncategorizedRules = rules.filter( |
| 26 | + (rule) => |
| 27 | + !rule.meta.docs.categories && |
| 28 | + !rule.meta.docs.extensionRule && |
| 29 | + !rule.meta.deprecated |
| 30 | +) |
| 31 | +const uncategorizedExtensionRule = rules.filter( |
| 32 | + (rule) => |
| 33 | + !rule.meta.docs.categories && |
| 34 | + rule.meta.docs.extensionRule && |
| 35 | + !rule.meta.deprecated |
| 36 | +) |
| 37 | +const deprecatedRules = rules.filter((rule) => rule.meta.deprecated) |
| 38 | + |
| 39 | +const sidebarCategories = [ |
| 40 | + { title: 'Base Rules', categoryIds: ['base'] }, |
| 41 | + { |
| 42 | + title: 'Priority A: Essential', |
| 43 | + categoryIds: ['vue3-essential', 'essential'] |
| 44 | + }, |
| 45 | + { |
| 46 | + title: 'Priority A: Essential for Vue.js 3.x', |
| 47 | + categoryIds: ['vue3-essential'] |
| 48 | + }, |
| 49 | + { title: 'Priority A: Essential for Vue.js 2.x', categoryIds: ['essential'] }, |
| 50 | + { |
| 51 | + title: 'Priority B: Strongly Recommended', |
| 52 | + categoryIds: ['vue3-strongly-recommended', 'strongly-recommended'] |
| 53 | + }, |
| 54 | + { |
| 55 | + title: 'Priority B: Strongly Recommended for Vue.js 3.x', |
| 56 | + categoryIds: ['vue3-strongly-recommended'] |
| 57 | + }, |
| 58 | + { |
| 59 | + title: 'Priority B: Strongly Recommended for Vue.js 2.x', |
| 60 | + categoryIds: ['strongly-recommended'] |
| 61 | + }, |
| 62 | + { |
| 63 | + title: 'Priority C: Recommended', |
| 64 | + categoryIds: ['vue3-recommended', 'recommended'] |
| 65 | + }, |
| 66 | + { |
| 67 | + title: 'Priority C: Recommended for Vue.js 3.x', |
| 68 | + categoryIds: ['vue3-recommended'] |
| 69 | + }, |
| 70 | + { |
| 71 | + title: 'Priority C: Recommended for Vue.js 2.x', |
| 72 | + categoryIds: ['recommended'] |
| 73 | + } |
| 74 | +] |
| 75 | + |
| 76 | +const categorizedRules: DefaultTheme.SidebarGroup[] = [] |
| 77 | +for (const { title, categoryIds } of sidebarCategories) { |
| 78 | + const categoryRules = rules |
| 79 | + .filter((rule) => rule.meta.docs.categories && !rule.meta.deprecated) |
| 80 | + .filter((rule) => |
| 81 | + categoryIds.every((categoryId) => |
| 82 | + rule.meta.docs.categories.includes(categoryId) |
| 83 | + ) |
| 84 | + ) |
| 85 | + const children: DefaultTheme.SidebarItem[] = categoryRules |
| 86 | + .filter(({ ruleId }) => { |
| 87 | + const exists = categorizedRules.some(({ items }) => |
| 88 | + items.some(({ text: alreadyRuleId }) => alreadyRuleId === ruleId) |
| 89 | + ) |
| 90 | + return !exists |
| 91 | + }) |
| 92 | + .map(({ ruleId, name }) => { |
| 93 | + return { |
| 94 | + text: ruleId, |
| 95 | + link: `/rules/${name}` |
| 96 | + } |
| 97 | + }) |
| 98 | + |
| 99 | + if (children.length === 0) { |
| 100 | + continue |
| 101 | + } |
| 102 | + categorizedRules.push({ |
| 103 | + text: title, |
| 104 | + collapsible: false, |
| 105 | + items: children |
| 106 | + }) |
| 107 | +} |
| 108 | + |
| 109 | +const extraCategories: DefaultTheme.SidebarGroup[] = [] |
| 110 | +if (uncategorizedRules.length > 0) { |
| 111 | + extraCategories.push({ |
| 112 | + text: 'Uncategorized', |
| 113 | + collapsible: false, |
| 114 | + items: uncategorizedRules.map(({ ruleId, name }) => ({ |
| 115 | + text: ruleId, |
| 116 | + link: `/rules/${name}` |
| 117 | + })) |
| 118 | + }) |
| 119 | +} |
| 120 | +if (uncategorizedExtensionRule.length > 0) { |
| 121 | + extraCategories.push({ |
| 122 | + text: 'Extension Rules', |
| 123 | + collapsible: false, |
| 124 | + items: uncategorizedExtensionRule.map(({ ruleId, name }) => ({ |
| 125 | + text: ruleId, |
| 126 | + link: `/rules/${name}` |
| 127 | + })) |
| 128 | + }) |
| 129 | +} |
| 130 | +if (deprecatedRules.length > 0) { |
| 131 | + extraCategories.push({ |
| 132 | + text: 'Deprecated', |
| 133 | + collapsible: false, |
| 134 | + items: deprecatedRules.map(({ ruleId, name }) => ({ |
| 135 | + text: ruleId, |
| 136 | + link: `/rules/${name}` |
| 137 | + })) |
| 138 | + }) |
| 139 | +} |
| 140 | + |
| 141 | +export default defineConfig({ |
| 142 | + base: '/', |
| 143 | + title: 'eslint-plugin-vue', |
| 144 | + description: 'Official ESLint plugin for Vue.js', |
| 145 | + head: [['link', { rel: 'icon', href: '/favicon.png' }]], |
| 146 | + |
| 147 | + vite: { |
| 148 | + publicDir: path.resolve(dirname, './public'), |
| 149 | + plugins: [vitePluginRequireResolve(), viteCommonjs()], |
| 150 | + resolve: { |
| 151 | + alias: { |
| 152 | + eslint: path.join(dirname, './build-system/shim/eslint.mjs'), |
| 153 | + assert: path.join(dirname, './build-system/shim/assert.mjs'), |
| 154 | + path: path.join(dirname, './build-system/shim/path.mjs'), |
| 155 | + |
| 156 | + tslib: path.join(dirname, '../../node_modules/tslib/tslib.es6.js'), |
| 157 | + esquery: path.join(dirname, './build-system/shim/esquery.mjs'), |
| 158 | + globby: path.join(dirname, './build-system/shim/globby.mjs') |
| 159 | + } |
| 160 | + }, |
| 161 | + define: { |
| 162 | + 'process.env.NODE_DEBUG': 'false', |
| 163 | + 'require.cache': '{}' |
| 164 | + } |
| 165 | + }, |
| 166 | + |
| 167 | + lastUpdated: true, |
| 168 | + themeConfig: { |
| 169 | + editLink: { |
| 170 | + pattern: |
| 171 | + 'https://github.com/vuejs/eslint-plugin-vue/edit/master/docs/:path' |
| 172 | + }, |
| 173 | + socialLinks: [ |
| 174 | + { |
| 175 | + icon: 'github', |
| 176 | + link: 'https://github.com/vuejs/eslint-plugin-vue' |
| 177 | + } |
| 178 | + ], |
| 179 | + |
| 180 | + nav: [ |
| 181 | + { text: 'User Guide', link: '/user-guide/' }, |
| 182 | + { text: 'Developer Guide', link: '/developer-guide/' }, |
| 183 | + { text: 'Rules', link: '/rules/' }, |
| 184 | + { |
| 185 | + text: 'Demo', |
| 186 | + link: 'https://ota-meshi.github.io/eslint-plugin-vue-demo/' |
| 187 | + } |
| 188 | + ], |
| 189 | + |
| 190 | + sidebar: { |
| 191 | + '/rules/': [ |
| 192 | + { |
| 193 | + text: 'Rules', |
| 194 | + items: [{ text: 'Available Rules', link: '/rules/' }] |
| 195 | + }, |
| 196 | + |
| 197 | + // Rules in each category. |
| 198 | + ...categorizedRules, |
| 199 | + |
| 200 | + // Rules in no category. |
| 201 | + ...extraCategories |
| 202 | + ], |
| 203 | + |
| 204 | + '/': [ |
| 205 | + { |
| 206 | + text: 'Guide', |
| 207 | + items: [ |
| 208 | + { text: 'Introduction', link: '/' }, |
| 209 | + { text: 'User Guide', link: '/user-guide/' }, |
| 210 | + { text: 'Developer Guide', link: '/developer-guide/' }, |
| 211 | + { text: 'Rules', link: '/rules/' } |
| 212 | + ] |
| 213 | + } |
| 214 | + ] |
| 215 | + }, |
| 216 | + |
| 217 | + algolia: { |
| 218 | + appId: '2L4MGZSULB', |
| 219 | + apiKey: 'fdf57932b27a6c230d01a890492ab76d', |
| 220 | + indexName: 'eslint-plugin-vue' |
| 221 | + } |
| 222 | + } |
| 223 | +}) |
0 commit comments