akurath
Version:
IDE Frontend for codepsaces.io
120 lines (111 loc) • 4.32 kB
JavaScript
var _ = require("lodash");
var escapeRegExp = function(str) {
return str.replace(/([.*+?\^${}()|\[\]\/\\])/g, "\\$1");
};
// taken from http://xregexp.com/
var grepEscapeRegExp = function(str) {
return str.replace(/[[\]{}()*+?.,\\^$|#\s"']/g, "\\$&");
};
var escapeShell = function(str) {
return str.replace(/([\\"'`$\s\(\)<>])/g, "\\$1");
};
// file types
var IGNORE_DIRS = {
".bzr" : "Bazaar",
".cdv" : "Codeville",
"~.dep" : "Interface Builder",
"~.dot" : "Interface Builder",
"~.nib" : "Interface Builder",
"~.plst" : "Interface Builder",
".git" : "Git",
".hg" : "Mercurial",
".pc" : "quilt",
".svn" : "Subversion",
"_MTN" : "Monotone",
"blib" : "Perl module building",
"CVS" : "CVS",
"RCS" : "RCS",
"SCCS" : "SCCS",
"_darcs" : "darcs",
"_sgbak" : "Vault/Fortress",
"autom4te.cache" : "autoconf",
"cover_db" : "Devel::Cover",
"_build" : "Module::Build",
"node_modules" : "Node",
};
var MAPPINGS = {
"actionscript": ["as", "mxml"],
"ada" : ["ada", "adb", "ads"],
"asm" : ["asm", "s"],
"batch" : ["bat", "cmd"],
//"binary" : q{Binary files, as defined by Perl's -B op (default: off)},
"cc" : ["c", "h", "xs"],
"cfmx" : ["cfc", "cfm", "cfml"],
"clojure" : ["clj"],
"cpp" : ["cpp", "cc", "cxx", "m", "hpp", "hh", "h", "hxx"],
"csharp" : ["cs"],
"css" : ["css", "less", "scss", "sass"],
"coffee" : ["coffee"],
"elisp" : ["el"],
"erlang" : ["erl", "hrl"],
"fortran" : ["f", "f77", "f90", "f95", "f03", "for", "ftn", "fpp"],
"haskell" : ["hs", "lhs"],
"hh" : ["h"],
"html" : ["htm", "html", "shtml", "xhtml"],
"jade" : ["jade"],
"java" : ["java", "properties"],
"groovy" : ["groovy"],
"js" : ["js"],
"json" : ["json"],
"latex" : ["latex", "ltx"],
"jsp" : ["jsp", "jspx", "jhtm", "jhtml"],
"lisp" : ["lisp", "lsp"],
"logiql" : ["logic", "lql"],
"lua" : ["lua"],
"make" : ["makefile", "Makefile"],
"mason" : ["mas", "mhtml", "mpl", "mtxt"],
"markdown" : ["md", "markdown"],
"objc" : ["m", "h"],
"objcpp" : ["mm", "h"],
"ocaml" : ["ml", "mli"],
"parrot" : ["pir", "pasm", "pmc", "ops", "pod", "pg", "tg"],
"perl" : ["pl", "pm", "pod", "t"],
"php" : ["php", "phpt", "php3", "php4", "php5", "phtml"],
"plone" : ["pt", "cpt", "metadata", "cpy", "py"],
"powershell" : ["ps1"],
"python" : ["py"],
"rake" : ["rakefile"],
"ruby" : ["rb", "ru", "rhtml", "rjs", "rxml", "erb", "rake", "gemspec"],
"scala" : ["scala"],
"scheme" : ["scm", "ss"],
"shell" : ["sh", "bash", "csh", "tcsh", "ksh", "zsh"],
//"skipped" : "q"{"Files but not directories normally skipped by ack ("default": "off")},
"smalltalk" : ["st"],
"sql" : ["sql", "ctl"],
"tcl" : ["tcl", "itcl", "itk"],
"tex" : ["tex", "cls", "sty"],
"text" : ["txt"],
"textile" : ["textile"],
"tt" : ["tt", "tt2", "ttml"],
"vb" : ["bas", "cls", "frm", "ctl", "vb", "resx"],
"vim" : ["vim"],
"yaml" : ["yaml", "yml"],
"xml" : ["xml", "dtd", "xslt", "ent", "rdf", "rss", "svg", "wsdl", "atom", "mathml", "mml"]
};
var exts = [];
for (var type in MAPPINGS) {
exts = exts.concat(MAPPINGS[type]);
}
// grep pattern matching for extensions
var PATTERN_EXT = _.unique(exts).join(",");
var dirs = _.keys(IGNORE_DIRS);
var PATTERN_DIR = escapeRegExp(dirs.join("|"));
var PATTERN_EDIR = " --exclude-dir="+dirs.join(" --exclude-dir=");
module.exports = {
'grepEscapeRegExp': grepEscapeRegExp,
'escapeRegExp': escapeRegExp,
'escapeShell': escapeShell,
'PATTERN_EXT': PATTERN_EXT,
'PATTERN_DIR': PATTERN_DIR,
'PATTERN_EDIR': PATTERN_EDIR
};