lookup-token.js 719 B

123456789101112131415161718192021
  1. #!/usr/bin/env node
  2. /** 检查一组 hex 在 uni.scss 中是否有等值令牌 */
  3. const fs = require('fs');
  4. const scss = fs.readFileSync('uni.scss', 'utf8');
  5. const HEXES = process.argv.slice(2);
  6. // 收集 uni.scss 中所有令牌定义
  7. const tokenDefs = [];
  8. for (const line of scss.split(/\r?\n/)) {
  9. const m = line.match(/^\s*(\$[\w-]+)\s*:\s*(#[0-9a-fA-F]{3,8})\s*;/);
  10. if (m) tokenDefs.push({ token: m[1], hex: m[2].toUpperCase() });
  11. }
  12. const byHex = {};
  13. for (const t of tokenDefs) {
  14. if (!byHex[t.hex]) byHex[t.hex] = [];
  15. byHex[t.hex].push(t.token);
  16. }
  17. for (const h of HEXES) {
  18. const up = h.toUpperCase();
  19. const tokens = byHex[up];
  20. console.log(up + ' -> ' + (tokens ? tokens.join(', ') : '(无令牌)'));
  21. }