Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/cuongvo/expose-loader int…
Browse files Browse the repository at this point in the history
…o cuongvo-master
  • Loading branch information
sokra committed May 21, 2015
2 parents ba4dd68 + 413ae77 commit a0f5c66
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions index.js
Expand Up @@ -4,22 +4,25 @@
*/

function accesorString(value) {
var depths = value.split(".");
var length = depths.length;
var childProperties = value.split(".");
var length = childProperties.length;
var propertyString = "global";
var result = "";

for (var i = 0; i < length; i++) {
result += "[" + JSON.stringify(depths[i]) + "]";
if (i > 0)
result += "if(!" + propertyString + ") " + propertyString + " = {};";
propertyString += "[" + JSON.stringify(childProperties[i]) + "]";
}

result += "module.exports = " + propertyString;
return result;
}

module.exports = function() {};
module.exports.pitch = function(remainingRequest) {
this.cacheable && this.cacheable();
if(!this.query) throw new Error("query parameter is missing");
return "module.exports = " +
"global" + accesorString(this.query.substr(1)) + " = " +
return accesorString(this.query.substr(1)) + " = " +
"require(" + JSON.stringify("-!" + remainingRequest) + ");";
};
};

0 comments on commit a0f5c66

Please sign in to comment.