wyt-cli 1.0.18 → 1.0.20

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.
@@ -1,7 +1,7 @@
1
1
  // commands/create.js
2
2
 
3
3
  import path from 'path';
4
- import { log_error, log_success, getPlainText, getInquirerOperationText } from '../lib/logger.js';
4
+ import { log_error, getInquirerOperationText } from '../lib/logger.js';
5
5
 
6
6
  // 外部依赖
7
7
  import { Command } from 'commander';
@@ -10,6 +10,7 @@ import { glob } from 'glob';
10
10
  import fs from 'fs-extra';
11
11
  // import ora from 'ora';
12
12
  import inquirer from 'inquirer';
13
+ import chalk from 'chalk';
13
14
  import ejs from 'ejs';
14
15
  import { checkTargetDir, getModuleMenuConfig, getProjectConfig } from '../lib/dir.js';
15
16
 
@@ -66,8 +67,14 @@ async function createProjectAction(projectName, options) {
66
67
 
67
68
  // 创建项目模版
68
69
  await createProject(projectName, options);
69
- log_success(
70
- `项目 ${projectName} 创建成功!\n\n${getPlainText('项目运行步骤:\n1. 请自行安装依赖 pnpm i\n2. 启动测试服务器 pnpm run dev')}\n\n`
70
+ console.log(
71
+ `\n\n${chalk.bgGreen.black(' 项目创建成功 ')} ${chalk.greenBright(projectName)}\n\n` +
72
+ `${chalk.cyan.bold('━━━━ 运行步骤 ━━━━')}\n` +
73
+ `${chalk.blue('1. 安装依赖')} ${chalk.yellow('pnpm install')}\n` +
74
+ `${chalk.blue('2. 启动开发服务器')} ${chalk.yellow('wyt-cli run')}\n\n` +
75
+ `${chalk.hex('#FFA500').bold('💡 注意事项:')}\n` +
76
+ `• 确保本地 ${chalk.yellow('Node.js >= 16.0 && pnpm 7.x+')} 版本\n` +
77
+ `• 建议使用 ${chalk.yellow('wyt-cli')} 命令行工具\n`
71
78
  );
72
79
  } catch (error) {
73
80
  log_error(error.message);
@@ -114,8 +121,30 @@ async function createProject(projectName, options) {
114
121
  // 更新 root -> project.json -> apps 配置
115
122
  await updateRootProjectJson(projectName, options);
116
123
 
117
- // 自动生成路由
124
+ // 自动生成路由文件
118
125
  generateRouteStructure(projectName, routeConfig);
126
+
127
+ // 自动生成路由配置文件 src/router/router-list.json
128
+ generateRouterList(projectName, routeConfig);
129
+ }
130
+
131
+ function generateRouterList(projectName, routeConfig) {
132
+ const filePath = path.join(path.resolve(process.cwd(), 'apps', projectName, 'src', 'router'), 'router-list.json');
133
+ const fileContent = {
134
+ defaultRoutes: routeConfig.map((item) => {
135
+ return {
136
+ name: item.name,
137
+ path: `/${item.path}`,
138
+ component: item.component.replace('@', '/src'),
139
+ };
140
+ }),
141
+ };
142
+
143
+ // 确保目标目录存在
144
+ fs.ensureDirSync(path.dirname(filePath));
145
+
146
+ // 写入路由配置文件
147
+ fs.writeJSONSync(filePath, fileContent);
119
148
  }
120
149
 
121
150
  // 自动生成路由
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.20",
4
4
  "description": "HRP3.0 项目命令行工具",
5
5
  "main": "index.js",
6
6
  "bin": {