WMS_MAIN/script/method-doc-list.cjs

50 lines
1.4 KiB
JavaScript

'use strict';
/**
* 列出 API 方法文档(支持按模块/关键字过滤)。
*
* 用法:
* node script/method-doc-list.cjs [--module wechat] [--search 用户须知] [--env production]
*/
const {
resolveEnv, createConnection, parseArgs, fail,
} = require('./method-doc-common.cjs');
(async () => {
const args = parseArgs();
const env = resolveEnv();
const module = args.get('module');
const search = args.get('search');
const conditions = [];
const values = [];
if (module) {
conditions.push('module=?');
values.push(module);
}
if (search) {
conditions.push('(method LIKE ? OR description LIKE ? OR group_name LIKE ?)');
const kw = `%${search}%`;
values.push(kw, kw, kw);
}
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
const conn = await createConnection(env);
const [ rows ] = await conn.query(
`SELECT method, module, group_name, is_need_login, is_need_auth, status, group_sort, item_sort
FROM wms_api_method_doc ${where}
ORDER BY group_sort ASC, item_sort ASC, id ASC`,
values
);
await conn.end();
console.log(`method count: ${rows.length}`);
for (const row of rows) {
console.log(
`${String(row.method).padEnd(48)} | ${String(row.module).padEnd(18)} | ${String(row.group_name).padEnd(16)}`
+ ` | login=${row.is_need_login} auth=${row.is_need_auth} status=${row.status}`
);
}
})().catch(e => fail(e.message));