UNPKG

transform-to-tailwindcss

Version:

🎨 Revolutionary CSS-to-TailwindCSS migration tool with surgical precision. Transform legacy stylesheets to utility-first classes instantly across Vue, React, Svelte, and Astro projects.

186 lines (182 loc) 7.46 kB
const require_transformCode = require('./transformCode-BkcX8lB7.cjs'); let node_fs = require("node:fs"); node_fs = require_transformCode.__toESM(node_fs); let node_path = require("node:path"); node_path = require_transformCode.__toESM(node_path); let node_process = require("node:process"); node_process = require_transformCode.__toESM(node_process); let fast_glob = require("fast-glob"); fast_glob = require_transformCode.__toESM(fast_glob); //#region node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js var require_picocolors = /* @__PURE__ */ require_transformCode.__commonJS({ "node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js": ((exports, module) => { let p = process || {}, argv = p.argv || [], env = p.env || {}; let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI); let formatter = (open, close, replace = open) => (input) => { let string = "" + input, index = string.indexOf(close, open.length); return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close; }; let replaceClose = (string, close, replace, index) => { let result = "", cursor = 0; do { result += string.substring(cursor, index) + replace; cursor = index + close.length; index = string.indexOf(close, cursor); } while (~index); return result + string.substring(cursor); }; let createColors = (enabled = isColorSupported) => { let f = enabled ? formatter : () => String; return { isColorSupported: enabled, reset: f("\x1B[0m", "\x1B[0m"), bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"), dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"), italic: f("\x1B[3m", "\x1B[23m"), underline: f("\x1B[4m", "\x1B[24m"), inverse: f("\x1B[7m", "\x1B[27m"), hidden: f("\x1B[8m", "\x1B[28m"), strikethrough: f("\x1B[9m", "\x1B[29m"), black: f("\x1B[30m", "\x1B[39m"), red: f("\x1B[31m", "\x1B[39m"), green: f("\x1B[32m", "\x1B[39m"), yellow: f("\x1B[33m", "\x1B[39m"), blue: f("\x1B[34m", "\x1B[39m"), magenta: f("\x1B[35m", "\x1B[39m"), cyan: f("\x1B[36m", "\x1B[39m"), white: f("\x1B[37m", "\x1B[39m"), gray: f("\x1B[90m", "\x1B[39m"), bgBlack: f("\x1B[40m", "\x1B[49m"), bgRed: f("\x1B[41m", "\x1B[49m"), bgGreen: f("\x1B[42m", "\x1B[49m"), bgYellow: f("\x1B[43m", "\x1B[49m"), bgBlue: f("\x1B[44m", "\x1B[49m"), bgMagenta: f("\x1B[45m", "\x1B[49m"), bgCyan: f("\x1B[46m", "\x1B[49m"), bgWhite: f("\x1B[47m", "\x1B[49m"), blackBright: f("\x1B[90m", "\x1B[39m"), redBright: f("\x1B[91m", "\x1B[39m"), greenBright: f("\x1B[92m", "\x1B[39m"), yellowBright: f("\x1B[93m", "\x1B[39m"), blueBright: f("\x1B[94m", "\x1B[39m"), magentaBright: f("\x1B[95m", "\x1B[39m"), cyanBright: f("\x1B[96m", "\x1B[39m"), whiteBright: f("\x1B[97m", "\x1B[39m"), bgBlackBright: f("\x1B[100m", "\x1B[49m"), bgRedBright: f("\x1B[101m", "\x1B[49m"), bgGreenBright: f("\x1B[102m", "\x1B[49m"), bgYellowBright: f("\x1B[103m", "\x1B[49m"), bgBlueBright: f("\x1B[104m", "\x1B[49m"), bgMagentaBright: f("\x1B[105m", "\x1B[49m"), bgCyanBright: f("\x1B[106m", "\x1B[49m"), bgWhiteBright: f("\x1B[107m", "\x1B[49m") }; }; module.exports = createColors(); module.exports.createColors = createColors; }) }); //#endregion //#region node_modules/.pnpm/@simon_he+colorize@0.0.1/node_modules/@simon_he/colorize/dist/index.mjs var import_picocolors = /* @__PURE__ */ require_transformCode.__toESM(require_picocolors(), 1); const RGB_LIKE_REGEX = /^(rgb|hsl|hsv|hwb)\(\s?(\d+),\s?(\d+),\s?(\d+)\s?\)$/; const ANSI_REGEX = /^(ansi|ansi256)\(\s?(\d+)\s?\)$/; const getMethod = (name, type) => type === "foreground" ? name : `bg${name[0].toUpperCase()}${name.slice(1)}`; function setColor(str, color, type) { if (!color) return str; if (color in import_picocolors.default) return import_picocolors.default[getMethod(color, type)](str); if (color.startsWith("#")) return import_picocolors.default[getMethod("hex", type)](color)(str); if (color.startsWith("ansi")) { const matches2 = ANSI_REGEX.exec(color); if (!matches2) return str; const method2 = getMethod(matches2[1], type); const value = Number(matches2[2]); return import_picocolors.default[method2](value)(str); } if (!(color.startsWith("rgb") || color.startsWith("hsl") || color.startsWith("hsv") || color.startsWith("hwb"))) return str; const matches = RGB_LIKE_REGEX.exec(color); if (!matches) return str; const method = getMethod(matches[1], type); const firstValue = Number(matches[2]); const secondValue = Number(matches[3]); const thirdValue = Number(matches[4]); return import_picocolors.default[method](firstValue, secondValue, thirdValue)(str); } function colorize(options) { const { text, color, bgColor, dimmed, bold, italic, underline, strikethrough, inverse } = options; let result = text; if (dimmed) result = import_picocolors.default.dim(result); if (color) result = setColor(result, color, "foreground"); if (bgColor) result = setColor(result, bgColor, "background"); if (bold) result = import_picocolors.default.bold(result); if (italic) result = import_picocolors.default.italic(result); if (underline) result = import_picocolors.default.underline(result); if (strikethrough) result = import_picocolors.default.strikethrough(result); if (inverse) result = import_picocolors.default.inverse(result); return result; } //#endregion //#region src/cli.ts const log = console.log; async function cli() { const asset = node_process.default.argv[2]; if (!asset) { log(colorize({ text: "需要指定一个目录", color: "red" })); return; } const fileDir = node_path.default.resolve(node_process.default.cwd(), asset); const isRevert = node_process.default.argv[3] === "-r" || node_process.default.argv[3] === "--revert"; (await (0, fast_glob.default)([ "**.vue", "**.tsx", "**.html", "**.svelte", "**.astro" ], { cwd: fileDir })).filter((entry) => !entry.endsWith(require_transformCode.TRANSFER_FLAG)).forEach(async (entry) => { const filepath = `${fileDir}/${entry}`; const suffix = entry.slice(entry.lastIndexOf(".") + 1); const newfilepath = filepath.endsWith(require_transformCode.TRANSFER_FLAG) ? filepath : filepath.replace(`.${suffix}`, `${require_transformCode.TRANSFER_FLAG}.${suffix}`); if (node_fs.default.existsSync(newfilepath)) { if (isRevert) { try { await node_fs.default.promises.unlink(newfilepath); log(colorize({ text: `${newfilepath} already revert`, color: "green" })); } catch (error) { log(colorize({ text: `revert failed: ${error}`, color: "red" })); } return; } log(colorize({ text: `${newfilepath} has transferred`, color: "yellow" })); return; } else if (isRevert) return; const codeTransfer = await require_transformCode.transformCode(await node_fs.default.promises.readFile(filepath, "utf-8"), { filepath, type: suffix }); try { await node_fs.default.promises.writeFile(newfilepath, codeTransfer); log(colorize({ text: `${newfilepath} transfer succeed`, color: "green" })); } catch (error) { log(colorize({ text: `${newfilepath} transfer failed: ${error}`, color: "red" })); } }); } cli(); //#endregion exports.cli = cli;