UNPKG

@mypaas/hcm-cli

Version:

Vant Cli 是一个 Vue 组件库构建工具,通过 Vant Cli 可以快速搭建一套功能完备的 Vue 组件库。

63 lines (62 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.replaceMd = exports.replaceScript = exports.replaceStyle = exports.markdownReplacer = exports.sfcReplacer = exports.scriptReplacer = exports.styleReplacer = void 0; const fs_1 = require("fs"); /** * Replace van to hcm * @param source * @returns {string} * * @example * .van-button => .hcm-button * [class*='hcm--'] => [class*='hcm--'] * \@keyframes hcm--circular => @keyframes hcm--circular */ function styleReplacer(source) { return source.replace(/([.'"\s])van([-\s])/g, ($0, $1, $2) => `${$1}hcm${$2}`); } exports.styleReplacer = styleReplacer; /** * Replace van to hcm * @param source * @returns {string} * * @example * van-dialog => hcm-dialog * vanTabs => hcmTabs * VanDialog => HcmDialog * $vant => $hcm * [Vant => [Hcm */ function scriptReplacer(source) { return source.replace(/([vV])an([-A-Z])/g, ($0, $1, $2) => `${$1 === 'v' ? 'h' : 'H'}cm${$2}`) .replace(/([$[])([vV])ant/g, ($0, $1, $2) => `${$1}${$2 === 'v' ? 'h' : 'H'}cm`); } exports.scriptReplacer = scriptReplacer; function sfcReplacer(source) { return source.replace(/([<@."'])([Vv])an/g, ($0, $1, $2) => $1 === '@' ? $0 : `${$1 || ''}${$2 === 'v' ? 'h' : 'H'}cm`) .replace(/<\/van/g, '</hcm') .replace(/([vV])an([-A-Z])/g, ($0, $1, $2) => `${$1 === 'v' ? 'h' : 'H'}cm${$2}`); } exports.sfcReplacer = sfcReplacer; function markdownReplacer(source) { return sfcReplacer(source); } exports.markdownReplacer = markdownReplacer; function replaceFile(filePath, replacer) { const source = fs_1.readFileSync(filePath, 'utf8'); const result = replacer(source); fs_1.writeFileSync(filePath, result, 'utf-8'); } function replaceStyle(filePath) { replaceFile(filePath, styleReplacer); } exports.replaceStyle = replaceStyle; function replaceScript(filePath) { replaceFile(filePath, scriptReplacer); } exports.replaceScript = replaceScript; function replaceMd(filePath) { replaceFile(filePath, markdownReplacer); } exports.replaceMd = replaceMd;