aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorkzc <zaxxon2011@gmail.com>2016-07-29 16:18:56 -0400
committerRichard van Velzen <rvanvelzen1@gmail.com>2016-08-14 21:46:38 +0200
commit72306b9885dffcc206b6637a9c22e54fa54a168d (patch)
tree9e3c68c836e7fd6e4b17076cb44a2f03bc05ba53 /tools
parent38756b1f269fec9fc7f13b82d014478662d00c4d (diff)
downloadtracifyjs-72306b9885dffcc206b6637a9c22e54fa54a168d.tar.gz
tracifyjs-72306b9885dffcc206b6637a9c22e54fa54a168d.zip
Add simple file globbing to bin/uglifyjs for Windows
Diffstat (limited to 'tools')
-rw-r--r--tools/node.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/node.js b/tools/node.js
index 179c69db..5a143759 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -261,3 +261,47 @@ exports.writeNameCache = function(filename, key, cache) {
fs.writeFileSync(filename, JSON.stringify(data, null, 2), "utf8");
}
};
+
+// A file glob function that only supports "*" and "?" wildcards in the basename.
+// Example: "foo/bar/*baz??.*.js"
+// Argument `glob` may be a string or an array of strings.
+// Returns an array of strings. Garbage in, garbage out.
+exports.simple_glob = function simple_glob(glob) {
+ var results = [];
+ if (Array.isArray(glob)) {
+ glob.forEach(function(elem) {
+ results = results.concat(simple_glob(elem));
+ });
+ return results;
+ }
+ if (glob.match(/\*|\?/)) {
+ var dir = path.dirname(glob);
+ try {
+ var entries = fs.readdirSync(dir);
+ } catch (ex) {}
+ if (entries) {
+ var pattern = "^" + (path.basename(glob)
+ .replace(/\(/g, "\\(")
+ .replace(/\)/g, "\\)")
+ .replace(/\{/g, "\\{")
+ .replace(/\}/g, "\\}")
+ .replace(/\[/g, "\\[")
+ .replace(/\]/g, "\\]")
+ .replace(/\+/g, "\\+")
+ .replace(/\^/g, "\\^")
+ .replace(/\$/g, "\\$")
+ .replace(/\*/g, "[^/\\\\]*")
+ .replace(/\./g, "\\.")
+ .replace(/\?/g, ".")) + "$";
+ var mod = process.platform === "win32" ? "i" : "";
+ var rx = new RegExp(pattern, mod);
+ for (var i in entries) {
+ if (rx.test(entries[i]))
+ results.push(dir + "/" + entries[i]);
+ }
+ }
+ }
+ if (results.length === 0)
+ results = [ glob ];
+ return results;
+};