46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 下线/删除 API 方法文档(默认软删 status=0,导出时排除;--hard 真实删除)。
|
||
*
|
||
* 用法:
|
||
* node script/method-doc-delete.cjs --method wechat.xxx --yes [--hard] [--bump] [--doc system] [--env production]
|
||
*/
|
||
|
||
const {
|
||
resolveEnv, createConnection, parseArgs, bumpVersion, today, fail,
|
||
} = require('./method-doc-common.cjs');
|
||
|
||
(async () => {
|
||
const args = parseArgs();
|
||
const env = resolveEnv();
|
||
const docName = args.get('doc') || 'system';
|
||
|
||
const method = args.get('method');
|
||
if (!method) fail('缺少 --method(方法名)');
|
||
if (!args.has('yes')) fail('危险操作:请追加 --yes 确认');
|
||
|
||
const hard = args.has('hard');
|
||
const bump = args.has('bump');
|
||
|
||
const conn = await createConnection(env);
|
||
const [ result ] = hard
|
||
? await conn.query('DELETE FROM wms_api_method_doc WHERE method=?', [ method ])
|
||
: await conn.query('UPDATE wms_api_method_doc SET status=0, updated_at=NOW() WHERE method=?', [ method ]);
|
||
|
||
if (result.affectedRows === 0) {
|
||
await conn.end();
|
||
fail(`method 不存在(${method})`);
|
||
}
|
||
|
||
if (bump) {
|
||
const [ metaRows ] = await conn.query('SELECT version FROM wms_method_doc_meta WHERE doc_name=?', [ docName ]);
|
||
const next = bumpVersion(metaRows[0] ? metaRows[0].version : '0.3.0');
|
||
await conn.query('UPDATE wms_method_doc_meta SET version=?, updated_at=? WHERE doc_name=?', [ next, today(), docName ]);
|
||
console.log(`[method-doc] 文档版本已升至 ${next}`);
|
||
}
|
||
|
||
await conn.end();
|
||
console.log(`[method-doc] 已${hard ? '真实删除' : '下线(status=0)'}:${method}(env=${env})`);
|
||
})().catch(e => fail(e.message));
|