|
75 | 75 |
|
76 | 76 | /**
|
77 | 77 | * Definition expression
|
78 |
| - * @type {RegExp} |
| 78 | + * @type {!RegExp} |
79 | 79 | */
|
80 | 80 | Preprocessor.EXPR = /([ ]*)\/\/[ ]+#(include_once|include|ifn?def|if|endif|else|elif|put|define)/g;
|
81 | 81 |
|
82 | 82 | /**
|
83 | 83 | * #include "path/to/file". Requires node.js' "fs" module.
|
84 |
| - * @type {RegExp} |
| 84 | + * @type {!RegExp} |
85 | 85 | */
|
86 | 86 | Preprocessor.INCLUDE = /(include_once|include)[ ]+"([^"\\]*(\\.[^"\\]*)*)"[ ]*\r?(?:\n|$)/g;
|
87 | 87 |
|
88 | 88 | /**
|
89 | 89 | * #ifdef/#ifndef SOMEDEFINE, #if EXPRESSION
|
90 |
| - * @type {RegExp} |
| 90 | + * @type {!RegExp} |
91 | 91 | */
|
92 | 92 | Preprocessor.IF = /(ifdef|ifndef|if)[ ]*([^\r\n]+)\r?\n/g;
|
93 | 93 |
|
94 | 94 | /**
|
95 | 95 | * #endif/#else, #elif EXPRESSION
|
96 |
| - * @type {RegExp} |
| 96 | + * @type {!RegExp} |
97 | 97 | */
|
98 | 98 | Preprocessor.ENDIF = /(endif|else|elif)([ ]+[^\r\n]+)?\r?(?:\n|$)/g;
|
99 | 99 |
|
100 | 100 | /**
|
101 | 101 | * #put EXPRESSION
|
102 |
| - * @type {RegExp} |
| 102 | + * @type {!RegExp} |
103 | 103 | */
|
104 | 104 | Preprocessor.PUT = /put[ ]+([^\n]+)[ ]*/g;
|
105 | 105 |
|
106 | 106 | /**
|
107 | 107 | * #define EXPRESSION
|
108 |
| - * @type {RegExp} |
| 108 | + * @type {!RegExp} |
109 | 109 | */
|
110 | 110 | Preprocessor.DEFINE = /define[ ]+([^\n]+)\r?(?:\n|$)/g;
|
111 | 111 |
|
| 112 | + /** |
| 113 | + * @type {!RegExp} |
| 114 | + * @inner |
| 115 | + */ |
| 116 | + var GLOB_EXP = /(?:^|[^\\])\*/; |
| 117 | + |
112 | 118 | /**
|
113 | 119 | * Strips slashes from an escaped string.
|
114 | 120 | * @param {string} str Escaped string
|
|
232 | 238 | throw(new Error("Failed to resolve include: "+this.baseDir+"/"+include));
|
233 | 239 | }
|
234 | 240 | try {
|
235 |
| - var key = include; |
236 |
| - include = require("fs").readFileSync(this.baseDir+"/"+include)+""; |
237 |
| - this.includes[key] = include; |
| 241 | + var key = include, |
| 242 | + fs = require("fs"); |
| 243 | + if (GLOB_EXP.test(include)) { |
| 244 | + var glob = require("glob"); |
| 245 | + verbose(' glob incl: '+this.baseDir+"/"+include); |
| 246 | + var _this = this; |
| 247 | + glob(this.baseDir+"/"+include, {"sync": true}, function(err, files) { |
| 248 | + if (err) throw(err); |
| 249 | + include = ''; |
| 250 | + for (var i=0; i<files.length; i++) { |
| 251 | + verbose(' incl: '+files[i]); |
| 252 | + var contents = fs.readFileSync(files[i])+""; |
| 253 | + _this.includes[key] = contents; |
| 254 | + include += contents; |
| 255 | + } |
| 256 | + }); |
| 257 | + } else { |
| 258 | + verbose(' incl: '+include); |
| 259 | + include = fs.readFileSync(this.baseDir+"/"+include)+""; |
| 260 | + this.includes[key] = include; |
| 261 | + } |
238 | 262 | } catch (e) {
|
239 |
| - throw(new Error("File not found: "+include+" ("+e+")")); |
| 263 | + throw(new Error("Include failed: "+include+" ("+e+")")); |
240 | 264 | }
|
241 | 265 | }
|
242 | 266 | this.source = this.source.substring(0, match.index)+Preprocessor.indent(include, indent)+this.source.substring(Preprocessor.INCLUDE.lastIndex);
|
|
0 commit comments