hlq-cli 1.0.0

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.
Files changed (88) hide show
  1. package/README.md +18 -0
  2. package/bin/index.js +16 -0
  3. package/lib/aesCreate.js +11 -0
  4. package/lib/axiosCreate.js +11 -0
  5. package/lib/create.js +172 -0
  6. package/lib/echartCreate.js +12 -0
  7. package/lib/jwtDecodeCreate.js +16 -0
  8. package/lib/rsaCreate.js +11 -0
  9. package/lib/stateCreate.js +34 -0
  10. package/lib/websocketCreate.js +16 -0
  11. package/package.json +21 -0
  12. package/templates/.env +1 -0
  13. package/templates/.env.dev +2 -0
  14. package/templates/.env.pro +2 -0
  15. package/templates/index.html +15 -0
  16. package/templates/package-lock.json +4058 -0
  17. package/templates/package.json +31 -0
  18. package/templates/public/config.js +1 -0
  19. package/templates/public/font/iconfont.css +579 -0
  20. package/templates/public/font/iconfont.js +1 -0
  21. package/templates/public/font/iconfont.ttf +0 -0
  22. package/templates/public/font/iconfont.woff +0 -0
  23. package/templates/public/font/iconfont.woff2 +0 -0
  24. package/templates/src/App.vue +35 -0
  25. package/templates/src/components/chart/barChart.vue +103 -0
  26. package/templates/src/components/chart/color.ts +43 -0
  27. package/templates/src/components/chart/lineChart.vue +114 -0
  28. package/templates/src/components/chart/mapChart.vue +135 -0
  29. package/templates/src/components/chart/mixedChart.vue +148 -0
  30. package/templates/src/components/chart/pieChart.vue +104 -0
  31. package/templates/src/components/chart/radarChart.vue +112 -0
  32. package/templates/src/components/chart/scatterChart.vue +144 -0
  33. package/templates/src/components/chart/sunburstChart.vue +183 -0
  34. package/templates/src/components/descript/index.vue +45 -0
  35. package/templates/src/components/dialog/index.vue +54 -0
  36. package/templates/src/components/drawer/index.vue +53 -0
  37. package/templates/src/components/form/component/cascader.vue +65 -0
  38. package/templates/src/components/form/component/checkbox.vue +31 -0
  39. package/templates/src/components/form/component/datePicker.vue +39 -0
  40. package/templates/src/components/form/component/dateRange.vue +36 -0
  41. package/templates/src/components/form/component/datetimePicker.vue +25 -0
  42. package/templates/src/components/form/component/fileUpload.vue +80 -0
  43. package/templates/src/components/form/component/formFun.ts +132 -0
  44. package/templates/src/components/form/component/imageUpload.vue +92 -0
  45. package/templates/src/components/form/component/input.vue +41 -0
  46. package/templates/src/components/form/component/location.vue +79 -0
  47. package/templates/src/components/form/component/radio.vue +31 -0
  48. package/templates/src/components/form/component/select.vue +66 -0
  49. package/templates/src/components/form/component/textarea.vue +26 -0
  50. package/templates/src/components/form/component/timePicker.vue +28 -0
  51. package/templates/src/components/form/component/upload.ts +20 -0
  52. package/templates/src/components/form/formInterface.ts +115 -0
  53. package/templates/src/components/form/index.vue +193 -0
  54. package/templates/src/components/form/item.vue +323 -0
  55. package/templates/src/components/groupForm/index.vue +91 -0
  56. package/templates/src/components/icon/index.vue +29 -0
  57. package/templates/src/components/layout/header.vue +238 -0
  58. package/templates/src/components/layout/index.vue +167 -0
  59. package/templates/src/components/layout/menu.vue +130 -0
  60. package/templates/src/components/layout/sideBarItem.vue +49 -0
  61. package/templates/src/components/searchBox/height.ts +9 -0
  62. package/templates/src/components/searchBox/index.vue +265 -0
  63. package/templates/src/components/table/index.vue +371 -0
  64. package/templates/src/components/table/table.ts +23 -0
  65. package/templates/src/components/tree/index.vue +222 -0
  66. package/templates/src/components/tree/lazyTree.vue +136 -0
  67. package/templates/src/data.d.ts +4 -0
  68. package/templates/src/main.ts +18 -0
  69. package/templates/src/router/index.ts +60 -0
  70. package/templates/src/store/menuInterface.ts +10 -0
  71. package/templates/src/store/permission.ts +59 -0
  72. package/templates/src/store/user.ts +24 -0
  73. package/templates/src/utils/alioss/index.ts +0 -0
  74. package/templates/src/utils/axios/http.ts +99 -0
  75. package/templates/src/utils/axios/index.ts +112 -0
  76. package/templates/src/utils/axios/service.ts +8 -0
  77. package/templates/src/utils/crypto/index.ts +28 -0
  78. package/templates/src/utils/rsa/index.ts +18 -0
  79. package/templates/src/utils/token/index.ts +6 -0
  80. package/templates/src/utils/tree/index.ts +74 -0
  81. package/templates/src/utils/websocket/index.ts +136 -0
  82. package/templates/src/views/login/index.vue +248 -0
  83. package/templates/src/views/templete/table.vue +122 -0
  84. package/templates/src/views/templete/tableConfig.ts +153 -0
  85. package/templates/tsconfig.app.json +19 -0
  86. package/templates/tsconfig.json +7 -0
  87. package/templates/tsconfig.node.json +23 -0
  88. package/templates/vite.config.ts +34 -0
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # vueNpmCLi
2
+
3
+ #### 介绍
4
+ 自定义vue脚手架
5
+
6
+ #### 软件架构
7
+ 软件架构说明
8
+
9
+
10
+ #### 安装教程
11
+
12
+ npm i
13
+ npm link
14
+ hlq-cli create my-project
15
+
16
+ #### 使用说明
17
+
18
+
package/bin/index.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { program } = require('commander')
4
+ const create = require('../lib/create')
5
+
6
+ // 定义 create 命令,<project-name> 是必需参数
7
+ program
8
+ .command('create <project-name>')
9
+ .description('创建一个新项目')
10
+ .action((projectName) => {
11
+ // 执行创建逻辑,将项目名传过去
12
+ create(projectName)
13
+ })
14
+
15
+ // 解析用户输入的命令行参数
16
+ program.parse(process.argv)
@@ -0,0 +1,11 @@
1
+ const path = require('path')
2
+ async function aesCreate(isAesUse, packageJsonContent, targetDir, fs) {
3
+ if (isAesUse) {
4
+ packageJsonContent.dependencies['crypto-js'] = '^4.2.0'
5
+ } else {
6
+ const aesDir = path.join(targetDir, 'src/utils/crypto.ts')
7
+ await fs.remove(aesDir)
8
+ console.log(`已移除文件 ${aesDir}`)
9
+ }
10
+ }
11
+ module.exports = aesCreate
@@ -0,0 +1,11 @@
1
+ const path = require('path')
2
+ async function axiosCreate(isAxiosUse, packageJsonContent, targetDir, fs) {
3
+ if (isAxiosUse) {
4
+ packageJsonContent.dependencies['axios'] = '^1.8.1'
5
+ } else {
6
+ const axiosDir = path.join(targetDir, 'src/utils/request.ts')
7
+ await fs.remove(axiosDir)
8
+ console.log(`已移除文件 ${axiosDir}`)
9
+ }
10
+ }
11
+ module.exports = axiosCreate
package/lib/create.js ADDED
@@ -0,0 +1,172 @@
1
+ const path = require('path')
2
+ const fs = require('fs-extra') // fs 的增强版,更方便
3
+ const inquirer = require('inquirer')
4
+ const { execSync } = require('child_process') // 用于自动安装依赖
5
+ const stateCreate = require('./stateCreate') // 引入 stateCreate 函数,用于创建状态管理
6
+ const echartCreate = require('./echartCreate') // 引入 echartCreate 函数,用于创建echart插件
7
+ const websocketCreate = require('./websocketCreate') // 引入 websocketCreate 函数,用于创建websocket插件函数
8
+ const aesCreate = require('./aesCreate') // 引入 aesCreate 函数,用于创建AES加密插件
9
+ const rsaCreate = require('./rsaCreate') // 引入 rsaCreate 函数,用于创建rsa加密插件
10
+ const jwtDecodeCreate = require('./jwtDecodeCreate') // 引入 jwtDecodeCreate 函数,用于创建jwt解析插件
11
+ const axiosCreate = require('./axiosCreate') // 引入 axiosCreate 函数,用于创建axios插件函数
12
+
13
+ const pluginsUse = async (plugins, packageJsonContent, targetDir, fs) => {
14
+ // 是否需要echart插件
15
+ const isEchartUse = plugins.includes('echarts')
16
+ try {
17
+ await echartCreate(isEchartUse, packageJsonContent, targetDir, fs)
18
+ } catch (error) {
19
+ console.error('处理echart插件失败:', error)
20
+ }
21
+ // 是否需要websocket插件
22
+ const isWebSocketUse = plugins.includes('websocket')
23
+ try {
24
+ await websocketCreate(isWebSocketUse, packageJsonContent, targetDir, fs)
25
+ } catch (error) {
26
+ console.error('处理websocket插件失败:', error)
27
+ }
28
+ // 是否需要AES加密插件
29
+ const isAesUse = plugins.includes('aes')
30
+ try {
31
+ await aesCreate(isAesUse, packageJsonContent, targetDir, fs)
32
+ } catch (error) {
33
+ console.error('处理AES加密插件失败:', error)
34
+ }
35
+ // 是否需要rsa加密插件
36
+ const isRsaUse = plugins.includes('rsa')
37
+ try {
38
+ await rsaCreate(isRsaUse, packageJsonContent, targetDir, fs)
39
+ } catch (error) {
40
+ console.error('处理rsa加密插件失败:', error)
41
+ }
42
+ // 是否需要jwt解析插件
43
+ const isJwtDecodeUse = plugins.includes('jwt-decode')
44
+ try {
45
+ await jwtDecodeCreate(isJwtDecodeUse, packageJsonContent, targetDir, fs)
46
+ } catch (error) {
47
+ console.error('处理jwt解析插件失败:', error)
48
+ }
49
+ // 是否需要axios插件
50
+ const isAxiosUse = plugins.includes('axios')
51
+ try {
52
+ await axiosCreate(isAxiosUse, packageJsonContent, targetDir, fs)
53
+ } catch (error) {
54
+ console.error('处理axios插件失败:', error)
55
+ }
56
+ }
57
+
58
+ module.exports = async (projectName) => {
59
+ // 输入密码
60
+ const { password } = await inquirer.prompt([
61
+ {
62
+ name: 'password',
63
+ type: 'password',
64
+ message: '请输入密码:',
65
+ },
66
+ ])
67
+ if (password !== 'qweasd') {
68
+ console.log('密码错误')
69
+ process.exit(1)
70
+ }
71
+
72
+ // 1. 获取目标路径
73
+ const targetDir = path.join(process.cwd(), projectName)
74
+
75
+ // 2. 检查同名文件夹是否存在,并询问是否覆盖
76
+ if (fs.existsSync(targetDir)) {
77
+ const { isOverwrite } = await inquirer.prompt([
78
+ {
79
+ name: 'isOverwrite',
80
+ type: 'confirm',
81
+ message: `目录 ${projectName} 已存在,是否覆盖?`,
82
+ default: false,
83
+ },
84
+ ])
85
+ if (isOverwrite) {
86
+ await fs.remove(targetDir)
87
+ console.log(`已移除旧目录 ${projectName}`)
88
+ } else {
89
+ console.log('操作已取消')
90
+ return
91
+ }
92
+ }
93
+
94
+ // 3. 定义模板路径 (这里使用了固定的模板,你可以根据inquirer的选择来动态配置)
95
+ const templateDir = path.join(__dirname, '../templates')
96
+
97
+ // 4. 复制模板文件到目标路径
98
+ console.log('正在拷贝项目模板...')
99
+ await fs.copy(templateDir, targetDir)
100
+ console.log('模板拷贝完成')
101
+
102
+ // 5. 处理模板中的动态内容,例如 package.json
103
+ const targetPackageJsonPath = path.join(targetDir, 'package.json')
104
+ const packageJsonContent = await fs.readJson(targetPackageJsonPath)
105
+ // 替换项目名称
106
+ packageJsonContent.name = projectName
107
+ // 状态管理插件
108
+ const { stateUse, plugins } = await inquirer.prompt([
109
+ {
110
+ name: 'stateUse',
111
+ type: 'list',
112
+ message: '选择状态管理方案:',
113
+ choices: [
114
+ { name: 'Pinia(推荐)', value: 'pinia' },
115
+ { name: 'Vuex', value: 'vuex' },
116
+ { name: '不使用状态管理', value: 'none' },
117
+ ],
118
+ default: 'pinia', // 默认选中
119
+ },
120
+ {
121
+ name: 'plugins',
122
+ type: 'checkbox',
123
+ message: '请选择需要安装的插件:',
124
+ choices: [
125
+ { name: 'ECharts 图表库', value: 'echarts', checked: false },
126
+ { name: 'WebSocket 实时通信', value: 'websocket', checked: false },
127
+ { name: 'Axios HTTP请求', value: 'axios', checked: false },
128
+ { name: 'token解析', value: 'jwt-decode', checked: false },
129
+ { name: 'rsa加密', value: 'rsa', checked: false },
130
+ { name: 'AES加密', value: 'aes', checked: false },
131
+ ],
132
+ pageSize: 30, // 可选:每页显示的选项数量
133
+ },
134
+ ])
135
+ try {
136
+ await stateCreate(stateUse, packageJsonContent, targetDir, fs)
137
+ } catch (error) {
138
+ console.error('处理状态管理插件失败:', error)
139
+ }
140
+ try {
141
+ await pluginsUse(plugins, packageJsonContent, targetDir, fs)
142
+ } catch (error) {
143
+ console.error('处理插件失败:', error)
144
+ }
145
+ // 你可以在这里替换或添加更多配置,比如 version, description 等
146
+ await fs.writeJson(targetPackageJsonPath, packageJsonContent, { spaces: 2 })
147
+ console.log('项目配置已更新')
148
+
149
+ // 6. 可选:自动安装依赖
150
+ const { shouldInstall } = await inquirer.prompt([
151
+ {
152
+ name: 'shouldInstall',
153
+ type: 'confirm',
154
+ message: '是否自动安装项目依赖?',
155
+ default: false,
156
+ },
157
+ ])
158
+
159
+ if (shouldInstall) {
160
+ console.log('正在安装依赖,请稍候...')
161
+ execSync('npm install', { cwd: targetDir, stdio: 'inherit' })
162
+ console.log('依赖安装完成')
163
+ }
164
+
165
+ // 7. 输出成功信息和后续指引
166
+ console.log(`
167
+ ✨ 项目创建成功!
168
+ 👉 请执行以下命令开始:
169
+ cd ${projectName}
170
+ npm run dev
171
+ `)
172
+ }
@@ -0,0 +1,12 @@
1
+ const path = require('path')
2
+ async function echartCreate(isEchartUse, packageJsonContent, targetDir, fs) {
3
+ if (isEchartUse) {
4
+ packageJsonContent.dependencies['echarts'] = '^6.0.0'
5
+ } else {
6
+ //删除targetDir/src/components/chart文件夹
7
+ const chartDir = path.join(targetDir, 'src/components/chart')
8
+ await fs.remove(chartDir)
9
+ console.log(`已移除目录 ${chartDir}`)
10
+ }
11
+ }
12
+ module.exports = echartCreate
@@ -0,0 +1,16 @@
1
+ const path = require('path')
2
+ async function jwtDecodeCreate(
3
+ isJwtDecodeUse,
4
+ packageJsonContent,
5
+ targetDir,
6
+ fs,
7
+ ) {
8
+ if (isJwtDecodeUse) {
9
+ packageJsonContent.dependencies['jwt-decode'] = '^4.0.0'
10
+ } else {
11
+ const jwtDecodeDir = path.join(targetDir, 'src/utils/token.ts')
12
+ await fs.remove(jwtDecodeDir)
13
+ console.log(`已移除文件 ${jwtDecodeDir}`)
14
+ }
15
+ }
16
+ module.exports = jwtDecodeCreate
@@ -0,0 +1,11 @@
1
+ const path = require('path')
2
+ async function rsaCreate(isRsaUse, packageJsonContent, targetDir, fs) {
3
+ if (isRsaUse) {
4
+ packageJsonContent.dependencies['jsencrypt'] = '^3.3.2'
5
+ } else {
6
+ const rsaDir = path.join(targetDir, 'src/utils/rsa.ts')
7
+ await fs.remove(rsaDir)
8
+ console.log(`已移除文件 ${rsaDir}`)
9
+ }
10
+ }
11
+ module.exports = rsaCreate
@@ -0,0 +1,34 @@
1
+ const path = require('path')
2
+ async function stateCreate(stateUse, packageJsonContent, targetDir, fs) {
3
+ if (stateUse === 'pinia') {
4
+ packageJsonContent.dependencies['pinia'] = '^3.0.1'
5
+ packageJsonContent.dependencies['pinia-plugin-persistedstate'] = '^4.2.0'
6
+ // 修改main.ts引入pinia插件
7
+ const mainTsPath = path.join(targetDir, 'src/main.ts')
8
+ let mainTsContent = await fs.readFile(mainTsPath, 'utf-8')
9
+ const piniaPluginImport = `import { createPinia } from "pinia";
10
+ import { createPersistedState } from "pinia-plugin-persistedstate";`
11
+ const piniaPluginUse = `const pinia = createPinia()
12
+ pinia.use(
13
+ createPersistedState({
14
+ storage: localStorage,
15
+ auto: true,
16
+ }),
17
+ )`
18
+ const piniaPluginMount = `app.use(pinia)`
19
+ mainTsContent = mainTsContent.replace(
20
+ /import App from '.\/App.vue'/,
21
+ `import App from './App.vue'\n${piniaPluginImport}`,
22
+ )
23
+ mainTsContent = mainTsContent.replace(
24
+ /const app = createApp\(App\)/,
25
+ `${piniaPluginUse}\nconst app = createApp(App)`,
26
+ )
27
+ mainTsContent = mainTsContent.replace(
28
+ /const app = createApp\(App\)/,
29
+ `const app = createApp(App)\n${piniaPluginMount}`,
30
+ )
31
+ await fs.writeFile(mainTsPath, mainTsContent)
32
+ }
33
+ }
34
+ module.exports = stateCreate
@@ -0,0 +1,16 @@
1
+ const path = require('path')
2
+ async function websocketCreate(
3
+ isWebSocketUse,
4
+ packageJsonContent,
5
+ targetDir,
6
+ fs,
7
+ ) {
8
+ if (isWebSocketUse) {
9
+ } else {
10
+ //删除targetDir/src/utils/socket.ts文件
11
+ const socketDir = path.join(targetDir, 'src/utils/socket.ts')
12
+ await fs.remove(socketDir)
13
+ console.log(`已移除文件 ${socketDir}`)
14
+ }
15
+ }
16
+ module.exports = websocketCreate
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "hlq-cli",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "bin": {
10
+ "hlq-cli": "bin/index.js"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "type": "commonjs",
16
+ "dependencies": {
17
+ "commander": "^15.0.0",
18
+ "fs-extra": "^11.3.5",
19
+ "inquirer": "^8.2.6"
20
+ }
21
+ }
package/templates/.env ADDED
@@ -0,0 +1 @@
1
+ VITE_BASE_URL='/ability-platform'
@@ -0,0 +1,2 @@
1
+ NODE_ENV='dev'
2
+ VITE_BASE_URL='/ability-platform'
@@ -0,0 +1,2 @@
1
+ NODE_ENV='pro'
2
+ VITE_BASE_URL='/ability-platform'
@@ -0,0 +1,15 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>{title}</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script src="/config.js"></script>
12
+ <script type="module" src="/src/main.ts"></script>
13
+ <script src="/font/iconfont.js"></script>
14
+ </body>
15
+ </html>