{"action":"created","issue":{"url":"https://api.github.com/repos/mattdesl/budo/issues/50","labels_url":"https://api.github.com/repos/mattdesl/budo/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/mattdesl/budo/issues/50/comments","events_url":"https://api.github.com/repos/mattdesl/budo/issues/50/events","html_url":"https://github.com/mattdesl/budo/issues/50","id":98432070,"number":50,"title":"Is there any way to pre-process files and send the output as stdin for live to refresh?","user":{"login":"zanona","id":32017,"avatar_url":"https://avatars.githubusercontent.com/u/32017?v=3","gravatar_id":"","url":"https://api.github.com/users/zanona","html_url":"https://github.com/zanona","followers_url":"https://api.github.com/users/zanona/followers","following_url":"https://api.github.com/users/zanona/following{/other_user}","gists_url":"https://api.github.com/users/zanona/gists{/gist_id}","starred_url":"https://api.github.com/users/zanona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zanona/subscriptions","organizations_url":"https://api.github.com/users/zanona/orgs","repos_url":"https://api.github.com/users/zanona/repos","events_url":"https://api.github.com/users/zanona/events{/privacy}","received_events_url":"https://api.github.com/users/zanona/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-31T17:09:28Z","updated_at":"2015-08-01T17:23:52Z","closed_at":null,"body":"I am trying to think on a way that would allow budo requests to `*.less,*.sass` files to activate the pre-processor, run the output through `auto-prefixer` and render the outcome as text, directly injected into a page without the need to generate a physical file, basically the same as it does by default with javascript files.\r\n\r\nWould that be somehow possible to achieve with budo?\r\nThe way it works is genius, but I only missing CSS pre-processors to really improve my workflow.\r\n\r\nIdeally this would be achievable if the `reload` method accepted the file contents instead of its path only, like:\r\n\r\n### main.less\r\n```less\r\nbody {\r\n    background: red;\r\n    p {\r\n        color: green;\r\n    }\r\n}\r\n```\r\n\r\n#### main.less compiled into .css and made available for rendering in-browser\r\n```js\r\napp\r\n  .watch('*.less', { interval: 300, usePolling: true })\r\n  .live()\r\n  .on('watch', function(type, file) {\r\n    if (path.extname(file) === '.less') {\r\n        less('./main.less').then(function (css) { \r\n            app.reload('main.less', css); //css => body { background: red; } p { color: green; }\r\n        })\r\n    }\r\n  })\r\n```\r\n\r\nThanks a lot"},"comment":{"url":"https://api.github.com/repos/mattdesl/budo/issues/comments/126938657","html_url":"https://github.com/mattdesl/budo/issues/50#issuecomment-126938657","issue_url":"https://api.github.com/repos/mattdesl/budo/issues/50","id":126938657,"user":{"login":"zanona","id":32017,"avatar_url":"https://avatars.githubusercontent.com/u/32017?v=3","gravatar_id":"","url":"https://api.github.com/users/zanona","html_url":"https://github.com/zanona","followers_url":"https://api.github.com/users/zanona/followers","following_url":"https://api.github.com/users/zanona/following{/other_user}","gists_url":"https://api.github.com/users/zanona/gists{/gist_id}","starred_url":"https://api.github.com/users/zanona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zanona/subscriptions","organizations_url":"https://api.github.com/users/zanona/orgs","repos_url":"https://api.github.com/users/zanona/repos","events_url":"https://api.github.com/users/zanona/events{/privacy}","received_events_url":"https://api.github.com/users/zanona/received_events","type":"User","site_admin":false},"created_at":"2015-08-01T17:23:52Z","updated_at":"2015-08-01T17:23:52Z","body":"hey @mattdesl,\r\nI played around with the source code and have managed to achieve that by adding another featured to the API. [Here you can see the comparison](https://github.com/mattdesl/budo/compare/master...zanona:api-custom-response?expand=1) and see what has changed, I tried to go inline with your structure, but please let me know if you find anything wrong with it.\r\n\r\nBut basically I have managed to achieve what I wanted by adding a new event to the api called `request`.\r\nSo `on('request', fn(req, res) {})` would give the user the ability to tweak the file content and render it through the server without having to provide physical files for that.\r\n\r\nWhen adding adding a new watch glob through the API, that glob will automatically be recreated in the server router as well, so, `watch('**/*.less')` will also give the user the ability to listen requests from the server.\r\n\r\nHave a look on how the `budo-config.js` file makes use of the API below:\r\n\r\n```js\r\n/*jslint node:true*/\r\nvar less = require('less'),\r\n    fs = require('fs'),\r\n    url = require('url'),\r\n    path = require('path'),\r\n    budo = require('budo')('app.js', { live: true, stream: process.stdout });\r\n\r\nbudo.watch('**/*.less')\r\n    .on('watch', function (type, file) {\r\n        if (file.match(/\\.less$/)) {\r\n           //trick to get live LESS injection\r\n           //even though `main.css` does not exists ;)\r\n            budo.reload(file.replace(/\\.less$/, '.css'));\r\n        }\r\n    })\r\n    .on('request', function (req, res) {\r\n        // this method will only be called to new extensions\r\n        // declared on budo.watch method\r\n        var file = url.parse(req.url).pathname;\r\n        file = path.join('./', file);\r\n        if (path.extname(file) === '.less') {\r\n            fs.readFile(file, function (err, o) {\r\n                less.render(o.toString(), function (err, o) {\r\n                    res.setHeader('content-type', 'text/css');\r\n                    res.setHeader('content-length', o.css.length);\r\n                    res.statusCode = req.statusCode || 200;\r\n                    res.end(o.css);\r\n                });\r\n            });\r\n        }\r\n    });\r\n```\r\nNow the trick to get livereload injection for LESS files was due the fact that it is we update the less file on the server, but as you can see, we ask Budo to reload a CSS file. It is strange, but work great.\r\n\r\n`budo.reload(file.replace(/\\.less$/, '.css'));`\r\n\r\nI am quite happy that I could be able to achieve this with budo since I am really amazed on how great module Budo already is and looking forward to hear your thoughts about it so perhaps hopefully we could think on a way to add that feature to Budo.\r\n\r\nAll the best."}}