valaxy 0.0.2 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -1
- package/bin/valaxy.js +11 -0
- package/dist/build-OOT6HK6S.js +1 -0
- package/dist/build-SG32QSQ3.mjs +1 -0
- package/dist/chunk-7JDYOPID.js +1 -0
- package/dist/chunk-JJEBEWGI.mjs +1 -0
- package/dist/chunk-L3EDI35I.js +1 -0
- package/dist/chunk-L5SNNWFJ.js +78 -0
- package/dist/chunk-MVJUGWXR.mjs +1 -0
- package/dist/chunk-QI435Q25.mjs +78 -0
- package/dist/config-d6527c8c.d.ts +174 -0
- package/dist/node/cli.d.ts +3 -0
- package/dist/node/cli.js +6 -0
- package/dist/node/cli.mjs +6 -0
- package/dist/node/index.d.ts +45 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.mjs +1 -0
- package/dist/types/index.d.ts +110 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.mjs +1 -0
- package/package.json +75 -3
- package/src/client/App.vue +16 -0
- package/src/client/components/AppLink.vue +20 -0
- package/src/client/components/PostCard.vue +69 -0
- package/src/client/components/PostList.vue +50 -0
- package/src/client/components/README.md +7 -0
- package/src/client/components/ValaxyCopyright.vue +80 -0
- package/src/client/components/ValaxyFooter.vue +53 -0
- package/src/client/components/ValaxyHamburger.vue +21 -0
- package/src/client/components/ValaxyMd.vue +71 -0
- package/src/client/components/ValaxyOverlay.vue +44 -0
- package/src/client/components/ValaxyPagination.vue +122 -0
- package/src/client/components/ValaxyRightSidebar.vue +32 -0
- package/src/client/components/ValaxySidebar.vue +35 -0
- package/src/client/components/ValaxyToc.vue +70 -0
- package/src/client/composables/category.ts +101 -0
- package/src/client/composables/comments/index.ts +1 -0
- package/src/client/composables/comments/waline.ts +60 -0
- package/src/client/composables/common.ts +27 -0
- package/src/client/composables/dark.ts +4 -0
- package/src/client/composables/features/index.ts +1 -0
- package/src/client/composables/features/katex.ts +15 -0
- package/src/client/composables/helper.ts +26 -0
- package/src/client/composables/index.ts +17 -0
- package/src/client/composables/layout.ts +7 -0
- package/src/client/composables/post.ts +96 -0
- package/src/client/composables/search/algolia.ts +114 -0
- package/src/client/composables/search/index.ts +0 -0
- package/src/client/composables/sidebar.ts +128 -0
- package/src/client/composables/tag.ts +70 -0
- package/src/client/composables/widgets/aplayer.ts +23 -0
- package/src/client/composables/widgets/backToTop.ts +28 -0
- package/src/client/composables/widgets/codepen.ts +12 -0
- package/src/client/composables/widgets/index.ts +3 -0
- package/src/client/index.html +24 -0
- package/src/client/layouts/404.vue +25 -0
- package/src/client/layouts/README.md +14 -0
- package/src/client/locales/README.md +7 -0
- package/src/client/locales/en.yml +107 -0
- package/src/client/locales/zh-CN.yml +106 -0
- package/src/client/main.ts +30 -0
- package/src/client/modules/README.md +11 -0
- package/src/client/modules/nprogress.ts +14 -0
- package/src/client/modules/pinia.ts +17 -0
- package/src/client/modules/pwa.ts +12 -0
- package/src/client/modules/valaxy.ts +42 -0
- package/src/client/pages/README.md +20 -0
- package/src/client/pages/[...all].vue +15 -0
- package/src/client/pages/about/index.md +5 -0
- package/src/client/pages/hi/[name].vue +52 -0
- package/src/client/pages/index.vue +3 -0
- package/src/client/pages/page/[page].vue +12 -0
- package/src/client/pages/posts/index.md +5 -0
- package/src/client/public/_headers +3 -0
- package/src/client/public/favicon.svg +21 -0
- package/src/client/public/pwa-192x192.png +0 -0
- package/src/client/public/pwa-512x512.png +0 -0
- package/src/client/public/safari-pinned-tab.svg +41 -0
- package/src/client/shims.d.ts +36 -0
- package/src/client/stores/app.ts +14 -0
- package/src/client/stores/user.ts +35 -0
- package/src/client/styles/common/button.scss +29 -0
- package/src/client/styles/common/code.scss +35 -0
- package/src/client/styles/common/hamburger.scss +56 -0
- package/src/client/styles/common/markdown.scss +43 -0
- package/src/client/styles/common/scrollbar.scss +34 -0
- package/src/client/styles/common/sidebar.scss +30 -0
- package/src/client/styles/common/transition.scss +23 -0
- package/src/client/styles/css-vars/dark.scss +17 -0
- package/src/client/styles/css-vars/index.scss +18 -0
- package/src/client/styles/css-vars/light.scss +9 -0
- package/src/client/styles/global/helper.scss +3 -0
- package/src/client/styles/global/index.scss +38 -0
- package/src/client/styles/global/nprogress.scss +14 -0
- package/src/client/styles/global/reset.scss +20 -0
- package/src/client/styles/index.scss +18 -0
- package/src/client/styles/mixins/config.scss +1 -0
- package/src/client/styles/mixins/index.scss +2 -0
- package/src/client/styles/mixins/size.scss +49 -0
- package/src/client/styles/mixins/variable.scss +30 -0
- package/src/client/styles/palette.scss +61 -0
- package/src/client/styles/vars.scss +39 -0
- package/src/client/styles/widgets/banner.scss +116 -0
- package/src/client/types.ts +3 -0
- package/src/client/utils/helper.ts +30 -0
- package/src/client/utils/index.ts +2 -0
- package/src/client/utils/time.ts +23 -0
- package/src/core/config.ts +51 -0
- package/src/core/index.ts +5 -0
- package/src/core/utils.ts +1 -0
- package/src/index.ts +2 -0
- package/src/node/build.ts +12 -0
- package/src/node/cli.ts +177 -0
- package/src/node/config.ts +43 -0
- package/src/node/index.ts +1 -0
- package/src/node/markdown/headings.ts +24 -0
- package/src/node/markdown/index.ts +74 -0
- package/src/node/markdown/markdown-it-container.ts +53 -0
- package/src/node/markdown/markdown-it-katex.ts +200 -0
- package/src/node/markdown/parseHeader.ts +70 -0
- package/src/node/markdown/slugify.ts +24 -0
- package/src/node/options.ts +90 -0
- package/src/node/plugins/extendConfig.ts +28 -0
- package/src/node/plugins/index.ts +91 -0
- package/src/node/plugins/markdown.ts +62 -0
- package/src/node/plugins/preset.ts +174 -0
- package/src/node/plugins/unocss.ts +106 -0
- package/src/node/plugins/valaxy.ts +1 -0
- package/src/node/server.ts +21 -0
- package/src/node/shims.d.ts +23 -0
- package/src/node/utils/cli.ts +105 -0
- package/src/node/utils/index.ts +26 -0
- package/src/node/vite.ts +83 -0
- package/src/types/config.ts +250 -0
- package/src/types/index.ts +2 -0
- package/src/types/posts.ts +107 -0
- package/tsup.config.ts +17 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import type { PluginOption } from 'vite'
|
|
4
|
+
|
|
5
|
+
import consola from 'consola'
|
|
6
|
+
|
|
7
|
+
import MarkdownIt from 'markdown-it'
|
|
8
|
+
import matter from 'gray-matter'
|
|
9
|
+
|
|
10
|
+
import Vue from '@vitejs/plugin-vue'
|
|
11
|
+
import Pages from 'vite-plugin-pages'
|
|
12
|
+
import Layouts from 'vite-plugin-vue-layouts'
|
|
13
|
+
import Components from 'unplugin-vue-components/vite'
|
|
14
|
+
import { VitePWA } from 'vite-plugin-pwa'
|
|
15
|
+
import VueI18n from '@intlify/vite-plugin-vue-i18n'
|
|
16
|
+
import Inspect from 'vite-plugin-inspect'
|
|
17
|
+
|
|
18
|
+
import chalk from 'chalk'
|
|
19
|
+
import type { ResolvedValaxyOptions, ValaxyServerOptions } from '../options'
|
|
20
|
+
import type { Mode } from '../vite'
|
|
21
|
+
import { setupMarkdownPlugins } from '../markdown'
|
|
22
|
+
import { createMarkdownPlugin, excerpt_separator } from './markdown'
|
|
23
|
+
import { createUnocssPlugin } from './unocss'
|
|
24
|
+
import { createConfigPlugin } from './extendConfig'
|
|
25
|
+
import { createValaxyPlugin } from '.'
|
|
26
|
+
|
|
27
|
+
export function ViteValaxyPlugins(
|
|
28
|
+
options: ResolvedValaxyOptions,
|
|
29
|
+
serverOptions: ValaxyServerOptions = {},
|
|
30
|
+
mode: Mode = 'dev',
|
|
31
|
+
): (PluginOption | PluginOption[])[] | undefined {
|
|
32
|
+
const { clientRoot, themeRoot, userRoot } = options
|
|
33
|
+
|
|
34
|
+
const MarkdownPlugin = createMarkdownPlugin(options)
|
|
35
|
+
const UnocssPlugin = createUnocssPlugin(options)
|
|
36
|
+
|
|
37
|
+
const ValaxyPlugin = createValaxyPlugin(options, serverOptions)
|
|
38
|
+
|
|
39
|
+
const mdIt = new MarkdownIt({ html: true })
|
|
40
|
+
const _md = setupMarkdownPlugins(mdIt, options.config.markdownIt)
|
|
41
|
+
|
|
42
|
+
const roots = [clientRoot, themeRoot, userRoot]
|
|
43
|
+
return [
|
|
44
|
+
Vue({
|
|
45
|
+
include: [/\.vue$/, /\.md$/],
|
|
46
|
+
template: {
|
|
47
|
+
compilerOptions: {
|
|
48
|
+
isCustomElement: (tag) => {
|
|
49
|
+
return ['meting-js'].includes(tag)
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}) as PluginOption,
|
|
54
|
+
|
|
55
|
+
ValaxyPlugin,
|
|
56
|
+
MarkdownPlugin,
|
|
57
|
+
createConfigPlugin(options),
|
|
58
|
+
|
|
59
|
+
// https://github.com/hannoeru/vite-plugin-pages
|
|
60
|
+
Pages({
|
|
61
|
+
extensions: ['vue', 'md'],
|
|
62
|
+
dirs: roots.map(root => `${root}/pages`),
|
|
63
|
+
/**
|
|
64
|
+
* we need get frontmatter before route, so write it in Pages.extendRoute
|
|
65
|
+
*/
|
|
66
|
+
extendRoute(route) {
|
|
67
|
+
let path = route.component
|
|
68
|
+
if (!route.meta) route.meta = {}
|
|
69
|
+
|
|
70
|
+
if (route.path === '/')
|
|
71
|
+
route.meta.layout = 'home'
|
|
72
|
+
|
|
73
|
+
roots.forEach((root) => {
|
|
74
|
+
const pagePath = root + route.component
|
|
75
|
+
if (fs.existsSync(pagePath))
|
|
76
|
+
path = pagePath
|
|
77
|
+
})
|
|
78
|
+
const md = fs.readFileSync(path, 'utf-8')
|
|
79
|
+
const { data, excerpt } = matter(md, { excerpt_separator })
|
|
80
|
+
|
|
81
|
+
// warn for post frontmatter
|
|
82
|
+
if (route.path.startsWith('/posts/')) {
|
|
83
|
+
route.meta.layout = 'post'
|
|
84
|
+
if (!data.date)
|
|
85
|
+
consola.warn(`You forgot to write ${chalk.yellow('date')} for post: ${chalk.dim(`${route.component}`)}`)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
route.meta = Object.assign(route.meta, {
|
|
89
|
+
frontmatter: Object.assign({ date: new Date() }, data),
|
|
90
|
+
excerpt: excerpt ? mdIt.render(excerpt) : '',
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
// to refactor
|
|
94
|
+
// get active header by runtime query head, not render
|
|
95
|
+
mdIt.render(md)
|
|
96
|
+
route.meta.headers = _md.__data?.headers
|
|
97
|
+
|
|
98
|
+
// set default updated
|
|
99
|
+
if (route.meta.frontmatter.updated)
|
|
100
|
+
route.meta.frontmatter.updated = route.meta.frontmatter.date
|
|
101
|
+
|
|
102
|
+
// set layout
|
|
103
|
+
if (data.layout)
|
|
104
|
+
route.meta.layout = data.layout
|
|
105
|
+
|
|
106
|
+
return route
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
|
|
110
|
+
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
|
|
111
|
+
Layouts({
|
|
112
|
+
layoutsDirs: roots.map(root => `${root}/layouts`),
|
|
113
|
+
}),
|
|
114
|
+
|
|
115
|
+
// https://github.com/antfu/unplugin-vue-components
|
|
116
|
+
Components({
|
|
117
|
+
extensions: ['vue', 'md'],
|
|
118
|
+
|
|
119
|
+
// allow auto import and register components used in markdown
|
|
120
|
+
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
|
|
121
|
+
|
|
122
|
+
// allow override
|
|
123
|
+
allowOverrides: true,
|
|
124
|
+
// override: user -> theme -> client
|
|
125
|
+
// latter override former
|
|
126
|
+
dirs: roots.map(root => `${root}/components`),
|
|
127
|
+
dts: `${options.userRoot}/components.d.ts`,
|
|
128
|
+
}),
|
|
129
|
+
|
|
130
|
+
// https://github.com/antfu/unocss
|
|
131
|
+
// UnocssPlugin,
|
|
132
|
+
UnocssPlugin,
|
|
133
|
+
|
|
134
|
+
// https://github.com/antfu/vite-plugin-pwa
|
|
135
|
+
VitePWA({
|
|
136
|
+
registerType: 'autoUpdate',
|
|
137
|
+
includeAssets: ['favicon.svg', 'safari-pinned-tab.svg'],
|
|
138
|
+
manifest: {
|
|
139
|
+
name: 'Theme Yun',
|
|
140
|
+
short_name: 'Yun',
|
|
141
|
+
theme_color: '#ffffff',
|
|
142
|
+
icons: [
|
|
143
|
+
{
|
|
144
|
+
src: '/pwa-192x192.png',
|
|
145
|
+
sizes: '192x192',
|
|
146
|
+
type: 'image/png',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
src: '/pwa-512x512.png',
|
|
150
|
+
sizes: '512x512',
|
|
151
|
+
type: 'image/png',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
src: '/pwa-512x512.png',
|
|
155
|
+
sizes: '512x512',
|
|
156
|
+
type: 'image/png',
|
|
157
|
+
purpose: 'any maskable',
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
}),
|
|
162
|
+
|
|
163
|
+
// https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
|
|
164
|
+
VueI18n({
|
|
165
|
+
runtimeOnly: true,
|
|
166
|
+
compositionOnly: true,
|
|
167
|
+
include: roots.map(root => `${root}/locales/**`),
|
|
168
|
+
}) as PluginOption,
|
|
169
|
+
|
|
170
|
+
// https://github.com/antfu/vite-plugin-inspect
|
|
171
|
+
// Visit http://localhost:3333/__inspect/ to see the inspector
|
|
172
|
+
mode === 'dev' && Inspect(),
|
|
173
|
+
]
|
|
174
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import defu from 'defu'
|
|
2
|
+
import type { VitePluginConfig } from 'unocss/vite'
|
|
3
|
+
import Unocss from 'unocss/vite'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
presetAttributify,
|
|
7
|
+
presetIcons,
|
|
8
|
+
presetTypography,
|
|
9
|
+
presetUno,
|
|
10
|
+
presetWebFonts,
|
|
11
|
+
transformerDirectives,
|
|
12
|
+
transformerVariantGroup,
|
|
13
|
+
} from 'unocss'
|
|
14
|
+
import type { ValaxyConfig } from 'valaxy'
|
|
15
|
+
import type { ThemeUserConfig } from 'valaxy-theme-yun/config'
|
|
16
|
+
import type { ResolvedValaxyOptions } from '../options'
|
|
17
|
+
|
|
18
|
+
export const createSafelist = (config: ValaxyConfig<ThemeUserConfig>) => {
|
|
19
|
+
const safeIcons: string[] = [
|
|
20
|
+
'i-ri-archive-line',
|
|
21
|
+
'i-ri-folder-2-line',
|
|
22
|
+
'i-ri-price-tag-3-line',
|
|
23
|
+
|
|
24
|
+
'i-ri-cloud-line',
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
const safelist = 'animate-fade-in prose prose-sm m-auto text-left'.split(' ').concat([
|
|
28
|
+
'rotate-y-180',
|
|
29
|
+
]).concat(safeIcons)
|
|
30
|
+
// generate icon safelist
|
|
31
|
+
if (config.social.length)
|
|
32
|
+
config.social.forEach(item => safelist.push(item.icon))
|
|
33
|
+
|
|
34
|
+
if (config.themeConfig.footer?.icon?.name)
|
|
35
|
+
safelist.push(config.themeConfig.footer?.icon?.name)
|
|
36
|
+
|
|
37
|
+
// sponsor icon
|
|
38
|
+
if (config.sponsor.methods.length)
|
|
39
|
+
config.sponsor.methods.forEach(item => safelist.push(item.icon))
|
|
40
|
+
|
|
41
|
+
const types = config.themeConfig.types
|
|
42
|
+
if (types) {
|
|
43
|
+
for (const type in types)
|
|
44
|
+
safelist.push(types[type].icon)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return safelist
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const createUnocssConfig = (options: ResolvedValaxyOptions) => {
|
|
51
|
+
const unocssConfig: VitePluginConfig = {
|
|
52
|
+
shortcuts: [
|
|
53
|
+
['yun-main', 'lt-md:pl-0'],
|
|
54
|
+
['yun-card', 'transition yun-transition shadow hover:shadow-lg'],
|
|
55
|
+
['btn', 'px-4 py-1 rounded inline-block bg-sky-600 text-white cursor-pointer hover:bg-sky-700 disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50'],
|
|
56
|
+
['icon-btn', 'inline-block cursor-pointer select-none opacity-75 transition duration-200 ease-in-out hover:opacity-100 hover:text-sky-600'],
|
|
57
|
+
['val-card', 'transition shadow hover:shadow-lg'],
|
|
58
|
+
],
|
|
59
|
+
presets: [
|
|
60
|
+
presetUno(),
|
|
61
|
+
presetAttributify(),
|
|
62
|
+
presetIcons({
|
|
63
|
+
scale: 1.2,
|
|
64
|
+
// warn: true,
|
|
65
|
+
}),
|
|
66
|
+
presetTypography(),
|
|
67
|
+
presetWebFonts({
|
|
68
|
+
fonts: {
|
|
69
|
+
serif: 'Noto Serif SC',
|
|
70
|
+
// sans: 'DM Sans',
|
|
71
|
+
// mono: 'DM Mono',
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
],
|
|
75
|
+
rules: [
|
|
76
|
+
// more see '~/styles/global/helper.scss'
|
|
77
|
+
['yun-transition', {
|
|
78
|
+
'transition-duration': 'var(--yun-transition-duration)',
|
|
79
|
+
}],
|
|
80
|
+
['yun-text-light', {
|
|
81
|
+
color: 'var(--yun-c-text-light)',
|
|
82
|
+
}],
|
|
83
|
+
['font-serif', {
|
|
84
|
+
'font-family': 'var(--yun-font-serif)',
|
|
85
|
+
}],
|
|
86
|
+
['font-sans', {
|
|
87
|
+
'font-family': 'var(--yun-font-sans)',
|
|
88
|
+
}],
|
|
89
|
+
['font-mono', {
|
|
90
|
+
'font-family': 'var(--yun-font-mono)',
|
|
91
|
+
}],
|
|
92
|
+
],
|
|
93
|
+
transformers: [
|
|
94
|
+
transformerDirectives(),
|
|
95
|
+
transformerVariantGroup(),
|
|
96
|
+
],
|
|
97
|
+
safelist: createSafelist(options.config),
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return defu(options.config.unocss, unocssConfig)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const createUnocssPlugin = (options: ResolvedValaxyOptions) => {
|
|
104
|
+
const config = createUnocssConfig(options)
|
|
105
|
+
return Unocss(config)
|
|
106
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VALAXY_CONFIG_ID = '@valaxyjs/config'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { InlineConfig } from 'vite'
|
|
2
|
+
import { createServer as createViteServer, mergeConfig } from 'vite'
|
|
3
|
+
|
|
4
|
+
import type { ResolvedValaxyOptions, ValaxyServerOptions } from './options'
|
|
5
|
+
import { createViteConfig } from './vite'
|
|
6
|
+
|
|
7
|
+
export async function createServer(
|
|
8
|
+
options: ResolvedValaxyOptions,
|
|
9
|
+
viteConfig: InlineConfig = {},
|
|
10
|
+
serverOptions: ValaxyServerOptions = {},
|
|
11
|
+
) {
|
|
12
|
+
// default editor vscode
|
|
13
|
+
process.env.EDITOR = process.env.EDITOR || 'code'
|
|
14
|
+
|
|
15
|
+
const server = await createViteServer(mergeConfig(
|
|
16
|
+
viteConfig,
|
|
17
|
+
createViteConfig(options, serverOptions),
|
|
18
|
+
))
|
|
19
|
+
|
|
20
|
+
return server
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare module 'markdown-it-attrs' {
|
|
2
|
+
const def: any
|
|
3
|
+
export default def
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module 'markdown-it-emoji' {
|
|
7
|
+
const def: any
|
|
8
|
+
export default def
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module 'markdown-it-table-of-contents' {
|
|
12
|
+
const def: any
|
|
13
|
+
export default def
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module 'markdown-it-container' {
|
|
17
|
+
const def: any
|
|
18
|
+
export default def
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module 'diacritics' {
|
|
22
|
+
export const remove: (str: string) => string
|
|
23
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
|
|
2
|
+
import * as readline from 'readline'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import os from 'os'
|
|
5
|
+
// import equal from 'fast-deep-equal'
|
|
6
|
+
|
|
7
|
+
import chalk from 'chalk'
|
|
8
|
+
import consola from 'consola'
|
|
9
|
+
import type { InlineConfig, ViteDevServer } from 'vite'
|
|
10
|
+
import { createServer } from '../server'
|
|
11
|
+
import type { ResolvedValaxyOptions } from '../options'
|
|
12
|
+
import { version } from '../../../package.json'
|
|
13
|
+
import { createSafelist } from '../plugins/unocss'
|
|
14
|
+
|
|
15
|
+
let server: ViteDevServer | undefined
|
|
16
|
+
|
|
17
|
+
export function printInfo(options: ResolvedValaxyOptions, port?: number, remote?: string | boolean) {
|
|
18
|
+
console.log()
|
|
19
|
+
console.log(` ${chalk.bold('🌌 Valaxy')} ${chalk.blue(`v${version}`)}`)
|
|
20
|
+
console.log()
|
|
21
|
+
console.log(`${chalk.dim(' 🪐 theme ')} > ${(options.theme ? chalk.green(options.theme) : chalk.gray('none'))}`)
|
|
22
|
+
console.log(` ${chalk.dim('📁')} ${chalk.dim(path.resolve(options.userRoot))}`)
|
|
23
|
+
if (port) {
|
|
24
|
+
console.log()
|
|
25
|
+
console.log(`${chalk.dim(' Preview ')} > ${chalk.cyan(`http://localhost:${chalk.bold(port)}/`)}`)
|
|
26
|
+
|
|
27
|
+
if (remote) {
|
|
28
|
+
Object.values(os.networkInterfaces())
|
|
29
|
+
.forEach(v => (v || [])
|
|
30
|
+
.filter(details => details.family === 'IPv4' && !details.address.includes('127.0.0.1'))
|
|
31
|
+
.forEach(({ address }) => {
|
|
32
|
+
console.log(`${chalk.dim(' Network ')} > ${chalk.blue(`http://${address}:${chalk.bold(port)}/`)}`)
|
|
33
|
+
}),
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log()
|
|
38
|
+
console.log(`${chalk.dim(' shortcuts ')} > ${chalk.underline('r')}${chalk.dim('estart | ')}${chalk.underline('o')}${chalk.dim('pen | ')}${chalk.underline('e')}${chalk.dim('dit')}`)
|
|
39
|
+
}
|
|
40
|
+
console.log()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function initServer(options: ResolvedValaxyOptions, viteConfig: InlineConfig) {
|
|
44
|
+
if (server)
|
|
45
|
+
await server.close()
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const safelist = createSafelist(options.config).concat(options.config.unocss.safelist || [])
|
|
49
|
+
|
|
50
|
+
server = await createServer(options, viteConfig, {
|
|
51
|
+
onConfigReload(newConfig, config) {
|
|
52
|
+
let reload = false
|
|
53
|
+
|
|
54
|
+
const iconChanged = newConfig.social.some((item, i) => {
|
|
55
|
+
return !safelist.includes(item.icon) && item.icon !== config.social[i].icon
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
if (iconChanged) {
|
|
59
|
+
consola.info('Find new icon, reload server...')
|
|
60
|
+
consola.info(`If you do not want to reload it, write icon name in ${chalk.green('config.unocss.safelist')}.`)
|
|
61
|
+
consola.info('For example: ["i-ri-cloud-line"]')
|
|
62
|
+
console.log()
|
|
63
|
+
reload = true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (reload)
|
|
67
|
+
initServer(options, viteConfig)
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
await server.listen()
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
consola.error('failed to start server. error:\n')
|
|
74
|
+
console.error(e)
|
|
75
|
+
process.exit(1)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* bind shortcut for terminal
|
|
81
|
+
*/
|
|
82
|
+
export function bindShortcut(SHORTCUTS: { name: string; fullName: string; action: () => void }[]) {
|
|
83
|
+
process.stdin.resume()
|
|
84
|
+
process.stdin.setEncoding('utf8')
|
|
85
|
+
readline.emitKeypressEvents(process.stdin)
|
|
86
|
+
if (process.stdin.isTTY)
|
|
87
|
+
process.stdin.setRawMode(true)
|
|
88
|
+
|
|
89
|
+
process.stdin.on('keypress', (str, key) => {
|
|
90
|
+
if (key.ctrl && key.name === 'c') {
|
|
91
|
+
process.exit()
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const [sh] = SHORTCUTS.filter(item => item.name === str)
|
|
95
|
+
if (sh) {
|
|
96
|
+
try {
|
|
97
|
+
sh.action()
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error(`Failed to execute shortcut ${sh.fullName}`, err)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { dirname } from 'path'
|
|
2
|
+
import consola from 'consola'
|
|
3
|
+
|
|
4
|
+
export function slash(str: string) {
|
|
5
|
+
return str.replace(/\\/g, '/')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function ensurePrefix(prefix: string, str: string) {
|
|
9
|
+
if (!str.startsWith(prefix))
|
|
10
|
+
return prefix + str
|
|
11
|
+
return str
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function toAtFS(path: string) {
|
|
15
|
+
return `/@fs${ensurePrefix('/', slash(path))}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function resolveImportPath(importName: string) {
|
|
19
|
+
try {
|
|
20
|
+
return dirname(require.resolve(importName))
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
|
|
24
|
+
consola.error(`Failed to resolve package ${importName}`)
|
|
25
|
+
throw new Error(`Failed to resolve package ${importName}`)
|
|
26
|
+
}
|
package/src/node/vite.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
|
|
3
|
+
import generateSitemap from 'vite-ssg-sitemap'
|
|
4
|
+
import type { InlineConfig } from 'vite'
|
|
5
|
+
import { searchForWorkspaceRoot } from 'vite'
|
|
6
|
+
import type { ResolvedValaxyOptions, ValaxyServerOptions } from './options'
|
|
7
|
+
|
|
8
|
+
import { ViteValaxyPlugins } from './plugins/preset'
|
|
9
|
+
import { VALAXY_CONFIG_ID } from './plugins/valaxy'
|
|
10
|
+
|
|
11
|
+
export type Mode = 'dev' | 'build'
|
|
12
|
+
|
|
13
|
+
export function createViteConfig(options: ResolvedValaxyOptions, serverOptions: ValaxyServerOptions = {}, mode: Mode = 'dev'): InlineConfig {
|
|
14
|
+
const { configFile } = options
|
|
15
|
+
|
|
16
|
+
const viteConfig: InlineConfig = {
|
|
17
|
+
// remove vue-i18n warnings
|
|
18
|
+
// https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags
|
|
19
|
+
// https://github.com/antfu/vitesse/issues/131
|
|
20
|
+
// https://github.com/intlify/vue-i18n-next/blob/dab6db19a1ef917425939275a41dfde9b6c61fe9/packages/vue-i18n-core/src/misc.ts#L20
|
|
21
|
+
// I create a issue https://github.com/intlify/vue-i18n-next/issues/961
|
|
22
|
+
// define: {
|
|
23
|
+
// __FEATURE_FULL_INSTALL__: 'false',
|
|
24
|
+
// __FEATURE_LEGACY_API__: 'false',
|
|
25
|
+
// __VUE_I18N_FULL_INSTALL__: 'false',
|
|
26
|
+
// __VUE_I18N_LEGACY_API__: 'false',
|
|
27
|
+
// },
|
|
28
|
+
|
|
29
|
+
resolve: {
|
|
30
|
+
alias: {
|
|
31
|
+
'@/': `${options.userRoot}/`,
|
|
32
|
+
'~/': `${options.clientRoot}/`,
|
|
33
|
+
'@valaxyjs/client': `${options.clientRoot}/`,
|
|
34
|
+
'valaxy/package.json': `${path.resolve(options.clientRoot, '../../package.json')}`,
|
|
35
|
+
'valaxy': `${path.resolve(options.clientRoot, '..')}`,
|
|
36
|
+
[VALAXY_CONFIG_ID]: `/${VALAXY_CONFIG_ID}`,
|
|
37
|
+
'@valaxyjs/core': `${path.resolve(options.clientRoot, '../core')}`,
|
|
38
|
+
[`valaxy-theme-${options.theme}`]: `${path.resolve(options.themeRoot)}/`,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
root: options.clientRoot,
|
|
43
|
+
// todo user base
|
|
44
|
+
// base: '/',
|
|
45
|
+
|
|
46
|
+
plugins: ViteValaxyPlugins(options, serverOptions, mode),
|
|
47
|
+
|
|
48
|
+
server: {
|
|
49
|
+
fs: {
|
|
50
|
+
allow: [
|
|
51
|
+
searchForWorkspaceRoot(options.clientRoot),
|
|
52
|
+
searchForWorkspaceRoot(options.userRoot),
|
|
53
|
+
searchForWorkspaceRoot(options.themeRoot),
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
optimizeDeps: {
|
|
59
|
+
entries: [path.resolve(options.clientRoot, 'main.ts'), configFile],
|
|
60
|
+
|
|
61
|
+
include: [
|
|
62
|
+
'vue',
|
|
63
|
+
'vue-router',
|
|
64
|
+
'@vueuse/core',
|
|
65
|
+
'@vueuse/head',
|
|
66
|
+
],
|
|
67
|
+
exclude: [
|
|
68
|
+
'vue-demi',
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (mode === 'build') {
|
|
74
|
+
// https://github.com/antfu/vite-ssg
|
|
75
|
+
viteConfig.ssgOptions = {
|
|
76
|
+
script: 'async',
|
|
77
|
+
formatting: 'minify',
|
|
78
|
+
onFinished() { generateSitemap() },
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return viteConfig
|
|
83
|
+
}
|