@vixt/vitepress 0.4.0 → 0.4.2

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.
@@ -0,0 +1,46 @@
1
+ import * as vite from 'vite';
2
+ import * as _vixt_core from '@vixt/core';
3
+ import { AppOptions, Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
4
+ import { Pinia } from 'pinia';
5
+ import { PluginOptions } from 'pinia-plugin-persistedstate';
6
+ import { EnhanceAppContext } from 'vitepress';
7
+ import UnoCSS from 'unocss/vite';
8
+ import AutoImport from 'unplugin-auto-import/vite';
9
+ import Components from 'unplugin-vue-components/vite';
10
+ import VueDevTools from 'vite-plugin-vue-devtools';
11
+
12
+ declare module '@vixt/core/client' {
13
+ interface VixtAppConfig {
14
+ /** https://github.com/prazdevs/pinia-plugin-persistedstate */
15
+ piniaPersistedState?: PluginOptions
16
+ }
17
+
18
+ interface VixtApp extends EnhanceAppContext {
19
+ pinia: Pinia
20
+ appConfig: VixtAppConfig
21
+ }
22
+ }
23
+
24
+ declare const appVitepress: _vixt_core.VixtModule<AppOptions>;
25
+
26
+ declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
27
+
28
+ declare module '@vixt/core' {
29
+ interface VixtOptions {
30
+ /** https://github.com/antfu/unplugin-vue-components */
31
+ components?: PluginOptions$1<typeof Components>;
32
+ /** https://github.com/antfu/unplugin-auto-import */
33
+ imports?: PluginOptions$1<typeof AutoImport>;
34
+ /** https://github.com/antfu/unocss */
35
+ unocss?: PluginOptions$1<typeof UnoCSS>;
36
+ /** https://github.com/webfansplz/vite-plugin-vue-devtools */
37
+ devtools?: PluginOptions$1<typeof VueDevTools> & {
38
+ enabled?: boolean;
39
+ };
40
+ }
41
+ }
42
+ declare const presetVitepress: _vixt_core.VixtModule<VixtOptions>;
43
+
44
+ declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
45
+
46
+ export { appVitepress, _default as default, generateMainTs, presetVitepress };
@@ -0,0 +1,46 @@
1
+ import * as vite from 'vite';
2
+ import * as _vixt_core from '@vixt/core';
3
+ import { AppOptions, Vixt, PluginOptions as PluginOptions$1, VixtOptions } from '@vixt/core';
4
+ import { Pinia } from 'pinia';
5
+ import { PluginOptions } from 'pinia-plugin-persistedstate';
6
+ import { EnhanceAppContext } from 'vitepress';
7
+ import UnoCSS from 'unocss/vite';
8
+ import AutoImport from 'unplugin-auto-import/vite';
9
+ import Components from 'unplugin-vue-components/vite';
10
+ import VueDevTools from 'vite-plugin-vue-devtools';
11
+
12
+ declare module '@vixt/core/client' {
13
+ interface VixtAppConfig {
14
+ /** https://github.com/prazdevs/pinia-plugin-persistedstate */
15
+ piniaPersistedState?: PluginOptions
16
+ }
17
+
18
+ interface VixtApp extends EnhanceAppContext {
19
+ pinia: Pinia
20
+ appConfig: VixtAppConfig
21
+ }
22
+ }
23
+
24
+ declare const appVitepress: _vixt_core.VixtModule<AppOptions>;
25
+
26
+ declare function generateMainTs(options: AppOptions, vixt: Vixt): string;
27
+
28
+ declare module '@vixt/core' {
29
+ interface VixtOptions {
30
+ /** https://github.com/antfu/unplugin-vue-components */
31
+ components?: PluginOptions$1<typeof Components>;
32
+ /** https://github.com/antfu/unplugin-auto-import */
33
+ imports?: PluginOptions$1<typeof AutoImport>;
34
+ /** https://github.com/antfu/unocss */
35
+ unocss?: PluginOptions$1<typeof UnoCSS>;
36
+ /** https://github.com/webfansplz/vite-plugin-vue-devtools */
37
+ devtools?: PluginOptions$1<typeof VueDevTools> & {
38
+ enabled?: boolean;
39
+ };
40
+ }
41
+ }
42
+ declare const presetVitepress: _vixt_core.VixtModule<VixtOptions>;
43
+
44
+ declare const _default: (options?: VixtOptions | undefined) => vite.PluginOption;
45
+
46
+ export { appVitepress, _default as default, generateMainTs, presetVitepress };
package/dist/index.mjs ADDED
@@ -0,0 +1,116 @@
1
+ import { generateClient, generateCss, generateAppConfig, generatePlugins, defineVixtModule, resolveLayersDirs, createVixtPlugin } from '@vixt/core';
2
+ import path from 'pathe';
3
+ import fs from 'fs-extra';
4
+ import defu from 'defu';
5
+ import UnoCSS from 'unocss/vite';
6
+ import AutoImport from 'unplugin-auto-import/vite';
7
+ import Components from 'unplugin-vue-components/vite';
8
+ import { VueRouterAutoImports } from 'unplugin-vue-router';
9
+ import VueDevTools from 'vite-plugin-vue-devtools';
10
+
11
+ function generateMainTs(options, vixt) {
12
+ const { buildDir } = vixt.options;
13
+ const mainTsPath = path.resolve(".vitepress/theme/index.ts");
14
+ if (!fs.existsSync(mainTsPath))
15
+ fs.outputFileSync(mainTsPath, `// Generated by Vixt
16
+ // This file transform from '${path.basename(buildDir)}/main.ts'
17
+ `);
18
+ generateClient(vixt);
19
+ const cssTemplate = generateCss(options);
20
+ const appConfigTemplate = generateAppConfig(vixt);
21
+ const pluginsTemplate = generatePlugins(vixt);
22
+ const code = `// Generated by Vixt
23
+ // This file transform to '.vitepress/theme/index.ts'
24
+ // @ts-nocheck
25
+ ${cssTemplate}
26
+ ${appConfigTemplate}
27
+ ${pluginsTemplate}
28
+
29
+ import 'uno.css'
30
+ import { createPinia } from 'pinia'
31
+ import { createPersistedState } from 'pinia-plugin-persistedstate'
32
+ import DefaultTheme from 'vitepress/theme'
33
+
34
+ export default {
35
+ extends: DefaultTheme,
36
+ enhanceApp(ctx) {
37
+ const pinia = createPinia()
38
+ pinia.use(createPersistedState(appConfig.piniaPersistedState))
39
+ ctx.app.use(pinia)
40
+ usePlugins({ ...ctx, pinia, appConfig })
41
+ },
42
+ }
43
+ `;
44
+ fs.outputFileSync(path.resolve(buildDir, "main.ts"), code);
45
+ return code;
46
+ }
47
+
48
+ const name$1 = "vixt:app-vitepress";
49
+ const defaults$1 = {
50
+ css: []
51
+ };
52
+ const appVitepress = defineVixtModule({
53
+ meta: { name: name$1, configKey: "app" },
54
+ defaults: defaults$1,
55
+ setup(options, vixt) {
56
+ let mainTsCode;
57
+ const mainTsPath = path.resolve(".vitepress/theme/index.ts");
58
+ return {
59
+ name: name$1,
60
+ configResolved() {
61
+ mainTsCode = generateMainTs(options, vixt);
62
+ },
63
+ transform: {
64
+ order: "pre",
65
+ handler(_, id) {
66
+ if (id !== mainTsPath)
67
+ return;
68
+ return mainTsCode;
69
+ }
70
+ }
71
+ };
72
+ }
73
+ });
74
+
75
+ const name = "vixt:preset-vitepress";
76
+ const presetVitepress = defineVixtModule({
77
+ meta: { name },
78
+ async setup(_, vixt) {
79
+ const { components = [], composables = [], constants = [], utils = [], stores = [] } = resolveLayersDirs([...vixt._layers].reverse());
80
+ const { buildTypesDir, buildImportsDir } = vixt.options;
81
+ const defaultOptions = {
82
+ components: {
83
+ dts: `${buildTypesDir}/components.d.ts`,
84
+ dirs: [...components].reverse(),
85
+ directoryAsNamespace: true,
86
+ collapseSamePrefixes: true,
87
+ extensions: ["vue", "md"],
88
+ include: [/\.vue$/, /\.vue\?vue/, /\.md$/]
89
+ },
90
+ imports: {
91
+ include: [/\.[jt]sx?$/, /\.vue$/, /\.vue\?vue/, /\.md/, /\.md\?md/],
92
+ imports: ["vue", "@vueuse/core", "pinia", VueRouterAutoImports],
93
+ dts: `${buildTypesDir}/auto-imports.d.ts`,
94
+ dirs: [composables, constants, stores, utils, buildImportsDir].flat(),
95
+ vueTemplate: true
96
+ },
97
+ unocss: {},
98
+ devtools: { enabled: false }
99
+ };
100
+ const options = vixt.options = defu(vixt.options, defaultOptions);
101
+ const plugins = [
102
+ Components(options.components),
103
+ AutoImport(options.imports),
104
+ UnoCSS(options.unocss),
105
+ options.devtools?.enabled && VueDevTools(options.devtools)
106
+ ];
107
+ return plugins;
108
+ }
109
+ });
110
+
111
+ const defaults = {
112
+ modules: [appVitepress, presetVitepress]
113
+ };
114
+ const index = createVixtPlugin({ defaults });
115
+
116
+ export { appVitepress, index as default, generateMainTs, presetVitepress };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/vitepress",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.4.2",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -19,8 +19,8 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "vitepress": "^1.6.3",
22
- "@vixt/core": "0.4.0",
23
- "@vixt/vue": "0.4.0"
22
+ "@vixt/core": "0.4.2",
23
+ "@vixt/vue": "0.4.2"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "unbuild",