-
Notifications
You must be signed in to change notification settings - Fork 8
/
watch-helper.js
executable file
路141 lines (118 loc) 路 3.77 KB
/
watch-helper.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'use strict';
//polyfills
const process = require('suman-browser-polyfills/modules/process');
const global = require('suman-browser-polyfills/modules/global');
//core
const assert = require('assert');
const util = require('util');
const path = require('path');
const fs = require('fs');
const cp = require('child_process');
//npm
const colors = require('colors/safe');
const inquirer = require('suman-inquirer');
//project
const _suman = global.__suman = (global.__suman || {});
const rejectionHandler = require('../interactive-rejection-handler');
const choices = require('./choices');
//////////////////////////////////////////////////////////////////
module.exports = function chooseWatchProperty (obj, backspaceCB) {
const keys = Object.keys(_suman.sumanConfig.watch || {});
_interactiveDebug(' WATCH HELPER obj => ', obj);
_suman.backspacing = false;
const prompt1 = [
{
type: 'confirm',
name: 'confirmNoWatchPropsInConfig',
onLeftKey: function () {
_suman.onBackspace(backspaceCB);
},
message: 'Please acknowledge that you have no properties in the watch object in your suman.conf.js config.',
when: function () {
_suman.backspacing = false;
console.log('\n\n --------------------------------------------- \n\n');
return true;
},
validate: function (item) {
return true;
}
}
];
const prompt2 = [
{
type: 'list',
name: 'useConfigWatchPresets',
message: 'Want to use the preset values on the watch object in your config?\n' +
' => These defaults look like => \n' + util.inspect(_suman.sumanConfig.watch, {
colors: true,
breakLength: 5
}) + '\n',
default: 0,
choices: [
'yes',
'no'
],
onLeftKey: function () {
_suman.onBackspace(backspaceCB);
},
when: function () {
_suman.backspacing = false;
console.log('\n\n ------------------------------------------ \n\n');
return true;
},
validate: function (item) {
}
},
{
type: 'list',
name: 'watchPresetProperty',
message: 'Which watch preset property do you wish to use?',
default: 0,
choices: keys,
onLeftKey: function () {
_suman.onBackspace(backspaceCB);
},
when: function (answers) {
if (answers.useConfigWatchPresets === 'yes') {
_suman.backspacing = false;
console.log('\n\n --------------------------------- \n\n');
return true;
}
},
validate: function (item) {
}
}
];
try {
require.resolve('suman-server');
}
catch (err) {
const p = {
type: 'confirm',
name: 'confirmNoSumanServerInstalled',
message: 'Please acknowledge that you will need to' +
' install the suman-server package if you wish to use the watch features,\n' +
' you can do that with ' + colors.magenta('"$ suman --use-server"') + ', (we will auto-generate this command for you later, this is just FYI).',
when: function () {
console.log('\n\n -------------------------------------- \n\n');
_suman.backspacing = false;
return true;
},
onLeftKey: function () {
_suman.onBackspace(backspaceCB);
},
validate: function (item) {
return true;
}
};
prompt1.unshift(p);
prompt2.unshift(p);
}
const z = keys.length < 1 ? prompt1 : prompt2;
return inquirer.prompt(z).then(function (answers) {
answers.mustInstallSumanServer = 'confirmNoSumanServerInstalled' in answers;
answers.allowChoose = answers.useConfigWatchPresets !== 'yes';
answers.watchProperty = answers.useConfigWatchPresets === 'yes' ? answers.watchPresetProperty : '';
return Object.assign(obj, answers);
});
};