@nguyenduclong/rdbtools
v1.0.2
Published
Bộ công cụ CLI nhỏ cho các tác vụ thường gặp:
Readme
rdbtools
Bộ công cụ CLI nhỏ cho các tác vụ thường gặp:
fix-sort-imports: sắp xếp thứ tựimportcho JS/TS.docx-to-md: chuyển file.docxsang Markdown, tách ảnh ra file riêng.md-extract: tách ảnh nhúng dạngdata:image/...;base64trong Markdown thành file ảnh.rdb-mock: chạy mock server có route tùy biến và proxy các route còn lại lên upstream.
Cài đặt
Dùng trực tiếp trong repo
npm installDùng như package CLI
npm install -g @nguyenduclong/rdbtoolsHoặc chạy qua npx:
npx @nguyenduclong/rdbtools <command>1) fix-sort-imports
Sắp xếp nhóm import theo cú pháp member (none, all, multiple, single), đồng thời sort tên trong { ... }.
Cách dùng
fix-sort-imports <file-or-dir> [...more] [--write=false]Ví dụ:
fix-sort-imports src
fix-sort-imports src/a.ts src/b.ts
fix-sort-imports src --write=falseGhi chú:
- Mặc định
--write=true(ghi đè file). - Bỏ qua các thư mục phổ biến như
node_modules,.git,dist,build,coverage,.next,.turbo,.yarn,out.
2) docx-to-md
Chuyển .docx thành Markdown, xuất ảnh thành file riêng trong thư mục output.
Cách dùng
docx-to-md <input-docx-file>Ví dụ:
docx-to-md ./docs/spec.docxKết quả:
- Tạo thư mục cùng tên file đầu vào (không gồm đuôi
.docx), ví dụdocs/spec/. - File markdown output:
docs/spec/spec.md. - Ảnh được xuất vào cùng thư mục output.
3) md-extract
Tách ảnh nhúng base64 trong file Markdown thành file ảnh riêng và rewrite lại link ảnh trong Markdown.
Cách dùng
md-extract <input-markdown-file>Ví dụ:
md-extract ./notes/report.mdKết quả:
- Tạo thư mục output theo tên file markdown, ví dụ
notes/report/. - File markdown đã rewrite:
notes/report/report.md. - Ảnh được xuất vào cùng thư mục output.
4) rdb-mock
Mock server dựa trên Express:
- Route khớp trong
mockRoutessẽ dùng handler mock. - Route còn lại sẽ proxy sang
sourceUrl.
Cách dùng
rdb-mock <path-to-mock-routes-file>Ví dụ file config (mock.config.cjs):
module.exports = {
sourceUrl: 'http://localhost:8000',
host: '127.0.0.1', // optional, mặc định lấy từ MOCK_HOST hoặc 127.0.0.1
port: 8001,
mockRoutes: [
{
path: '/tenant/pats/',
method: 'GET',
handle: (req, res) => res.status(200).json({ results: [] }),
},
],
// optional
middlewares: [],
};Chạy:
rdb-mock ./mock.config.cjsHealth check:
curl http://127.0.0.1:8001/__mock/healthScripts npm
npm run extract-md-images -- <input-md-file>
npm run docx-to-md -- <input-docx-file>
npm run rdb-mock -- <path-to-config>License
ISC
