Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-admin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
linweijiong
jinfa-admin
Commits
8e52991a
Commit
8e52991a
authored
Apr 20, 2022
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: 优化paas菜单的获取
parent
c0a96c98
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
8 deletions
+104
-8
pullRemoteRouterList.js
scripts/pullRemoteRouterList.js
+5
-0
index.js
scripts/utils/index.js
+91
-0
yarn.lock
yarn.lock
+8
-8
No files found.
scripts/pullRemoteRouterList.js
View file @
8e52991a
...
...
@@ -9,6 +9,7 @@ const Axios = require('axios').default;
const
deepClone
=
require
(
'clone'
)
const
fs
=
require
(
'fs'
)
const
path
=
require
(
'path'
)
const
{
validateRouterJson
}
=
require
(
'./utils'
)
const
BACK_GATEWAY
=
process
.
env
.
BACK_GATEWAY
const
source
=
99
...
...
@@ -106,6 +107,10 @@ async function batchAxiosHttps() {
// if (err) throw err
// })
// code2component(asyncHttpQueue.router.routerList, asyncHttpQueue.router.componentList)
if
(
!
validateRouterJson
(
asyncHttpQueue
.
router
.
routerList
))
{
return
false
}
fs
.
writeFile
(
path
.
resolve
(
__dirname
,
'../config/router.config.json'
),
`
${
JSON
.
stringify
(
asyncHttpQueue
.
router
.
routerList
)}
`
,
function
(
err
)
{
if
(
err
)
throw
err
})
...
...
scripts/utils/index.js
View file @
8e52991a
const
path
=
require
(
'path'
)
const
fs
=
require
(
'fs'
)
function
validateRouterJson
(
json
,
testLocalJson
)
{
const
excludes
=
[
'.DS_Store'
,
'.umi'
,
'.umi-production'
]
let
dispatchs
=
[]
let
hashMapReSource
=
{}
const
resourcePath
=
path
.
resolve
(
process
.
cwd
(),
'src'
)
if
(
testLocalJson
)
{
// 测试
hashMapReSource
=
Array
.
isArray
(
testLocalJson
)
?
transformJson
(
testLocalJson
)
:
testLocalJson
}
else
{
dispatchs
=
dispatchDir
(
path
.
resolve
(
resourcePath
,
'pages'
),
excludes
)
// 本地的json
while
(
dispatchs
.
length
)
{
const
item
=
dispatchs
.
shift
()
hashMapReSource
[
item
]
=
true
dispatchs
.
push
(...
dispatchDir
(
item
,
excludes
))
}
}
// 拉下来的json文件
function
transformJson
(
json
)
{
return
Array
.
isArray
(
json
)
?
json
.
reduce
((
target
,
maps
)
=>
{
if
(
maps
.
component
)
{
target
[
maps
.
component
.
replace
(
'@'
,
resourcePath
).
replace
(
'./'
,
resourcePath
+
'/pages/'
)]
=
true
}
if
(
maps
.
routes
)
{
target
=
Object
.
assign
(
target
,
transformJson
(
maps
.
routes
))
}
return
target
},
{})
:
json
}
// 远程拉下来的json文件
const
tempHashMap
=
transformJson
(
json
)
const
warnPaths
=
compareJson
(
tempHashMap
,
hashMapReSource
)
if
(
warnPaths
.
length
>
0
)
{
console
.
warn
(
'---------- warn ----------'
)
console
.
warn
(
'出现路由文件不匹配'
)
console
.
warn
(
'---------- warn ----------'
)
console
.
log
(
warnPaths
)
return
false
}
return
true
}
function
dispatchDir
(
rpath
,
excludes
)
{
if
(
fs
.
statSync
(
rpath
).
isFile
())
{
return
[]
}
return
fs
.
readdirSync
(
rpath
).
reduce
((
dispatchs
,
dir
)
=>
{
if
(
excludes
.
includes
(
dir
))
{
return
dispatchs
}
const
nearDir
=
path
.
resolve
(
rpath
,
dir
)
if
(
fs
.
statSync
(
nearDir
).
isDirectory
())
{
dispatchs
.
push
(
nearDir
)
}
else
{
if
(
path
.
extname
(
nearDir
)
===
'.tsx'
)
{
dispatchs
.
push
(
nearDir
)
}
}
return
dispatchs
},
[])
}
function
compareJson
(
json1
,
json2
)
{
const
results
=
[]
for
(
const
item
in
json1
)
{
if
(
!
json2
[
item
]
&&
!
json2
[
item
+
'.tsx'
])
{
results
.
push
(
item
)
}
}
return
results
}
/**
* 对router文件做校验,若本地目录不存在该路径,则给出警告,而不覆盖错误的路由
*/
exports
.
validateRouterJson
=
validateRouterJson
yarn.lock
View file @
8e52991a
...
...
@@ -10308,13 +10308,13 @@ rc-motion@^2.0.0, rc-motion@^2.0.1, rc-motion@^2.2.0, rc-motion@^2.3.0, rc-motio
rc-util "^5.2.1"
rc-motion@^2.4.0:
version "2.
4.7
"
resolved "https://registry.npmjs.org/rc-motion/-/rc-motion-2.
4.7.tgz#74f0d9dd16bbeb6cb5a905777ce9d492bb95cb77
"
integrity sha512-
GmC8dYoxCWrGb2pf0JLok97AGdrOFwaCQIJY1xyhnoOYVZuysU419ITu6OCBcjp3SpeogHK80HA6DIwY1cBblg
==
version "2.
5.1
"
resolved "https://registry.npmjs.org/rc-motion/-/rc-motion-2.
5.1.tgz#3eceb7d891079c0f67a72639d30e168b91839e03
"
integrity sha512-
h3GKMjFJkK+4z6fNfVlIMrb7WFCZsreivVvHOBb38cKcpKDx5g3kpHwn5Ekbo1+g0nnC02Dtap2trfCAPGxllw
==
dependencies:
"@babel/runtime" "^7.11.1"
classnames "^2.2.1"
rc-util "^5.
19.2
"
rc-util "^5.
21.0
"
rc-notification@~4.5.7:
version "4.5.7"
...
...
@@ -10641,10 +10641,10 @@ rc-util@^5.0.0, rc-util@^5.0.1, rc-util@^5.0.6, rc-util@^5.0.7, rc-util@^5.12.0,
react-is "^16.12.0"
shallowequal "^1.1.0"
rc-util@^5.0.5, rc-util@^5.13.0, rc-util@^5.13.1, rc-util@^5.
19.2
:
version "5.
19.6
"
resolved "https://registry.npmjs.org/rc-util/-/rc-util-5.
19.6.tgz#76d714fd116d22bc5fd7421939589e27c1dfad19
"
integrity sha512-
/xJ8UtpbuJj7+2ftxVQM6gUzLY+Towq4iB6sP6/2hhn6mwWNLij2I+1qOkLv75I1jqWKpS+gU8A2EmbfLtGxN
g==
rc-util@^5.0.5, rc-util@^5.13.0, rc-util@^5.13.1, rc-util@^5.
21.0
:
version "5.
21.0
"
resolved "https://registry.npmjs.org/rc-util/-/rc-util-5.
21.0.tgz#3c97bbfa3e89354746978b15d275b7b7ef007045
"
integrity sha512-
5THhvHk69Mqfn9CHoqOWKFjfOrJop0364bT2NU8baMthJCiyfJs3SyDfJJbKZqw9LHhw17eMpat3g4WVFmLIn
g==
dependencies:
"@babel/runtime" "^7.12.5"
react-is "^16.12.0"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment