wyt-cli 1.0.18 → 1.0.19
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/bin/commands/create.js
CHANGED
|
@@ -114,8 +114,30 @@ async function createProject(projectName, options) {
|
|
|
114
114
|
// 更新 root -> project.json -> apps 配置
|
|
115
115
|
await updateRootProjectJson(projectName, options);
|
|
116
116
|
|
|
117
|
-
//
|
|
117
|
+
// 自动生成路由文件
|
|
118
118
|
generateRouteStructure(projectName, routeConfig);
|
|
119
|
+
|
|
120
|
+
// 自动生成路由配置文件 src/router/router-list.json
|
|
121
|
+
generateRouterList(projectName, routeConfig);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function generateRouterList(projectName, routeConfig) {
|
|
125
|
+
const filePath = path.join(path.resolve(process.cwd(), 'apps', projectName, 'src', 'router'), 'router-list.json');
|
|
126
|
+
const fileContent = {
|
|
127
|
+
defaultRoutes: routeConfig.map((item) => {
|
|
128
|
+
return {
|
|
129
|
+
name: item.name,
|
|
130
|
+
path: `/${item.path}`,
|
|
131
|
+
component: item.component.replace('@', '/src'),
|
|
132
|
+
};
|
|
133
|
+
}),
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// 确保目标目录存在
|
|
137
|
+
fs.ensureDirSync(path.dirname(filePath));
|
|
138
|
+
|
|
139
|
+
// 写入路由配置文件
|
|
140
|
+
fs.writeJSONSync(filePath, fileContent);
|
|
119
141
|
}
|
|
120
142
|
|
|
121
143
|
// 自动生成路由
|
package/bin/main.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createRouter, createWebHashHistory } from 'vue-router';
|
|
2
|
+
import { defaultRoutes } from './router-list.json';
|
|
2
3
|
const basename = process.env.NODE_ENV === 'production' ? '/<%= projectName %>/' : '';
|
|
3
4
|
|
|
4
|
-
let autoRoutes = `<%- JSON.stringify(routeConfig) %>`;
|
|
5
|
-
autoRoutes =
|
|
5
|
+
// let autoRoutes = `<%- JSON.stringify(routeConfig) %>`;
|
|
6
|
+
const autoRoutes = defaultRoutes.map((item) => {
|
|
6
7
|
return {
|
|
7
8
|
...item,
|
|
8
|
-
|
|
9
|
-
component: () => import(/* @vite-ignore */ item.component.replace('@', '/src')),
|
|
9
|
+
component: () => import(/* @vite-ignore */ item.component),
|
|
10
10
|
};
|
|
11
11
|
});
|
|
12
12
|
const routes = [
|