Skip to content

Instantly share code, notes, and snippets.

@janmisek
Last active August 29, 2015 14:19
Show Gist options
  • Save janmisek/14d5b473ddc1cfdd0ca7 to your computer and use it in GitHub Desktop.
Save janmisek/14d5b473ddc1cfdd0ca7 to your computer and use it in GitHub Desktop.
Broccoli filter to get output from spawned process

Package.json

{
  "name": "broccoli-aglio",
  "version": "0.1.0",
  "description": "Broccoli filter to get output from spawned process",
  "author": "Jan Misek <jan.misek@rclick.cz> (https://github.com/janmisek)",
  "license": "MIT",
  "devDependencies": {
    "aglio": "^1.18.0",
    "broccoli": "^0.15.3",
    "broccoli-filter": "^0.1.12",
    "broccoli-static-compiler": "^0.2.1",
    "rsvp": "^3.0.18",
    "spawn-sync": "^1.0.6"
  },
  "dependencies": {
    "fs-extra": "^0.18.0"
  }
}

Brocfile.js

var rsvp = require('rsvp');
var spawn = require('spawn-sync');
var Filter = require('broccoli-filter');
var pickFiles = require('broccoli-static-compiler');

Compiler.prototype = Object.create(Filter.prototype);
Compiler.prototype.constructor = Compiler;
function Compiler (inputTree, options) {
    if (!(this instanceof Compiler)) {
        return new Compiler(inputTree, options);
    }
    this.inputTree = inputTree;
    this.options = options || {};
}

Compiler.prototype.extensions = ['md'];
Compiler.prototype.targetExtension = 'html';

Compiler.prototype.processFile = function (srcDir, destDir, relativePath) {
    var src =  srcDir + '/' + relativePath;
    var dst = destDir + '/' + this.getDestFilePath(relativePath);
    var out = spawn('/usr/bin/aglio', ['-i', src, '-o', dst]);

    return rsvp.resolve();
};

var files = pickFiles('./api', {
    srcDir: './',
    destDir: './'
});

module.exports = Compiler(files);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment