import { checkFormKeyEnter } from "./check/check-form-enter-key/index"; import { checkTableLoading } from "./check/check-table-loading/index"; import { checkCopyLink } from "./check/check-copy-link"; import { IOption } from "./type"; import fs from "fs"; export const checkInteractionPlugin = (option?: IOption) => { const defaultOptions: IOption = { isCheckTableCopyLink: true, isCheckFormEnterKey: true, isCheckTableLoading: true, }; const pluginOptions: IOption = Object.assign(defaultOptions, option); return { name: "check-interaction-plugin", transform(code: string, id: string) { const vueAndTsxRegex = /\.(vue|tsx)$/.test(id); const nodeModulesRegex = /\/node_modules\//g.test(id); const filterRegex = /.+\?vue&type=script&lang\.tsx$/.test(id); if (!vueAndTsxRegex || nodeModulesRegex || filterRegex) { return code; } const sourceCode = fs.readFileSync(id, { encoding: "utf-8" }); // 检查el-form if (pluginOptions.isCheckFormEnterKey) { checkFormKeyEnter(sourceCode, id); } // 检查el-table if (pluginOptions.isCheckTableLoading) { checkTableLoading(sourceCode, id); } // 检查table当中 if (pluginOptions.isCheckTableCopyLink) { checkCopyLink(sourceCode, id); } }, }; };