diff --git a/less-middleware/less-middleware-tests.ts b/less-middleware/less-middleware-tests.ts new file mode 100644 index 0000000000..0a84203b60 --- /dev/null +++ b/less-middleware/less-middleware-tests.ts @@ -0,0 +1,28 @@ +/// + +import express = require('express'); +import lessMiddleware = require('less-middleware'); +var app = express(); + +app.use(lessMiddleware('public', { + cacheFile: null, + debug: false, + dest: 'dest', + force: false, + once: false, + pathRoot: 'root', + postprocess: { + css: function(css, req) { return css; }, + }, + preprocess: { + less: function(src, req) { return src; }, + path: function(pathname, req) { return pathname; }, + importPaths: function(paths, req) { return paths; } + }, + render: { + compress: 'auto', + yuicompress: false, + paths: ['foo', 'bar'] + }, + storeCss: function(css, req, next) {}, +})); diff --git a/less-middleware/less-middleware.d.ts b/less-middleware/less-middleware.d.ts new file mode 100644 index 0000000000..ee0e0069d5 --- /dev/null +++ b/less-middleware/less-middleware.d.ts @@ -0,0 +1,108 @@ +// Type definitions for less-middleware 2.0.1 +// Project: https://github.com/emberfeather/less.js-middleware +// Definitions by: Federico Bond +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/* =================== USAGE =================== + + import lessMiddleware = require('less-middleware'); + app.use(lessMiddleware(source, options)); + + =============================================== */ + +/// + +declare module "less-middleware" { + import express = require('express'); + + /** + * Middleware created to allow processing of Less files for Connect JS framework + * and by extension the Express JS framework + */ + function lessMiddleware(source: string, options?: { + /** + * Show more verbose logging? + */ + debug?: boolean; + + /** + * Destination directory to output the compiled .css files. + */ + dest?: string; + + /** + * Always re-compile less files on each request. + */ + force?: boolean; + + /** + * Only recompile once after each server restart. + * Useful for reducing disk i/o on production. + */ + once?: boolean; + + /** + * Common root of the source and destination. + * It is prepended to both the source and destination before being used. + */ + pathRoot?: string; + + /** + * Object containing functions relevant to preprocessing data. + */ + postprocess?: { + + /** + * Function that modifies the compiled css output before being stored. + */ + css?(css: string, req: express.Request): string; + }; + + /** + * Object containing functions relevant to preprocessing data. + */ + preprocess?: { + + /** + * Function that modifies the raw less output before being parsed and compiled. + */ + less?(css: string, req: express.Request): string; + + /** + * Function that modifies the less pathname before being loaded from the filesystem. + */ + path?(pathname: string, req: express.Request): string; + + /** + * Function that modifies the import paths used by the less parser per request. + */ + importPaths?(paths: string[], req: express.Request): string[]; + }; + + /** + * Options for the less render. + */ + render?: { + + compress?: string; + yuicompress?: boolean; + paths?: string[]; + }; + + /** + * Function that is in charge of storing the css in the filesystem. + */ + storeCss?(pathname: string, css: string, req: express.Request, next: Function): void; + + /** + * Path to a JSON file that will be used to cache less data across server restarts. + * This can greatly speed up initial load time after a server restart - if the less + * files haven't changed and the css files still exist, specifying this option will + * mean that the less files don't need to be recompiled after a server restart. + */ + cacheFile?: string; + + }): express.RequestHandler; + + export = lessMiddleware; +}