@gx-design-vue/create-gx-cli 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (256) hide show
  1. package/package.json +1 -1
  2. package/src/main.js +1 -0
  3. package/template-design-pro/.editorconfig +19 -0
  4. package/template-design-pro/.env +2 -0
  5. package/template-design-pro/.env.development +18 -0
  6. package/template-design-pro/.env.pro +32 -0
  7. package/template-design-pro/.env.production +32 -0
  8. package/template-design-pro/.env.test +20 -0
  9. package/template-design-pro/.eslintignore +16 -0
  10. package/template-design-pro/.eslintrc.js +64 -0
  11. package/template-design-pro/.gitpod.yml +6 -0
  12. package/template-design-pro/.husky/pre-commit +4 -0
  13. package/template-design-pro/.prettierignore +9 -0
  14. package/template-design-pro/.stylelintignore +3 -0
  15. package/template-design-pro/.yarnclean +48 -0
  16. package/template-design-pro/LICENSE +21 -0
  17. package/template-design-pro/README.md +111 -0
  18. package/template-design-pro/build/constant.ts +6 -0
  19. package/template-design-pro/build/generate/generateModifyVars.ts +18 -0
  20. package/template-design-pro/build/getConfigFileName.ts +13 -0
  21. package/template-design-pro/build/script/buildConf.ts +44 -0
  22. package/template-design-pro/build/script/postBuild.ts +25 -0
  23. package/template-design-pro/build/script/reSetRootHtml.ts +20 -0
  24. package/template-design-pro/build/utils.ts +85 -0
  25. package/template-design-pro/build/vite/cdn.ts +7 -0
  26. package/template-design-pro/build/vite/optimizer.ts +22 -0
  27. package/template-design-pro/build/vite/plugin/autoImport.ts +18 -0
  28. package/template-design-pro/build/vite/plugin/compress.ts +35 -0
  29. package/template-design-pro/build/vite/plugin/hmr.ts +25 -0
  30. package/template-design-pro/build/vite/plugin/html.ts +47 -0
  31. package/template-design-pro/build/vite/plugin/index.ts +89 -0
  32. package/template-design-pro/build/vite/plugin/mock.ts +20 -0
  33. package/template-design-pro/build/vite/plugin/pwa.ts +37 -0
  34. package/template-design-pro/build/vite/plugin/styleImport.ts +129 -0
  35. package/template-design-pro/build/vite/plugin/visualizer.ts +17 -0
  36. package/template-design-pro/build/vite/plugin/vite-plugin-antd-theme/index.ts +24 -0
  37. package/template-design-pro/build/vite/plugin/vite-plugin-mock/createMockServer.ts +303 -0
  38. package/template-design-pro/build/vite/plugin/vite-plugin-mock/createProdMockServer.ts +93 -0
  39. package/template-design-pro/build/vite/plugin/vite-plugin-mock/index.ts +68 -0
  40. package/template-design-pro/build/vite/plugin/vite-plugin-mock/types.ts +30 -0
  41. package/template-design-pro/build/vite/plugin/vite-plugin-mock/utils.ts +26 -0
  42. package/template-design-pro/commitlint.config.js +32 -0
  43. package/template-design-pro/config/config.ts +14 -0
  44. package/template-design-pro/config/default/animate.ts +30 -0
  45. package/template-design-pro/config/default/defaultSettings.ts +75 -0
  46. package/template-design-pro/config/default/network.ts +16 -0
  47. package/template-design-pro/config/default/proxy.ts +26 -0
  48. package/template-design-pro/config/default/theme.ts +43 -0
  49. package/template-design-pro/config/default/themeColor.ts +62 -0
  50. package/template-design-pro/index.html +45 -0
  51. package/template-design-pro/jest.config.mjs +36 -0
  52. package/template-design-pro/mock/_createProductionServer.ts +19 -0
  53. package/template-design-pro/mock/_util.ts +55 -0
  54. package/template-design-pro/mock/controller/menu.ts +85 -0
  55. package/template-design-pro/mock/controller/notices.ts +114 -0
  56. package/template-design-pro/mock/system/dict.ts +60 -0
  57. package/template-design-pro/mock/system/user.ts +218 -0
  58. package/template-design-pro/package.json +151 -0
  59. package/template-design-pro/pnpm-lock.yaml +9913 -0
  60. package/template-design-pro/postcss.config.js +5 -0
  61. package/template-design-pro/prettier.config.js +18 -0
  62. package/template-design-pro/public/resource/css/index.css +171 -0
  63. package/template-design-pro/public/resource/img/favicon.ico +0 -0
  64. package/template-design-pro/public/resource/img/logo.png +0 -0
  65. package/template-design-pro/public/resource/img/pro_icon.svg +5 -0
  66. package/template-design-pro/public/resource/img/pwa-192x192.png +0 -0
  67. package/template-design-pro/public/resource/img/pwa-512x512.png +0 -0
  68. package/template-design-pro/src/App.vue +47 -0
  69. package/template-design-pro/src/assets/error_images/403.png +0 -0
  70. package/template-design-pro/src/assets/error_images/404.png +0 -0
  71. package/template-design-pro/src/assets/error_images/cloud.png +0 -0
  72. package/template-design-pro/src/assets/login_images/login_background.svg +69 -0
  73. package/template-design-pro/src/assets/logo.png +0 -0
  74. package/template-design-pro/src/assets/menu_font/iconfont.css +94 -0
  75. package/template-design-pro/src/assets/menu_font/iconfont.eot +0 -0
  76. package/template-design-pro/src/assets/menu_font/iconfont.js +1 -0
  77. package/template-design-pro/src/assets/menu_font/iconfont.json +142 -0
  78. package/template-design-pro/src/assets/menu_font/iconfont.svg +57 -0
  79. package/template-design-pro/src/assets/menu_font/iconfont.ttf +0 -0
  80. package/template-design-pro/src/assets/menu_font/iconfont.woff +0 -0
  81. package/template-design-pro/src/assets/menu_font/iconfont.woff2 +0 -0
  82. package/template-design-pro/src/assets/menu_font/index.less +94 -0
  83. package/template-design-pro/src/common/global.ts +1 -0
  84. package/template-design-pro/src/components/GDesign/ProLayout/BasicLayout.less +80 -0
  85. package/template-design-pro/src/components/GDesign/ProLayout/BasicLayout.tsx +342 -0
  86. package/template-design-pro/src/components/GDesign/ProLayout/PageLoading.tsx +20 -0
  87. package/template-design-pro/src/components/GDesign/ProLayout/RenderTypings.ts +31 -0
  88. package/template-design-pro/src/components/GDesign/ProLayout/RouteContext.tsx +82 -0
  89. package/template-design-pro/src/components/GDesign/ProLayout/WrapContent.tsx +69 -0
  90. package/template-design-pro/src/components/GDesign/ProLayout/components/GlobalFooter/index.tsx +88 -0
  91. package/template-design-pro/src/components/GDesign/ProLayout/components/GlobalHeader/DefaultHeader.tsx +189 -0
  92. package/template-design-pro/src/components/GDesign/ProLayout/components/GlobalHeader/Header.less +8 -0
  93. package/template-design-pro/src/components/GDesign/ProLayout/components/GlobalHeader/index.tsx +105 -0
  94. package/template-design-pro/src/components/GDesign/ProLayout/components/GlobalHeader/props.ts +69 -0
  95. package/template-design-pro/src/components/GDesign/ProLayout/components/GlobalHeader/style.less +144 -0
  96. package/template-design-pro/src/components/GDesign/ProLayout/components/LogoContent/index.tsx +81 -0
  97. package/template-design-pro/src/components/GDesign/ProLayout/components/LogoContent/props.ts +29 -0
  98. package/template-design-pro/src/components/GDesign/ProLayout/components/MultiTab/index.tsx +384 -0
  99. package/template-design-pro/src/components/GDesign/ProLayout/components/MultiTab/props.ts +15 -0
  100. package/template-design-pro/src/components/GDesign/ProLayout/components/MultiTab/style.less +79 -0
  101. package/template-design-pro/src/components/GDesign/ProLayout/components/NoticeIcon/NoticeIcon.tsx +148 -0
  102. package/template-design-pro/src/components/GDesign/ProLayout/components/NoticeIcon/NoticeList.module.less +115 -0
  103. package/template-design-pro/src/components/GDesign/ProLayout/components/NoticeIcon/NoticeList.tsx +154 -0
  104. package/template-design-pro/src/components/GDesign/ProLayout/components/NoticeIcon/index.less +39 -0
  105. package/template-design-pro/src/components/GDesign/ProLayout/components/NoticeIcon/index.tsx +133 -0
  106. package/template-design-pro/src/components/GDesign/ProLayout/components/PageContainer/index.tsx +190 -0
  107. package/template-design-pro/src/components/GDesign/ProLayout/components/PageContainer/props.ts +48 -0
  108. package/template-design-pro/src/components/GDesign/ProLayout/components/PageContainer/style.less +128 -0
  109. package/template-design-pro/src/components/GDesign/ProLayout/components/PageContainer/typings.ts +0 -0
  110. package/template-design-pro/src/components/GDesign/ProLayout/components/RightContent/AvatarDropdown.tsx +63 -0
  111. package/template-design-pro/src/components/GDesign/ProLayout/components/RightContent/HeaderSearch.tsx +122 -0
  112. package/template-design-pro/src/components/GDesign/ProLayout/components/RightContent/headerSearch.less +30 -0
  113. package/template-design-pro/src/components/GDesign/ProLayout/components/RightContent/index.tsx +95 -0
  114. package/template-design-pro/src/components/GDesign/ProLayout/components/RightContent/style.less +90 -0
  115. package/template-design-pro/src/components/GDesign/ProLayout/components/SettingDrawer/BlockCheckbox.tsx +70 -0
  116. package/template-design-pro/src/components/GDesign/ProLayout/components/SettingDrawer/LayoutSetting.tsx +107 -0
  117. package/template-design-pro/src/components/GDesign/ProLayout/components/SettingDrawer/ThemeColor.tsx +68 -0
  118. package/template-design-pro/src/components/GDesign/ProLayout/components/SettingDrawer/index.tsx +346 -0
  119. package/template-design-pro/src/components/GDesign/ProLayout/components/SiderMenu/BaseMenu.tsx +224 -0
  120. package/template-design-pro/src/components/GDesign/ProLayout/components/SiderMenu/SiderMenu.tsx +224 -0
  121. package/template-design-pro/src/components/GDesign/ProLayout/components/SiderMenu/index.tsx +43 -0
  122. package/template-design-pro/src/components/GDesign/ProLayout/components/SiderMenu/props.ts +112 -0
  123. package/template-design-pro/src/components/GDesign/ProLayout/components/SiderMenu/style.less +262 -0
  124. package/template-design-pro/src/components/GDesign/ProLayout/components/SiderMenu/typings.ts +44 -0
  125. package/template-design-pro/src/components/GDesign/ProLayout/default.less +2 -0
  126. package/template-design-pro/src/components/GDesign/ProLayout/defaultSettings.ts +121 -0
  127. package/template-design-pro/src/components/GDesign/ProLayout/hooks/context/index.ts +45 -0
  128. package/template-design-pro/src/components/GDesign/ProLayout/index.ts +43 -0
  129. package/template-design-pro/src/components/GDesign/ProLayout/props.ts +57 -0
  130. package/template-design-pro/src/components/GDesign/ProLayout/style.less +272 -0
  131. package/template-design-pro/src/components/GDesign/ProLayout/typings.ts +1 -0
  132. package/template-design-pro/src/components/GDesign/ProLayout/utils/getMenuData.ts +31 -0
  133. package/template-design-pro/src/components/GDesign/ProLayout/utils/index.ts +94 -0
  134. package/template-design-pro/src/components/GDesign/ProLayout/utils/isImg/index.ts +6 -0
  135. package/template-design-pro/src/components/GDesign/ProLayout/utils/isUrl/index.ts +5 -0
  136. package/template-design-pro/src/components/GDesign/Result/index.tsx +142 -0
  137. package/template-design-pro/src/components/GDesign/Result/style.less +140 -0
  138. package/template-design-pro/src/components/GDesign/Scrollbars/components/Bar/index.tsx +56 -0
  139. package/template-design-pro/src/components/GDesign/Scrollbars/components/Bar/props.ts +23 -0
  140. package/template-design-pro/src/components/GDesign/Scrollbars/components/Thumb/index.tsx +164 -0
  141. package/template-design-pro/src/components/GDesign/Scrollbars/components/Thumb/props.ts +11 -0
  142. package/template-design-pro/src/components/GDesign/Scrollbars/context.ts +10 -0
  143. package/template-design-pro/src/components/GDesign/Scrollbars/index.tsx +200 -0
  144. package/template-design-pro/src/components/GDesign/Scrollbars/props.ts +65 -0
  145. package/template-design-pro/src/components/GDesign/Scrollbars/style.less +85 -0
  146. package/template-design-pro/src/components/GDesign/Scrollbars/util.ts +40 -0
  147. package/template-design-pro/src/components/GDesign/utils/index.ts +7 -0
  148. package/template-design-pro/src/components/PageLoading/index.tsx +44 -0
  149. package/template-design-pro/src/components/PageTransition/index.vue +98 -0
  150. package/template-design-pro/src/components/index.ts +6 -0
  151. package/template-design-pro/src/core/ant-design/index.ts +14 -0
  152. package/template-design-pro/src/core/gx-admin-design/index.ts +7 -0
  153. package/template-design-pro/src/core/gx-admin-directives/index.ts +8 -0
  154. package/template-design-pro/src/core/gx-admin-directives/permission.ts +28 -0
  155. package/template-design-pro/src/core/gx-design/index.ts +7 -0
  156. package/template-design-pro/src/core/gx-pro-design/index.ts +10 -0
  157. package/template-design-pro/src/core/index.ts +27 -0
  158. package/template-design-pro/src/design/ant-design/index.less +4 -0
  159. package/template-design-pro/src/design/ant-design/layout.less +29 -0
  160. package/template-design-pro/src/design/ant-design/menu.less +55 -0
  161. package/template-design-pro/src/design/ant-design/table.less +67 -0
  162. package/template-design-pro/src/design/ant-design/tooltip.less +13 -0
  163. package/template-design-pro/src/design/color.less +1 -0
  164. package/template-design-pro/src/design/config.less +5 -0
  165. package/template-design-pro/src/design/index.less +41 -0
  166. package/template-design-pro/src/design/mixin.less +66 -0
  167. package/template-design-pro/src/design/normalize.less +390 -0
  168. package/template-design-pro/src/global.less +15 -0
  169. package/template-design-pro/src/hooks/core/index.ts +3 -0
  170. package/template-design-pro/src/hooks/core/useRequest/index.ts +70 -0
  171. package/template-design-pro/src/hooks/core/useRequest/typings.ts +0 -0
  172. package/template-design-pro/src/hooks/event/index.ts +3 -0
  173. package/template-design-pro/src/hooks/event/useClipboard.ts +14 -0
  174. package/template-design-pro/src/hooks/system/index.ts +5 -0
  175. package/template-design-pro/src/hooks/system/useDict.ts +62 -0
  176. package/template-design-pro/src/hooks/system/usePermissions.ts +39 -0
  177. package/template-design-pro/src/hooks/typings.ts +17 -0
  178. package/template-design-pro/src/layout/BasicLayout.vue +104 -0
  179. package/template-design-pro/src/layout/BlankLayout.vue +5 -0
  180. package/template-design-pro/src/layout/ContentView.vue +76 -0
  181. package/template-design-pro/src/layout/IframeView.vue +1 -0
  182. package/template-design-pro/src/layout/UserLayout.vue +7 -0
  183. package/template-design-pro/src/main.ts +34 -0
  184. package/template-design-pro/src/plugins/index.ts +3 -0
  185. package/template-design-pro/src/router/guard/index.ts +84 -0
  186. package/template-design-pro/src/router/guard/permissions.ts +73 -0
  187. package/template-design-pro/src/router/guard/stateGuard.ts +11 -0
  188. package/template-design-pro/src/router/helper/routeHelper.ts +244 -0
  189. package/template-design-pro/src/router/helper/utils.ts +19 -0
  190. package/template-design-pro/src/router/index.ts +30 -0
  191. package/template-design-pro/src/router/routes/index.ts +85 -0
  192. package/template-design-pro/src/router/routes/modules/workplace.ts +19 -0
  193. package/template-design-pro/src/services/common/index.ts +11 -0
  194. package/template-design-pro/src/services/controller/router.ts +10 -0
  195. package/template-design-pro/src/services/controller/user.ts +35 -0
  196. package/template-design-pro/src/services/system/dictData.ts +10 -0
  197. package/template-design-pro/src/services/system/notices.ts +9 -0
  198. package/template-design-pro/src/store/index.ts +32 -0
  199. package/template-design-pro/src/store/modules/dict.ts +27 -0
  200. package/template-design-pro/src/store/modules/permission.ts +19 -0
  201. package/template-design-pro/src/store/modules/routes.ts +110 -0
  202. package/template-design-pro/src/store/modules/settings.ts +102 -0
  203. package/template-design-pro/src/store/modules/tabsRouter.ts +73 -0
  204. package/template-design-pro/src/store/modules/user.ts +153 -0
  205. package/template-design-pro/src/utils/accessToken.ts +93 -0
  206. package/template-design-pro/src/utils/crypto.ts +39 -0
  207. package/template-design-pro/src/utils/env.ts +52 -0
  208. package/template-design-pro/src/utils/fetchFile.ts +79 -0
  209. package/template-design-pro/src/utils/index.ts +127 -0
  210. package/template-design-pro/src/utils/pageTitle.ts +17 -0
  211. package/template-design-pro/src/utils/request/XHR.ts +131 -0
  212. package/template-design-pro/src/utils/request/axiosCancel.ts +60 -0
  213. package/template-design-pro/src/utils/request/checkStatus.ts +26 -0
  214. package/template-design-pro/src/utils/request/index.ts +145 -0
  215. package/template-design-pro/src/utils/request/typings.ts +114 -0
  216. package/template-design-pro/src/utils/storage.ts +194 -0
  217. package/template-design-pro/src/utils/uploadFile.ts +26 -0
  218. package/template-design-pro/src/utils/util.ts +278 -0
  219. package/template-design-pro/src/utils/validate.ts +221 -0
  220. package/template-design-pro/src/views/Iframe/index.vue +76 -0
  221. package/template-design-pro/src/views/MenuOne/index.vue +15 -0
  222. package/template-design-pro/src/views/MenuTwo/index.vue +13 -0
  223. package/template-design-pro/src/views/exception/403/index.vue +9 -0
  224. package/template-design-pro/src/views/exception/404/index.vue +9 -0
  225. package/template-design-pro/src/views/user/login/index.vue +110 -0
  226. package/template-design-pro/src/views/user/login/style.less +38 -0
  227. package/template-design-pro/stylelint.config.js +106 -0
  228. package/template-design-pro/tests/__mocks__/fileMock.ts +1 -0
  229. package/template-design-pro/tests/__mocks__/styleMock.ts +1 -0
  230. package/template-design-pro/tests/__mocks__/workerMock.ts +5 -0
  231. package/template-design-pro/tests/server/README.md +15 -0
  232. package/template-design-pro/tests/server/controller/FileController.ts +18 -0
  233. package/template-design-pro/tests/server/controller/UserController.ts +15 -0
  234. package/template-design-pro/tests/server/ecosystem.config.js +18 -0
  235. package/template-design-pro/tests/server/index.ts +63 -0
  236. package/template-design-pro/tests/server/nodemon.json +8 -0
  237. package/template-design-pro/tests/server/package.json +36 -0
  238. package/template-design-pro/tests/server/routes.ts +23 -0
  239. package/template-design-pro/tests/server/service/FileService.ts +54 -0
  240. package/template-design-pro/tests/server/service/UserService.ts +25 -0
  241. package/template-design-pro/tests/server/tsconfig.json +15 -0
  242. package/template-design-pro/tests/server/utils.ts +9 -0
  243. package/template-design-pro/tests/server/yarn.lock +2955 -0
  244. package/template-design-pro/tests/test.spec.ts +16 -0
  245. package/template-design-pro/tsconfig.json +47 -0
  246. package/template-design-pro/types/auto-imports.d.ts +61 -0
  247. package/template-design-pro/types/config.d.ts +100 -0
  248. package/template-design-pro/types/global.d.ts +103 -0
  249. package/template-design-pro/types/gx-components.d.ts +24 -0
  250. package/template-design-pro/types/index.d.ts +13 -0
  251. package/template-design-pro/types/mock.d.ts +23 -0
  252. package/template-design-pro/types/module.d.ts +16 -0
  253. package/template-design-pro/types/response.d.ts +15 -0
  254. package/template-design-pro/types/route.d.ts +89 -0
  255. package/template-design-pro/vite.config.ts +136 -0
  256. package/template-design-pro/yarn.lock +9697 -0
@@ -0,0 +1,303 @@
1
+ import type { MockMethod } from '/types/mock'
2
+ import type {
3
+ Recordable,
4
+ ViteMockOptions,
5
+ NodeModuleWithCompile,
6
+ RespThisType,
7
+ } from './types'
8
+
9
+ import path from 'path'
10
+ import fs from 'fs'
11
+ import chokidar from 'chokidar'
12
+ import chalk from 'chalk'
13
+ import url from 'url'
14
+ import fg from 'fast-glob'
15
+ import Mock from 'mockjs'
16
+ import { build } from 'esbuild'
17
+ import { pathToRegexp, match } from 'path-to-regexp'
18
+ import { isArray, isFunction, sleep, isRegExp } from './utils'
19
+ // @ts-ignore
20
+ import { IncomingMessage, NextHandleFunction } from 'connect'
21
+ import module from 'module'
22
+
23
+ export let mockData: MockMethod[] = []
24
+
25
+ export async function createMockServer(
26
+ opt: ViteMockOptions = { mockPath: 'mock', configPath: 'vite.mock.config' },
27
+ ) {
28
+ opt = {
29
+ mockPath: 'mock',
30
+ watchFiles: true,
31
+ supportTs: true,
32
+ configPath: 'vite.mock.config.ts',
33
+ logger: true,
34
+ ...opt,
35
+ }
36
+
37
+ if (mockData.length > 0) return
38
+ mockData = await getMockConfig(opt)
39
+ await createWatch(opt)
40
+ }
41
+
42
+ // request match
43
+ export async function requestMiddleware(opt: ViteMockOptions) {
44
+ const { logger = true } = opt
45
+ const middleware: NextHandleFunction = async (req, res, next) => {
46
+ let queryParams: {
47
+ query?: {
48
+ [key: string]: any
49
+ }
50
+ pathname?: string | null
51
+ } = {}
52
+
53
+ if (req.url) {
54
+ queryParams = url.parse(req.url, true)
55
+ }
56
+
57
+ const reqUrl = queryParams.pathname
58
+
59
+ const matchRequest = mockData.find((item) => {
60
+ if (!reqUrl || !item || !item.url) {
61
+ return false
62
+ }
63
+ if (item.method && item.method.toUpperCase() !== req.method) {
64
+ return false
65
+ }
66
+ return pathToRegexp(item.url).test(reqUrl)
67
+ })
68
+
69
+ if (matchRequest) {
70
+ const isGet = req.method && req.method.toUpperCase() === 'GET'
71
+ const { response, rawResponse, timeout, statusCode, url } = matchRequest
72
+
73
+ if (timeout) {
74
+ await sleep(timeout)
75
+ }
76
+
77
+ const urlMatch = match(url, { decode: decodeURIComponent })
78
+
79
+ let query = queryParams.query
80
+ if (reqUrl) {
81
+ if ((isGet && JSON.stringify(query) === '{}') || !isGet) {
82
+ const params = (urlMatch(reqUrl) as any).params
83
+ if (JSON.stringify(params) !== '{}') {
84
+ query = (urlMatch(reqUrl) as any).params || {}
85
+ } else {
86
+ query = queryParams.query || {}
87
+ }
88
+ }
89
+ }
90
+
91
+ const self: RespThisType = { req, res, parseJson: parseJson.bind(null, req) }
92
+ if (isFunction(rawResponse)) {
93
+ await rawResponse.bind(self)(req, res)
94
+ } else {
95
+ const body = await parseJson(req)
96
+ res.setHeader('Content-Type', 'application/json')
97
+ res.statusCode = statusCode || 200
98
+ const mockResponse = isFunction(response)
99
+ ? response.bind(self)({ url: req.url, body, query, headers: req.headers })
100
+ : response
101
+ res.end(JSON.stringify(Mock.mock(mockResponse)))
102
+ }
103
+
104
+ logger && loggerOutput('request invoke', req.url!)
105
+ return
106
+ }
107
+ next()
108
+ }
109
+ return middleware
110
+ }
111
+
112
+ // create watch mock
113
+ function createWatch(opt: ViteMockOptions) {
114
+ const { configPath, logger, watchFiles } = opt
115
+
116
+ if (!watchFiles) {
117
+ return
118
+ }
119
+
120
+ const { absConfigPath, absMockPath } = getPath(opt)
121
+
122
+ if (process.env.VITE_DISABLED_WATCH_MOCK === 'true') {
123
+ return
124
+ }
125
+
126
+ const watchDir = []
127
+ const exitsConfigPath = fs.existsSync(absConfigPath)
128
+
129
+ exitsConfigPath && configPath ? watchDir.push(absConfigPath) : watchDir.push(absMockPath)
130
+
131
+ const watcher = chokidar.watch(watchDir, {
132
+ ignoreInitial: true,
133
+ })
134
+
135
+ watcher.on('all', async (event, file) => {
136
+ logger && loggerOutput(`mock file ${event}`, file)
137
+ mockData = await getMockConfig(opt)
138
+ })
139
+ }
140
+
141
+ // clear cache
142
+ function cleanRequireCache(opt: ViteMockOptions) {
143
+ if (!require.cache) {
144
+ return
145
+ }
146
+ const { absConfigPath, absMockPath } = getPath(opt)
147
+ Object.keys(require.cache).forEach((file) => {
148
+ if (file === absConfigPath || file.indexOf(absMockPath) > -1) {
149
+ delete require.cache[file]
150
+ }
151
+ })
152
+ }
153
+
154
+ function parseJson(req: IncomingMessage): Promise<Recordable> {
155
+ return new Promise((resolve) => {
156
+ let body = ''
157
+ let jsonStr = ''
158
+ req.on('data', function (chunk) {
159
+ body += chunk
160
+ })
161
+ req.on('end', function () {
162
+ try {
163
+ jsonStr = JSON.parse(body)
164
+ } catch (err) {
165
+ jsonStr = ''
166
+ }
167
+ resolve(jsonStr as any)
168
+ return
169
+ })
170
+ })
171
+ }
172
+
173
+ // load mock .ts files and watch
174
+ async function getMockConfig(opt: ViteMockOptions) {
175
+ cleanRequireCache(opt)
176
+ const { absConfigPath, absMockPath } = getPath(opt)
177
+ const { ignore, configPath, logger } = opt
178
+
179
+ let ret: MockMethod[] = []
180
+
181
+ if (configPath && fs.existsSync(absConfigPath)) {
182
+ logger && loggerOutput(`load mock data from`, absConfigPath)
183
+ ret = await resolveModule(absConfigPath)
184
+ return ret
185
+ }
186
+
187
+ const mockFiles = fg
188
+ .sync(`**/*.{ts,js}`, {
189
+ cwd: absMockPath,
190
+ })
191
+ .filter((item) => {
192
+ if (!ignore) {
193
+ return true
194
+ }
195
+ if (isFunction(ignore)) {
196
+ return ignore(item)
197
+ }
198
+ if (isRegExp(ignore)) {
199
+ return !ignore.test(path.basename(item))
200
+ }
201
+ return true
202
+ })
203
+ try {
204
+ ret = []
205
+ const resolveModulePromiseList = []
206
+
207
+ for (let index = 0; index < mockFiles.length; index++) {
208
+ const mockFile = mockFiles[index]
209
+ resolveModulePromiseList.push(resolveModule(path.join(absMockPath, mockFile)))
210
+ }
211
+
212
+ const loadAllResult = await Promise.all(resolveModulePromiseList)
213
+ for (const resultModule of loadAllResult) {
214
+ let mod = resultModule
215
+ if (!isArray(mod)) {
216
+ mod = [mod]
217
+ }
218
+ ret = [...ret, ...mod]
219
+ }
220
+ } catch (error) {
221
+ loggerOutput(`mock reload error`, error)
222
+ ret = []
223
+ }
224
+ return ret
225
+ }
226
+
227
+ // Inspired by vite
228
+ // support mock .ts files
229
+ async function resolveModule(p: string): Promise<any> {
230
+ const result = await build({
231
+ entryPoints: [p],
232
+ outfile: 'out.js',
233
+ write: false,
234
+ platform: 'node',
235
+ bundle: true,
236
+ format: 'cjs',
237
+ metafile: true,
238
+ target: 'es2015',
239
+ })
240
+ const { text } = result.outputFiles[0]
241
+
242
+ return await loadConfigFromBundledFile(p, text)
243
+ }
244
+
245
+ // get custom config file path and mock dir path
246
+ function getPath(opt: ViteMockOptions) {
247
+ const { mockPath, configPath } = opt
248
+ const cwd = process.cwd()
249
+ const absMockPath = path.join(cwd, mockPath || '')
250
+ const absConfigPath = path.join(cwd, configPath || '')
251
+ return {
252
+ absMockPath,
253
+ absConfigPath,
254
+ }
255
+ }
256
+
257
+ function loggerOutput(title: string, msg: string, type: 'info' | 'error' = 'info') {
258
+ const tag =
259
+ type === 'info' ? chalk.cyan.bold(`[vite:mock]`) : chalk.red.bold(`[vite:mock-server]`)
260
+ return console.log(
261
+ `${chalk.dim(new Date().toLocaleTimeString())} ${tag} ${chalk.green(title)} ${chalk.dim(msg)}`,
262
+ )
263
+ }
264
+
265
+ // Parse file content
266
+ export async function loadConfigFromBundledFile(fileName: string, bundledCode: string) {
267
+ const extension = path.extname(fileName)
268
+
269
+ // @ts-expect-error
270
+ const extensions = module.Module._extensions
271
+ let defaultLoader: any
272
+ const isJs = extension === '.js'
273
+ if (isJs) {
274
+ defaultLoader = extensions[extension]!
275
+ }
276
+
277
+ extensions[extension] = (module: NodeModule, filename: string) => {
278
+ if (filename === fileName) {
279
+ (module as NodeModuleWithCompile)._compile(bundledCode, filename)
280
+ } else {
281
+ if (!isJs) {
282
+ extensions[extension]!(module, filename)
283
+ } else {
284
+ defaultLoader(module, filename)
285
+ }
286
+ }
287
+ }
288
+ let config
289
+ try {
290
+ if (isJs && require && require.cache) {
291
+ delete require.cache[fileName]
292
+ }
293
+ const raw = require(fileName)
294
+ config = raw.__esModule ? raw.default : raw
295
+ if (defaultLoader && isJs) {
296
+ extensions[extension] = defaultLoader
297
+ }
298
+ } catch (error) {
299
+ console.error(error)
300
+ }
301
+
302
+ return config
303
+ }
@@ -0,0 +1,93 @@
1
+ /* eslint-disable */
2
+ import mockJs from 'mockjs'
3
+ import { pathToRegexp } from 'path-to-regexp'
4
+
5
+ const Mock = mockJs as any
6
+ export function createProdMockServer(mockList: any[]) {
7
+ Mock.XHR.prototype.__send = Mock.XHR.prototype.send
8
+ Mock.XHR.prototype.send = function () {
9
+ if (this.custom.xhr) {
10
+ this.custom.xhr.withCredentials = this.withCredentials || false
11
+
12
+ if (this.responseType) {
13
+ this.custom.xhr.responseType = this.responseType
14
+ }
15
+ }
16
+ if (this.custom.requestHeaders) {
17
+ const headers: any = {}
18
+ for (let k in this.custom.requestHeaders) {
19
+ headers[k.toString().toLowerCase()] = this.custom.requestHeaders[k]
20
+ }
21
+ this.custom.options = Object.assign({}, this.custom.options, { headers })
22
+ }
23
+ this.__send.apply(this, arguments)
24
+ }
25
+
26
+ Mock.XHR.prototype.proxy_open = Mock.XHR.prototype.open
27
+
28
+ Mock.XHR.prototype.open = function () {
29
+ let responseType = this.responseType
30
+ this.proxy_open(...arguments)
31
+ if (this.custom.xhr) {
32
+ if (responseType) {
33
+ this.custom.xhr.responseType = responseType
34
+ }
35
+ }
36
+ }
37
+
38
+ for (const { url, method, response, timeout } of mockList) {
39
+ __setupMock__(timeout)
40
+ Mock.mock(
41
+ pathToRegexp(url, undefined, { end: false }),
42
+ method || 'get',
43
+ __XHR2ExpressReqWrapper__(response),
44
+ )
45
+ }
46
+ }
47
+
48
+ function __param2Obj__(url: string) {
49
+ const search = url.split('?')[1]
50
+ if (!search) {
51
+ return {}
52
+ }
53
+ return JSON.parse(
54
+ '{"' +
55
+ decodeURIComponent(search)
56
+ .replace(/"/g, '\\"')
57
+ .replace(/&/g, '","')
58
+ .replace(/=/g, '":"')
59
+ .replace(/\+/g, ' ') +
60
+ '"}',
61
+ )
62
+ }
63
+
64
+ function __XHR2ExpressReqWrapper__(handle: (d: any) => any) {
65
+ return function (options: any) {
66
+ let result = null
67
+ if (typeof handle === 'function') {
68
+ const { body, type, url, headers } = options
69
+
70
+ let b = body
71
+ try {
72
+ b = JSON.parse(body)
73
+ } catch {}
74
+ result = handle({
75
+ method: type,
76
+ body: b,
77
+ query: __param2Obj__(url),
78
+ headers,
79
+ })
80
+ } else {
81
+ result = handle
82
+ }
83
+
84
+ return Mock.mock(result)
85
+ }
86
+ }
87
+
88
+ function __setupMock__(timeout = 0) {
89
+ timeout &&
90
+ Mock.setup({
91
+ timeout,
92
+ })
93
+ }
@@ -0,0 +1,68 @@
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 } from 'vite'
10
+ import { ResolvedConfig, normalizePath } from 'vite'
11
+ import type { ViteMockOptions } from './types'
12
+ import { createMockServer, requestMiddleware } from './createMockServer'
13
+ import { getDefaultPath, fileExists } from '../../../utils'
14
+
15
+ export function viteMockServe(opt: ViteMockOptions = {}): Plugin {
16
+ let defaultPath = getDefaultPath()
17
+ if (!fileExists(defaultPath)) {
18
+ defaultPath = getDefaultPath(false)
19
+ if (!fileExists(defaultPath)) {
20
+ defaultPath = ''
21
+ }
22
+ }
23
+
24
+ const defaultEnter = normalizePath(defaultPath)
25
+ const { injectFile = defaultEnter } = opt
26
+
27
+ let isDev = false
28
+ let config: ResolvedConfig
29
+ let needSourcemap = false
30
+
31
+ return {
32
+ name: 'vite:mock',
33
+ enforce: 'pre',
34
+ configResolved(resolvedConfig) {
35
+ config = resolvedConfig
36
+ isDev = config.command === 'serve'
37
+ needSourcemap = !!resolvedConfig.build.sourcemap
38
+ isDev && createMockServer(opt)
39
+ },
40
+
41
+ configureServer: async ({ middlewares }) => {
42
+ const { localEnabled = isDev } = opt
43
+ if (!localEnabled) {
44
+ return
45
+ }
46
+ const middleware = await requestMiddleware(opt)
47
+ middlewares.use(middleware)
48
+ },
49
+
50
+ async transform(code: string, id: string) {
51
+ if (isDev || !injectFile || !id.endsWith(injectFile)) {
52
+ return null
53
+ }
54
+
55
+ const { prodEnabled = true, injectCode = '' } = opt
56
+ if (!prodEnabled) {
57
+ return null
58
+ }
59
+
60
+ return {
61
+ map: needSourcemap ? this.getCombinedSourcemap() : null,
62
+ code: `${code}\n${injectCode}`
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ export * from './types'
@@ -0,0 +1,30 @@
1
+ import type { IncomingMessage, ServerResponse } from 'http'
2
+
3
+ export interface ViteMockOptions {
4
+ mockPath?: string
5
+ configPath?: string
6
+ ignore?: RegExp | ((fileName: string) => boolean)
7
+ watchFiles?: boolean
8
+ localEnabled?: boolean
9
+ prodEnabled?: boolean
10
+ injectFile?: string
11
+ injectCode?: string
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 Recordable<T = any> = Record<string, T>
27
+
28
+ export interface NodeModuleWithCompile extends NodeModule {
29
+ _compile(code: string, filename: string): any
30
+ }
@@ -0,0 +1,26 @@
1
+ const toString = Object.prototype.toString
2
+
3
+ export function is(val: unknown, type: string) {
4
+ return toString.call(val) === `[object ${type}]`
5
+ }
6
+
7
+ // eslint-disable-next-line
8
+ export function isFunction<T = Function>(val: unknown): val is T {
9
+ return is(val, 'Function') || is(val, 'AsyncFunction')
10
+ }
11
+
12
+ export function isArray(val: any): val is Array<any> {
13
+ return val && Array.isArray(val)
14
+ }
15
+
16
+ export function isRegExp(val: unknown): val is RegExp {
17
+ return is(val, 'RegExp')
18
+ }
19
+
20
+ export function sleep(time: number) {
21
+ return new Promise((resolve) => {
22
+ setTimeout(() => {
23
+ resolve('')
24
+ }, time)
25
+ })
26
+ }
@@ -0,0 +1,32 @@
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
+ };
@@ -0,0 +1,14 @@
1
+ import type { configSeting } from '/types/config'
2
+ import theme from './default/theme'
3
+ import network from './default/network'
4
+ import animate from './default/animate'
5
+ import defaultSettings from './default/defaultSettings'
6
+
7
+ export * from './default/proxy'
8
+
9
+ export default {
10
+ theme,
11
+ network,
12
+ animate,
13
+ defaultSettings
14
+ } as configSeting
@@ -0,0 +1,30 @@
1
+ import type { animateConfig } from '/types/config'
2
+
3
+ const direct_s = [ 'left', 'right' ]
4
+ const direct_1 = [ 'left', 'right', 'down', 'up' ]
5
+ const direct_1_b = [ 'downBig', 'upBig', 'leftBig', 'rightBig' ]
6
+ const direct_2 = [ 'topLeft', 'bottomRight', 'topRight', 'bottomLeft' ]
7
+ const direct_3 = [ 'downLeft', 'upRight', 'downRight', 'upLeft' ]
8
+ // animate.css 配置
9
+ const animateSeting: animateConfig = {
10
+ preset: [
11
+ //预设动画配置
12
+ { name: 'back', alias: '渐近', directions: direct_1 },
13
+ { name: 'bounce', alias: '弹跳', directions: direct_1.concat('default') },
14
+ {
15
+ name: 'fade',
16
+ alias: '淡化',
17
+ directions: direct_1
18
+ .concat(direct_1_b)
19
+ .concat(direct_2)
20
+ .concat('default')
21
+ },
22
+ { name: 'flip', alias: '翻转', directions: [ 'x', 'y' ] },
23
+ { name: 'lightSpeed', alias: '光速', directions: direct_s },
24
+ { name: 'rotate', alias: '旋转', directions: direct_3.concat('default') },
25
+ { name: 'roll', alias: '翻滚', directions: [ 'default' ] },
26
+ { name: 'zoom', alias: '缩放', directions: direct_1.concat('default') },
27
+ { name: 'slide', alias: '滑动', directions: direct_1 }
28
+ ]
29
+ }
30
+ export default animateSeting
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @description 导出默认通用配置
3
+ */
4
+ import type { settingConfig } from '/types/config'
5
+
6
+ const defaultSettings: settingConfig = {
7
+ //开发以及部署时的URL,hash模式时在不确定二级目录名称的情况下建议使用""代表相对路径或者"/二级目录/",history模式默认使用"/"或者"/二级目录/"
8
+ publicPath: './',
9
+ //生产环境构建文件的目录名
10
+ outputDir: 'dist',
11
+ //放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
12
+ assetsDir: 'assets',
13
+ //标题 (包括初次加载雪花屏的标题 页面的标题 浏览器的标题)
14
+ title: 'GX Pro Admin',
15
+ //短标题
16
+ shortName: 'gx_pro_admin',
17
+ //标题分隔符
18
+ titleSeparator: ' - ',
19
+ //标题是否反转 如果为false:"page - title",如果为ture:"title - page"
20
+ titleReverse: false,
21
+ //是否开启水印
22
+ waterMark: true,
23
+ //水印字符
24
+ waterMarkTitle: 'GX Pro Admin',
25
+ //滚动区域选择器
26
+ viewScrollRoot: '#gx-pro-admin>.gx-scrollbar>.gx-scrollbar-wrap',
27
+ //开启cdn
28
+ useCdn: true,
29
+ //开启proxy
30
+ useProxy: true,
31
+ // proxy target
32
+ proxyTarget: 'http://127.0.0.1:3000',
33
+ // 接口前缀
34
+ requestPrefix: '/api',
35
+ //开发环境端口号
36
+ devPort: 8080,
37
+ //pro版本copyright可随意修改
38
+ copyright: 'gx12358 2539306317@qq.com',
39
+ //缓存路由的最大数量
40
+ keepAliveMaxNum: 99,
41
+ //初次页面加载时间
42
+ routerLoadTime: 200,
43
+ //路由模式,可选值为 browser 或 hash
44
+ routerMode: 'hash',
45
+ //不经过token校验的路由
46
+ routesWhiteList: [ '/user/login', '/user/register', '/exception/404', '/exception/403' ],
47
+ //加载时显示文字
48
+ loadingText: '正在加载中...',
49
+ //token名称
50
+ tokenName: 'Authorization',
51
+ //token在localStorage、sessionStorage、cookie存储的key的名称
52
+ tokenTableName: 'GxAccessToken',
53
+ //token存储位置localStorage sessionStorage cookie
54
+ storage: 'localStorage',
55
+ //token失效回退到登录页时是否记录本次的路由
56
+ recordRoute: false,
57
+ //是否显示logo,不显示时设置false,显示时请填写remixIcon图标名称,暂时只支持设置remixIcon
58
+ logo: 'vuejs-fill',
59
+ //是否开启登录拦截
60
+ loginInterception: true,
61
+ //是否开启登录RSA加密
62
+ loginRSA: false,
63
+ //authentication(前端导出路由)和all(后端导出路由)两种方式
64
+ authentication: 'all',
65
+ //是否开启roles字段进行角色权限控制(如果是all模式后端完全处理角色并进行json组装,可设置false不处理路由中的roles字段)
66
+ rolesControl: true,
67
+ //vertical gallery comprehensive common布局时是否只保持一个子菜单的展开
68
+ uniqueOpened: false,
69
+ //vertical布局时默认展开的菜单path,使用逗号隔开建议只展开一个
70
+ defaultOpeneds: [ '' ],
71
+ //需要加loading层的请求,防止重复提交
72
+ debounce: [ 'doEdit' ]
73
+ }
74
+
75
+ export default defaultSettings
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description 导出默认网路配置
3
+ **/
4
+ import type { networkConfig } from '/types/config'
5
+
6
+ const networkSetting: networkConfig = {
7
+ //配后端数据的接收方式application/json;charset=UTF-8 或 application/x-www-form-urlencoded;charset=UTF-8
8
+ contentType: 'application/json;charset=UTF-8',
9
+ //消息框消失时间
10
+ messageDuration: 3000,
11
+ //最长请求时间
12
+ requestTimeout: 10000,
13
+ //操作正常code,支持String、Array、int多种类型
14
+ successCode: [ 200, 0 ]
15
+ }
16
+ export default networkSetting