compile.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Script to process all the less files and convert them to CSS files
  2. // Run from themes/dijit/claro like:
  3. //
  4. // $ node compile.js
  5. var fs = require('fs'), // file system access
  6. path = require('path'), // get directory from file name
  7. less = require('../../../util/less'); // less processor
  8. var options = {
  9. compress: false,
  10. optimization: 1,
  11. silent: false
  12. };
  13. var allFiles = [].concat(
  14. fs.readdirSync("."),
  15. fs.readdirSync("form").map(function(fname){ return "form/"+fname; }),
  16. fs.readdirSync("layout").map(function(fname){ return "layout/"+fname; })
  17. ),
  18. lessFiles = allFiles.filter(function(name){ return name && name != "variables.less" && /\.less$/.test(name); });
  19. lessFiles.forEach(function(fname){
  20. console.log("=== " + fname);
  21. fs.readFile(fname, 'utf-8', function(e, data){
  22. if(e){
  23. console.error("lessc: " + e.message);
  24. process.exit(1);
  25. }
  26. new(less.Parser)({
  27. paths: [path.dirname(fname)],
  28. optimization: options.optimization,
  29. filename: fname
  30. }).parse(data, function(err, tree){
  31. if(err){
  32. less.writeError(err, options);
  33. process.exit(1);
  34. }else{
  35. try{
  36. var css = tree.toCSS({ compress: options.compress }),
  37. outputFname = fname.replace('.less', '.css');
  38. var fd = fs.openSync(outputFname, "w");
  39. fs.writeSync(fd, css, 0, "utf8");
  40. }catch(e){
  41. less.writeError(e, options);
  42. process.exit(2);
  43. }
  44. }
  45. });
  46. });
  47. });