UNPKG

browsernizr2

Version:

Modernizr wrapper for use with browserify

93 lines (73 loc) 2.49 kB
// Generated by CoffeeScript 1.7.1 (function() { var depth, file, findFiles, fs, libPath, lib_dir, modernizr_dir, path, src, tests_dir, unAMD, work_dir, _i, _j, _k, _len, _len1, _ref, _ref1; path = require('path'); fs = require('fs'); require('shelljs/global'); unAMD = function(src, reqPath) { var exports, i, modules, names, req, requires, _i, _ref, _ref1; if (reqPath == null) { reqPath = './'; } requires = src.match(/define\((\[.*\])[ ,\)]+function[ ]*\((.*)\)/); exports = src.match(/return\s+([^;]*)[;\s]*?\}\);\s*?$/); src = src.replace(/define\(.*?\{/, ''); src = src.replace(/(return\s+.*\s*?\}\);\s*?$|\}\);\s*?$)/, ''); if (requires != null) { modules = eval(requires[1]); names = requires[2].split(',').map(function(s) { return s.trim(); }); req = ''; for (i = _i = 0, _ref = modules.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { if (((_ref1 = names[i]) != null ? _ref1.length : void 0) > 0) { req += "var " + names[i] + " = "; } req += "require('" + reqPath + modules[i] + "');\n"; } src = "" + req + "\n" + src + "\n"; } if (exports != null) { src += "\nmodule.exports = " + exports[1] + ";"; } return src; }; findFiles = function(location) { return find(location).filter(function(file) { return !fs.statSync(file).isDirectory(); }); }; work_dir = path.resolve(__dirname, './../'); modernizr_dir = path.join(work_dir, './node_modules/modernizr'); lib_dir = path.join(work_dir, './lib'); tests_dir = path.join(work_dir, './test'); if (test('-d', lib_dir)) { rm('-rf', "" + lib_dir + "/*"); } if (test('-d', tests_dir)) { rm('-rf', "" + tests_dir + "/*"); } cd(modernizr_dir); cp('-r', './src/*', "" + lib_dir + "/"); cp('-r', './feature-detects/*', "" + tests_dir + "/"); cd(lib_dir); _ref = findFiles('.'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { file = _ref[_i]; src = cat(file); unAMD(src).to(file); } cd(tests_dir); _ref1 = findFiles('.'); for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { file = _ref1[_j]; src = cat(file); depth = file.split('/').length; libPath = './'; for (_k = 0; 0 <= depth ? _k < depth : _k > depth; 0 <= depth ? _k++ : _k--) { libPath += '../'; } libPath += 'lib/'; unAMD(src, libPath).to(file); } }).call(this);