@vixt/core 0.3.6 → 0.4.1

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.
@@ -1,17 +1,9 @@
1
- import { f as VixtAppConfig } from '../shared/core.zLZQlpAE.mjs';
2
- import { Pinia } from 'pinia';
3
- import { App, Plugin } from 'vue';
4
- import { Router, RouteRecord } from 'vue-router';
5
- import 'c12';
6
- import 'vite';
7
-
8
1
  interface VixtApp {
9
- app: App;
10
- router: Router;
11
- routes: RouteRecord[];
12
- pinia: Pinia;
13
2
  appConfig: VixtAppConfig;
14
3
  }
4
+ interface VixtAppConfig extends Record<string, any> {
5
+ }
6
+ declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
15
7
 
16
8
  interface PluginDefinition {
17
9
  name?: string;
@@ -20,10 +12,7 @@ interface PluginDefinition {
20
12
  interface VixtPlugin {
21
13
  (this: void, vixt: VixtApp): any;
22
14
  }
23
-
24
- declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
25
-
26
- declare function defineVuePlugin<Options = any[]>(plugin: Plugin<Options>): Plugin<Options>;
27
15
  declare function defineVixtPlugin(definition: PluginDefinition | VixtPlugin): VixtPlugin;
28
16
 
29
- export { type PluginDefinition, type VixtApp, VixtAppConfig, type VixtPlugin, defineAppConfig, defineVixtPlugin, defineVuePlugin };
17
+ export { defineAppConfig, defineVixtPlugin };
18
+ export type { PluginDefinition, VixtApp, VixtAppConfig, VixtPlugin };
@@ -1,17 +1,9 @@
1
- import { f as VixtAppConfig } from '../shared/core.zLZQlpAE.js';
2
- import { Pinia } from 'pinia';
3
- import { App, Plugin } from 'vue';
4
- import { Router, RouteRecord } from 'vue-router';
5
- import 'c12';
6
- import 'vite';
7
-
8
1
  interface VixtApp {
9
- app: App;
10
- router: Router;
11
- routes: RouteRecord[];
12
- pinia: Pinia;
13
2
  appConfig: VixtAppConfig;
14
3
  }
4
+ interface VixtAppConfig extends Record<string, any> {
5
+ }
6
+ declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
15
7
 
16
8
  interface PluginDefinition {
17
9
  name?: string;
@@ -20,10 +12,7 @@ interface PluginDefinition {
20
12
  interface VixtPlugin {
21
13
  (this: void, vixt: VixtApp): any;
22
14
  }
23
-
24
- declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
25
-
26
- declare function defineVuePlugin<Options = any[]>(plugin: Plugin<Options>): Plugin<Options>;
27
15
  declare function defineVixtPlugin(definition: PluginDefinition | VixtPlugin): VixtPlugin;
28
16
 
29
- export { type PluginDefinition, type VixtApp, VixtAppConfig, type VixtPlugin, defineAppConfig, defineVixtPlugin, defineVuePlugin };
17
+ export { defineAppConfig, defineVixtPlugin };
18
+ export type { PluginDefinition, VixtApp, VixtAppConfig, VixtPlugin };
@@ -2,13 +2,10 @@ function defineAppConfig(config) {
2
2
  return config;
3
3
  }
4
4
 
5
- function defineVuePlugin(plugin) {
6
- return plugin;
7
- }
8
5
  function defineVixtPlugin(definition) {
9
6
  if (typeof definition == "function")
10
7
  return defineVixtPlugin({ setup: definition });
11
8
  return (vixt) => definition.setup?.(vixt);
12
9
  }
13
10
 
14
- export { defineAppConfig, defineVixtPlugin, defineVuePlugin };
11
+ export { defineAppConfig, defineVixtPlugin };
@@ -0,0 +1,182 @@
1
+ import * as c12 from 'c12';
2
+ import { LoadConfigOptions, ConfigLayer, ConfigLayerMeta } from 'c12';
3
+ import * as vite from 'vite';
4
+ import { PluginOption, ResolvedConfig } from 'vite';
5
+ import { RawVueCompilerOptions } from '@vue/language-core';
6
+ import { TSConfig } from 'pkg-types';
7
+ import Checker from 'vite-plugin-checker';
8
+
9
+ type Property = Record<string, string>;
10
+ interface AppHead {
11
+ meta?: Property[];
12
+ link?: Property[];
13
+ style?: Property[];
14
+ script?: Property[];
15
+ title?: Property[];
16
+ noscript?: Property[];
17
+ }
18
+ interface AppOptions {
19
+ head?: AppHead;
20
+ /**
21
+ * @default /
22
+ */
23
+ baseURL?: string;
24
+ /**
25
+ * @default 'app'
26
+ */
27
+ rootId?: string;
28
+ /**
29
+ * @default 'div'
30
+ */
31
+ rootTag?: string;
32
+ /** inject css files */
33
+ css?: string[];
34
+ /**
35
+ * @default './loading.html'
36
+ */
37
+ loadingTemplate?: string;
38
+ /**
39
+ * @default '/src/main.ts'(vue)
40
+ * @default '/src/main.tsx'(react)
41
+ * @example 'entry.ts'(means '/src/entry.ts') or './entry.ts'
42
+ */
43
+ entryFile?: string;
44
+ }
45
+
46
+ interface Vixt {
47
+ options: VixtOptions;
48
+ _layers: VixtConfigLayer[];
49
+ _modules: VixtModule[];
50
+ }
51
+ declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
52
+ declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
53
+
54
+ type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
55
+ type ModuleOptions = Record<string, any>;
56
+ interface ModuleMeta extends Record<string, any> {
57
+ name?: string;
58
+ configKey?: string;
59
+ }
60
+ interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
61
+ meta?: ModuleMeta;
62
+ defaults?: T | ((vixt: Vixt) => T);
63
+ setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
64
+ }
65
+ interface VixtModule<T extends ModuleOptions = ModuleOptions> {
66
+ (this: void, inlineOptions: T, vixt: Vixt): PluginOption;
67
+ getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
68
+ getMeta?: () => ModuleMeta;
69
+ }
70
+ declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
71
+ declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
72
+ declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
73
+ declare function applyLayerModules(layers: VixtConfigLayer[]): Promise<VixtModule[]>;
74
+
75
+ interface VixtOptions extends Record<string, any> {
76
+ /**
77
+ * @default process.cwd()
78
+ */
79
+ rootDir?: string;
80
+ /**
81
+ * @default '<rootDir>/.vixt'
82
+ */
83
+ buildDir?: string;
84
+ /**
85
+ * @default '<buildDir>/types'
86
+ */
87
+ buildTypesDir?: string;
88
+ /**
89
+ * @default '<buildDir>/layers'
90
+ */
91
+ buildLayersDir?: string;
92
+ /**
93
+ * @default '<buildDir>/imports'
94
+ */
95
+ buildImportsDir?: string;
96
+ /**
97
+ * @default '<rootDir>/src'
98
+ */
99
+ srcDir?: string;
100
+ /** modules */
101
+ modules?: VixtModule[];
102
+ /** use on configResolved */
103
+ vite?: ResolvedConfig;
104
+ meta?: VixtConfigLayerMeta;
105
+ /** layers */
106
+ extends?: string[];
107
+ app?: AppOptions;
108
+ }
109
+ interface VixtConfigLayerMeta extends ConfigLayerMeta {
110
+ /** layer name */
111
+ name?: string;
112
+ /** layer alias */
113
+ alias?: string;
114
+ }
115
+ interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
116
+ /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
117
+ cwd?: string;
118
+ }
119
+ declare function defineVixtConfig(input: VixtOptions): VixtOptions;
120
+ declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, ConfigLayerMeta>>;
121
+ declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): {
122
+ meta: VixtConfigLayerMeta;
123
+ /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
124
+ cwd?: string;
125
+ config: VixtOptions | null;
126
+ source?: string;
127
+ sourceOptions?: c12.SourceOptions<VixtOptions, VixtConfigLayerMeta> | undefined;
128
+ configFile?: string;
129
+ }[];
130
+ declare function isSamePath(a: string, b: string): boolean;
131
+ declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
132
+
133
+ /**
134
+ * Load workspace and cwd env variables by default
135
+ */
136
+ declare function loadEnv(mode?: string, envDir?: string | false, prefixes?: string | string[]): ImportMeta["env"];
137
+ /**
138
+ * find the workspace dir
139
+ */
140
+ declare function findUpWorkspaceDir(): string | undefined;
141
+ /**
142
+ * Load workspace env variables
143
+ */
144
+ declare function loadWorkspaceEnv(mode?: string, prefixes?: string | string[]): Record<string, string>;
145
+
146
+ declare const config: VixtModule<ModuleOptions>;
147
+
148
+ declare module '@vixt/core' {
149
+ interface VixtOptions {
150
+ typescript?: TypescriptOptions;
151
+ }
152
+ }
153
+ interface TypescriptOptions {
154
+ references?: (string | {
155
+ path?: string;
156
+ content?: string;
157
+ })[];
158
+ tsConfig?: TSConfig & {
159
+ vueCompilerOptions?: RawVueCompilerOptions;
160
+ };
161
+ /** https://github.com/fi3ework/vite-plugin-checker */
162
+ typeCheck?: Parameters<typeof Checker>[0];
163
+ /**
164
+ * Generate a `*.vue` shim
165
+ * @default false
166
+ */
167
+ shim?: boolean;
168
+ }
169
+ declare const typescript: VixtModule<TypescriptOptions>;
170
+
171
+ declare function generateAppConfig(vixt: Vixt): string;
172
+
173
+ declare function generateClient(vixt: Vixt): void;
174
+
175
+ declare function generateCss(options: AppOptions): string;
176
+
177
+ declare function generateIndexHtml(options: AppOptions, vixt: Vixt): string;
178
+
179
+ declare function generatePlugins(vixt: Vixt): string;
180
+
181
+ export { applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, generateAppConfig, generateClient, generateCss, generateIndexHtml, generatePlugins, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
182
+ export type { AppHead, AppOptions, ModuleDefinition, ModuleMeta, ModuleOptions, PluginOptions, TypescriptOptions, Vixt, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions };
@@ -0,0 +1,182 @@
1
+ import * as c12 from 'c12';
2
+ import { LoadConfigOptions, ConfigLayer, ConfigLayerMeta } from 'c12';
3
+ import * as vite from 'vite';
4
+ import { PluginOption, ResolvedConfig } from 'vite';
5
+ import { RawVueCompilerOptions } from '@vue/language-core';
6
+ import { TSConfig } from 'pkg-types';
7
+ import Checker from 'vite-plugin-checker';
8
+
9
+ type Property = Record<string, string>;
10
+ interface AppHead {
11
+ meta?: Property[];
12
+ link?: Property[];
13
+ style?: Property[];
14
+ script?: Property[];
15
+ title?: Property[];
16
+ noscript?: Property[];
17
+ }
18
+ interface AppOptions {
19
+ head?: AppHead;
20
+ /**
21
+ * @default /
22
+ */
23
+ baseURL?: string;
24
+ /**
25
+ * @default 'app'
26
+ */
27
+ rootId?: string;
28
+ /**
29
+ * @default 'div'
30
+ */
31
+ rootTag?: string;
32
+ /** inject css files */
33
+ css?: string[];
34
+ /**
35
+ * @default './loading.html'
36
+ */
37
+ loadingTemplate?: string;
38
+ /**
39
+ * @default '/src/main.ts'(vue)
40
+ * @default '/src/main.tsx'(react)
41
+ * @example 'entry.ts'(means '/src/entry.ts') or './entry.ts'
42
+ */
43
+ entryFile?: string;
44
+ }
45
+
46
+ interface Vixt {
47
+ options: VixtOptions;
48
+ _layers: VixtConfigLayer[];
49
+ _modules: VixtModule[];
50
+ }
51
+ declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
52
+ declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
53
+
54
+ type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
55
+ type ModuleOptions = Record<string, any>;
56
+ interface ModuleMeta extends Record<string, any> {
57
+ name?: string;
58
+ configKey?: string;
59
+ }
60
+ interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
61
+ meta?: ModuleMeta;
62
+ defaults?: T | ((vixt: Vixt) => T);
63
+ setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
64
+ }
65
+ interface VixtModule<T extends ModuleOptions = ModuleOptions> {
66
+ (this: void, inlineOptions: T, vixt: Vixt): PluginOption;
67
+ getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
68
+ getMeta?: () => ModuleMeta;
69
+ }
70
+ declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
71
+ declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
72
+ declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
73
+ declare function applyLayerModules(layers: VixtConfigLayer[]): Promise<VixtModule[]>;
74
+
75
+ interface VixtOptions extends Record<string, any> {
76
+ /**
77
+ * @default process.cwd()
78
+ */
79
+ rootDir?: string;
80
+ /**
81
+ * @default '<rootDir>/.vixt'
82
+ */
83
+ buildDir?: string;
84
+ /**
85
+ * @default '<buildDir>/types'
86
+ */
87
+ buildTypesDir?: string;
88
+ /**
89
+ * @default '<buildDir>/layers'
90
+ */
91
+ buildLayersDir?: string;
92
+ /**
93
+ * @default '<buildDir>/imports'
94
+ */
95
+ buildImportsDir?: string;
96
+ /**
97
+ * @default '<rootDir>/src'
98
+ */
99
+ srcDir?: string;
100
+ /** modules */
101
+ modules?: VixtModule[];
102
+ /** use on configResolved */
103
+ vite?: ResolvedConfig;
104
+ meta?: VixtConfigLayerMeta;
105
+ /** layers */
106
+ extends?: string[];
107
+ app?: AppOptions;
108
+ }
109
+ interface VixtConfigLayerMeta extends ConfigLayerMeta {
110
+ /** layer name */
111
+ name?: string;
112
+ /** layer alias */
113
+ alias?: string;
114
+ }
115
+ interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
116
+ /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
117
+ cwd?: string;
118
+ }
119
+ declare function defineVixtConfig(input: VixtOptions): VixtOptions;
120
+ declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, ConfigLayerMeta>>;
121
+ declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): {
122
+ meta: VixtConfigLayerMeta;
123
+ /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
124
+ cwd?: string;
125
+ config: VixtOptions | null;
126
+ source?: string;
127
+ sourceOptions?: c12.SourceOptions<VixtOptions, VixtConfigLayerMeta> | undefined;
128
+ configFile?: string;
129
+ }[];
130
+ declare function isSamePath(a: string, b: string): boolean;
131
+ declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
132
+
133
+ /**
134
+ * Load workspace and cwd env variables by default
135
+ */
136
+ declare function loadEnv(mode?: string, envDir?: string | false, prefixes?: string | string[]): ImportMeta["env"];
137
+ /**
138
+ * find the workspace dir
139
+ */
140
+ declare function findUpWorkspaceDir(): string | undefined;
141
+ /**
142
+ * Load workspace env variables
143
+ */
144
+ declare function loadWorkspaceEnv(mode?: string, prefixes?: string | string[]): Record<string, string>;
145
+
146
+ declare const config: VixtModule<ModuleOptions>;
147
+
148
+ declare module '@vixt/core' {
149
+ interface VixtOptions {
150
+ typescript?: TypescriptOptions;
151
+ }
152
+ }
153
+ interface TypescriptOptions {
154
+ references?: (string | {
155
+ path?: string;
156
+ content?: string;
157
+ })[];
158
+ tsConfig?: TSConfig & {
159
+ vueCompilerOptions?: RawVueCompilerOptions;
160
+ };
161
+ /** https://github.com/fi3ework/vite-plugin-checker */
162
+ typeCheck?: Parameters<typeof Checker>[0];
163
+ /**
164
+ * Generate a `*.vue` shim
165
+ * @default false
166
+ */
167
+ shim?: boolean;
168
+ }
169
+ declare const typescript: VixtModule<TypescriptOptions>;
170
+
171
+ declare function generateAppConfig(vixt: Vixt): string;
172
+
173
+ declare function generateClient(vixt: Vixt): void;
174
+
175
+ declare function generateCss(options: AppOptions): string;
176
+
177
+ declare function generateIndexHtml(options: AppOptions, vixt: Vixt): string;
178
+
179
+ declare function generatePlugins(vixt: Vixt): string;
180
+
181
+ export { applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, generateAppConfig, generateClient, generateCss, generateIndexHtml, generatePlugins, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
182
+ export type { AppHead, AppOptions, ModuleDefinition, ModuleMeta, ModuleOptions, PluginOptions, TypescriptOptions, Vixt, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, VixtOptions };
@@ -124,7 +124,7 @@ function installModule(module, inlineOptions, vixt) {
124
124
  async function applyLayerModules(layers) {
125
125
  const { modules: modulesDirs = [] } = resolveLayersDirs(layers);
126
126
  const modules = [];
127
- for (const m of modulesDirs) {
127
+ for (const m of modulesDirs.reverse()) {
128
128
  if (fs.existsSync(m)) {
129
129
  const files = fs.readdirSync(m);
130
130
  for (const f of files) {
@@ -238,18 +238,6 @@ declare module '*.vue' {
238
238
  const codePath = path.resolve(buildTypesDir, "vue-shim.d.ts");
239
239
  fs.outputFileSync(codePath, code);
240
240
  }
241
- function genarateGlobalComponents(options, vixt) {
242
- const { buildTypesDir } = vixt.options;
243
- const codePath = path.resolve(buildTypesDir, "global-components.d.ts");
244
- const code = `
245
- import type { GlobalComponents as _GlobalComponents } from '@vue/runtime-core'
246
-
247
- declare module 'vue'{
248
- interface GlobalComponents extends _GlobalComponents {}
249
- }
250
- `;
251
- fs.outputFileSync(codePath, code);
252
- }
253
241
  function generateEnvDts(env, vixt) {
254
242
  const { buildTypesDir } = vixt.options;
255
243
  const codePath = path.resolve(buildTypesDir, "vite-env.d.ts");
@@ -306,7 +294,6 @@ const typescript = defineVixtModule({
306
294
  generateTsConfig(options, vixt);
307
295
  generateVixtDts(options, vixt);
308
296
  genarateShim(options, vixt);
309
- genarateGlobalComponents(options, vixt);
310
297
  generateEnvDts(config.env, vixt);
311
298
  }
312
299
  },
@@ -315,6 +302,123 @@ const typescript = defineVixtModule({
315
302
  }
316
303
  });
317
304
 
305
+ function generateAppConfig(vixt) {
306
+ const { buildImportsDir } = vixt.options;
307
+ let appConfigsImportTemplate = "";
308
+ let appConfigsMergeTemplate = "";
309
+ let i = 0;
310
+ for (const layer of vixt._layers) {
311
+ const appConfigPath = path.resolve(layer.config.srcDir, "app.config.ts");
312
+ if (fs.existsSync(appConfigPath)) {
313
+ const appConfigName = `__app_config_${i}`;
314
+ appConfigsImportTemplate += `import ${appConfigName} from '${appConfigPath}'
315
+ `;
316
+ appConfigsMergeTemplate += `${appConfigName}, `;
317
+ i++;
318
+ }
319
+ }
320
+ const globalAppConfigKey = "__VIXT_APP_CONFIG";
321
+ const appConfigTemplate = `
322
+ import { defu } from 'defu'
323
+ ${appConfigsImportTemplate}
324
+ const appConfig = defu(${appConfigsMergeTemplate}{})
325
+ globalThis.${globalAppConfigKey} = appConfig
326
+ `;
327
+ fs.outputFileSync(path.resolve(buildImportsDir, `app.config.ts`), `// Generated by Vixt
328
+ // @ts-nocheck
329
+ import type { VixtAppConfig } from '@vixt/core/client'
330
+
331
+ export const useAppConfig = () => globalThis.${globalAppConfigKey} as VixtAppConfig
332
+ `);
333
+ return appConfigTemplate;
334
+ }
335
+
336
+ function generateClient(vixt) {
337
+ const { buildImportsDir } = vixt.options;
338
+ fs.outputFileSync(
339
+ path.resolve(buildImportsDir, `client.ts`),
340
+ `// Generated by Vixt
341
+ export { defineAppConfig, defineVixtPlugin } from '@vixt/core/client'
342
+ `
343
+ );
344
+ }
345
+
346
+ function generateCss(options) {
347
+ const cssTemplate = options?.css?.map((css) => `import '${css}'`).join("\n") ?? "";
348
+ return cssTemplate;
349
+ }
350
+
351
+ function resolveHeadTag(tag, attrs) {
352
+ const attrsStr = Object.entries(attrs).filter(([k]) => k !== "children").map(([k, v]) => `${k}="${v}"`).join(" ");
353
+ return attrs?.children ? `<${tag} ${attrsStr}>${attrs.children}</${tag}>` : `<${tag} ${attrsStr} />`;
354
+ }
355
+ function generateIndexHtml(options, vixt) {
356
+ const { buildDir, rootDir, srcDir } = vixt.options;
357
+ const indexHtmlPath = path.resolve(rootDir, "index.html");
358
+ if (!fs.existsSync(indexHtmlPath))
359
+ fs.outputFileSync(indexHtmlPath, `<!-- Generated by Vixt -->
360
+ <!-- This file transform from '${path.basename(buildDir)}/index.html' -->
361
+ `);
362
+ const { head = {}, rootTag, rootId, entryFile } = options;
363
+ const headTemplate = Object.entries(head).filter(([k]) => k !== "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
364
+ const noscriptTemplate = Object.entries(head).filter(([k]) => k === "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
365
+ let { loadingTemplate = "" } = options;
366
+ if (!loadingTemplate) {
367
+ for (const layer of vixt._layers) {
368
+ const loadingTemplatePath = path.resolve(layer.cwd, "loading.html");
369
+ if (fs.existsSync(loadingTemplatePath)) {
370
+ loadingTemplate = fs.readFileSync(loadingTemplatePath, "utf-8");
371
+ break;
372
+ }
373
+ }
374
+ }
375
+ const entryFilePath = /&\.|\//.test(entryFile ?? "") ? entryFile : `${srcDir.replace(rootDir, "")}/${entryFile}`;
376
+ const code = `<!DOCTYPE html>
377
+ <html>
378
+ <head>
379
+ ${headTemplate}
380
+ </head>
381
+ <body>
382
+ <${rootTag} id="${rootId}">
383
+ ${loadingTemplate}
384
+ </${rootTag}>
385
+ <script type="module" src="${entryFilePath}"><\/script>
386
+ ${noscriptTemplate}
387
+ </body>
388
+ </html>
389
+ `;
390
+ fs.outputFileSync(path.resolve(buildDir, "index.html"), code);
391
+ return code;
392
+ }
393
+
394
+ function generatePlugins(vixt) {
395
+ const { plugins: pluginsDirs = [] } = resolveLayersDirs(vixt._layers);
396
+ let pluginsImportTemplate = "";
397
+ let pluginsMergeTemplate = "";
398
+ let i = 0;
399
+ for (const pluginsDir of pluginsDirs.reverse()) {
400
+ const files = fs.existsSync(pluginsDir) ? fs.readdirSync(pluginsDir) : [];
401
+ for (const f of files) {
402
+ const p = path.resolve(pluginsDir, f);
403
+ const pluginName = `__plugin_${i}`;
404
+ pluginsImportTemplate += `import ${pluginName} from '${p}'
405
+ `;
406
+ pluginsMergeTemplate += `${pluginName}, `;
407
+ i++;
408
+ }
409
+ }
410
+ const pluginsTemplate = `
411
+ ${pluginsImportTemplate}
412
+ const plugins = [${pluginsMergeTemplate}]
413
+ function usePlugins(options) {
414
+ for (const plugin of plugins) {
415
+ typeof plugin === 'function' && plugin(options)
416
+ }
417
+ }
418
+ `;
419
+ return pluginsTemplate;
420
+ }
421
+
318
422
  async function loadVixt(opts) {
319
423
  const result = await loadVixtConfig(defu(opts, {
320
424
  defaults: {
@@ -343,4 +447,4 @@ function createVixtPlugin(loadOptions) {
343
447
  });
344
448
  }
345
449
 
346
- export { applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
450
+ export { applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, generateAppConfig, generateClient, generateCss, generateIndexHtml, generatePlugins, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
package/package.json CHANGED
@@ -1,33 +1,30 @@
1
1
  {
2
2
  "name": "@vixt/core",
3
3
  "type": "module",
4
- "version": "0.3.6",
4
+ "version": "0.4.1",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
8
8
  "repository": "https://github.com/SoulLyoko/vixt.git",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs"
11
+ "types": "./dist/node/index.d.ts",
12
+ "import": "./dist/node/index.mjs"
13
13
  },
14
14
  "./client": {
15
15
  "types": "./dist/client/index.d.ts",
16
16
  "import": "./dist/client/index.mjs"
17
- },
18
- "./client/App.vue": {
19
- "import": "./dist/client/App.vue"
20
17
  }
21
18
  },
22
- "main": "dist/index.mjs",
23
- "types": "dist/index.d.ts",
19
+ "main": "./dist/node/index.mjs",
20
+ "types": "./dist/node/index.d.ts",
24
21
  "files": [
25
22
  "dist"
26
23
  ],
27
24
  "dependencies": {
28
25
  "@types/fs-extra": "^11.0.4",
29
26
  "@vue/tsconfig": "^0.7.0",
30
- "c12": "^3.0.3",
27
+ "c12": "^3.0.4",
31
28
  "cac": "^6.7.14",
32
29
  "defu": "^6.1.4",
33
30
  "find-up": "^7.0.0",
@@ -37,10 +34,10 @@
37
34
  "pkg-types": "^2.1.0",
38
35
  "tsx": "^4.19.4",
39
36
  "vite": "^6.3.5",
40
- "vite-plugin-checker": "^0.9.3",
41
- "vue-tsc": "^2.2.10"
37
+ "vite-plugin-checker": "^0.9.3"
42
38
  },
43
39
  "scripts": {
44
- "build": "unbuild"
40
+ "build": "unbuild",
41
+ "dev": "unbuild --stub"
45
42
  }
46
43
  }
@@ -1,3 +0,0 @@
1
- <template>
2
- <RouterView />
3
- </template>
package/dist/index.d.mts DELETED
@@ -1,70 +0,0 @@
1
- import { V as VixtOptions, a as VixtConfigLayer, b as VixtConfigLayerMeta, M as ModuleOptions, c as ModuleDefinition, d as VixtModule, e as Vixt } from './shared/core.zLZQlpAE.mjs';
2
- export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig } from './shared/core.zLZQlpAE.mjs';
3
- import * as c12 from 'c12';
4
- import { LoadConfigOptions } from 'c12';
5
- import { RawVueCompilerOptions } from '@vue/language-core';
6
- import { TSConfig } from 'pkg-types';
7
- import Checker from 'vite-plugin-checker';
8
- import * as vite from 'vite';
9
- import { PluginOption } from 'vite';
10
-
11
- declare function defineVixtConfig(input: VixtOptions): VixtOptions;
12
- declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, c12.ConfigLayerMeta>>;
13
- declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): {
14
- meta: VixtConfigLayerMeta;
15
- cwd?: string;
16
- config: VixtOptions | null;
17
- source?: string;
18
- sourceOptions?: c12.SourceOptions<VixtOptions, VixtConfigLayerMeta> | undefined;
19
- configFile?: string;
20
- }[];
21
- declare function isSamePath(a: string, b: string): boolean;
22
- declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
23
-
24
- /**
25
- * Load workspace and cwd env variables by default
26
- */
27
- declare function loadEnv(mode?: string, envDir?: string | false, prefixes?: string | string[]): ImportMeta["env"];
28
- /**
29
- * find the workspace dir
30
- */
31
- declare function findUpWorkspaceDir(): string | undefined;
32
- /**
33
- * Load workspace env variables
34
- */
35
- declare function loadWorkspaceEnv(mode?: string, prefixes?: string | string[]): Record<string, string>;
36
-
37
- declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
38
- declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
39
- declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
40
- declare function applyLayerModules(layers: VixtConfigLayer[]): Promise<VixtModule[]>;
41
-
42
- declare const config: VixtModule<ModuleOptions>;
43
-
44
- declare module '@vixt/core' {
45
- interface VixtOptions {
46
- typescript?: TypescriptOptions;
47
- }
48
- }
49
- interface TypescriptOptions {
50
- references?: (string | {
51
- path?: string;
52
- content?: string;
53
- })[];
54
- tsConfig?: TSConfig & {
55
- vueCompilerOptions?: RawVueCompilerOptions;
56
- };
57
- /** https://github.com/fi3ework/vite-plugin-checker */
58
- typeCheck?: Parameters<typeof Checker>[0];
59
- /**
60
- * Generate a `*.vue` shim
61
- * @default false
62
- */
63
- shim?: boolean;
64
- }
65
- declare const typescript: VixtModule<TypescriptOptions>;
66
-
67
- declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
68
- declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
69
-
70
- export { ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, type VixtOptions, applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
package/dist/index.d.ts DELETED
@@ -1,70 +0,0 @@
1
- import { V as VixtOptions, a as VixtConfigLayer, b as VixtConfigLayerMeta, M as ModuleOptions, c as ModuleDefinition, d as VixtModule, e as Vixt } from './shared/core.zLZQlpAE.js';
2
- export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig } from './shared/core.zLZQlpAE.js';
3
- import * as c12 from 'c12';
4
- import { LoadConfigOptions } from 'c12';
5
- import { RawVueCompilerOptions } from '@vue/language-core';
6
- import { TSConfig } from 'pkg-types';
7
- import Checker from 'vite-plugin-checker';
8
- import * as vite from 'vite';
9
- import { PluginOption } from 'vite';
10
-
11
- declare function defineVixtConfig(input: VixtOptions): VixtOptions;
12
- declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, c12.ConfigLayerMeta>>;
13
- declare function applyLayers(layers: VixtConfigLayer[], config: VixtOptions): {
14
- meta: VixtConfigLayerMeta;
15
- cwd?: string;
16
- config: VixtOptions | null;
17
- source?: string;
18
- sourceOptions?: c12.SourceOptions<VixtOptions, VixtConfigLayerMeta> | undefined;
19
- configFile?: string;
20
- }[];
21
- declare function isSamePath(a: string, b: string): boolean;
22
- declare function resolveLayersDirs(layers?: VixtConfigLayer[]): Record<string, string[] | undefined>;
23
-
24
- /**
25
- * Load workspace and cwd env variables by default
26
- */
27
- declare function loadEnv(mode?: string, envDir?: string | false, prefixes?: string | string[]): ImportMeta["env"];
28
- /**
29
- * find the workspace dir
30
- */
31
- declare function findUpWorkspaceDir(): string | undefined;
32
- /**
33
- * Load workspace env variables
34
- */
35
- declare function loadWorkspaceEnv(mode?: string, prefixes?: string | string[]): Record<string, string>;
36
-
37
- declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
38
- declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
39
- declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
40
- declare function applyLayerModules(layers: VixtConfigLayer[]): Promise<VixtModule[]>;
41
-
42
- declare const config: VixtModule<ModuleOptions>;
43
-
44
- declare module '@vixt/core' {
45
- interface VixtOptions {
46
- typescript?: TypescriptOptions;
47
- }
48
- }
49
- interface TypescriptOptions {
50
- references?: (string | {
51
- path?: string;
52
- content?: string;
53
- })[];
54
- tsConfig?: TSConfig & {
55
- vueCompilerOptions?: RawVueCompilerOptions;
56
- };
57
- /** https://github.com/fi3ework/vite-plugin-checker */
58
- typeCheck?: Parameters<typeof Checker>[0];
59
- /**
60
- * Generate a `*.vue` shim
61
- * @default false
62
- */
63
- shim?: boolean;
64
- }
65
- declare const typescript: VixtModule<TypescriptOptions>;
66
-
67
- declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
68
- declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
69
-
70
- export { ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtConfigLayerMeta, VixtModule, type VixtOptions, applyLayerModules, applyLayers, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, findUpWorkspaceDir, installModule, isSamePath, loadEnv, loadVixt, loadVixtConfig, loadWorkspaceEnv, resolveLayersDirs, typescript };
@@ -1,73 +0,0 @@
1
- import { ConfigLayer, ConfigLayerMeta } from 'c12';
2
- import { PluginOption, ResolvedConfig } from 'vite';
3
-
4
- interface Vixt {
5
- options: VixtOptions;
6
- _layers: VixtConfigLayer[];
7
- _modules: VixtModule[];
8
- }
9
-
10
- type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
11
- type ModuleOptions = Record<string, any>;
12
- interface ModuleMeta extends Record<string, any> {
13
- name?: string;
14
- configKey?: string;
15
- }
16
- interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
17
- meta?: ModuleMeta;
18
- defaults?: T | ((vixt: Vixt) => T);
19
- setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
20
- }
21
- interface VixtModule<T extends ModuleOptions = ModuleOptions> {
22
- (this: void, inlineOptions: T, vixt: Vixt): PluginOption;
23
- getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
24
- getMeta?: () => ModuleMeta;
25
- }
26
-
27
- interface VixtOptions extends Record<string, any> {
28
- /**
29
- * @default process.cwd()
30
- */
31
- rootDir?: string;
32
- /**
33
- * @default '<rootDir>/.vixt'
34
- */
35
- buildDir?: string;
36
- /**
37
- * @default '<buildDir>/types'
38
- */
39
- buildTypesDir?: string;
40
- /**
41
- * @default '<buildDir>/layers'
42
- */
43
- buildLayersDir?: string;
44
- /**
45
- * @default '<buildDir>/imports'
46
- */
47
- buildImportsDir?: string;
48
- /**
49
- * @default '<rootDir>/src'
50
- */
51
- srcDir?: string;
52
- /** modules */
53
- modules?: VixtModule[];
54
- /** use on configResolved */
55
- vite?: ResolvedConfig;
56
- meta?: VixtConfigLayerMeta;
57
- /** layers */
58
- extends?: string[];
59
- }
60
- interface VixtConfigLayerMeta extends ConfigLayerMeta {
61
- /** layer name */
62
- name?: string;
63
- /** layer alias */
64
- alias?: string;
65
- }
66
- interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
67
- /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
68
- cwd?: string;
69
- }
70
- interface VixtAppConfig extends Record<string, any> {
71
- }
72
-
73
- export type { ModuleOptions as M, PluginOptions as P, VixtOptions as V, VixtConfigLayer as a, VixtConfigLayerMeta as b, ModuleDefinition as c, VixtModule as d, Vixt as e, VixtAppConfig as f, ModuleMeta as g };
@@ -1,73 +0,0 @@
1
- import { ConfigLayer, ConfigLayerMeta } from 'c12';
2
- import { PluginOption, ResolvedConfig } from 'vite';
3
-
4
- interface Vixt {
5
- options: VixtOptions;
6
- _layers: VixtConfigLayer[];
7
- _modules: VixtModule[];
8
- }
9
-
10
- type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
11
- type ModuleOptions = Record<string, any>;
12
- interface ModuleMeta extends Record<string, any> {
13
- name?: string;
14
- configKey?: string;
15
- }
16
- interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
17
- meta?: ModuleMeta;
18
- defaults?: T | ((vixt: Vixt) => T);
19
- setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption | void;
20
- }
21
- interface VixtModule<T extends ModuleOptions = ModuleOptions> {
22
- (this: void, inlineOptions: T, vixt: Vixt): PluginOption;
23
- getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
24
- getMeta?: () => ModuleMeta;
25
- }
26
-
27
- interface VixtOptions extends Record<string, any> {
28
- /**
29
- * @default process.cwd()
30
- */
31
- rootDir?: string;
32
- /**
33
- * @default '<rootDir>/.vixt'
34
- */
35
- buildDir?: string;
36
- /**
37
- * @default '<buildDir>/types'
38
- */
39
- buildTypesDir?: string;
40
- /**
41
- * @default '<buildDir>/layers'
42
- */
43
- buildLayersDir?: string;
44
- /**
45
- * @default '<buildDir>/imports'
46
- */
47
- buildImportsDir?: string;
48
- /**
49
- * @default '<rootDir>/src'
50
- */
51
- srcDir?: string;
52
- /** modules */
53
- modules?: VixtModule[];
54
- /** use on configResolved */
55
- vite?: ResolvedConfig;
56
- meta?: VixtConfigLayerMeta;
57
- /** layers */
58
- extends?: string[];
59
- }
60
- interface VixtConfigLayerMeta extends ConfigLayerMeta {
61
- /** layer name */
62
- name?: string;
63
- /** layer alias */
64
- alias?: string;
65
- }
66
- interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
67
- /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
68
- cwd?: string;
69
- }
70
- interface VixtAppConfig extends Record<string, any> {
71
- }
72
-
73
- export type { ModuleOptions as M, PluginOptions as P, VixtOptions as V, VixtConfigLayer as a, VixtConfigLayerMeta as b, ModuleDefinition as c, VixtModule as d, Vixt as e, VixtAppConfig as f, ModuleMeta as g };