UNPKG

t-comm

Version:

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

40 lines (35 loc) 1.23 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var fs_fs = require('../fs/fs.js'); require('../nodejs/crypto.js'); require('../nodejs/fs.js'); require('../nodejs/os.js'); 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 = fs_fs.readFileSync(filePath); var res = []; res = Array.from(new Set(content.match(extractRegexp))); console.log('[extractClass] res: ', res); fs_fs.writeFileSync(targetFilePath, res, true); } exports.extractClass = extractClass;