Created
October 5, 2015 02:16
-
-
Save tjstebbing/d4880922efadedacfcb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var fs = require('fs'); | |
module.exports = function(context) { | |
this.cachable(true); | |
//this.addDependency(path); | |
} | |
module.exports.pitch = function(remainingRequest, precedingRequest, data) { | |
var self = this; | |
var opts = JSON.parse(self.query.slice(1)); | |
var components = opts.components || []; | |
if(opts.dir) { | |
var dir = path.normalize(opts.dir); | |
var bits = fs.readdirSync(dir); | |
components = components.concat(bits.map( | |
function(b){return path.join(dir, b);})); | |
} | |
return components.map(loadComponent).join('\n'); | |
function loadComponent(p) { | |
var files = fs.readdirSync(p); | |
var comp = path.basename(p); | |
if(files.indexOf('index.js') == -1) { | |
self.emitError("component at "+p+" requires an index.js file."); | |
} | |
if(files.indexOf('index.html') == -1) { | |
self.emitError("component at "+p+" requires an index.html file."); | |
} | |
if(files.indexOf('test.js') == -1) { | |
// self.emitWarning("component at "+p+" missing a test.js file."); | |
} | |
self.addDependency('index.html'); | |
self.addDependency('index.js'); | |
self.context = p; | |
var template = path.join(p, 'index.html'); | |
return "riot.tag(`"+fs.readFileSync(template)+"`, require('./index.js'));"; | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment