1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var path = require('path');
|
7 |
|
8 | function accesorString(value) {
|
9 | var childProperties = value.split(".");
|
10 | var length = childProperties.length;
|
11 | var propertyString = "global";
|
12 | var result = "";
|
13 |
|
14 | for(var i = 0; i < length; i++) {
|
15 | if(i > 0)
|
16 | result += "if(!" + propertyString + ") " + propertyString + " = {};\n";
|
17 | propertyString += "[" + JSON.stringify(childProperties[i]) + "]";
|
18 | }
|
19 |
|
20 | result += "module.exports = " + propertyString;
|
21 | return result;
|
22 | }
|
23 |
|
24 | module.exports = function() {};
|
25 | module.exports.pitch = function(remainingRequest) {
|
26 |
|
27 |
|
28 |
|
29 | const newRequestPath = remainingRequest.replace(
|
30 | this.resourcePath,
|
31 | '.' + path.sep + path.relative(this.context, this.resourcePath)
|
32 | );
|
33 | this.cacheable && this.cacheable();
|
34 | if(!this.query) throw new Error("query parameter is missing");
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | this._module.userRequest = this._module.userRequest + '-exposed';
|
43 | return accesorString(this.query.substr(1)) + " = " +
|
44 | "require(" + JSON.stringify("-!" + newRequestPath) + ");";
|
45 | };
|