Add simple file globbing to bin/uglifyjs for Windows
This commit is contained in:
@@ -273,6 +273,9 @@ if (ARGS.comments != null) {
|
||||
|
||||
var files = ARGS._.slice();
|
||||
|
||||
if (process.platform === "win32")
|
||||
files = UglifyJS.simple_glob(files);
|
||||
|
||||
if (ARGS.self) {
|
||||
if (files.length > 0) {
|
||||
print_error("WARN: Ignoring input files since --self was passed");
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user