| [81bc7da] | 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 | isIBMi: require('os').type() === 'OS400',
|
|---|
| 21 | isRequired: (function () {
|
|---|
| 22 | var p = module.parent;
|
|---|
| 23 | while (p) {
|
|---|
| 24 | // in electron.js engine it happens
|
|---|
| 25 | if (!p.filename) {
|
|---|
| 26 | return true;
|
|---|
| 27 | }
|
|---|
| 28 | if (p.filename.indexOf('bin' + path.sep + 'nodemon.js') !== -1) {
|
|---|
| 29 | return false;
|
|---|
| 30 | }
|
|---|
| 31 | p = p.parent;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | return true;
|
|---|
| 35 | })(),
|
|---|
| 36 | home: process.env.HOME || process.env.HOMEPATH,
|
|---|
| 37 | quiet: function () {
|
|---|
| 38 | // nukes the logging
|
|---|
| 39 | if (!this.debug) {
|
|---|
| 40 | for (var method in utils.log) {
|
|---|
| 41 | if (typeof utils.log[method] === 'function') {
|
|---|
| 42 | utils.log[method] = noop;
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | },
|
|---|
| 47 | reset: function () {
|
|---|
| 48 | if (!this.debug) {
|
|---|
| 49 | for (var method in utils.log) {
|
|---|
| 50 | if (typeof utils.log[method] === 'function') {
|
|---|
| 51 | delete utils.log[method];
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 | this.debug = false;
|
|---|
| 56 | },
|
|---|
| 57 | regexpToText: function (t) {
|
|---|
| 58 | return t
|
|---|
| 59 | .replace(/\.\*\\./g, '*.')
|
|---|
| 60 | .replace(/\\{2}/g, '^^')
|
|---|
| 61 | .replace(/\\/g, '')
|
|---|
| 62 | .replace(/\^\^/g, '\\');
|
|---|
| 63 | },
|
|---|
| 64 | stringify: function (exec, args) {
|
|---|
| 65 | // serializes an executable string and array of arguments into a string
|
|---|
| 66 | args = args || [];
|
|---|
| 67 |
|
|---|
| 68 | return [exec]
|
|---|
| 69 | .concat(
|
|---|
| 70 | args.map(function (arg) {
|
|---|
| 71 | // if an argument contains a space, we want to show it with quotes
|
|---|
| 72 | // around it to indicate that it is a single argument
|
|---|
| 73 | if (arg.length > 0 && arg.indexOf(' ') === -1) {
|
|---|
| 74 | return arg;
|
|---|
| 75 | }
|
|---|
| 76 | // this should correctly escape nested quotes
|
|---|
| 77 | return JSON.stringify(arg);
|
|---|
| 78 | })
|
|---|
| 79 | )
|
|---|
| 80 | .join(' ')
|
|---|
| 81 | .trim();
|
|---|
| 82 | },
|
|---|
| 83 | });
|
|---|
| 84 |
|
|---|
| 85 | utils.log = require('./log')(utils.isRequired);
|
|---|
| 86 |
|
|---|
| 87 | Object.defineProperty(utils, 'debug', {
|
|---|
| 88 | set: function (value) {
|
|---|
| 89 | this.log.debug = value;
|
|---|
| 90 | },
|
|---|
| 91 | get: function () {
|
|---|
| 92 | return this.log.debug;
|
|---|
| 93 | },
|
|---|
| 94 | });
|
|---|
| 95 |
|
|---|
| 96 | Object.defineProperty(utils, 'colours', {
|
|---|
| 97 | set: function (value) {
|
|---|
| 98 | this.log.useColours = value;
|
|---|
| 99 | },
|
|---|
| 100 | get: function () {
|
|---|
| 101 | return this.log.useColours;
|
|---|
| 102 | },
|
|---|
| 103 | });
|
|---|