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.
package/bin/commands/create.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// commands/create.js
|
|
2
2
|
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { log_error,
|
|
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
|
-
|
|
70
|
-
|
|
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,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 = [
|