wyt-cli 1.0.16 → 1.0.18

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.
@@ -30,7 +30,7 @@ export default function () {
30
30
  type: 'rawlist',
31
31
  name: 'runstyle',
32
32
  message: `请选择项目运行方式:` + getInquirerOperationText('list'),
33
- default: 1,
33
+ default: 0,
34
34
  choices: [
35
35
  { name: '方式1:运行所有项目', value: 0 },
36
36
  { name: '方式2:运行指定项目', value: 1 },
@@ -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
  })),
@@ -62,28 +62,79 @@ export default function () {
62
62
  }
63
63
 
64
64
  // 运行项目
65
- function runProject(projects = [], appsDir) {
66
- projects.forEach((project) => {
65
+ async function runProject(projects = [], appsDir) {
66
+ // 更新 packages 最新版本
67
+ log_info(`🔄 检查并更新 packages 最新版本...`);
68
+ await execa('pnpm', ['install'], {
69
+ cwd: process.cwd(),
70
+ stdio: 'inherit',
71
+ });
72
+
73
+ // 运行命令
74
+ const command = 'npm run dev';
75
+ const commandEnv = {
76
+ ...process.env,
77
+ NODE_ENV: 'development',
78
+ PROJECT_RUN_MODE: 'wyt-cli',
79
+ };
80
+
81
+ // 运行项目文档
82
+ log_info(`🚀 启动项目文档...`);
83
+ const docsPath = path.join(process.cwd(), 'docs');
84
+ const docsProcess = execa(command, {
85
+ cwd: docsPath,
86
+ stdio: 'inherit',
87
+ env: commandEnv,
88
+ });
89
+ docsProcess.on('exit', (code) => {
90
+ if (code !== 0) log_error(`项目文档异常退出 (CODE: ${code})`);
91
+ });
92
+
93
+ // 运行项目
94
+ const configPath = path.join(process.cwd(), 'project.json');
95
+ let config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
96
+ if (config.apps) {
97
+ // 初始化
98
+ config.apps.forEach((app, index) => {
99
+ config.apps[index] = {
100
+ ...app,
101
+ lastRun: false,
102
+ };
103
+ });
104
+ }
105
+ projects.forEach(async (project) => {
67
106
  const projectName = project.name;
68
107
  if (projectName) {
69
108
  const projectPath = path.join(appsDir, projectName);
70
109
  if (!fs.existsSync(projectPath)) {
71
110
  throw new Error(`项目 ${projectName} 不存在`);
72
111
  }
73
- // 准备运行命令
74
- const command = 'npm run dev';
112
+
75
113
  // 执行命令
76
114
  log_info(`🚀 启动项目 ${projectName}...`);
115
+ // 更新项目启动状态
116
+ const targetIndex = config.apps.findIndex((app) => app.name === projectName);
117
+ if (targetIndex !== -1) {
118
+ config.apps[targetIndex].lastRun = true;
119
+ }
120
+
77
121
  const subprocess = execa(command, {
78
122
  cwd: projectPath,
79
123
  stdio: 'inherit',
80
- env: {
81
- NODE_ENV: 'development',
82
- },
124
+ env: commandEnv,
125
+ });
126
+
127
+ // 新增信号处理逻辑
128
+ process.on('SIGINT', () => {
129
+ log_info('正在优雅关闭进程...');
130
+ subprocess.kill('SIGINT'); // 杀死子进程
131
+ process.exit(0); // 退出父进程
83
132
  });
84
133
  subprocess.on('exit', (code) => {
85
134
  if (code !== 0) log_error(`项目 ${projectName} 异常退出 (CODE: ${code})`);
86
135
  });
87
136
  }
88
137
  });
138
+
139
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
89
140
  }
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';
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "version": "1.0.0",
5
5
  "type": "module",
6
- "description": "个人工作台",
6
+ "description": "",
7
7
  "devServer": {
8
8
  "port": "<%= devServerPort %>"
9
9
  },
@@ -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
  }
@@ -6,7 +6,7 @@ const projectConfig = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), '..
6
6
  const ProxyURL = projectConfig.apiUrl || 'https://hrp3.wytdev.com';
7
7
 
8
8
  export default defineConfig({
9
- base: './',
9
+ base: process.env.NODE_ENV == 'development' ? './' : '/<%= projectName %>',
10
10
  build: {
11
11
  outDir: '<%= buildOutDir %>',
12
12
  emptyOutDir: true, // 清空输出目录
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wyt-cli",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "HRP3.0 项目命令行工具",
5
5
  "main": "index.js",
6
6
  "bin": {