@vixt/core 0.0.15 → 0.1.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.
@@ -0,0 +1,29 @@
1
+ import { App, Plugin } from 'vue';
2
+ import { Router, RouteRecord } from 'vue-router';
3
+ import { Pinia } from 'pinia';
4
+ import { f as VixtAppConfig } from '../shared/core.66c5bb58.mjs';
5
+ import 'vite';
6
+ import 'c12';
7
+
8
+ interface VixtApp {
9
+ app: App;
10
+ router: Router;
11
+ routes: RouteRecord[];
12
+ pinia: Pinia;
13
+ appConfig: VixtAppConfig;
14
+ }
15
+
16
+ interface PluginDefinition {
17
+ name?: string;
18
+ setup?: (this: void, vixt: VixtApp) => any;
19
+ }
20
+ interface VixtPlugin {
21
+ (this: void, vixt: VixtApp): any;
22
+ }
23
+
24
+ declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
25
+
26
+ declare function defineVuePlugin<Options = any[]>(plugin: Plugin<Options>): Plugin<Options>;
27
+ declare function defineVixtPlugin(definition: PluginDefinition | VixtPlugin): VixtPlugin;
28
+
29
+ export { type PluginDefinition, type VixtApp, VixtAppConfig, type VixtPlugin, defineAppConfig, defineVixtPlugin, defineVuePlugin };
@@ -0,0 +1,29 @@
1
+ import { App, Plugin } from 'vue';
2
+ import { Router, RouteRecord } from 'vue-router';
3
+ import { Pinia } from 'pinia';
4
+ import { f as VixtAppConfig } from '../shared/core.66c5bb58.js';
5
+ import 'vite';
6
+ import 'c12';
7
+
8
+ interface VixtApp {
9
+ app: App;
10
+ router: Router;
11
+ routes: RouteRecord[];
12
+ pinia: Pinia;
13
+ appConfig: VixtAppConfig;
14
+ }
15
+
16
+ interface PluginDefinition {
17
+ name?: string;
18
+ setup?: (this: void, vixt: VixtApp) => any;
19
+ }
20
+ interface VixtPlugin {
21
+ (this: void, vixt: VixtApp): any;
22
+ }
23
+
24
+ declare function defineAppConfig(config: VixtAppConfig): VixtAppConfig;
25
+
26
+ declare function defineVuePlugin<Options = any[]>(plugin: Plugin<Options>): Plugin<Options>;
27
+ declare function defineVixtPlugin(definition: PluginDefinition | VixtPlugin): VixtPlugin;
28
+
29
+ export { type PluginDefinition, type VixtApp, VixtAppConfig, type VixtPlugin, defineAppConfig, defineVixtPlugin, defineVuePlugin };
@@ -0,0 +1,14 @@
1
+ function defineAppConfig(config) {
2
+ return config;
3
+ }
4
+
5
+ function defineVuePlugin(plugin) {
6
+ return plugin;
7
+ }
8
+ function defineVixtPlugin(definition) {
9
+ if (typeof definition == "function")
10
+ return defineVixtPlugin({ setup: definition });
11
+ return (vixt) => definition.setup?.(vixt);
12
+ }
13
+
14
+ export { defineAppConfig, defineVixtPlugin, defineVuePlugin };
package/dist/index.d.mts CHANGED
@@ -1,66 +1,14 @@
1
- import * as vite from 'vite';
2
- import { PluginOption, ResolvedConfig, TransformResult } from 'vite';
3
- import * as c12 from 'c12';
4
- import { ConfigLayer, LoadConfigOptions } from 'c12';
1
+ import { V as VixtModule, M as ModuleOptions, a as Vixt, b as VixtOptions, c as VixtConfigLayer, d as ModuleDefinition } from './shared/core.66c5bb58.mjs';
2
+ export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig, e as VixtConfigLayerMeta } from './shared/core.66c5bb58.mjs';
5
3
  import { TSConfig } from 'pkg-types';
6
4
  import Checker from 'vite-plugin-checker';
5
+ import * as c12 from 'c12';
6
+ import { LoadConfigOptions } from 'c12';
7
+ import * as vite from 'vite';
8
+ import { PluginOption } from 'vite';
7
9
 
8
10
  declare const alias: VixtModule<ModuleOptions>;
9
11
 
10
- interface Vixt {
11
- options: VixtOptions;
12
- _layers: VixtConfigLayer[];
13
- _modules: VixtModule[];
14
- }
15
-
16
- type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
17
- type ModuleOptions = Record<string, any>;
18
- interface ModuleMeta extends Record<string, any> {
19
- name?: string;
20
- configKey?: string;
21
- }
22
- interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
23
- meta?: ModuleMeta;
24
- defaults?: T | ((vixt: Vixt) => T);
25
- setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption;
26
- }
27
- interface VixtModule<T extends ModuleOptions = ModuleOptions> {
28
- (this: void, inlineOptions: T, vixt: Vixt): PluginOption;
29
- getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
30
- getMeta?: () => ModuleMeta;
31
- }
32
-
33
- interface VixtOptions extends Record<string, any> {
34
- /**
35
- * @default process.cwd()
36
- */
37
- rootDir?: string;
38
- /**
39
- * @default '.vixt'
40
- */
41
- buildDir?: string;
42
- /**
43
- * @default '.vixt/types'
44
- */
45
- buildTypesDir?: string;
46
- /**
47
- * @default '.vixt/layers'
48
- */
49
- buildLayersDir?: string;
50
- /** layers */
51
- extends?: string[];
52
- /** modules */
53
- modules?: VixtModule[];
54
- /** use on configResolved */
55
- vite?: ResolvedConfig;
56
- }
57
- interface VixtConfigLayer extends ConfigLayer<VixtOptions> {
58
- /** layer path before copy */
59
- relatedCwd?: string;
60
- /** layer path after copy to buildLayersDir */
61
- cwd?: string;
62
- }
63
-
64
12
  declare module '@vixt/core' {
65
13
  interface VixtOptions {
66
14
  app?: AppOptions;
@@ -89,11 +37,10 @@ interface AppOptions {
89
37
  * @default 'div'
90
38
  */
91
39
  rootTag?: string;
92
- /**
93
- * @default '<buildDir>/main.ts'
94
- */
40
+ /** content of main.ts */
95
41
  main?: string;
96
- transformMain?: (vixt: Vixt) => Promise<TransformResult | string | null | void> | TransformResult | string | null | void;
42
+ /** transform main.ts */
43
+ transformMain?: (code: string, vixt: Vixt) => string | undefined;
97
44
  css?: string[];
98
45
  /**
99
46
  * @default './loading.html'
@@ -136,4 +83,4 @@ declare function applyLayerModules(layers?: VixtConfigLayer[]): Promise<VixtModu
136
83
  declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
137
84
  declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
138
85
 
139
- export { type AppHead, type AppOptions, type ModuleDefinition, type ModuleMeta, type ModuleOptions, type PluginOptions, type TypescriptOptions, type Vixt, type VixtConfigLayer, type VixtModule, type VixtOptions, alias, app, applyLayerModules, buildDir, buildLayersDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, typescript };
86
+ export { type AppHead, type AppOptions, ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtModule, type VixtOptions, alias, app, applyLayerModules, buildDir, buildLayersDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, typescript };
package/dist/index.d.ts CHANGED
@@ -1,66 +1,14 @@
1
- import * as vite from 'vite';
2
- import { PluginOption, ResolvedConfig, TransformResult } from 'vite';
3
- import * as c12 from 'c12';
4
- import { ConfigLayer, LoadConfigOptions } from 'c12';
1
+ import { V as VixtModule, M as ModuleOptions, a as Vixt, b as VixtOptions, c as VixtConfigLayer, d as ModuleDefinition } from './shared/core.66c5bb58.js';
2
+ export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig, e as VixtConfigLayerMeta } from './shared/core.66c5bb58.js';
5
3
  import { TSConfig } from 'pkg-types';
6
4
  import Checker from 'vite-plugin-checker';
5
+ import * as c12 from 'c12';
6
+ import { LoadConfigOptions } from 'c12';
7
+ import * as vite from 'vite';
8
+ import { PluginOption } from 'vite';
7
9
 
8
10
  declare const alias: VixtModule<ModuleOptions>;
9
11
 
10
- interface Vixt {
11
- options: VixtOptions;
12
- _layers: VixtConfigLayer[];
13
- _modules: VixtModule[];
14
- }
15
-
16
- type PluginOptions<Options = any> = (Options extends (...args: any[]) => any ? Parameters<Options>[0] : Options);
17
- type ModuleOptions = Record<string, any>;
18
- interface ModuleMeta extends Record<string, any> {
19
- name?: string;
20
- configKey?: string;
21
- }
22
- interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
23
- meta?: ModuleMeta;
24
- defaults?: T | ((vixt: Vixt) => T);
25
- setup?: (this: void, resolvedOptions: T, vixt: Vixt) => PluginOption;
26
- }
27
- interface VixtModule<T extends ModuleOptions = ModuleOptions> {
28
- (this: void, inlineOptions: T, vixt: Vixt): PluginOption;
29
- getOptions?: (inlineOptions?: T, Vixt?: Vixt) => T;
30
- getMeta?: () => ModuleMeta;
31
- }
32
-
33
- interface VixtOptions extends Record<string, any> {
34
- /**
35
- * @default process.cwd()
36
- */
37
- rootDir?: string;
38
- /**
39
- * @default '.vixt'
40
- */
41
- buildDir?: string;
42
- /**
43
- * @default '.vixt/types'
44
- */
45
- buildTypesDir?: string;
46
- /**
47
- * @default '.vixt/layers'
48
- */
49
- buildLayersDir?: string;
50
- /** layers */
51
- extends?: string[];
52
- /** modules */
53
- modules?: VixtModule[];
54
- /** use on configResolved */
55
- vite?: ResolvedConfig;
56
- }
57
- interface VixtConfigLayer extends ConfigLayer<VixtOptions> {
58
- /** layer path before copy */
59
- relatedCwd?: string;
60
- /** layer path after copy to buildLayersDir */
61
- cwd?: string;
62
- }
63
-
64
12
  declare module '@vixt/core' {
65
13
  interface VixtOptions {
66
14
  app?: AppOptions;
@@ -89,11 +37,10 @@ interface AppOptions {
89
37
  * @default 'div'
90
38
  */
91
39
  rootTag?: string;
92
- /**
93
- * @default '<buildDir>/main.ts'
94
- */
40
+ /** content of main.ts */
95
41
  main?: string;
96
- transformMain?: (vixt: Vixt) => Promise<TransformResult | string | null | void> | TransformResult | string | null | void;
42
+ /** transform main.ts */
43
+ transformMain?: (code: string, vixt: Vixt) => string | undefined;
97
44
  css?: string[];
98
45
  /**
99
46
  * @default './loading.html'
@@ -136,4 +83,4 @@ declare function applyLayerModules(layers?: VixtConfigLayer[]): Promise<VixtModu
136
83
  declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
137
84
  declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
138
85
 
139
- export { type AppHead, type AppOptions, type ModuleDefinition, type ModuleMeta, type ModuleOptions, type PluginOptions, type TypescriptOptions, type Vixt, type VixtConfigLayer, type VixtModule, type VixtOptions, alias, app, applyLayerModules, buildDir, buildLayersDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, typescript };
86
+ export { type AppHead, type AppOptions, ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtModule, type VixtOptions, alias, app, applyLayerModules, buildDir, buildLayersDir, buildTypesDir, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadVixt, loadVixtConfig, resolveLayersDirs, rootDir, typescript };
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import path from 'pathe';
2
- import { cwd } from 'node:process';
3
2
  import fs from 'fs-extra';
4
3
  import 'tsx/esm';
5
4
  import { pathToFileURL } from 'mlly';
6
5
  import defu from 'defu';
6
+ import { cwd } from 'node:process';
7
7
  import { loadConfig } from 'c12';
8
8
  import Checker from 'vite-plugin-checker';
9
9
 
@@ -12,19 +12,25 @@ const alias = defineVixtModule({
12
12
  meta: { name: name$3 },
13
13
  setup(_, vixt) {
14
14
  const { rootDir, buildDir } = vixt.options;
15
+ const defaultAlias = {
16
+ "@": `${path.resolve(rootDir, "src")}`,
17
+ "~": `${path.resolve(rootDir, "src")}`,
18
+ "@@": path.resolve(rootDir),
19
+ "~~": path.resolve(rootDir)
20
+ };
21
+ for (const layer of vixt._layers) {
22
+ if (layer.meta?.alias) {
23
+ defaultAlias[layer.meta.alias] = layer.cwd;
24
+ }
25
+ }
26
+ defaultAlias["#"] = path.resolve(rootDir, buildDir);
15
27
  return {
16
28
  name: name$3,
17
29
  config() {
18
30
  return {
19
31
  root: rootDir,
20
32
  resolve: {
21
- alias: {
22
- "@": `${path.resolve(rootDir, "src")}`,
23
- "~": `${path.resolve(rootDir, "src")}`,
24
- "@@": path.resolve(rootDir),
25
- "~~": path.resolve(rootDir),
26
- "#": path.resolve(rootDir, buildDir)
27
- }
33
+ alias: defaultAlias
28
34
  }
29
35
  };
30
36
  }
@@ -52,20 +58,29 @@ async function loadVixtConfig(opts) {
52
58
  ...opts?.defaults
53
59
  }
54
60
  });
55
- result.layers = result.layers?.filter((e) => e.cwd).map((e) => {
56
- if (e.cwd !== rootDir) {
57
- const layerRootDir = e.cwd.split("/").pop();
58
- const newCwd = path.resolve(rootDir, buildLayersDir, layerRootDir);
59
- fs.copySync(e.cwd, newCwd, { filter: (src) => {
60
- const nodeModulesPath = path.resolve(e.cwd, "node_modules");
61
- const tsConfigPath = path.resolve(e.cwd, "tsconfig.json");
62
- return !isSamePath(src, nodeModulesPath) && !isSamePath(src, tsConfigPath);
63
- } });
64
- return { ...e, relatedCwd: e.cwd, cwd: newCwd };
61
+ result.layers = mapLayers(result.layers?.filter((e) => e.cwd) ?? []);
62
+ return result;
63
+ }
64
+ function mapLayers(layers) {
65
+ return layers.map((layer) => {
66
+ const meta = layer.config?.meta ?? {};
67
+ const layerName = meta.name || layer.cwd.split("/").pop();
68
+ if (!isSamePath(layer.cwd, path.resolve(rootDir)))
69
+ meta.alias = `#/layers/${layerName}`;
70
+ if (layer.cwd?.includes("node_modules")) {
71
+ const newCwd = path.resolve(rootDir, buildLayersDir, layerName);
72
+ fs.copySync(layer.cwd, newCwd, {
73
+ filter: (src) => {
74
+ const nodeModulesPath = path.resolve(layer.cwd, "node_modules");
75
+ const tsConfigPath = path.resolve(layer.cwd, "tsconfig.json");
76
+ return !isSamePath(src, nodeModulesPath) && !isSamePath(src, tsConfigPath);
77
+ }
78
+ });
79
+ layer.cwd = newCwd;
65
80
  }
66
- return e;
81
+ meta.relative = path.join(path.relative(`${rootDir}/src`, `${layer.cwd}/src`));
82
+ return { ...layer, meta };
67
83
  });
68
- return result;
69
84
  }
70
85
  function isSamePath(a, b) {
71
86
  return path.resolve(a) === path.resolve(b);
@@ -132,21 +147,24 @@ function resolveHeadTag(tag, attrs) {
132
147
  return attrs?.children ? `<${tag} ${attrsStr}>${attrs.children}</${tag}>` : `<${tag} ${attrsStr} />`;
133
148
  }
134
149
  function generateIndexHtml(options, vixt) {
135
- const { buildDir: buildDir2, rootDir } = vixt.options;
136
- const { head = {}, rootTag, rootId, main, loadingTemplate: loading = "" } = options || {};
150
+ const { buildDir, rootDir } = vixt.options;
151
+ fs.outputFileSync(path.resolve(rootDir, "index.html"), `<!-- Generated by Vixt -->
152
+ <!-- This file transform from '${buildDir}/index.html' -->
153
+ `);
154
+ const { head = {}, rootTag, rootId } = options;
137
155
  const headTemplate = Object.entries(head).filter(([k]) => k !== "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
138
156
  const noscriptTemplate = Object.entries(head).filter(([k]) => k === "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
139
- let loadingTemplate = "";
140
- if (/^\.|\//.test(loading)) {
141
- const loadingTemplatePath = path.resolve(rootDir, loading);
142
- if (fs.existsSync(loadingTemplatePath)) {
143
- loadingTemplate = fs.readFileSync(loadingTemplatePath, "utf-8");
157
+ let { loadingTemplate } = options;
158
+ if (!loadingTemplate) {
159
+ for (const layer of vixt._layers) {
160
+ const loadingTemplatePath = path.resolve(layer.cwd, "loading.html");
161
+ if (fs.existsSync(loadingTemplatePath)) {
162
+ loadingTemplate = fs.readFileSync(loadingTemplatePath, "utf-8");
163
+ break;
164
+ }
144
165
  }
145
- } else if (loading) {
146
- loadingTemplate = loading;
147
166
  }
148
- const code = `
149
- <!doctype html>
167
+ const code = `<!DOCTYPE html>
150
168
  <html>
151
169
  <head>
152
170
  ${headTemplate}
@@ -155,12 +173,56 @@ ${headTemplate}
155
173
  <${rootTag} id="${rootId}">
156
174
  ${loadingTemplate}
157
175
  </${rootTag}>
158
- <script type="module" src="${main}"><\/script>
176
+ <script type="module" src="/src/main.ts"><\/script>
159
177
  ${noscriptTemplate}
160
178
  </body>
161
179
  </html>
162
180
  `;
163
- fs.outputFileSync(path.resolve(rootDir, `${buildDir2}/index.html`), code);
181
+ fs.outputFileSync(path.resolve(rootDir, `${buildDir}/index.html`), code);
182
+ return code;
183
+ }
184
+ function generateMainTs(options, vixt) {
185
+ const { buildDir, rootDir } = vixt.options;
186
+ fs.outputFileSync(path.resolve(rootDir, "src", "main.ts"), `// Generated by Vixt
187
+ // This file transform from '${buildDir}/main.ts'
188
+ `);
189
+ const cssTemplate = options?.css?.map((css) => `import '${css}'`).reverse().join("\n");
190
+ let appComponentImportTempate = "";
191
+ let appConfigsImportTemplate = "";
192
+ let appConfigsMergeTemplate = "";
193
+ let pluginsImportTemplate = "";
194
+ let pluginsMergeTemplate = "";
195
+ vixt._layers.forEach((layer, i) => {
196
+ const appComponentPath = path.resolve(layer.cwd, "src", "App.vue");
197
+ if (fs.existsSync(appComponentPath) && !appComponentImportTempate) {
198
+ const appComponentRelativePath = `./${path.join(layer.meta.relative, "App.vue")}`;
199
+ appComponentImportTempate = `import App from '${appComponentRelativePath}'`;
200
+ }
201
+ const appConfigPath = `./${path.join(layer.meta.relative, "app.config.ts")}`;
202
+ const appConfigsName = `__app_config__${i}`;
203
+ appConfigsImportTemplate += `const ${appConfigsName} = Object.values(import.meta.glob('${appConfigPath}', { import: 'default', eager: true }))[0]
204
+ `;
205
+ appConfigsMergeTemplate += `${appConfigsName}, `;
206
+ const pluginsPath = `./${path.join(layer.meta.relative, "plugins/*.ts")}`;
207
+ const pluginsName = `__plugins__${i}`;
208
+ pluginsImportTemplate += `const ${pluginsName} = Object.values(import.meta.glob('${pluginsPath}', { import: 'default', eager: true }))
209
+ `;
210
+ pluginsMergeTemplate += `...${pluginsName}, `;
211
+ });
212
+ let code = `// Generated by Vixt
213
+ // This file transform to 'src/main.ts'
214
+ // @ts-nocheck
215
+ ${appComponentImportTempate}
216
+ ${cssTemplate}
217
+ import { defu } from 'defu'
218
+
219
+ ${appConfigsImportTemplate}
220
+ ${pluginsImportTemplate}
221
+ const appConfig = defu(${appConfigsMergeTemplate}{})
222
+ const plugins = [${pluginsMergeTemplate}].reverse()
223
+ `;
224
+ code = options.transformMain?.(code, vixt) || code;
225
+ fs.outputFileSync(path.resolve(rootDir, buildDir, "main.ts"), code);
164
226
  return code;
165
227
  }
166
228
  const name$2 = "vixt:app";
@@ -168,8 +230,6 @@ const defaults$1 = {
168
230
  rootId: "app",
169
231
  rootTag: "div",
170
232
  baseURL: "/",
171
- loadingTemplate: "./loading.html",
172
- main: `${buildDir}/main.ts`,
173
233
  head: {
174
234
  meta: [
175
235
  { charset: "utf-8" },
@@ -182,22 +242,22 @@ const app = defineVixtModule({
182
242
  meta: { name: name$2, configKey: "app" },
183
243
  defaults: defaults$1,
184
244
  setup(options, vixt) {
185
- generateIndexHtml(options, vixt);
245
+ const indexHtmlCode = generateIndexHtml(options, vixt);
246
+ const mainTsCode = generateMainTs(options, vixt);
186
247
  return {
187
248
  name: name$2,
188
249
  transformIndexHtml: {
189
250
  order: "pre",
190
251
  handler() {
191
- const { buildDir: buildDir2 } = vixt.options;
192
- return fs.readFileSync(path.resolve(cwd(), `${buildDir2}/index.html`), { encoding: "utf-8" });
252
+ return indexHtmlCode;
193
253
  }
194
254
  },
195
255
  transform: {
196
256
  order: "pre",
197
257
  handler(code, id) {
198
- if (!id.includes(options.main))
258
+ if (!id.includes("/src/main.ts"))
199
259
  return;
200
- return options.transformMain?.(vixt);
260
+ return mainTsCode;
201
261
  }
202
262
  }
203
263
  };
@@ -218,6 +278,21 @@ const config = defineVixtModule({
218
278
  }
219
279
  });
220
280
 
281
+ function generateTsConfig(options, vixt) {
282
+ const { buildDir, rootDir } = vixt.options;
283
+ const codePath = path.resolve(rootDir, buildDir, "tsconfig.json");
284
+ const layersDirs = [];
285
+ const layersAlias = {};
286
+ for (const layer of vixt._layers) {
287
+ layersDirs.push(layer.cwd);
288
+ if (layer.meta?.alias) {
289
+ layersAlias[`${layer.meta.alias}/*`] = [`${path.relative(path.resolve(rootDir, buildDir), layer.cwd)}/*`];
290
+ }
291
+ }
292
+ const tsConfig = defu(options.tsConfig, { compilerOptions: { paths: layersAlias }, include: layersDirs });
293
+ const code = JSON.stringify(tsConfig, null, 2);
294
+ fs.outputFileSync(codePath, code);
295
+ }
221
296
  function generateVixtDts(options, vixt) {
222
297
  const { buildDir, rootDir } = vixt.options;
223
298
  const codePath = path.resolve(rootDir, buildDir, "vixt.d.ts");
@@ -231,29 +306,8 @@ function generateVixtDts(options, vixt) {
231
306
  return "";
232
307
  }
233
308
  }).concat("export {}").join("\n");
234
- code && fs.outputFileSync(codePath, code);
235
- }
236
- function generateTsConfig(options, vixt) {
237
- const { buildDir, rootDir } = vixt.options;
238
- const codePath = path.resolve(rootDir, buildDir, "tsconfig.json");
239
- const layersDirs = vixt._layers.map((e) => [e.cwd, e.relatedCwd]).flat().filter((e) => e);
240
- const tsConfig = defu(options.tsConfig, { include: layersDirs });
241
- const code = JSON.stringify(tsConfig, null, 2);
242
- fs.outputFileSync(codePath, code);
243
- }
244
- function generateEnvDts(options, vixt, env) {
245
- const { buildTypesDir, rootDir } = vixt.options;
246
- const codePath = path.resolve(rootDir, buildTypesDir, "vite-env.d.ts");
247
- const values = Object.entries(env).map(([key, value]) => `/** ${key}=${value} */
248
- ${key}: ${typeof value}`).join("\n ");
249
- const code = `interface ImportMeta {
250
- readonly env: ImportMetaEnv
251
- }
252
- interface ImportMetaEnv {
253
- ${values}
254
- }
255
- `;
256
- fs.outputFileSync(codePath, code);
309
+ if (code)
310
+ fs.outputFileSync(codePath, code);
257
311
  }
258
312
  function genarateShims(options, vixt) {
259
313
  const { buildTypesDir, rootDir } = vixt.options;
@@ -280,6 +334,20 @@ declare module 'vue'{
280
334
  `;
281
335
  fs.outputFileSync(codePath, code);
282
336
  }
337
+ function generateEnvDts(env, vixt) {
338
+ const { buildTypesDir, rootDir } = vixt.options;
339
+ const codePath = path.resolve(rootDir, buildTypesDir, "vite-env.d.ts");
340
+ const values = Object.entries(env).map(([key, value]) => `/** ${key}=${value} */
341
+ ${key}: ${typeof value}`).join("\n ");
342
+ const code = `interface ImportMeta {
343
+ readonly env: ImportMetaEnv
344
+ }
345
+ interface ImportMetaEnv {
346
+ ${values}
347
+ }
348
+ `;
349
+ fs.outputFileSync(codePath, code);
350
+ }
283
351
  const name = "vixt:typescript";
284
352
  const defaults = {
285
353
  // references: ['types/vite-env.d.ts', 'types/shims.d.ts', 'types/global-components.d.ts'],
@@ -287,11 +355,8 @@ const defaults = {
287
355
  extends: "@vue/tsconfig/tsconfig.dom.json",
288
356
  compilerOptions: {
289
357
  paths: {
290
- "@": ["../src"],
291
358
  "@/*": ["../src/*"],
292
- "~": ["../src"],
293
359
  "~/*": ["../src/*"],
294
- "#": ["."],
295
360
  "#/*": ["./*"]
296
361
  },
297
362
  types: ["vite/client"]
@@ -306,15 +371,15 @@ const typescript = defineVixtModule({
306
371
  meta: { name, configKey: "typescript" },
307
372
  defaults,
308
373
  setup(options, vixt) {
374
+ generateTsConfig(options, vixt);
375
+ generateVixtDts(options, vixt);
376
+ genarateShims(options, vixt);
377
+ genarateGlobalComponents(options, vixt);
309
378
  return [
310
379
  {
311
380
  name,
312
381
  configResolved(config) {
313
- generateVixtDts(options, vixt);
314
- generateTsConfig(options, vixt);
315
- generateEnvDts(options, vixt, config.env);
316
- genarateShims(options, vixt);
317
- genarateGlobalComponents(options, vixt);
382
+ generateEnvDts(config.env, vixt);
318
383
  }
319
384
  },
320
385
  Checker(options.typeCheck ?? {})
@@ -0,0 +1,67 @@
1
+ import { PluginOption, ResolvedConfig } from 'vite';
2
+ import { ConfigLayerMeta, ConfigLayer } from 'c12';
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;
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 '.vixt'
34
+ */
35
+ buildDir?: string;
36
+ /**
37
+ * @default '.vixt/types'
38
+ */
39
+ buildTypesDir?: string;
40
+ /**
41
+ * @default '.vixt/layers'
42
+ */
43
+ buildLayersDir?: string;
44
+ /** modules */
45
+ modules?: VixtModule[];
46
+ /** use on configResolved */
47
+ vite?: ResolvedConfig;
48
+ meta?: VixtConfigLayerMeta;
49
+ /** layers */
50
+ extends?: string[];
51
+ }
52
+ interface VixtConfigLayerMeta extends ConfigLayerMeta {
53
+ /** layer name */
54
+ name?: string;
55
+ /** layer alias */
56
+ alias?: string;
57
+ /** relative path from `<layer.cwd>/src` to `<rootDir>/src` */
58
+ relative?: string;
59
+ }
60
+ interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
61
+ /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, change cwd */
62
+ cwd?: string;
63
+ }
64
+ interface VixtAppConfig extends Record<string, any> {
65
+ }
66
+
67
+ export type { ModuleOptions as M, PluginOptions as P, VixtModule as V, Vixt as a, VixtOptions as b, VixtConfigLayer as c, ModuleDefinition as d, VixtConfigLayerMeta as e, VixtAppConfig as f, ModuleMeta as g };
@@ -0,0 +1,67 @@
1
+ import { PluginOption, ResolvedConfig } from 'vite';
2
+ import { ConfigLayerMeta, ConfigLayer } from 'c12';
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;
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 '.vixt'
34
+ */
35
+ buildDir?: string;
36
+ /**
37
+ * @default '.vixt/types'
38
+ */
39
+ buildTypesDir?: string;
40
+ /**
41
+ * @default '.vixt/layers'
42
+ */
43
+ buildLayersDir?: string;
44
+ /** modules */
45
+ modules?: VixtModule[];
46
+ /** use on configResolved */
47
+ vite?: ResolvedConfig;
48
+ meta?: VixtConfigLayerMeta;
49
+ /** layers */
50
+ extends?: string[];
51
+ }
52
+ interface VixtConfigLayerMeta extends ConfigLayerMeta {
53
+ /** layer name */
54
+ name?: string;
55
+ /** layer alias */
56
+ alias?: string;
57
+ /** relative path from `<layer.cwd>/src` to `<rootDir>/src` */
58
+ relative?: string;
59
+ }
60
+ interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
61
+ /** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, change cwd */
62
+ cwd?: string;
63
+ }
64
+ interface VixtAppConfig extends Record<string, any> {
65
+ }
66
+
67
+ export type { ModuleOptions as M, PluginOptions as P, VixtModule as V, Vixt as a, VixtOptions as b, VixtConfigLayer as c, ModuleDefinition as d, VixtConfigLayerMeta as e, VixtAppConfig as f, ModuleMeta as g };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/core",
3
3
  "type": "module",
4
- "version": "0.0.15",
4
+ "version": "0.1.1",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -10,6 +10,10 @@
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.mjs"
13
+ },
14
+ "./client": {
15
+ "types": "./dist/client/index.d.ts",
16
+ "import": "./dist/client/index.mjs"
13
17
  }
14
18
  },
15
19
  "main": "dist/index.mjs",