@vixt/core 0.1.10 → 0.1.11
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/App.vue +3 -0
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/index.d.mts +17 -10
- package/dist/index.d.ts +17 -10
- package/dist/index.mjs +142 -75
- package/dist/shared/{core.accf0e85.d.mts → core.a9343bb9.d.mts} +13 -3
- package/dist/shared/{core.accf0e85.d.ts → core.a9343bb9.d.ts} +13 -3
- package/package.json +8 -4
package/dist/client/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { App, Plugin } from 'vue';
|
|
2
2
|
import { Router, RouteRecord } from 'vue-router';
|
|
3
3
|
import { Pinia } from 'pinia';
|
|
4
|
-
import { f as VixtAppConfig } from '../shared/core.
|
|
4
|
+
import { f as VixtAppConfig } from '../shared/core.a9343bb9.mjs';
|
|
5
5
|
import 'vite';
|
|
6
6
|
import 'c12';
|
|
7
7
|
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { App, Plugin } from 'vue';
|
|
2
2
|
import { Router, RouteRecord } from 'vue-router';
|
|
3
3
|
import { Pinia } from 'pinia';
|
|
4
|
-
import { f as VixtAppConfig } from '../shared/core.
|
|
4
|
+
import { f as VixtAppConfig } from '../shared/core.a9343bb9.js';
|
|
5
5
|
import 'vite';
|
|
6
6
|
import 'c12';
|
|
7
7
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { V as VixtModule, M as ModuleOptions, a as Vixt, b as VixtOptions, c as VixtConfigLayer, d as ModuleDefinition } from './shared/core.
|
|
2
|
-
export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig, e as VixtConfigLayerMeta } from './shared/core.
|
|
1
|
+
import { V as VixtModule, M as ModuleOptions, a as Vixt, b as VixtOptions, c as VixtConfigLayer, d as ModuleDefinition } from './shared/core.a9343bb9.mjs';
|
|
2
|
+
export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig, e as VixtConfigLayerMeta } from './shared/core.a9343bb9.mjs';
|
|
3
3
|
import { TSConfig } from 'pkg-types';
|
|
4
|
+
import { RawVueCompilerOptions } from '@vue/language-core';
|
|
4
5
|
import Checker from 'vite-plugin-checker';
|
|
5
6
|
import * as c12 from 'c12';
|
|
6
7
|
import { LoadConfigOptions } from 'c12';
|
|
@@ -37,6 +38,7 @@ interface AppOptions {
|
|
|
37
38
|
* @default 'div'
|
|
38
39
|
*/
|
|
39
40
|
rootTag?: string;
|
|
41
|
+
/** inject css files */
|
|
40
42
|
css?: string[];
|
|
41
43
|
/**
|
|
42
44
|
* @default './loading.html'
|
|
@@ -59,26 +61,31 @@ interface TypescriptOptions {
|
|
|
59
61
|
path?: string;
|
|
60
62
|
content?: string;
|
|
61
63
|
})[];
|
|
62
|
-
tsConfig?: TSConfig
|
|
64
|
+
tsConfig?: TSConfig & {
|
|
65
|
+
vueCompilerOptions?: RawVueCompilerOptions;
|
|
66
|
+
};
|
|
63
67
|
/** https://github.com/fi3ework/vite-plugin-checker */
|
|
64
68
|
typeCheck?: Parameters<typeof Checker>[0];
|
|
69
|
+
/**
|
|
70
|
+
* Generate a `*.vue` shim
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
73
|
+
shim?: boolean;
|
|
65
74
|
}
|
|
66
75
|
declare const typescript: VixtModule<TypescriptOptions>;
|
|
67
76
|
|
|
68
77
|
declare function defineVixtConfig(input: VixtOptions): VixtOptions;
|
|
69
|
-
declare const rootDir: string;
|
|
70
|
-
declare const buildDir = ".vixt";
|
|
71
|
-
declare const buildTypesDir = ".vixt/types";
|
|
72
|
-
declare const buildLayersDir = ".vixt/layers";
|
|
73
78
|
declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, c12.ConfigLayerMeta>>;
|
|
74
|
-
declare function resolveLayersDirs(layers
|
|
79
|
+
declare function resolveLayersDirs(layers: VixtConfigLayer[] | undefined, config: VixtOptions): Record<string, string[] | undefined>;
|
|
80
|
+
|
|
81
|
+
declare function loadEnv(mode?: string, envDir?: string, prefixes?: string | string[]): ImportMeta["env"];
|
|
75
82
|
|
|
76
83
|
declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
|
|
77
84
|
declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
|
|
78
85
|
declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
|
|
79
|
-
declare function applyLayerModules(layers
|
|
86
|
+
declare function applyLayerModules(layers: VixtConfigLayer[], config: VixtOptions): Promise<VixtModule[]>;
|
|
80
87
|
|
|
81
88
|
declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
|
|
82
89
|
declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
|
|
83
90
|
|
|
84
|
-
export { type AppHead, type AppOptions, ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtModule, type VixtOptions, alias, app, applyLayerModules,
|
|
91
|
+
export { type AppHead, type AppOptions, ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtModule, type VixtOptions, alias, app, applyLayerModules, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadEnv, loadVixt, loadVixtConfig, resolveLayersDirs, typescript };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { V as VixtModule, M as ModuleOptions, a as Vixt, b as VixtOptions, c as VixtConfigLayer, d as ModuleDefinition } from './shared/core.
|
|
2
|
-
export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig, e as VixtConfigLayerMeta } from './shared/core.
|
|
1
|
+
import { V as VixtModule, M as ModuleOptions, a as Vixt, b as VixtOptions, c as VixtConfigLayer, d as ModuleDefinition } from './shared/core.a9343bb9.js';
|
|
2
|
+
export { g as ModuleMeta, P as PluginOptions, f as VixtAppConfig, e as VixtConfigLayerMeta } from './shared/core.a9343bb9.js';
|
|
3
3
|
import { TSConfig } from 'pkg-types';
|
|
4
|
+
import { RawVueCompilerOptions } from '@vue/language-core';
|
|
4
5
|
import Checker from 'vite-plugin-checker';
|
|
5
6
|
import * as c12 from 'c12';
|
|
6
7
|
import { LoadConfigOptions } from 'c12';
|
|
@@ -37,6 +38,7 @@ interface AppOptions {
|
|
|
37
38
|
* @default 'div'
|
|
38
39
|
*/
|
|
39
40
|
rootTag?: string;
|
|
41
|
+
/** inject css files */
|
|
40
42
|
css?: string[];
|
|
41
43
|
/**
|
|
42
44
|
* @default './loading.html'
|
|
@@ -59,26 +61,31 @@ interface TypescriptOptions {
|
|
|
59
61
|
path?: string;
|
|
60
62
|
content?: string;
|
|
61
63
|
})[];
|
|
62
|
-
tsConfig?: TSConfig
|
|
64
|
+
tsConfig?: TSConfig & {
|
|
65
|
+
vueCompilerOptions?: RawVueCompilerOptions;
|
|
66
|
+
};
|
|
63
67
|
/** https://github.com/fi3ework/vite-plugin-checker */
|
|
64
68
|
typeCheck?: Parameters<typeof Checker>[0];
|
|
69
|
+
/**
|
|
70
|
+
* Generate a `*.vue` shim
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
73
|
+
shim?: boolean;
|
|
65
74
|
}
|
|
66
75
|
declare const typescript: VixtModule<TypescriptOptions>;
|
|
67
76
|
|
|
68
77
|
declare function defineVixtConfig(input: VixtOptions): VixtOptions;
|
|
69
|
-
declare const rootDir: string;
|
|
70
|
-
declare const buildDir = ".vixt";
|
|
71
|
-
declare const buildTypesDir = ".vixt/types";
|
|
72
|
-
declare const buildLayersDir = ".vixt/layers";
|
|
73
78
|
declare function loadVixtConfig(opts?: LoadConfigOptions<VixtOptions>): Promise<c12.ResolvedConfig<VixtOptions, c12.ConfigLayerMeta>>;
|
|
74
|
-
declare function resolveLayersDirs(layers
|
|
79
|
+
declare function resolveLayersDirs(layers: VixtConfigLayer[] | undefined, config: VixtOptions): Record<string, string[] | undefined>;
|
|
80
|
+
|
|
81
|
+
declare function loadEnv(mode?: string, envDir?: string, prefixes?: string | string[]): ImportMeta["env"];
|
|
75
82
|
|
|
76
83
|
declare function defineVitePlugin<Options = any>(pluginFn: (options?: Options) => PluginOption): (options?: Options) => PluginOption;
|
|
77
84
|
declare function defineVixtModule<T extends ModuleOptions>(definition: ModuleDefinition<T> | VixtModule<T>): VixtModule<T>;
|
|
78
85
|
declare function installModule(module: VixtModule, inlineOptions: any, vixt: Vixt): PluginOption;
|
|
79
|
-
declare function applyLayerModules(layers
|
|
86
|
+
declare function applyLayerModules(layers: VixtConfigLayer[], config: VixtOptions): Promise<VixtModule[]>;
|
|
80
87
|
|
|
81
88
|
declare function loadVixt(opts?: LoadConfigOptions<VixtOptions>): Promise<Vixt>;
|
|
82
89
|
declare function createVixtPlugin(loadOptions: LoadConfigOptions<VixtOptions>): (options?: VixtOptions | undefined) => vite.PluginOption;
|
|
83
90
|
|
|
84
|
-
export { type AppHead, type AppOptions, ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtModule, type VixtOptions, alias, app, applyLayerModules,
|
|
91
|
+
export { type AppHead, type AppOptions, ModuleDefinition, ModuleOptions, type TypescriptOptions, Vixt, VixtConfigLayer, VixtModule, type VixtOptions, alias, app, applyLayerModules, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadEnv, loadVixt, loadVixtConfig, resolveLayersDirs, typescript };
|
package/dist/index.mjs
CHANGED
|
@@ -3,27 +3,29 @@ import fs from 'fs-extra';
|
|
|
3
3
|
import 'tsx/esm';
|
|
4
4
|
import { pathToFileURL } from 'mlly';
|
|
5
5
|
import defu from 'defu';
|
|
6
|
-
import { cwd } from 'node:process';
|
|
6
|
+
import { cwd, env } from 'node:process';
|
|
7
7
|
import { loadConfig } from 'c12';
|
|
8
8
|
import Checker from 'vite-plugin-checker';
|
|
9
|
+
import { cac } from 'cac';
|
|
10
|
+
import { loadEnv as loadEnv$1 } from 'vite';
|
|
9
11
|
|
|
10
12
|
const name$3 = "vixt:alias";
|
|
11
13
|
const alias = defineVixtModule({
|
|
12
14
|
meta: { name: name$3 },
|
|
13
15
|
setup(_, vixt) {
|
|
14
|
-
const { rootDir, buildDir } = vixt.options;
|
|
16
|
+
const { rootDir, buildDir, srcDir } = vixt.options;
|
|
15
17
|
const defaultAlias = {
|
|
16
|
-
"@":
|
|
17
|
-
"~":
|
|
18
|
-
"@@":
|
|
19
|
-
"~~":
|
|
18
|
+
"@": srcDir,
|
|
19
|
+
"~": srcDir,
|
|
20
|
+
"@@": rootDir,
|
|
21
|
+
"~~": rootDir
|
|
20
22
|
};
|
|
21
23
|
for (const layer of vixt._layers) {
|
|
22
24
|
if (layer.meta?.alias) {
|
|
23
25
|
defaultAlias[layer.meta.alias] = layer.cwd;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
|
-
defaultAlias["#"] =
|
|
28
|
+
defaultAlias["#"] = buildDir;
|
|
27
29
|
return {
|
|
28
30
|
name: name$3,
|
|
29
31
|
config() {
|
|
@@ -41,34 +43,43 @@ const alias = defineVixtModule({
|
|
|
41
43
|
function defineVixtConfig(input) {
|
|
42
44
|
return input;
|
|
43
45
|
}
|
|
44
|
-
const rootDir = path.resolve(cwd());
|
|
45
|
-
const buildDir = ".vixt";
|
|
46
|
-
const buildTypesDir = `${buildDir}/types`;
|
|
47
|
-
const buildLayersDir = `${buildDir}/layers`;
|
|
48
46
|
async function loadVixtConfig(opts) {
|
|
47
|
+
const rootDir = path.resolve(cwd());
|
|
48
|
+
const buildDirName = ".vixt";
|
|
49
|
+
const buildDir = path.resolve(rootDir, buildDirName);
|
|
50
|
+
const buildTypesDir = path.resolve(buildDir, "types");
|
|
51
|
+
const buildLayersDir = path.resolve(buildDir, "layers");
|
|
52
|
+
const buildImportsDir = path.resolve(buildDir, "imports");
|
|
53
|
+
const srcDirName = "src";
|
|
54
|
+
const srcDir = path.resolve(rootDir, srcDirName);
|
|
49
55
|
const result = await loadConfig({
|
|
50
56
|
name: "vixt",
|
|
51
57
|
rcFile: false,
|
|
52
58
|
...opts,
|
|
53
59
|
defaults: {
|
|
54
60
|
rootDir,
|
|
61
|
+
buildDirName,
|
|
55
62
|
buildDir,
|
|
56
63
|
buildTypesDir,
|
|
57
64
|
buildLayersDir,
|
|
65
|
+
buildImportsDir,
|
|
66
|
+
srcDirName,
|
|
67
|
+
srcDir,
|
|
58
68
|
...opts?.defaults
|
|
59
69
|
}
|
|
60
70
|
});
|
|
61
|
-
result.layers = mapLayers(result.layers?.filter((e) => e.cwd) ?? []);
|
|
71
|
+
result.layers = mapLayers(result.layers?.filter((e) => e.cwd) ?? [], result.config);
|
|
62
72
|
return result;
|
|
63
73
|
}
|
|
64
|
-
function mapLayers(layers) {
|
|
74
|
+
function mapLayers(layers, config) {
|
|
75
|
+
const { rootDir, buildLayersDir } = config;
|
|
65
76
|
return layers.map((layer) => {
|
|
66
77
|
const meta = layer.config?.meta ?? {};
|
|
67
78
|
const layerName = meta.name || layer.cwd.split("/").pop();
|
|
68
79
|
if (!isSamePath(layer.cwd, path.resolve(rootDir)))
|
|
69
80
|
meta.alias = `#/layers/${layerName}`;
|
|
70
81
|
if (layer.cwd?.includes("node_modules")) {
|
|
71
|
-
const newCwd = path.resolve(
|
|
82
|
+
const newCwd = path.resolve(buildLayersDir, layerName);
|
|
72
83
|
fs.copySync(layer.cwd, newCwd, {
|
|
73
84
|
filter: (src) => {
|
|
74
85
|
const nodeModulesPath = path.resolve(layer.cwd, "node_modules");
|
|
@@ -78,19 +89,19 @@ function mapLayers(layers) {
|
|
|
78
89
|
});
|
|
79
90
|
layer.cwd = newCwd;
|
|
80
91
|
}
|
|
81
|
-
meta.relative = path.join(path.relative(`${rootDir}/src`, `${layer.cwd}/src`));
|
|
82
92
|
return { ...layer, meta };
|
|
83
93
|
});
|
|
84
94
|
}
|
|
85
95
|
function isSamePath(a, b) {
|
|
86
96
|
return path.resolve(a) === path.resolve(b);
|
|
87
97
|
}
|
|
88
|
-
function resolveLayersDirs(layers = []) {
|
|
98
|
+
function resolveLayersDirs(layers = [], config) {
|
|
99
|
+
const { srcDirName } = config;
|
|
89
100
|
const dirs = {};
|
|
90
101
|
for (const layer of layers) {
|
|
91
|
-
const contents = fs.readdirSync(path.resolve(layer.cwd,
|
|
102
|
+
const contents = fs.readdirSync(path.resolve(layer.cwd, srcDirName));
|
|
92
103
|
for (const content of contents) {
|
|
93
|
-
const fileOrDirPath = path.resolve(layer.cwd,
|
|
104
|
+
const fileOrDirPath = path.resolve(layer.cwd, srcDirName, content);
|
|
94
105
|
if (fs.statSync(fileOrDirPath).isDirectory()) {
|
|
95
106
|
dirs[content] ?? (dirs[content] = []);
|
|
96
107
|
dirs[content].push(fileOrDirPath);
|
|
@@ -126,8 +137,8 @@ function defineVixtModule(definition) {
|
|
|
126
137
|
function installModule(module, inlineOptions, vixt) {
|
|
127
138
|
return module(inlineOptions, vixt);
|
|
128
139
|
}
|
|
129
|
-
async function applyLayerModules(layers) {
|
|
130
|
-
const { modules: modulesDir = [] } = resolveLayersDirs(layers);
|
|
140
|
+
async function applyLayerModules(layers, config) {
|
|
141
|
+
const { modules: modulesDir = [] } = resolveLayersDirs(layers, config);
|
|
131
142
|
const modules = [];
|
|
132
143
|
for (const m of modulesDir) {
|
|
133
144
|
if (fs.existsSync(m)) {
|
|
@@ -150,11 +161,11 @@ function resolveHeadTag(tag, attrs) {
|
|
|
150
161
|
return attrs?.children ? `<${tag} ${attrsStr}>${attrs.children}</${tag}>` : `<${tag} ${attrsStr} />`;
|
|
151
162
|
}
|
|
152
163
|
function generateIndexHtml(options, vixt) {
|
|
153
|
-
const { buildDir, rootDir } = vixt.options;
|
|
164
|
+
const { buildDir, buildDirName, rootDir } = vixt.options;
|
|
154
165
|
const indexHtmlPath = path.resolve(rootDir, "index.html");
|
|
155
166
|
if (!fs.existsSync(indexHtmlPath))
|
|
156
167
|
fs.outputFileSync(indexHtmlPath, `<!-- Generated by Vixt -->
|
|
157
|
-
<!-- This file transform from '${
|
|
168
|
+
<!-- This file transform from '${buildDirName}/index.html' -->
|
|
158
169
|
`);
|
|
159
170
|
const { head = {}, rootTag, rootId } = options;
|
|
160
171
|
const headTemplate = Object.entries(head).filter(([k]) => k !== "noscript").map(([tag, attrs]) => attrs.map((e) => resolveHeadTag(tag, e))).flat().join("\n");
|
|
@@ -183,53 +194,96 @@ ${noscriptTemplate}
|
|
|
183
194
|
</body>
|
|
184
195
|
</html>
|
|
185
196
|
`;
|
|
186
|
-
fs.outputFileSync(path.resolve(
|
|
197
|
+
fs.outputFileSync(path.resolve(buildDir, "index.html"), code);
|
|
187
198
|
return code;
|
|
188
199
|
}
|
|
189
|
-
function
|
|
190
|
-
const {
|
|
191
|
-
const mainTsPath = path.resolve(rootDir, "src", "main.ts");
|
|
192
|
-
if (!fs.existsSync(mainTsPath))
|
|
193
|
-
fs.outputFileSync(mainTsPath, `// Generated by Vixt
|
|
194
|
-
// This file transform from '${buildDir}/main.ts'
|
|
195
|
-
`);
|
|
196
|
-
const cssTemplate = options?.css?.map((css) => `import '${css}'`).join("\n") ?? "";
|
|
197
|
-
let appComponentImportTempate = "";
|
|
200
|
+
function generateAppConfig(vixt) {
|
|
201
|
+
const { buildImportsDir, srcDir, srcDirName } = vixt.options;
|
|
198
202
|
let appConfigsImportTemplate = "";
|
|
199
203
|
let appConfigsMergeTemplate = "";
|
|
204
|
+
let i = 0;
|
|
205
|
+
for (const layer of vixt._layers) {
|
|
206
|
+
const appConfigPath = path.resolve(layer.cwd, srcDirName, "app.config.ts");
|
|
207
|
+
if (fs.existsSync(appConfigPath)) {
|
|
208
|
+
const appConfigName = `__app_config_${i}`;
|
|
209
|
+
appConfigsImportTemplate += `import ${appConfigName} from '${appConfigPath}'
|
|
210
|
+
`;
|
|
211
|
+
appConfigsMergeTemplate += `${appConfigName}, `;
|
|
212
|
+
i++;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const appConfigTemplate = `
|
|
216
|
+
import { defu } from 'defu'
|
|
217
|
+
${appConfigsImportTemplate}
|
|
218
|
+
const appConfig = defu(${appConfigsMergeTemplate}{})
|
|
219
|
+
function useAppConfig() {
|
|
220
|
+
return appConfig
|
|
221
|
+
}
|
|
222
|
+
export { useAppConfig }
|
|
223
|
+
`;
|
|
224
|
+
const mainTsPath = path.resolve(srcDir, "main.ts");
|
|
225
|
+
fs.outputFileSync(path.resolve(buildImportsDir, `app.config.ts`), `// @ts-nocheck
|
|
226
|
+
export { useAppConfig } from '${mainTsPath}'`);
|
|
227
|
+
return appConfigTemplate;
|
|
228
|
+
}
|
|
229
|
+
function generatePlugins(vixt) {
|
|
230
|
+
const { srcDirName } = vixt.options;
|
|
200
231
|
let pluginsImportTemplate = "";
|
|
201
232
|
let pluginsMergeTemplate = "";
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
appConfigsImportTemplate += `const ${appConfigsName} = Object.values(import.meta.glob('${appConfigPath}', { import: 'default', eager: true }))[0]
|
|
233
|
+
let i = 0;
|
|
234
|
+
for (const layer of [...vixt._layers].reverse()) {
|
|
235
|
+
const pluginsDir = path.resolve(layer.cwd, srcDirName, "plugins");
|
|
236
|
+
const files = fs.existsSync(pluginsDir) ? fs.readdirSync(pluginsDir) : [];
|
|
237
|
+
for (const f of files) {
|
|
238
|
+
const p = path.resolve(pluginsDir, f);
|
|
239
|
+
const pluginName = `__plugin_${i}`;
|
|
240
|
+
pluginsImportTemplate += `import ${pluginName} from '${p}'
|
|
211
241
|
`;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
242
|
+
pluginsMergeTemplate += `${pluginName}, `;
|
|
243
|
+
i++;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const pluginsTemplate = `
|
|
247
|
+
${pluginsImportTemplate}
|
|
248
|
+
const plugins = [${pluginsMergeTemplate}]
|
|
249
|
+
function usePlugins(options) {
|
|
250
|
+
for (const plugin of plugins) {
|
|
251
|
+
typeof plugin === 'function' && plugin(options)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
216
254
|
`;
|
|
217
|
-
|
|
218
|
-
|
|
255
|
+
return pluginsTemplate;
|
|
256
|
+
}
|
|
257
|
+
function getAppComponentPath(vixt) {
|
|
258
|
+
const { srcDirName } = vixt.options;
|
|
259
|
+
for (const layer of vixt._layers) {
|
|
260
|
+
const appComponentPath = path.resolve(layer.cwd, srcDirName, "App.vue");
|
|
261
|
+
if (fs.existsSync(appComponentPath))
|
|
262
|
+
return appComponentPath;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function generateMainTs(options, vixt) {
|
|
266
|
+
const { buildDir, buildDirName, srcDir } = vixt.options;
|
|
267
|
+
const mainTsPath = path.resolve(srcDir, "main.ts");
|
|
268
|
+
if (!fs.existsSync(mainTsPath))
|
|
269
|
+
fs.outputFileSync(mainTsPath, `// Generated by Vixt
|
|
270
|
+
// This file transform from '${buildDirName}/main.ts'
|
|
271
|
+
`);
|
|
272
|
+
const appComponentPath = getAppComponentPath(vixt) || "@vixt/core/client/App.vue";
|
|
273
|
+
const appComponentTemplate = `import App from '${appComponentPath}'`;
|
|
274
|
+
const cssTemplate = options?.css?.map((css) => `import '${css}'`).join("\n") ?? "";
|
|
275
|
+
const appConfigTemplate = generateAppConfig(vixt);
|
|
276
|
+
const pluginsTemplate = generatePlugins(vixt);
|
|
219
277
|
let code = `// Generated by Vixt
|
|
220
278
|
// This file transform to 'src/main.ts'
|
|
221
279
|
// @ts-nocheck
|
|
222
|
-
${
|
|
280
|
+
${appComponentTemplate}
|
|
223
281
|
${cssTemplate}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
${appConfigsImportTemplate}
|
|
227
|
-
${pluginsImportTemplate}
|
|
228
|
-
const appConfig = defu(${appConfigsMergeTemplate}{})
|
|
229
|
-
const plugins = [${pluginsMergeTemplate}].reverse()
|
|
282
|
+
${appConfigTemplate}
|
|
283
|
+
${pluginsTemplate}
|
|
230
284
|
`;
|
|
231
285
|
code = options.transformMain?.(code, vixt) || code;
|
|
232
|
-
fs.outputFileSync(path.resolve(
|
|
286
|
+
fs.outputFileSync(path.resolve(buildDir, "main.ts"), code);
|
|
233
287
|
return code;
|
|
234
288
|
}
|
|
235
289
|
const name$2 = "vixt:app";
|
|
@@ -241,9 +295,8 @@ const defaults$1 = {
|
|
|
241
295
|
head: {
|
|
242
296
|
meta: [
|
|
243
297
|
{ charset: "utf-8" },
|
|
244
|
-
{ name: "viewport", content: "width=device-width, initial-scale=1
|
|
245
|
-
]
|
|
246
|
-
noscript: [{ children: "This website requires JavaScript to function properly. Please enable JavaScript to continue." }]
|
|
298
|
+
{ name: "viewport", content: "width=device-width, initial-scale=1" }
|
|
299
|
+
]
|
|
247
300
|
}
|
|
248
301
|
};
|
|
249
302
|
const app = defineVixtModule({
|
|
@@ -252,6 +305,7 @@ const app = defineVixtModule({
|
|
|
252
305
|
setup(options, vixt) {
|
|
253
306
|
let indexHtmlCode;
|
|
254
307
|
let mainTsCode;
|
|
308
|
+
const mainTsPath = path.resolve(vixt.options.srcDir, "main.ts");
|
|
255
309
|
return {
|
|
256
310
|
name: name$2,
|
|
257
311
|
configResolved() {
|
|
@@ -267,7 +321,7 @@ const app = defineVixtModule({
|
|
|
267
321
|
transform: {
|
|
268
322
|
order: "pre",
|
|
269
323
|
handler(_, id) {
|
|
270
|
-
if (
|
|
324
|
+
if (id !== mainTsPath)
|
|
271
325
|
return;
|
|
272
326
|
return mainTsCode;
|
|
273
327
|
}
|
|
@@ -291,14 +345,14 @@ const config = defineVixtModule({
|
|
|
291
345
|
});
|
|
292
346
|
|
|
293
347
|
function generateTsConfig(options, vixt) {
|
|
294
|
-
const { buildDir
|
|
295
|
-
const codePath = path.resolve(
|
|
348
|
+
const { buildDir } = vixt.options;
|
|
349
|
+
const codePath = path.resolve(buildDir, "tsconfig.json");
|
|
296
350
|
const layersDirs = [];
|
|
297
351
|
const layersAlias = {};
|
|
298
352
|
for (const layer of vixt._layers) {
|
|
299
353
|
layersDirs.push(layer.cwd);
|
|
300
354
|
if (layer.meta?.alias) {
|
|
301
|
-
const layerRelativePath = `./${path.relative(
|
|
355
|
+
const layerRelativePath = `./${path.relative(buildDir, layer.cwd)}/*`;
|
|
302
356
|
layersAlias[`${layer.meta.alias}/*`] = [layerRelativePath];
|
|
303
357
|
}
|
|
304
358
|
}
|
|
@@ -307,13 +361,13 @@ function generateTsConfig(options, vixt) {
|
|
|
307
361
|
fs.outputFileSync(codePath, code);
|
|
308
362
|
}
|
|
309
363
|
function generateVixtDts(options, vixt) {
|
|
310
|
-
const { buildDir
|
|
311
|
-
const codePath = path.resolve(
|
|
364
|
+
const { buildDir } = vixt.options;
|
|
365
|
+
const codePath = path.resolve(buildDir, "vixt.d.ts");
|
|
312
366
|
const code = options.references?.map((reference) => {
|
|
313
367
|
if (typeof reference === "string") {
|
|
314
368
|
return `/// <reference path="${reference}" />`;
|
|
315
369
|
} else if (typeof reference === "object" && reference.path && reference.content) {
|
|
316
|
-
fs.outputFileSync(path.resolve(
|
|
370
|
+
fs.outputFileSync(path.resolve(buildDir, reference.path), reference.content);
|
|
317
371
|
return `/// <reference path="${reference.path}" />`;
|
|
318
372
|
} else {
|
|
319
373
|
return "";
|
|
@@ -322,8 +376,10 @@ function generateVixtDts(options, vixt) {
|
|
|
322
376
|
if (code)
|
|
323
377
|
fs.outputFileSync(codePath, code);
|
|
324
378
|
}
|
|
325
|
-
function
|
|
326
|
-
|
|
379
|
+
function genarateShim(options, vixt) {
|
|
380
|
+
if (!options.shim)
|
|
381
|
+
return;
|
|
382
|
+
const { buildTypesDir } = vixt.options;
|
|
327
383
|
const code = `
|
|
328
384
|
declare module '*.vue' {
|
|
329
385
|
import type { DefineComponent } from 'vue'
|
|
@@ -332,12 +388,12 @@ declare module '*.vue' {
|
|
|
332
388
|
export default component
|
|
333
389
|
}
|
|
334
390
|
`;
|
|
335
|
-
const codePath = path.resolve(
|
|
391
|
+
const codePath = path.resolve(buildTypesDir, "vue-shim.d.ts");
|
|
336
392
|
fs.outputFileSync(codePath, code);
|
|
337
393
|
}
|
|
338
394
|
function genarateGlobalComponents(options, vixt) {
|
|
339
|
-
const { buildTypesDir
|
|
340
|
-
const codePath = path.resolve(
|
|
395
|
+
const { buildTypesDir } = vixt.options;
|
|
396
|
+
const codePath = path.resolve(buildTypesDir, "global-components.d.ts");
|
|
341
397
|
const code = `
|
|
342
398
|
import type { GlobalComponents as _GlobalComponents } from '@vue/runtime-core'
|
|
343
399
|
|
|
@@ -348,8 +404,8 @@ declare module 'vue'{
|
|
|
348
404
|
fs.outputFileSync(codePath, code);
|
|
349
405
|
}
|
|
350
406
|
function generateEnvDts(env, vixt) {
|
|
351
|
-
const { buildTypesDir
|
|
352
|
-
const codePath = path.resolve(
|
|
407
|
+
const { buildTypesDir } = vixt.options;
|
|
408
|
+
const codePath = path.resolve(buildTypesDir, "vite-env.d.ts");
|
|
353
409
|
const values = Object.entries(env).map(([key, value]) => `/** ${key}=${value} */
|
|
354
410
|
${key}: ${typeof value}`).join("\n ");
|
|
355
411
|
const code = `interface ImportMeta {
|
|
@@ -389,7 +445,7 @@ const typescript = defineVixtModule({
|
|
|
389
445
|
configResolved(config) {
|
|
390
446
|
generateTsConfig(options, vixt);
|
|
391
447
|
generateVixtDts(options, vixt);
|
|
392
|
-
|
|
448
|
+
genarateShim(options, vixt);
|
|
393
449
|
genarateGlobalComponents(options, vixt);
|
|
394
450
|
generateEnvDts(config.env, vixt);
|
|
395
451
|
}
|
|
@@ -399,13 +455,24 @@ const typescript = defineVixtModule({
|
|
|
399
455
|
}
|
|
400
456
|
});
|
|
401
457
|
|
|
458
|
+
function loadEnv(mode, envDir, prefixes) {
|
|
459
|
+
const parsedArgv = cac().parse();
|
|
460
|
+
mode = mode || parsedArgv.options.mode || parsedArgv.options.m || env.NODE_ENV;
|
|
461
|
+
return {
|
|
462
|
+
MODE: mode,
|
|
463
|
+
DEV: env.NODE_ENV !== "production",
|
|
464
|
+
PROD: env.NODE_ENV === "production",
|
|
465
|
+
...loadEnv$1(mode, envDir || cwd(), prefixes)
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
|
|
402
469
|
async function loadVixt(opts) {
|
|
403
470
|
const result = await loadVixtConfig(defu(opts, {
|
|
404
471
|
defaults: {
|
|
405
472
|
modules: [alias, app, config, typescript]
|
|
406
473
|
}
|
|
407
474
|
}));
|
|
408
|
-
const layerModules = await applyLayerModules(result.layers);
|
|
475
|
+
const layerModules = await applyLayerModules(result.layers ?? [], result.config);
|
|
409
476
|
const vixt = {
|
|
410
477
|
options: result.config,
|
|
411
478
|
_layers: result.layers ?? [],
|
|
@@ -421,4 +488,4 @@ function createVixtPlugin(loadOptions) {
|
|
|
421
488
|
});
|
|
422
489
|
}
|
|
423
490
|
|
|
424
|
-
export { alias, app, applyLayerModules,
|
|
491
|
+
export { alias, app, applyLayerModules, config, createVixtPlugin, defineVitePlugin, defineVixtConfig, defineVixtModule, installModule, loadEnv, loadVixt, loadVixtConfig, resolveLayersDirs, typescript };
|
|
@@ -29,6 +29,10 @@ interface VixtOptions extends Record<string, any> {
|
|
|
29
29
|
* @default process.cwd()
|
|
30
30
|
*/
|
|
31
31
|
rootDir?: string;
|
|
32
|
+
/**
|
|
33
|
+
* @default '.vixt'
|
|
34
|
+
*/
|
|
35
|
+
buildDirName?: string;
|
|
32
36
|
/**
|
|
33
37
|
* @default '<rootDir>/.vixt'
|
|
34
38
|
*/
|
|
@@ -41,6 +45,14 @@ interface VixtOptions extends Record<string, any> {
|
|
|
41
45
|
* @default '<buildDir>/layers'
|
|
42
46
|
*/
|
|
43
47
|
buildLayersDir?: string;
|
|
48
|
+
/**
|
|
49
|
+
* @default '<buildDir>/imports'
|
|
50
|
+
*/
|
|
51
|
+
buildImportsDir?: string;
|
|
52
|
+
/**
|
|
53
|
+
* @default 'src'
|
|
54
|
+
*/
|
|
55
|
+
srcDirName?: string;
|
|
44
56
|
/**
|
|
45
57
|
* @default '<rootDir>/src'
|
|
46
58
|
*/
|
|
@@ -58,11 +70,9 @@ interface VixtConfigLayerMeta extends ConfigLayerMeta {
|
|
|
58
70
|
name?: string;
|
|
59
71
|
/** layer alias */
|
|
60
72
|
alias?: string;
|
|
61
|
-
/** relative path from `<layer.cwd>/src` to `<rootDir>/src` */
|
|
62
|
-
relative?: string;
|
|
63
73
|
}
|
|
64
74
|
interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
|
|
65
|
-
/** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, change cwd */
|
|
75
|
+
/** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
|
|
66
76
|
cwd?: string;
|
|
67
77
|
}
|
|
68
78
|
interface VixtAppConfig extends Record<string, any> {
|
|
@@ -29,6 +29,10 @@ interface VixtOptions extends Record<string, any> {
|
|
|
29
29
|
* @default process.cwd()
|
|
30
30
|
*/
|
|
31
31
|
rootDir?: string;
|
|
32
|
+
/**
|
|
33
|
+
* @default '.vixt'
|
|
34
|
+
*/
|
|
35
|
+
buildDirName?: string;
|
|
32
36
|
/**
|
|
33
37
|
* @default '<rootDir>/.vixt'
|
|
34
38
|
*/
|
|
@@ -41,6 +45,14 @@ interface VixtOptions extends Record<string, any> {
|
|
|
41
45
|
* @default '<buildDir>/layers'
|
|
42
46
|
*/
|
|
43
47
|
buildLayersDir?: string;
|
|
48
|
+
/**
|
|
49
|
+
* @default '<buildDir>/imports'
|
|
50
|
+
*/
|
|
51
|
+
buildImportsDir?: string;
|
|
52
|
+
/**
|
|
53
|
+
* @default 'src'
|
|
54
|
+
*/
|
|
55
|
+
srcDirName?: string;
|
|
44
56
|
/**
|
|
45
57
|
* @default '<rootDir>/src'
|
|
46
58
|
*/
|
|
@@ -58,11 +70,9 @@ interface VixtConfigLayerMeta extends ConfigLayerMeta {
|
|
|
58
70
|
name?: string;
|
|
59
71
|
/** layer alias */
|
|
60
72
|
alias?: string;
|
|
61
|
-
/** relative path from `<layer.cwd>/src` to `<rootDir>/src` */
|
|
62
|
-
relative?: string;
|
|
63
73
|
}
|
|
64
74
|
interface VixtConfigLayer extends ConfigLayer<VixtOptions, VixtConfigLayerMeta> {
|
|
65
|
-
/** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, change cwd */
|
|
75
|
+
/** when layer is in node_modules, layer will copy to `<buildLayersDir>/<layerName>`, and change cwd */
|
|
66
76
|
cwd?: string;
|
|
67
77
|
}
|
|
68
78
|
interface VixtAppConfig extends Record<string, any> {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vixt/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.11",
|
|
5
5
|
"author": "SoulLyoko<https://github.com/SoulLyoko>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/SoulLyoko/vixt#readme",
|
|
@@ -14,6 +14,9 @@
|
|
|
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"
|
|
17
20
|
}
|
|
18
21
|
},
|
|
19
22
|
"main": "dist/index.mjs",
|
|
@@ -25,15 +28,16 @@
|
|
|
25
28
|
"@types/fs-extra": "11.0.4",
|
|
26
29
|
"@vue/tsconfig": "^0.5.1",
|
|
27
30
|
"c12": "^1.11.1",
|
|
31
|
+
"cac": "^6.7.14",
|
|
28
32
|
"defu": "^6.1.4",
|
|
29
33
|
"fs-extra": "^11.2.0",
|
|
30
34
|
"mlly": "1.7.1",
|
|
31
35
|
"pathe": "^1.1.2",
|
|
32
36
|
"pkg-types": "^1.1.3",
|
|
33
|
-
"tsx": "^4.
|
|
34
|
-
"vite": "^5.4.
|
|
37
|
+
"tsx": "^4.17.0",
|
|
38
|
+
"vite": "^5.4.1",
|
|
35
39
|
"vite-plugin-checker": "^0.7.2",
|
|
36
|
-
"vue-tsc": "
|
|
40
|
+
"vue-tsc": "2.0.26"
|
|
37
41
|
},
|
|
38
42
|
"scripts": {
|
|
39
43
|
"build": "unbuild"
|