Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
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
shenshaokai
jinfa-platform
Commits
6b9a4d07
Commit
6b9a4d07
authored
Apr 20, 2022
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: 优化获取paas菜单功能
parent
cd3db032
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
0 deletions
+98
-0
pullRemoteRouterList.js
scripts/pullRemoteRouterList.js
+7
-0
index.js
scripts/utils/index.js
+91
-0
No files found.
scripts/pullRemoteRouterList.js
View file @
6b9a4d07
...
...
@@ -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
=
1
...
...
@@ -57,6 +58,7 @@ function code2component(components, codes) {
})
}
// 批量组装接口
async
function
batchAxiosHttps
()
{
const
asyncHttpQueue
=
deepClone
(
serviceConfig
)
...
...
@@ -105,9 +107,14 @@ 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
})
}
module
.
exports
=
batchAxiosHttps
scripts/utils/index.js
View file @
6b9a4d07
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
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