wyt-cli 1.0.17 → 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
  // 自动生成路由
@@ -42,7 +42,7 @@ export default function () {
42
42
  message: '请选择要运行的项目:' + getInquirerOperationText('checkbox'),
43
43
  when: (answers) => answers.runstyle == 1,
44
44
  choices: projects.map((p) => ({
45
- checked: p.name === 'core' || p.name === 'mw',
45
+ checked: p.name === 'core',
46
46
  name: `${p.name} (端口号: ${p.port || '未配置'})`,
47
47
  value: p,
48
48
  })),
@@ -72,12 +72,19 @@ async function runProject(projects = [], appsDir) {
72
72
 
73
73
  // 运行命令
74
74
  const command = 'npm run dev';
75
+ const commandEnv = {
76
+ ...process.env,
77
+ NODE_ENV: 'development',
78
+ PROJECT_RUN_MODE: 'wyt-cli',
79
+ };
80
+
75
81
  // 运行项目文档
76
82
  log_info(`🚀 启动项目文档...`);
77
83
  const docsPath = path.join(process.cwd(), 'docs');
78
84
  const docsProcess = execa(command, {
79
85
  cwd: docsPath,
80
86
  stdio: 'inherit',
87
+ env: commandEnv,
81
88
  });
82
89
  docsProcess.on('exit', (code) => {
83
90
  if (code !== 0) log_error(`项目文档异常退出 (CODE: ${code})`);
@@ -114,9 +121,14 @@ async function runProject(projects = [], appsDir) {
114
121
  const subprocess = execa(command, {
115
122
  cwd: projectPath,
116
123
  stdio: 'inherit',
117
- env: {
118
- NODE_ENV: 'development',
119
- },
124
+ env: commandEnv,
125
+ });
126
+
127
+ // 新增信号处理逻辑
128
+ process.on('SIGINT', () => {
129
+ log_info('正在优雅关闭进程...');
130
+ subprocess.kill('SIGINT'); // 杀死子进程
131
+ process.exit(0); // 退出父进程
120
132
  });
121
133
  subprocess.on('exit', (code) => {
122
134
  if (code !== 0) log_error(`项目 ${projectName} 异常退出 (CODE: ${code})`);
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';
@@ -13,19 +13,19 @@
13
13
  "preview": "vite preview"
14
14
  },
15
15
  "dependencies": {
16
- "@element-plus/icons-vue": "^2.3.1",
16
+ "@element-plus/icons-vue": "catalog:",
17
17
  "@wyt/components": "workspace:^",
18
18
  "@wyt/utils": "workspace:^",
19
- "element-plus": "^2.10.2",
20
- "pinia": "^2.0.28",
21
- "sass": "^1.89.2",
22
- "vue": "^3.5.13",
23
- "vue-router": "^4.5.0",
24
- "wujie-polyfill": "^1.1.3",
25
- "wujie-vue3": "^1.0.24"
19
+ "element-plus": "catalog:",
20
+ "pinia": "catalog:",
21
+ "sass": "catalog:",
22
+ "vue": "catalog:",
23
+ "vue-router": "catalog:",
24
+ "wujie-polyfill": "catalog:",
25
+ "wujie-vue3": "catalog:"
26
26
  },
27
27
  "devDependencies": {
28
- "@vitejs/plugin-vue": "^5.2.1",
29
- "vite": "^6.0.5"
28
+ "@vitejs/plugin-vue": "catalog:",
29
+ "vite": "catalog:"
30
30
  }
31
31
  }
@@ -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.17",
3
+ "version": "1.0.19",
4
4
  "description": "HRP3.0 项目命令行工具",
5
5
  "main": "index.js",
6
6
  "bin": {