@gx-design-vue/create-gx-cli 0.1.12 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. package/bin/create-gx-cli +3 -2
  2. package/package.json +4 -4
  3. package/src/cli.js +9 -7
  4. package/src/git.js +8 -5
  5. package/src/main.js +29 -16
  6. package/template-mobile-vant-cli/package.json +5 -5
  7. package/template-gx-design-thin/.editorconfig +0 -19
  8. package/template-gx-design-thin/.env +0 -4
  9. package/template-gx-design-thin/.env.development +0 -15
  10. package/template-gx-design-thin/.env.production +0 -28
  11. package/template-gx-design-thin/.eslintignore +0 -16
  12. package/template-gx-design-thin/.prettierignore +0 -9
  13. package/template-gx-design-thin/LICENSE +0 -21
  14. package/template-gx-design-thin/README.md +0 -112
  15. package/template-gx-design-thin/build/constant.ts +0 -1
  16. package/template-gx-design-thin/build/generate/generateModifyVars.ts +0 -14
  17. package/template-gx-design-thin/build/rollupOptions/index.ts +0 -22
  18. package/template-gx-design-thin/build/util/hash.ts +0 -17
  19. package/template-gx-design-thin/build/util/index.ts +0 -131
  20. package/template-gx-design-thin/build/vite/cdn.ts +0 -63
  21. package/template-gx-design-thin/build/vite/optimizer.ts +0 -26
  22. package/template-gx-design-thin/build/vite/plugin/appConfig.ts +0 -91
  23. package/template-gx-design-thin/build/vite/plugin/autoImport.ts +0 -26
  24. package/template-gx-design-thin/build/vite/plugin/compress.ts +0 -31
  25. package/template-gx-design-thin/build/vite/plugin/html.ts +0 -39
  26. package/template-gx-design-thin/build/vite/plugin/index.ts +0 -75
  27. package/template-gx-design-thin/build/vite/plugin/mock.ts +0 -14
  28. package/template-gx-design-thin/build/vite/plugin/pwa.ts +0 -31
  29. package/template-gx-design-thin/build/vite/plugin/visualizer.ts +0 -14
  30. package/template-gx-design-thin/build/vite/plugin/viteMock/client.ts +0 -88
  31. package/template-gx-design-thin/build/vite/plugin/viteMock/createMockServer.ts +0 -271
  32. package/template-gx-design-thin/build/vite/plugin/viteMock/index.ts +0 -69
  33. package/template-gx-design-thin/build/vite/plugin/viteMock/types.ts +0 -48
  34. package/template-gx-design-thin/build/vite/plugin/viteMock/utils.ts +0 -48
  35. package/template-gx-design-thin/build/vite/plugin/viteNotice.ts +0 -40
  36. package/template-gx-design-thin/commitlint.config.cjs +0 -32
  37. package/template-gx-design-thin/config/default/defaultSettings.ts +0 -78
  38. package/template-gx-design-thin/config/default/network.ts +0 -10
  39. package/template-gx-design-thin/config/default/proxy.ts +0 -47
  40. package/template-gx-design-thin/config/default/theme.ts +0 -3
  41. package/template-gx-design-thin/config/index.ts +0 -11
  42. package/template-gx-design-thin/eslint.config.js +0 -51
  43. package/template-gx-design-thin/index.html +0 -42
  44. package/template-gx-design-thin/mock/_createProductionServer.ts +0 -19
  45. package/template-gx-design-thin/mock/_util.ts +0 -33
  46. package/template-gx-design-thin/mock/config/menu.ts +0 -21
  47. package/template-gx-design-thin/mock/config/user.ts +0 -123
  48. package/template-gx-design-thin/mock/datasSource/system/menu.ts +0 -10
  49. package/template-gx-design-thin/mock/datasSource/user/account.ts +0 -30
  50. package/template-gx-design-thin/mock/datasSource/user/index.ts +0 -47
  51. package/template-gx-design-thin/mock/util/crypto.ts +0 -23
  52. package/template-gx-design-thin/mock/util/table.ts +0 -92
  53. package/template-gx-design-thin/mock/util/utils.ts +0 -73
  54. package/template-gx-design-thin/package.json +0 -129
  55. package/template-gx-design-thin/pnpm-lock.yaml +0 -12575
  56. package/template-gx-design-thin/prettier.config.cjs +0 -18
  57. package/template-gx-design-thin/public/resource/css/index.css +0 -119
  58. package/template-gx-design-thin/public/resource/css/normalize.css +0 -396
  59. package/template-gx-design-thin/public/resource/img/favicon.ico +0 -0
  60. package/template-gx-design-thin/public/resource/img/logo.png +0 -0
  61. package/template-gx-design-thin/public/resource/img/pro_icon.svg +0 -1
  62. package/template-gx-design-thin/public/resource/img/pwa-192x192.png +0 -0
  63. package/template-gx-design-thin/public/resource/img/pwa-512x512.png +0 -0
  64. package/template-gx-design-thin/src/App.vue +0 -42
  65. package/template-gx-design-thin/src/assets/error_images/403.png +0 -0
  66. package/template-gx-design-thin/src/assets/error_images/404.png +0 -0
  67. package/template-gx-design-thin/src/assets/error_images/cloud.png +0 -0
  68. package/template-gx-design-thin/src/assets/login_images/login_background.svg +0 -1
  69. package/template-gx-design-thin/src/assets/logo.png +0 -0
  70. package/template-gx-design-thin/src/assets/menu_font/iconfont.css +0 -94
  71. package/template-gx-design-thin/src/assets/menu_font/iconfont.eot +0 -0
  72. package/template-gx-design-thin/src/assets/menu_font/iconfont.js +0 -1
  73. package/template-gx-design-thin/src/assets/menu_font/iconfont.json +0 -142
  74. package/template-gx-design-thin/src/assets/menu_font/iconfont.svg +0 -1
  75. package/template-gx-design-thin/src/assets/menu_font/iconfont.ttf +0 -0
  76. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff +0 -0
  77. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff2 +0 -0
  78. package/template-gx-design-thin/src/assets/menu_font/index.less +0 -94
  79. package/template-gx-design-thin/src/assets/public_icon/iconfont.css +0 -42
  80. package/template-gx-design-thin/src/assets/public_icon/iconfont.eot +0 -0
  81. package/template-gx-design-thin/src/assets/public_icon/iconfont.js +0 -1
  82. package/template-gx-design-thin/src/assets/public_icon/iconfont.json +0 -51
  83. package/template-gx-design-thin/src/assets/public_icon/iconfont.svg +0 -1
  84. package/template-gx-design-thin/src/assets/public_icon/iconfont.ttf +0 -0
  85. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff +0 -0
  86. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff2 +0 -0
  87. package/template-gx-design-thin/src/assets/public_icon/index.less +0 -42
  88. package/template-gx-design-thin/src/assets/public_images/nodata.svg +0 -1
  89. package/template-gx-design-thin/src/common/global.ts +0 -4
  90. package/template-gx-design-thin/src/components/GDesign/Result/index.tsx +0 -144
  91. package/template-gx-design-thin/src/components/GDesign/Result/style.less +0 -140
  92. package/template-gx-design-thin/src/components/GDesign/utils/index.ts +0 -7
  93. package/template-gx-design-thin/src/components/GlobalLayout/Confirm/index.ts +0 -21
  94. package/template-gx-design-thin/src/components/GlobalLayout/Empty/index.vue +0 -18
  95. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/index.tsx +0 -126
  96. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/style.ts +0 -77
  97. package/template-gx-design-thin/src/components/GlobalLayout/Spin/index.tsx +0 -30
  98. package/template-gx-design-thin/src/components/PageLoading/index.tsx +0 -51
  99. package/template-gx-design-thin/src/components/index.ts +0 -6
  100. package/template-gx-design-thin/src/core/ant-design/index.ts +0 -10
  101. package/template-gx-design-thin/src/core/gx-admin-design/index.ts +0 -6
  102. package/template-gx-design-thin/src/core/gx-design/index.ts +0 -6
  103. package/template-gx-design-thin/src/core/gx-pro-design/index.ts +0 -8
  104. package/template-gx-design-thin/src/core/index.ts +0 -84
  105. package/template-gx-design-thin/src/design/ant-design/index.less +0 -4
  106. package/template-gx-design-thin/src/design/ant-design/layout.less +0 -22
  107. package/template-gx-design-thin/src/design/ant-design/menu.less +0 -48
  108. package/template-gx-design-thin/src/design/ant-design/spin.less +0 -23
  109. package/template-gx-design-thin/src/design/ant-design/tooltip.less +0 -7
  110. package/template-gx-design-thin/src/design/color.less +0 -1
  111. package/template-gx-design-thin/src/design/config.less +0 -5
  112. package/template-gx-design-thin/src/design/imageEditor.less +0 -180
  113. package/template-gx-design-thin/src/design/index.less +0 -95
  114. package/template-gx-design-thin/src/design/mixin.less +0 -65
  115. package/template-gx-design-thin/src/design/normalize.less +0 -391
  116. package/template-gx-design-thin/src/design/root.less +0 -3
  117. package/template-gx-design-thin/src/hooks/core/index.ts +0 -3
  118. package/template-gx-design-thin/src/hooks/core/useRequest/index.ts +0 -118
  119. package/template-gx-design-thin/src/hooks/event/index.ts +0 -3
  120. package/template-gx-design-thin/src/hooks/event/useClipboard.ts +0 -15
  121. package/template-gx-design-thin/src/hooks/web/index.ts +0 -5
  122. package/template-gx-design-thin/src/hooks/web/useThemeStyle.ts +0 -16
  123. package/template-gx-design-thin/src/layout/BasicLayout.vue +0 -123
  124. package/template-gx-design-thin/src/layout/BlankLayout.vue +0 -5
  125. package/template-gx-design-thin/src/layout/ContentView.vue +0 -50
  126. package/template-gx-design-thin/src/layout/IframeView.vue +0 -1
  127. package/template-gx-design-thin/src/layout/UserLayout.vue +0 -7
  128. package/template-gx-design-thin/src/main.ts +0 -34
  129. package/template-gx-design-thin/src/plugins/index.ts +0 -2
  130. package/template-gx-design-thin/src/router/guard/index.ts +0 -83
  131. package/template-gx-design-thin/src/router/guard/permissions.ts +0 -70
  132. package/template-gx-design-thin/src/router/guard/stateGuard.ts +0 -10
  133. package/template-gx-design-thin/src/router/helper/routeHelper.ts +0 -223
  134. package/template-gx-design-thin/src/router/helper/utils.ts +0 -19
  135. package/template-gx-design-thin/src/router/index.ts +0 -31
  136. package/template-gx-design-thin/src/router/routes/index.ts +0 -86
  137. package/template-gx-design-thin/src/router/routes/modules/dataSource.ts +0 -12
  138. package/template-gx-design-thin/src/services/common/index.ts +0 -11
  139. package/template-gx-design-thin/src/services/systemCenter/index.ts +0 -1
  140. package/template-gx-design-thin/src/services/systemCenter/menu.ts +0 -9
  141. package/template-gx-design-thin/src/services/userCenter/account.ts +0 -42
  142. package/template-gx-design-thin/src/services/userCenter/index.ts +0 -28
  143. package/template-gx-design-thin/src/store/index.ts +0 -32
  144. package/template-gx-design-thin/src/store/modules/dict.ts +0 -28
  145. package/template-gx-design-thin/src/store/modules/global.ts +0 -42
  146. package/template-gx-design-thin/src/store/modules/permission.ts +0 -19
  147. package/template-gx-design-thin/src/store/modules/routes.ts +0 -113
  148. package/template-gx-design-thin/src/store/modules/tabsRouter.ts +0 -76
  149. package/template-gx-design-thin/src/store/modules/user.ts +0 -136
  150. package/template-gx-design-thin/src/utils/accessToken.ts +0 -80
  151. package/template-gx-design-thin/src/utils/crypto/base64.ts +0 -101
  152. package/template-gx-design-thin/src/utils/crypto/index.ts +0 -57
  153. package/template-gx-design-thin/src/utils/env.ts +0 -50
  154. package/template-gx-design-thin/src/utils/fetchFile.ts +0 -81
  155. package/template-gx-design-thin/src/utils/index.ts +0 -123
  156. package/template-gx-design-thin/src/utils/pageTitle.ts +0 -20
  157. package/template-gx-design-thin/src/utils/request/XHR.ts +0 -139
  158. package/template-gx-design-thin/src/utils/request/axiosCancel.ts +0 -69
  159. package/template-gx-design-thin/src/utils/request/checkStatus.ts +0 -25
  160. package/template-gx-design-thin/src/utils/request/index.ts +0 -144
  161. package/template-gx-design-thin/src/utils/request/typings.ts +0 -171
  162. package/template-gx-design-thin/src/utils/storage.ts +0 -199
  163. package/template-gx-design-thin/src/utils/uploadFile.ts +0 -27
  164. package/template-gx-design-thin/src/utils/util.ts +0 -198
  165. package/template-gx-design-thin/src/utils/validate.ts +0 -216
  166. package/template-gx-design-thin/src/views/Iframe/index.vue +0 -76
  167. package/template-gx-design-thin/src/views/Page/one.vue +0 -13
  168. package/template-gx-design-thin/src/views/Page/two.vue +0 -13
  169. package/template-gx-design-thin/src/views/exception/403/index.vue +0 -7
  170. package/template-gx-design-thin/src/views/exception/404/index.vue +0 -9
  171. package/template-gx-design-thin/src/views/user/login/index.vue +0 -109
  172. package/template-gx-design-thin/src/views/user/login/style.less +0 -38
  173. package/template-gx-design-thin/tsconfig.json +0 -46
  174. package/template-gx-design-thin/types/ant-design-import.d.ts +0 -99
  175. package/template-gx-design-thin/types/auto-imports.d.ts +0 -81
  176. package/template-gx-design-thin/types/components.d.ts +0 -24
  177. package/template-gx-design-thin/types/config.d.ts +0 -44
  178. package/template-gx-design-thin/types/global.d.ts +0 -97
  179. package/template-gx-design-thin/types/mock.d.ts +0 -16
  180. package/template-gx-design-thin/types/module.d.ts +0 -20
  181. package/template-gx-design-thin/types/response.d.ts +0 -15
  182. package/template-gx-design-thin/unocss.config.ts +0 -101
  183. package/template-gx-design-thin/vite.config.ts +0 -120
  184. package/template-gx-design-thin/yarn.lock +0 -9492
@@ -1,271 +0,0 @@
1
- import type { MockMethod, Recordable, RespThisType, ViteMockOptions } from './types'
2
- import path from 'node:path'
3
- import fs from 'node:fs'
4
- import chokidar from 'chokidar'
5
- import colors from 'picocolors'
6
- import url from 'node:url'
7
- import fg from 'fast-glob'
8
- import Mock from 'mockjs'
9
- import { match, pathToRegexp } from 'path-to-regexp'
10
- import { isAbsPath, isArray, isFunction, isRegExp, sleep } from './utils'
11
- import type { IncomingMessage, NextHandleFunction } from 'connect'
12
- import type { GetOutputFile } from 'bundle-require'
13
- import { bundleRequire, JS_EXT_RE } from 'bundle-require'
14
- import type { ResolvedConfig } from 'vite'
15
-
16
- export let mockData: MockMethod[] = []
17
-
18
- export async function createMockServer(
19
- opt: ViteMockOptions = { mockPath: 'mock', configPath: 'vite.mock.config' },
20
- config: ResolvedConfig,
21
- ) {
22
- opt = {
23
- mockPath: 'mock',
24
- watchFiles: true,
25
- configPath: 'vite.mock.config.ts',
26
- logger: true,
27
- cors: true,
28
- ...opt,
29
- }
30
-
31
- if (mockData.length > 0)
32
- return
33
- mockData = await getMockConfig(opt, config)
34
- await createWatch(opt, config)
35
- }
36
-
37
- // request match
38
- export async function requestMiddleware(opt: ViteMockOptions) {
39
- const { logger = true } = opt
40
- const middleware: NextHandleFunction = async (req, res, next) => {
41
- let queryParams: {
42
- query?: {
43
- [key: string]: any
44
- }
45
- pathname?: string | null
46
- } = {}
47
-
48
- if (req.url) {
49
- queryParams = url.parse(req.url, true)
50
- }
51
-
52
- const reqUrl = queryParams.pathname
53
-
54
- const matchRequest = mockData.find((item) => {
55
- if (!reqUrl || !item || !item.url) {
56
- return false
57
- }
58
- if (item.method && item.method.toUpperCase() !== req.method) {
59
- return false
60
- }
61
- return pathToRegexp(item.url).test(reqUrl)
62
- })
63
-
64
- if (matchRequest) {
65
- const isGet = req.method && req.method.toUpperCase() === 'GET'
66
- const { response, rawResponse, timeout, statusCode, url } = matchRequest
67
-
68
- if (timeout) {
69
- await sleep(timeout)
70
- }
71
-
72
- const urlMatch = match(url, { decode: decodeURIComponent })
73
-
74
- let query = queryParams.query as any
75
- if (reqUrl) {
76
- if ((isGet && JSON.stringify(query) === '{}') || !isGet) {
77
- const params = (urlMatch(reqUrl) as any).params
78
- if (JSON.stringify(params) !== '{}') {
79
- query = (urlMatch(reqUrl) as any).params || {}
80
- } else {
81
- query = queryParams.query || {}
82
- }
83
- }
84
- }
85
-
86
- const self: RespThisType = { req, res, parseJson: parseJson.bind(null, req) }
87
- if (isFunction(rawResponse)) {
88
- await rawResponse.bind(self)(req, res)
89
- } else {
90
- const body = await parseJson(req)
91
- res.setHeader('Content-Type', 'application/json')
92
- if (opt) {
93
- res.setHeader('Access-Control-Allow-Credentials', true)
94
- res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*')
95
- }
96
- res.statusCode = statusCode || 200
97
- const mockResponse = isFunction(response)
98
- ? response.bind(self)({ url: req.url as any, body, query, headers: req.headers })
99
- : response
100
- res.end(JSON.stringify(Mock.mock(mockResponse)))
101
- }
102
-
103
- logger && loggerOutput('request invoke', req.url!)
104
- return
105
- }
106
- next()
107
- }
108
- return middleware
109
- }
110
-
111
- // create watch mock
112
- function createWatch(opt: ViteMockOptions, config: ResolvedConfig) {
113
- const { configPath, logger, watchFiles } = opt
114
-
115
- if (!watchFiles) {
116
- return
117
- }
118
-
119
- const { absConfigPath, absMockPath } = getPath(opt)
120
-
121
- if (process.env.VITE_DISABLED_WATCH_MOCK === 'true') {
122
- return
123
- }
124
-
125
- const watchDir = []
126
- const exitsConfigPath = fs.existsSync(absConfigPath)
127
-
128
- exitsConfigPath && configPath ? watchDir.push(absConfigPath) : watchDir.push(absMockPath)
129
-
130
- const watcher = chokidar.watch(watchDir, {
131
- ignoreInitial: true,
132
- // ignore files generated by `bundle require`
133
- ignored: '**/_*.bundled_*.(mjs|cjs)',
134
- })
135
-
136
- watcher.on('all', async (event, file) => {
137
- logger && loggerOutput(`mock file ${event}`, file)
138
- mockData = await getMockConfig(opt, config)
139
- })
140
- }
141
-
142
- // clear cache
143
- // function cleanRequireCache(opt: ViteMockOptions) {
144
- // if (typeof require === 'undefined' || !require.cache) {
145
- // return
146
- // }
147
- // const { absConfigPath, absMockPath } = getPath(opt)
148
- // Object.keys(require.cache).forEach((file) => {
149
- // if (file === absConfigPath || file.indexOf(absMockPath) > -1) {
150
- // delete require.cache[file]
151
- // }
152
- // })
153
- // }
154
-
155
- function parseJson(req: IncomingMessage): Promise<Recordable> {
156
- return new Promise((resolve) => {
157
- let body = ''
158
- let jsonStr = ''
159
- req.on('data', function (chunk) {
160
- body += chunk
161
- })
162
- req.on('end', function () {
163
- try {
164
- jsonStr = JSON.parse(body)
165
- } catch (err) {
166
- jsonStr = ''
167
- }
168
- resolve(jsonStr as any)
169
- return
170
- })
171
- })
172
- }
173
-
174
- // load mock .ts files and watch
175
- async function getMockConfig(opt: ViteMockOptions, config: ResolvedConfig) {
176
- const { absConfigPath, absMockPath } = getPath(opt)
177
- const { ignore, configPath, logger } = opt
178
-
179
- let ret: MockMethod[] = []
180
- if (configPath && fs.existsSync(absConfigPath)) {
181
- logger && loggerOutput(`load mock data from`, absConfigPath)
182
- ret = await resolveModule(absConfigPath, config)
183
- return ret
184
- }
185
-
186
- const mockFiles = fg
187
- .sync(`**/*.{ts,mjs,js}`, {
188
- cwd: absMockPath,
189
- })
190
- .filter((item) => {
191
- if (!ignore) {
192
- return true
193
- }
194
- if (isFunction(ignore)) {
195
- return !ignore(item)
196
- }
197
- if (isRegExp(ignore)) {
198
- return !ignore.test(path.basename(item))
199
- }
200
- return true
201
- })
202
- try {
203
- ret = []
204
- const resolveModulePromiseList = []
205
-
206
- for (let index = 0; index < mockFiles.length; index++) {
207
- const mockFile = mockFiles[index]
208
- resolveModulePromiseList.push(resolveModule(path.join(absMockPath, mockFile), config))
209
- }
210
- const loadAllResult = await Promise.all(resolveModulePromiseList)
211
- for (const resultModule of loadAllResult) {
212
- let mod = resultModule
213
- if (!isArray(mod)) {
214
- mod = [mod]
215
- }
216
- ret = [...ret, ...mod]
217
- }
218
- } catch (error: any) {
219
- loggerOutput(`mock reload error`, error)
220
- ret = []
221
- }
222
- return ret
223
- }
224
-
225
- // fixed file generation format
226
- // use a random path to avoid import cache
227
- const getOutputFile: GetOutputFile = (filepath, format) => {
228
- const dirname = path.dirname(filepath)
229
- const basename = path.basename(filepath)
230
- const randomname = `${Date.now()}_${Math.random().toString(36).substring(2, 15)}`
231
- return path.resolve(
232
- dirname,
233
- `_${basename.replace(JS_EXT_RE, `.bundled_${randomname}.${format === 'esm' ? 'mjs' : 'cjs'}`)}`,
234
- )
235
- }
236
-
237
- // Inspired by vite
238
- // support mock .ts files
239
- async function resolveModule(p: string, config: ResolvedConfig): Promise<any> {
240
- const mockData = await bundleRequire({
241
- filepath: p,
242
- getOutputFile,
243
- })
244
-
245
- let mod = mockData.mod.default || mockData.mod
246
- if (isFunction(mod)) {
247
- mod = await mod({ env: config.env, mode: config.mode, command: config.command })
248
- }
249
- return mod
250
- }
251
-
252
- // get custom config file path and mock dir path
253
- function getPath(opt: ViteMockOptions) {
254
- const { mockPath, configPath } = opt
255
- const cwd = process.cwd()
256
- const absMockPath = isAbsPath(mockPath) ? mockPath! : path.join(cwd, mockPath || '')
257
- const absConfigPath = path.join(cwd, configPath || '')
258
- return {
259
- absMockPath,
260
- absConfigPath,
261
- }
262
- }
263
-
264
- function loggerOutput(title: string, msg: string, type: 'info' | 'error' = 'info') {
265
- const tag = type === 'info' ? colors.cyan(`[vite:mock]`) : colors.red(`[vite:mock-server]`)
266
- return console.log(
267
- `${colors.dim(new Date().toLocaleTimeString())} ${tag} ${colors.green(title)} ${colors.dim(
268
- msg,
269
- )}`,
270
- )
271
- }
@@ -1,69 +0,0 @@
1
- (async () => {
2
- try {
3
- await import('mockjs')
4
- } catch (e) {
5
- throw new Error('vite-plugin-vue-mock requires mockjs to be present in the dependency tree.')
6
- }
7
- })()
8
-
9
- import type { Plugin, ResolvedConfig } from 'vite'
10
- import { normalizePath } from 'vite'
11
- import path from 'node:path'
12
- import type { ViteMockOptions } from './types'
13
- import { fileExists } from './utils'
14
- import { createMockServer, requestMiddleware } from './createMockServer'
15
-
16
- function getDefaultPath(supportTs = true) {
17
- return path.resolve(process.cwd(), `src/main.${supportTs ? 'ts' : 'js'}`)
18
- }
19
-
20
- export function viteMockServe(opt: ViteMockOptions = {}): Plugin {
21
- let isDev = false
22
- let needSourcemap = false
23
- let config: ResolvedConfig
24
- let defaultPath = getDefaultPath()
25
- if (!fileExists(defaultPath)) {
26
- defaultPath = getDefaultPath(false)
27
- if (!fileExists(defaultPath)) {
28
- defaultPath = ''
29
- }
30
- }
31
-
32
- const defaultEnter = normalizePath(defaultPath)
33
-
34
- const { injectFile = defaultEnter } = opt
35
-
36
- return {
37
- name: 'vite:mock',
38
- enforce: 'pre' as const,
39
- configResolved(resolvedConfig) {
40
- config = resolvedConfig
41
- isDev = config.command === 'serve'
42
- needSourcemap = !!resolvedConfig.build.sourcemap
43
- isDev && createMockServer(opt, config)
44
- },
45
-
46
- configureServer: async ({ middlewares }) => {
47
- const { enable = isDev } = opt
48
- if (!enable) {
49
- return
50
- }
51
- const middleware = await requestMiddleware(opt)
52
- middlewares.use(middleware)
53
- },
54
- transform: (code, id) => {
55
- if (isDev || !injectFile || !id.endsWith(injectFile)) {
56
- return null
57
- }
58
-
59
- const { injectCode = '' } = opt
60
-
61
- return {
62
- map: needSourcemap ? this.getCombinedSourcemap() : null,
63
- code: `${code}\n${injectCode}`
64
- }
65
- }
66
- }
67
- }
68
-
69
- export * from './types'
@@ -1,48 +0,0 @@
1
- import { IncomingMessage, ServerResponse } from 'http'
2
-
3
- export interface ViteMockOptions {
4
- mockPath?: string;
5
- configPath?: string;
6
- injectFile?: string;
7
- injectCode?: string;
8
- ignore?: RegExp | ((fileName: string) => boolean);
9
- watchFiles?: boolean;
10
- enable?: boolean;
11
- cors?: boolean;
12
- /**
13
- * Automatic recognition, no need to configure again
14
- * @deprecated Deprecated after 2.8.0
15
- */
16
- supportTs?: boolean;
17
- logger?: boolean;
18
- }
19
-
20
- export interface RespThisType {
21
- req: IncomingMessage
22
- res: ServerResponse
23
- parseJson: () => any
24
- }
25
-
26
- export type MethodType = 'get' | 'post' | 'put' | 'delete' | 'patch'
27
-
28
- export type Recordable<T = any> = Record<string, T>
29
-
30
- export declare interface MockMethod {
31
- url: string
32
- method?: MethodType
33
- timeout?: number
34
- statusCode?: number
35
- response?:
36
- | ((
37
- this: RespThisType,
38
- opt: { url: Recordable; body: Recordable; query: Recordable; headers: Recordable },
39
- ) => any)
40
- | any
41
- rawResponse?: (this: RespThisType, req: IncomingMessage, res: ServerResponse) => void
42
- }
43
-
44
- export interface MockConfig {
45
- env: Record<string, any>
46
- mode: string
47
- command: 'build' | 'serve'
48
- }
@@ -1,48 +0,0 @@
1
- import fs from 'node:fs'
2
-
3
- const toString = Object.prototype.toString
4
-
5
- export function is(val: unknown, type: string) {
6
- return toString.call(val) === `[object ${type}]`
7
- }
8
-
9
- export function fileExists(f: string) {
10
- try {
11
- fs.accessSync(f, fs.constants.W_OK);
12
- return true;
13
- } catch (error) {
14
- return false;
15
- }
16
- }
17
-
18
- export function isFunction<T = Function>(val: unknown): val is T {
19
- return is(val, 'Function') || is(val, 'AsyncFunction')
20
- }
21
-
22
- export function isArray(val: any): val is Array<any> {
23
- return val && Array.isArray(val)
24
- }
25
-
26
- export function isRegExp(val: unknown): val is RegExp {
27
- return is(val, 'RegExp')
28
- }
29
-
30
- export function isAbsPath(path: string | undefined) {
31
- if (!path) {
32
- return false
33
- }
34
- // Windows 路径格式:C:\ 或 \\ 开头,或已含盘符(D:\path\to\file)
35
- if (/^([a-zA-Z]:\\|\\\\|(?:\/|\uFF0F){2,})/.test(path)) {
36
- return true
37
- }
38
- // Unix/Linux 路径格式:/ 开头
39
- return /^\/[^/]/.test(path)
40
- }
41
-
42
- export function sleep(time: number) {
43
- return new Promise((resolve) => {
44
- setTimeout(() => {
45
- resolve('')
46
- }, time)
47
- })
48
- }
@@ -1,40 +0,0 @@
1
- import type { Plugin } from 'vite'
2
- import chalk from 'chalk'
3
- import { readPackageJSON } from 'pkg-types'
4
- import { defaultSettings } from '../../../config'
5
- import { getPackageSize, getRootPath, rootPath } from '../../util'
6
-
7
- const { outputDir } = defaultSettings
8
-
9
- export default async function viteNotice(): Promise<Plugin> {
10
- let config: { command: string }
11
- const { name = '' } = await readPackageJSON(rootPath)
12
-
13
- return {
14
- name: 'vite:notice',
15
- configResolved(resolvedConfig) {
16
- config = resolvedConfig
17
- },
18
- buildStart() {
19
- console.log(
20
- chalk.bold(
21
- chalk.green(
22
- `👏Welcome to use ${chalk.blue(
23
- '[gx-design-pro]'
24
- )}, If you feel good, remember to click on the link below to give a star https://github.com/gx12358/vue3-antd-admin`
25
- )
26
- )
27
- )
28
- },
29
- closeBundle() {
30
- if (config.command === 'build') {
31
- getPackageSize({
32
- folder: getRootPath(outputDir),
33
- callBack: (size: string) => {
34
- console.log(chalk.bold(chalk.green(`✨ ${chalk.blue(`[${name}]`)} all build successfully, Total files ${size}`)))
35
- }
36
- })
37
- }
38
- }
39
- }
40
- }
@@ -1,32 +0,0 @@
1
- module.exports = {
2
- ignores: [(commit) => commit.includes('init')],
3
- extends: ['@commitlint/config-conventional'],
4
- rules: {
5
- 'body-leading-blank': [2, 'always'],
6
- 'footer-leading-blank': [1, 'always'],
7
- 'header-max-length': [2, 'always', 108],
8
- 'subject-empty': [2, 'never'],
9
- 'type-empty': [2, 'never'],
10
- 'type-enum': [
11
- 2,
12
- 'always',
13
- [
14
- 'feat',
15
- 'fix',
16
- 'perf',
17
- 'style',
18
- 'docs',
19
- 'test',
20
- 'refactor',
21
- 'build',
22
- 'ci',
23
- 'chore',
24
- 'revert',
25
- 'wip',
26
- 'workflow',
27
- 'types',
28
- 'release',
29
- ],
30
- ],
31
- },
32
- };
@@ -1,78 +0,0 @@
1
- /**
2
- * @description 导出默认通用配置
3
- */
4
- const settingConfig: SettingConfig = {
5
- // 开发以及部署时的URL,hash模式时在不确定二级目录名称的情况下建议使用""代表相对路径或者"/二级目录/",history模式默认使用"/"或者"/二级目录/"
6
- publicPath: './',
7
- // 生产环境构建文件的目录名
8
- outputDir: 'dist',
9
- // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
10
- assetsDir: 'static',
11
- // 标题 (包括初次加载雪花屏的标题 页面的标题 浏览器的标题)
12
- title: 'GX Pro Admin',
13
- // 短标题
14
- shortName: 'gx_pro_admin',
15
- // 标题分隔符
16
- titleSeparator: ' - ',
17
- // 标题是否反转 如果为false:"page - title",如果为ture:"title - page"
18
- titleReverse: false,
19
- // 是否开启水印
20
- waterMark: true,
21
- // 水印字符
22
- waterMarkTitle: 'GX Pro Admin',
23
- // 滚动区域选择器
24
- viewScrollRoot: '#gx-pro-admin>.gx-scrollbar>.gx-scrollbar-wrap',
25
- // 开启cdn
26
- useCdn: true,
27
- // cdn 地址
28
- cdnUrl: 'https://cdn.bootcdn.net/ajax/libs/{name}/{version}/{path}',
29
- // cdn 模块集合
30
- cdnModules: [
31
- {
32
- name: 'axios',
33
- globalName: 'axios',
34
- path: 'axios.min.js'
35
- },
36
- {
37
- name: 'dayjs',
38
- globalName: 'dayjs',
39
- path: 'dayjs.min.js'
40
- }
41
- ],
42
- // 开启proxy
43
- useProxy: true,
44
- // proxy target
45
- proxyTarget: 'http://127.0.0.1:3000',
46
- // 接口前缀
47
- requestPrefix: '/api',
48
- // mock-接口前缀
49
- mockPrefixUrl: '/mock-server',
50
- // 开发环境端口号
51
- devPort: 9280,
52
- // pro版本copyright可随意修改
53
- copyright: 'gx12358 2539306317@qq.com',
54
- // 缓存路由的最大数量
55
- keepAliveMaxNum: 99,
56
- // 路由模式,可选值为 browser 或 hash
57
- routerMode: 'hash',
58
- // 不经过token校验的路由
59
- routesWhiteList: [ '/user/login', '/user/register', '/exception/404', '/exception/403' ],
60
- // token名称
61
- tokenName: 'Authorization',
62
- // token在localStorage、sessionStorage、cookie存储的key的名称
63
- tokenTableName: 'GxAccessToken',
64
- // token存储位置localStorage sessionStorage cookie
65
- storage: 'localStorage',
66
- // token失效回退到登录页时是否记录本次的路由
67
- recordRoute: false,
68
- // 是否开启登录拦截
69
- loginInterception: true,
70
- // 是否开启登录RSA加密
71
- loginRSA: false,
72
- // front(前端导出路由)和 all(后端导出路由)两种方式
73
- authentication: 'all',
74
- // mock数据是否检查token
75
- checkMockToken: true
76
- }
77
-
78
- export default settingConfig
@@ -1,10 +0,0 @@
1
- /**
2
- * @description 导出默认网路配置
3
- **/
4
- const networkSetting: NetworkConfig = {
5
- // 最长请求时间
6
- requestTimeout: 10000,
7
- // 操作正常code,支持String、Array、Number多种类型
8
- successCode: [ 200, 0 ]
9
- }
10
- export default networkSetting
@@ -1,47 +0,0 @@
1
- /**
2
- * 在生产环境 代理是无法生效的,所以这里没有生产环境的配置
3
- * The agent cannot take effect in the production environment
4
- * so there is no configuration of the production environment
5
- * For details, please see
6
- * https://pro.ant.design/docs/deploy
7
- */
8
- import type { ProxyOptions } from 'vite'
9
- import { isObject, isString } from '@gx-design-vue/pro-utils'
10
- import defaultSettings from './defaultSettings'
11
-
12
- type ProxyTargetList = ProxyOptions & { rewrite: (path: string) => string }
13
-
14
- export function createProxy(prefix) {
15
- const ret = {
16
- dev: {},
17
- test: {},
18
- pre: {}
19
- }
20
-
21
- if (isObject(defaultSettings.proxyTarget)) {
22
- Object.keys(defaultSettings.proxyTarget).forEach((prefix) => {
23
- const proxy = {
24
- target: `${defaultSettings.proxyTarget[prefix]}`,
25
- changeOrigin: true,
26
- ws: true,
27
- rewrite: path => path.replace(new RegExp(`^${prefix}`), '')
28
- } as ProxyTargetList
29
-
30
- ret.dev[prefix] = proxy
31
- ret.test[prefix] = proxy
32
- ret.pre[prefix] = proxy
33
- })
34
- } else if (isString(defaultSettings.proxyTarget)) {
35
- const proxy = {
36
- target: `${defaultSettings.proxyTarget}`,
37
- changeOrigin: true,
38
- ws: true,
39
- rewrite: path => path.replace(new RegExp(`^${prefix}`), '')
40
- }
41
- ret.dev[prefix] = proxy
42
- ret.test[prefix] = proxy
43
- ret.pre[prefix] = proxy
44
- }
45
-
46
- return ret
47
- }
@@ -1,3 +0,0 @@
1
- export default {
2
- colorPrimary: '#1677FF'
3
- } as ProAliasToken
@@ -1,11 +0,0 @@
1
- import theme from './default/theme'
2
- import network from './default/network'
3
- import defaultSettings from './default/defaultSettings'
4
-
5
- export * from './default/proxy'
6
-
7
- export {
8
- theme,
9
- network,
10
- defaultSettings
11
- }