requisite
Version:
A cosmic javascript bundler.
114 lines (103 loc) • 2.77 kB
JavaScript
// Generated by CoffeeScript 1.12.5
var fs, os, path;
fs = require('fs');
os = require('os');
path = require('path');
exports.formatDate = function(date) {
if (date == null) {
date = new Date;
}
return (/\d{2}:\d{2}:\d{2}/.exec(date))[0];
};
exports.graph = function(mod) {
var depth, i, idx, len, line, lines, nextDepth, nextLine, ref, ref1, seen, walkdeps;
seen = {};
walkdeps = function(mod, fn, depth) {
var k, ref, results, v;
if (depth == null) {
depth = 0;
}
if (seen[mod.requireAs]) {
fn(mod, depth, true);
return;
}
seen[mod.requireAs] = true;
depth += 1;
ref = mod.dependencies;
results = [];
for (k in ref) {
v = ref[k];
if ((fn(v, depth)) !== false) {
results.push(walkdeps(v, fn, depth));
} else {
results.push(void 0);
}
}
return results;
};
console.log(mod.requireAs);
lines = [];
walkdeps(mod, function(mod, depth, seen) {
var line;
if (seen) {
lines.pop();
return;
}
line = '├─' + mod.requireAs;
if (depth > 0) {
line = (new Array(depth * 2)).join(' ') + line;
}
return lines.push([line, depth]);
});
for (idx = i = 0, len = lines.length; i < len; idx = ++i) {
ref = lines[idx], line = ref[0], depth = ref[1];
if (lines[idx + 1] == null) {
lines[idx][0] = line.replace('├─', '└─');
} else {
ref1 = lines[idx + 1], nextLine = ref1[0], nextDepth = ref1[1];
if ((nextLine != null) && depth !== nextDepth) {
lines[idx][0] = line.replace('├─', '└─');
}
}
}
return console.log(((function() {
var j, len1, results;
results = [];
for (j = 0, len1 = lines.length; j < len1; j++) {
line = lines[j];
results.push(line[0]);
}
return results;
})()).join('\n'));
};
exports.requireTry = function(pkg) {
var err;
try {
return require(pkg);
} catch (error) {
err = error;
console.error("Unable to require '" + pkg + "'. Try `npm install -g " + pkg + "`.");
throw new Error("Missing compiler");
}
};
exports.normalizePath = function(absolutePath, basePath) {
var normalizedPath, start;
if ((absolutePath.indexOf(basePath)) !== -1) {
normalizedPath = absolutePath.replace(basePath, '');
} else {
start = absolutePath.indexOf('node_modules');
normalizedPath = absolutePath.substring(start, absolutePath.length);
}
if (os.platform() === 'win32') {
return normalizedPath.replace(/^\\+/, '');
} else {
return normalizedPath.replace(/^\/+/, '');
}
};
exports.isFunction = function(fn) {
return typeof fn === 'function';
};
exports.isString = function(s) {
return typeof s === 'string';
};
//# sourceMappingURL=utils.js.map