less-lint.coffee 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env node
  2. fs = require 'fs'
  3. less = require 'less'
  4. args = process.argv.slice(1)
  5. options = {}
  6. args = args.filter (arg) ->
  7. match = arg.match(/^-I(.+)$/)
  8. if match
  9. options.paths.push(match[1]);
  10. return false
  11. match = arg.match(/^--?([a-z][\-0-9a-z]*)(?:=([^\s]+))?$/i)
  12. if match
  13. arg = match[1]
  14. else
  15. return arg
  16. switch arg
  17. when 'strict-imports' then options.strictImports = true
  18. when 'include-path'
  19. options.paths = match[2].split(if os.type().match(/Windows/) then ';' else ':')
  20. .map (p) ->
  21. if p
  22. return path.resolve(process.cwd(), p)
  23. when 'O0' then options.optimization = 0
  24. when 'O1' then options.optimization = 1
  25. when 'O2' then options.optimization = 2
  26. options.filename = args[1]
  27. parser = new(less.Parser) options
  28. fs.readFile(options.filename, 'utf-8', (err,data) ->
  29. parser.parse(data, (err, tree) ->
  30. if err
  31. less.writeError err
  32. process.exit(1)
  33. )
  34. )