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.
@@ -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,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  import { require } from './lib/utils.js';
3
3
  import { LOWEST_NODE_VERSION } from './lib/const.js';
4
4
  import { log_error, log_warning } from './lib/logger.js';
@@ -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 = JSON.parse(autoRoutes).map((item) => {
5
+ // let autoRoutes = `<%- JSON.stringify(routeConfig) %>`;
6
+ const autoRoutes = defaultRoutes.map((item) => {
6
7
  return {
7
8
  ...item,
8
- path: `/${item.path}`,
9
- component: () => import(/* @vite-ignore */ item.component.replace('@', '/src')),
9
+ component: () => import(/* @vite-ignore */ item.component),
10
10
  };
11
11
  });
12
12
  const routes = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wyt-cli",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "HRP3.0 项目命令行工具",
5
5
  "main": "index.js",
6
6
  "bin": {