index.js
2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var noop = function () { };
var path = require('path');
const semver = require('semver');
var version = process.versions.node.split('.') || [null, null, null];
var utils = (module.exports = {
semver: semver,
satisfies: test => semver.satisfies(process.versions.node, test),
version: {
major: parseInt(version[0] || 0, 10),
minor: parseInt(version[1] || 0, 10),
patch: parseInt(version[2] || 0, 10),
},
clone: require('./clone'),
merge: require('./merge'),
bus: require('./bus'),
isWindows: process.platform === 'win32',
isMac: process.platform === 'darwin',
isLinux: process.platform === 'linux',
isRequired: (function () {
var p = module.parent;
while (p) {
// in electron.js engine it happens
if (!p.filename) {
return true;
}
if (p.filename.indexOf('bin' + path.sep + 'nodemon.js') !== -1) {
return false;
}
p = p.parent;
}
return true;
})(),
home: process.env.HOME || process.env.HOMEPATH,
quiet: function () {
// nukes the logging
if (!this.debug) {
for (var method in utils.log) {
if (typeof utils.log[method] === 'function') {
utils.log[method] = noop;
}
}
}
},
reset: function () {
if (!this.debug) {
for (var method in utils.log) {
if (typeof utils.log[method] === 'function') {
delete utils.log[method];
}
}
}
this.debug = false;
},
regexpToText: function (t) {
return t
.replace(/\.\*\\./g, '*.')
.replace(/\\{2}/g, '^^')
.replace(/\\/g, '')
.replace(/\^\^/g, '\\');
},
stringify: function (exec, args) {
// serializes an executable string and array of arguments into a string
args = args || [];
return [exec]
.concat(
args.map(function (arg) {
// if an argument contains a space, we want to show it with quotes
// around it to indicate that it is a single argument
if (arg.length > 0 && arg.indexOf(' ') === -1) {
return arg;
}
// this should correctly escape nested quotes
return JSON.stringify(arg);
})
)
.join(' ')
.trim();
},
});
utils.log = require('./log')(utils.isRequired);
Object.defineProperty(utils, 'debug', {
set: function (value) {
this.log.debug = value;
},
get: function () {
return this.log.debug;
},
});
Object.defineProperty(utils, 'colours', {
set: function (value) {
this.log.useColours = value;
},
get: function () {
return this.log.useColours;
},
});