File: modules/less.js

Recommend this page to a friend!
  Classes of Thomas Björk  >  Node.js Background Jobs  >  modules/less.js  >  Download  
File: modules/less.js
Role: Example script
Content type: text/plain
Description: Example script
Class: Node.js Background Jobs
Run background jobs using Node.js modules
Author: By
Last change: Added an AutoReloadModule function that automatically reloads a module when it changes.
Added the Unload functions to modules which loads modules of its own.
Date: 2 months ago
Size: 652 bytes
 

Contents

Class file image Download
exports.UExecute = function(parts) {
  return false;
};

exports.TExecute = function(parts, client) {
  var e, less, nodeLess, s;
  nodeLess = true;
  try {
    s = require.resolve("less");
    if (s.length === 0) {
      nodeLess = false;
    }
  } catch (_error) {
    e = _error;
    nodeLess = false;
  }
  if (nodeLess) {
    less = require("less");
    s = parts[1];
    return less.render(s, function(e, css) {
      client.write(css);
      client.end();
    });
  } else {
    client.write("404: LESS not available");
    client.end();
  }
};

exports.Unload = function() {
  var name = require.resolve('less');
  delete require.cache[name];
}