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