less-lint.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Generated by CoffeeScript 1.3.3
  2. (function() {
  3. var args, fs, less, options, parser;
  4. fs = require('fs');
  5. less = require('less');
  6. args = process.argv.slice(1);
  7. options = {};
  8. args = args.filter(function(arg) {
  9. var match;
  10. match = arg.match(/^-I(.+)$/);
  11. if (match) {
  12. options.paths.push(match[1]);
  13. return false;
  14. }
  15. match = arg.match(/^--?([a-z][\-0-9a-z]*)(?:=([^\s]+))?$/i);
  16. if (match) {
  17. arg = match[1];
  18. } else {
  19. return arg;
  20. }
  21. switch (arg) {
  22. case 'strict-imports':
  23. return options.strictImports = true;
  24. case 'include-path':
  25. return options.paths = match[2].split(os.type().match(/Windows/) ? ';' : ':').map(function(p) {
  26. if (p) {
  27. return path.resolve(process.cwd(), p);
  28. }
  29. });
  30. case 'O0':
  31. return options.optimization = 0;
  32. case 'O1':
  33. return options.optimization = 1;
  34. case 'O2':
  35. return options.optimization = 2;
  36. }
  37. });
  38. options.filename = args[1];
  39. parser = new less.Parser(options);
  40. fs.readFile(options.filename, 'utf-8', function(err, data) {
  41. return parser.parse(data, function(err, tree) {
  42. if (err) {
  43. less.writeError(err);
  44. return process.exit(1);
  45. }
  46. });
  47. });
  48. }).call(this);