UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

36 lines (33 loc) 1.14 kB
import { readFileSync, writeFileSync } from '../fs/fs.mjs'; import '../nodejs/crypto.mjs'; import '../nodejs/fs.mjs'; import '../nodejs/os.mjs'; var DEFAULT_EXTRACT_REGEXP = /(?<=class=")([^"=/?).]+?)(?=")/g; // /(?!class=")(?=tip)([^"]+)/g /** * 提取 Vue 组件的 class * @param {obj} params 参数 * @param {string} params.filePath 源文件地址 * @param {string} [params.targetFilePath] 输出文件地址 * @param {Regexp} [params.extractRegexp] 提取正则 * @example * * ```ts * extractClass({ * filePath: 'xxx.vue', * }) * ``` */ function extractClass(_ref) { var filePath = _ref.filePath, _ref$targetFilePath = _ref.targetFilePath, targetFilePath = _ref$targetFilePath === void 0 ? './log/extract-class.md' : _ref$targetFilePath, _ref$extractRegexp = _ref.extractRegexp, extractRegexp = _ref$extractRegexp === void 0 ? DEFAULT_EXTRACT_REGEXP : _ref$extractRegexp; var content = readFileSync(filePath); var res = []; res = Array.from(new Set(content.match(extractRegexp))); console.log('[extractClass] res: ', res); writeFileSync(targetFilePath, res, true); } export { extractClass };