@vixt/core 0.0.15 → 0.1.0
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/dist/client/index.d.mts +29 -0
- package/dist/client/index.d.ts +29 -0
- package/dist/client/index.mjs +14 -0
- package/dist/index.d.mts +10 -63
- package/dist/index.d.ts +10 -63
- package/dist/index.mjs +131 -66
- package/dist/shared/core.28e7fb8c.d.mts +67 -0
- package/dist/shared/core.28e7fb8c.d.ts +67 -0
- package/package.json +5 -1
|
@@ -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.28e7fb8c.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.28e7fb8c.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
|
|
2
|
-
|
|
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.28e7fb8c.mjs';
|
|
2
|
+
export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig, e as VixtConfigLayerMeta } from './shared/core.28e7fb8c.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
|
-
|
|
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,
|
|
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
|
|
2
|
-
|
|
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.28e7fb8c.js';
|
|
2
|
+
export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig, e as VixtConfigLayerMeta } from './shared/core.28e7fb8c.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
|
-
|
|
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,
|
|
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
|
@@ -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,28 @@ async function loadVixtConfig(opts) {
|
|
|
52
58
|
...opts?.defaults
|
|
53
59
|
}
|
|
54
60
|
});
|
|
55
|
-
result.layers = result.layers?.filter((e) => e.cwd)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
meta.name && (meta.alias = `#/layers/${meta.name}`);
|
|
69
|
+
if (layer.cwd?.includes("node_modules")) {
|
|
70
|
+
const newCwd = path.resolve(rootDir, buildLayersDir, layerName);
|
|
71
|
+
fs.copySync(layer.cwd, newCwd, {
|
|
72
|
+
filter: (src) => {
|
|
73
|
+
const nodeModulesPath = path.resolve(layer.cwd, "node_modules");
|
|
74
|
+
const tsConfigPath = path.resolve(layer.cwd, "tsconfig.json");
|
|
75
|
+
return !isSamePath(src, nodeModulesPath) && !isSamePath(src, tsConfigPath);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
layer.cwd = newCwd;
|
|
65
79
|
}
|
|
66
|
-
|
|
80
|
+
meta.relative = path.join("./", path.relative(`${rootDir}/src`, layer.cwd));
|
|
81
|
+
return { ...layer, meta };
|
|
67
82
|
});
|
|
68
|
-
return result;
|
|
69
83
|
}
|
|
70
84
|
function isSamePath(a, b) {
|
|
71
85
|
return path.resolve(a) === path.resolve(b);
|
|
@@ -132,18 +146,22 @@ function resolveHeadTag(tag, attrs) {
|
|
|
132
146
|
return attrs?.children ? `<${tag} ${attrsStr}>${attrs.children}</${tag}>` : `<${tag} ${attrsStr} />`;
|
|
133
147
|
}
|
|
134
148
|
function generateIndexHtml(options, vixt) {
|
|
135
|
-
const { buildDir
|
|
136
|
-
|
|
149
|
+
const { buildDir, rootDir } = vixt.options;
|
|
150
|
+
fs.outputFileSync(path.resolve(rootDir, "index.html"), `<!-- Generated by Vixt -->
|
|
151
|
+
<!-- This file transform from '${buildDir}/index.html' -->
|
|
152
|
+
`);
|
|
153
|
+
const { head = {}, rootTag, rootId } = options;
|
|
137
154
|
const headTemplate = Object.entries(head).filter(([k]) => k !== "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
|
|
138
155
|
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 (
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
156
|
+
let { loadingTemplate } = options;
|
|
157
|
+
if (!loadingTemplate) {
|
|
158
|
+
for (const layer of vixt._layers) {
|
|
159
|
+
const loadingTemplatePath = path.resolve(layer.cwd, "loading.html");
|
|
160
|
+
if (fs.existsSync(loadingTemplatePath)) {
|
|
161
|
+
loadingTemplate = fs.readFileSync(loadingTemplatePath, "utf-8");
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
144
164
|
}
|
|
145
|
-
} else if (loading) {
|
|
146
|
-
loadingTemplate = loading;
|
|
147
165
|
}
|
|
148
166
|
const code = `
|
|
149
167
|
<!doctype html>
|
|
@@ -155,21 +173,62 @@ ${headTemplate}
|
|
|
155
173
|
<${rootTag} id="${rootId}">
|
|
156
174
|
${loadingTemplate}
|
|
157
175
|
</${rootTag}>
|
|
158
|
-
<script type="module" src="
|
|
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, `${
|
|
181
|
+
fs.outputFileSync(path.resolve(rootDir, `${buildDir}/index.html`), code);
|
|
164
182
|
return code;
|
|
165
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.join(layer.cwd, "/src/App.vue");
|
|
197
|
+
if (fs.existsSync(appComponentPath) && !appComponentImportTempate) {
|
|
198
|
+
const appComponentRelativePath = path.join(layer.meta.relative, "/src/App.vue");
|
|
199
|
+
appComponentImportTempate = `import App from '${appComponentRelativePath}'`;
|
|
200
|
+
}
|
|
201
|
+
const appConfigPath = path.join(layer.meta.relative, "/src/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, "/src/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);
|
|
226
|
+
}
|
|
166
227
|
const name$2 = "vixt:app";
|
|
167
228
|
const defaults$1 = {
|
|
168
229
|
rootId: "app",
|
|
169
230
|
rootTag: "div",
|
|
170
231
|
baseURL: "/",
|
|
171
|
-
loadingTemplate: "./loading.html",
|
|
172
|
-
main: `${buildDir}/main.ts`,
|
|
173
232
|
head: {
|
|
174
233
|
meta: [
|
|
175
234
|
{ charset: "utf-8" },
|
|
@@ -183,21 +242,22 @@ const app = defineVixtModule({
|
|
|
183
242
|
defaults: defaults$1,
|
|
184
243
|
setup(options, vixt) {
|
|
185
244
|
generateIndexHtml(options, vixt);
|
|
245
|
+
generateMainTs(options, vixt);
|
|
246
|
+
const { rootDir, buildDir } = vixt.options;
|
|
186
247
|
return {
|
|
187
248
|
name: name$2,
|
|
188
249
|
transformIndexHtml: {
|
|
189
250
|
order: "pre",
|
|
190
251
|
handler() {
|
|
191
|
-
|
|
192
|
-
return fs.readFileSync(path.resolve(cwd(), `${buildDir2}/index.html`), { encoding: "utf-8" });
|
|
252
|
+
return fs.readFileSync(path.resolve(cwd(), `${buildDir}/index.html`), { encoding: "utf-8" });
|
|
193
253
|
}
|
|
194
254
|
},
|
|
195
255
|
transform: {
|
|
196
256
|
order: "pre",
|
|
197
257
|
handler(code, id) {
|
|
198
|
-
if (!id.includes(
|
|
258
|
+
if (!id.includes("/src/main.ts"))
|
|
199
259
|
return;
|
|
200
|
-
return
|
|
260
|
+
return fs.readFileSync(path.resolve(rootDir, buildDir, "main.ts"), "utf-8");
|
|
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}/*`] = [`${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");
|
|
@@ -233,28 +308,6 @@ function generateVixtDts(options, vixt) {
|
|
|
233
308
|
}).concat("export {}").join("\n");
|
|
234
309
|
code && fs.outputFileSync(codePath, code);
|
|
235
310
|
}
|
|
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);
|
|
257
|
-
}
|
|
258
311
|
function genarateShims(options, vixt) {
|
|
259
312
|
const { buildTypesDir, rootDir } = vixt.options;
|
|
260
313
|
const code = `
|
|
@@ -280,18 +333,30 @@ declare module 'vue'{
|
|
|
280
333
|
`;
|
|
281
334
|
fs.outputFileSync(codePath, code);
|
|
282
335
|
}
|
|
336
|
+
function generateEnvDts(env, vixt) {
|
|
337
|
+
const { buildTypesDir, rootDir } = vixt.options;
|
|
338
|
+
const codePath = path.resolve(rootDir, buildTypesDir, "vite-env.d.ts");
|
|
339
|
+
const values = Object.entries(env).map(([key, value]) => `/** ${key}=${value} */
|
|
340
|
+
${key}: ${typeof value}`).join("\n ");
|
|
341
|
+
const code = `interface ImportMeta {
|
|
342
|
+
readonly env: ImportMetaEnv
|
|
343
|
+
}
|
|
344
|
+
interface ImportMetaEnv {
|
|
345
|
+
${values}
|
|
346
|
+
}
|
|
347
|
+
`;
|
|
348
|
+
fs.outputFileSync(codePath, code);
|
|
349
|
+
}
|
|
283
350
|
const name = "vixt:typescript";
|
|
284
351
|
const defaults = {
|
|
285
352
|
// references: ['types/vite-env.d.ts', 'types/shims.d.ts', 'types/global-components.d.ts'],
|
|
286
353
|
tsConfig: {
|
|
287
354
|
extends: "@vue/tsconfig/tsconfig.dom.json",
|
|
288
355
|
compilerOptions: {
|
|
356
|
+
baseUrl: "./",
|
|
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
|
-
|
|
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 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 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
|
|
4
|
+
"version": "0.1.0",
|
|
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",
|