mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #24587 from overleaf/bg-fix-web-routes-script
fix bin/routes script GitOrigin-RevId: bc791cf01ce3321ec4badffe2cbc8c4ea93ba381
This commit is contained in:
@@ -39,9 +39,9 @@ const routerCall = callExpression => {
|
||||
(routerName === 'app' || routerName.match('^.*[rR]outer$'))
|
||||
) {
|
||||
return {
|
||||
routerName: routerName,
|
||||
routerName,
|
||||
method: property.name,
|
||||
args: args,
|
||||
args,
|
||||
}
|
||||
} else {
|
||||
return null
|
||||
@@ -55,27 +55,30 @@ const formatMethodCall = expression => {
|
||||
const parseAndPrintRoutesSync = path => {
|
||||
const content = fs.readFileSync(path)
|
||||
// Walk the AST (Abstract Syntax Tree)
|
||||
acornWalk.simple(acorn.parse(content), {
|
||||
// We only care about call expression ( like `a.b()` )
|
||||
CallExpression(node) {
|
||||
const call = routerCall(node)
|
||||
if (call) {
|
||||
const firstArg = _.first(call.args)
|
||||
try {
|
||||
print(
|
||||
` ${formatRouterName(call.routerName)}\t .${call.method} \t: ${
|
||||
firstArg.value
|
||||
} => ${call.args.slice(1).map(formatMethodCall).join(' => ')}`
|
||||
)
|
||||
} catch (e) {
|
||||
print('>> Error')
|
||||
print(e)
|
||||
print(JSON.stringify(call))
|
||||
process.exit(1)
|
||||
acornWalk.simple(
|
||||
acorn.parse(content, { sourceType: 'module', ecmaVersion: 2020 }),
|
||||
{
|
||||
// We only care about call expression ( like `a.b()` )
|
||||
CallExpression(node) {
|
||||
const call = routerCall(node)
|
||||
if (call) {
|
||||
const firstArg = _.first(call.args)
|
||||
try {
|
||||
print(
|
||||
` ${formatRouterName(call.routerName)}\t .${call.method} \t: ${
|
||||
firstArg.value
|
||||
} => ${call.args.slice(1).map(formatMethodCall).join(' => ')}`
|
||||
)
|
||||
} catch (e) {
|
||||
print('>> Error')
|
||||
print(e)
|
||||
print(JSON.stringify(call))
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const routerNameMapping = {
|
||||
@@ -101,7 +104,7 @@ const main = () => {
|
||||
}
|
||||
|
||||
// Find all routers
|
||||
glob('*[rR]outer.js', { matchBase: true }, (err, files) => {
|
||||
glob('*[rR]outer.*js', { matchBase: true }, (err, files) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user