less/LessUnit.js

const Unit = require('libflitter/Unit')
const path = require('path')

/**
 * Provides a JIT compiler for Less stles.
 * Serves them at /style-asset from the specified asset folder.
 * 
 * @extends module:libflitter/Unit~Unit
 * @module flitter-less/LessUnit
 */
class LessUnit extends Unit {
    
    /**
     * Initialize the class and get the Less file dir.
     * @param {string} style_path - Path to the *.less files to be served.
     */
    constructor( style_path = './app/assets/less' ){
        super()
        this.directory = path.resolve(style_path)
    }
    
    /**
     * Initialize the unit.
     * Registers the Less compiler with the underlying Express app.
     * @param {module:libflitter/app/FlitterApp~FlitterApp} app
     * @param {module:libflitter/Context~Context} context
     * @returns {Promise<void>}
     */
    async go(app, context){
        
        const less_compiler = require('express-less')
        app.express.use('/style-asset', less_compiler(path.resolve(this.directory)))
    }
}

module.exports = exports = LessUnit