hsl.mjs 587 B

123456789101112131415161718192021222324
  1. #!/env/node
  2. import * as path from 'path'
  3. import * as fs from 'fs'
  4. console.time('[hsl]')
  5. const args = process.argv
  6. const CWD = process.cwd()
  7. const targetFile = path.resolve(CWD, args[2])
  8. if (!fs.existsSync(targetFile))
  9. throw new Error(`Target file not found! [${targetFile}]`)
  10. const targetFileContent = fs.readFileSync(targetFile)?.toString()
  11. const exportHSLFileContent =
  12. targetFileContent.replace(/: (.+)%;/g, `: hsl($1%);`)
  13. const exportHSLFilePath = targetFile.replace(/\.css$/, '_hsl.css')
  14. fs.writeFileSync(exportHSLFilePath, exportHSLFileContent)
  15. console.timeEnd('[hsl]')