1 | var utils = require('./utils');
|
2 | var debug = require('debug');
|
3 |
|
4 | /**
|
5 | * @description Create a debug instance based on your package.json alias/name.
|
6 | *
|
7 | * The challenge here is to figure out where your package.json exist.
|
8 | *
|
9 | * @param {String} name - Name of the debug unit.
|
10 | * @return {Function}
|
11 | */
|
12 | module.exports = function initDebug(name) {
|
13 | var parentPath = utils.getCallerRoot();
|
14 | var alias, pkg;
|
15 |
|
16 | try {
|
17 | pkg = require(parentPath + '/package.json');
|
18 |
|
19 | if (pkg.alias) {
|
20 | alias = pkg.alias;
|
21 | } else {
|
22 | alias = pkg.name;
|
23 | }
|
24 |
|
25 | } catch (err) {
|
26 | alias = 'undefined';
|
27 | }
|
28 |
|
29 | return debug(alias + ':' + name);
|
30 | };
|
31 |
|
32 | module.exports._base = debug;
|