@jsreport/jsreport-cli 3.0.0-beta.2 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +16 -12
- package/cli.js +93 -93
- package/example.config.json +43 -43
- package/example.server.js +14 -14
- package/index.js +20 -22
- package/jsreport.config.js +8 -8
- package/lib/cliExtension.js +59 -59
- package/lib/{createCommandParser.js → commander/createCommandParser.js} +44 -45
- package/lib/commander/createCustomCommandBuilder.js +150 -0
- package/lib/commander/createLogger.js +51 -0
- package/lib/commander/executeCommand.js +37 -0
- package/lib/commander/getCommandEventName.js +4 -0
- package/lib/commander/index.js +279 -0
- package/lib/commander/jsreportInstance.js +98 -0
- package/lib/commander/registerCommand.js +91 -0
- package/lib/commander/startCommand.js +234 -0
- package/lib/commander/startProcessing.js +208 -0
- package/lib/commands/_initializeApp.js +206 -208
- package/lib/commands/configure.js +393 -395
- package/lib/commands/help.js +453 -454
- package/lib/commands/init.js +76 -77
- package/lib/commands/kill.js +85 -86
- package/lib/commands/render.js +490 -488
- package/lib/commands/repair.js +55 -56
- package/lib/commands/start.js +72 -74
- package/lib/commands/win-install.js +124 -126
- package/lib/commands/win-uninstall.js +100 -102
- package/lib/daemonHandler.js +164 -164
- package/lib/daemonInstance.js +225 -225
- package/lib/{registerExtensionsCommands.js → detectAndRegisterExtensionsCommands.js} +74 -74
- package/lib/instanceHandler.js +316 -316
- package/lib/keepAliveProcess.js +205 -205
- package/lib/{errorUtils.js → utils/error.js} +149 -127
- package/lib/{getTempPaths.js → utils/getTempPaths.js} +39 -39
- package/lib/{normalizePathOptionOrArg.js → utils/normalizePathOptionOrArg.js} +41 -41
- package/lib/{normalizeSocketPath.js → utils/normalizeSocketPath.js} +9 -9
- package/lib/{startSocketServer.js → utils/startSocketServer.js} +53 -53
- package/package.json +105 -106
- package/test/testUtils.js +197 -198
- package/lib/commander.js +0 -1108
package/lib/commands/help.js
CHANGED
|
@@ -1,454 +1,453 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[`${command}
|
|
16
|
-
[`${command}
|
|
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
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
let
|
|
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
|
-
jsreportInstance.options = jsreportInstance.options || {}
|
|
110
|
-
jsreportInstance.options.extensions =
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
error
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
'
|
|
211
|
-
'
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
let
|
|
233
|
-
let
|
|
234
|
-
let
|
|
235
|
-
let
|
|
236
|
-
let
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
type =
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
//
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
defaults &&
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
typeof defaults[propName] === '
|
|
314
|
-
typeof defaults[propName] === '
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
schema.
|
|
379
|
-
schema.properties
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
schema.
|
|
385
|
-
(
|
|
386
|
-
|
|
387
|
-
schema.items.type &&
|
|
388
|
-
schema.items.
|
|
389
|
-
schema.items.properties
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
customCase === '
|
|
405
|
-
customCase
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
schema.
|
|
415
|
-
schema.properties
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
defaults &&
|
|
420
|
-
typeof defaults === 'object'
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
schema.
|
|
433
|
-
schema.items &&
|
|
434
|
-
schema.items.
|
|
435
|
-
schema.items.properties
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
ui.div({ text:
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
1
|
+
const cliui = require('cliui')
|
|
2
|
+
const chalk = require('chalk')
|
|
3
|
+
const omit = require('lodash.omit')
|
|
4
|
+
|
|
5
|
+
const description = 'Prints information about a command or topic'
|
|
6
|
+
const command = 'help'
|
|
7
|
+
const positionalArgs = '[commandOrTopic]'
|
|
8
|
+
|
|
9
|
+
exports.command = `${command} ${positionalArgs}`
|
|
10
|
+
exports.description = description
|
|
11
|
+
|
|
12
|
+
function getExamples (command) {
|
|
13
|
+
return [
|
|
14
|
+
[`${command} render`, 'Print information about the render command'],
|
|
15
|
+
[`${command} start`, 'Print information about the start command'],
|
|
16
|
+
[`${command} config`, 'Print information about jsreport configuration input format']
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.builder = (yargs) => {
|
|
21
|
+
const examples = getExamples(`jsreport ${command}`)
|
|
22
|
+
|
|
23
|
+
examples.forEach((examp) => {
|
|
24
|
+
yargs.example(examp[0], examp[1])
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
yargs
|
|
29
|
+
.usage([
|
|
30
|
+
`${description}\n`,
|
|
31
|
+
`Usage:\n\njsreport ${command} <commandOrTopic>\n`,
|
|
32
|
+
'Topics Available:\n',
|
|
33
|
+
'config -> print details about the configuration shape and types that the current jsreport instance in project supports\n'
|
|
34
|
+
].join('\n'))
|
|
35
|
+
// we just define positional argument here to describe it for help usage,
|
|
36
|
+
// but in order to have the property "argv.commandOrTopic" with sanitized value we will need to put the
|
|
37
|
+
// positional argument in the command string too, however in this case we can't do that because
|
|
38
|
+
// the help command has some conflicts with the yargs.help()
|
|
39
|
+
.positional('commandOrTopic', {
|
|
40
|
+
type: 'string',
|
|
41
|
+
description: 'Command or Topic to get help usage'
|
|
42
|
+
})
|
|
43
|
+
// we need to handle the help option directly since there is a conflict
|
|
44
|
+
// in yargs when a custom command is called the same that the option used in .help()
|
|
45
|
+
// (that option registers an implicit command with the same name that the option passed)
|
|
46
|
+
.option('help', {
|
|
47
|
+
global: true,
|
|
48
|
+
alias: 'h',
|
|
49
|
+
description: 'Show Help',
|
|
50
|
+
type: 'boolean'
|
|
51
|
+
})
|
|
52
|
+
.check((argv, hash) => {
|
|
53
|
+
if (argv && argv.help) {
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!argv || !argv.commandOrTopic) {
|
|
58
|
+
throw new Error('"commandOrTopic" argument is required')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return true
|
|
62
|
+
})
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.handler = async (argv) => {
|
|
67
|
+
const context = argv.context
|
|
68
|
+
const cwd = context.cwd
|
|
69
|
+
const logger = context.logger
|
|
70
|
+
const getInstance = context.getInstance
|
|
71
|
+
const initInstance = context.initInstance
|
|
72
|
+
let commandOrTopic = argv.commandOrTopic
|
|
73
|
+
let helpResult
|
|
74
|
+
|
|
75
|
+
const getCommandHelp = context.getCommandHelp
|
|
76
|
+
|
|
77
|
+
if (argv.help) {
|
|
78
|
+
commandOrTopic = 'help'
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (commandOrTopic === 'config') {
|
|
82
|
+
logger.debug(`searching information about "${commandOrTopic}" as topic`)
|
|
83
|
+
|
|
84
|
+
let jsreportInstance
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
let _instance
|
|
88
|
+
|
|
89
|
+
// look up for an instance in CWD
|
|
90
|
+
try {
|
|
91
|
+
_instance = await getInstance(cwd)
|
|
92
|
+
} catch (e) {
|
|
93
|
+
const error = new Error('Couldn\'t find a jsreport installation necessary to check the configuration options')
|
|
94
|
+
|
|
95
|
+
error.originalError = e
|
|
96
|
+
|
|
97
|
+
throw error
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
logger.debug('disabling express extension..')
|
|
101
|
+
|
|
102
|
+
if (typeof _instance === 'function') {
|
|
103
|
+
jsreportInstance = _instance()
|
|
104
|
+
} else {
|
|
105
|
+
jsreportInstance = _instance
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
jsreportInstance.options = jsreportInstance.options || {}
|
|
109
|
+
jsreportInstance.options.extensions = jsreportInstance.options.extensions || {}
|
|
110
|
+
jsreportInstance.options.extensions.express = Object.assign(
|
|
111
|
+
{},
|
|
112
|
+
jsreportInstance.options.extensions.express,
|
|
113
|
+
{ start: false }
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
await initInstance(jsreportInstance)
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return onCriticalError(e)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
helpResult = schemaToConfigFormat(jsreportInstance, jsreportInstance.optionsValidator.getRootSchema())
|
|
123
|
+
} catch (e) {
|
|
124
|
+
return onCriticalError(e)
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
logger.debug(`searching information about "${commandOrTopic}" as command`)
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
helpResult = await getCommandHelp(commandOrTopic, context)
|
|
131
|
+
} catch (e) {
|
|
132
|
+
if (e.notFound !== true) {
|
|
133
|
+
return onCriticalError(e)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (helpResult != null && typeof helpResult === 'string') {
|
|
138
|
+
helpResult = { output: helpResult }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!helpResult) {
|
|
143
|
+
return logger.info(`no information found for command or topic "${commandOrTopic}", to get the list of commands supported on your installation run "jsreport -h" and try again with a supported command or topic`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
logger.info(helpResult.output)
|
|
147
|
+
|
|
148
|
+
return helpResult
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function onCriticalError (err) {
|
|
152
|
+
const error = new Error(`A critical error occurred while trying to execute the ${command} command`)
|
|
153
|
+
error.originalError = err
|
|
154
|
+
throw error
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function schemaToConfigFormat (instance, rootSchema) {
|
|
158
|
+
const rawUI = cliui()
|
|
159
|
+
const outputUI = cliui()
|
|
160
|
+
|
|
161
|
+
function convert (ui, addStyles = true) {
|
|
162
|
+
try {
|
|
163
|
+
ui.div({
|
|
164
|
+
text: 'Configuration format description for local jsreport instance:',
|
|
165
|
+
padding: [0, 0, 1, 0]
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
ui.div('{')
|
|
169
|
+
|
|
170
|
+
printProperties(ui, rootSchema.properties, {
|
|
171
|
+
defaults: instance.defaults,
|
|
172
|
+
required: rootSchema.required,
|
|
173
|
+
addStyles
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
ui.div('}')
|
|
177
|
+
|
|
178
|
+
return ui.toString()
|
|
179
|
+
} catch (e) {
|
|
180
|
+
e.message = `A problem happened while trying to convert schema to help description. ${e.message}`
|
|
181
|
+
throw e
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const results = {}
|
|
186
|
+
const toConvert = [rawUI, outputUI]
|
|
187
|
+
|
|
188
|
+
toConvert.forEach((ui, idx) => {
|
|
189
|
+
if (idx === 0) {
|
|
190
|
+
results.raw = convert(ui, false)
|
|
191
|
+
} else {
|
|
192
|
+
results.output = convert(ui)
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
return results
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function printProperties (ui, props, {
|
|
200
|
+
required = [],
|
|
201
|
+
defaults,
|
|
202
|
+
level = 1,
|
|
203
|
+
printRestProps = false,
|
|
204
|
+
addStyles = true
|
|
205
|
+
}) {
|
|
206
|
+
const baseLeftPadding = level === 1 ? 2 : 3
|
|
207
|
+
|
|
208
|
+
const knowProps = [
|
|
209
|
+
'type', 'required', 'properties', 'items', 'not', 'anyOf', 'allOf', 'oneOf',
|
|
210
|
+
'default', 'defaultNotInitialized', 'enum', 'format', 'pattern',
|
|
211
|
+
'description', 'title', '$jsreport-constantOrArray'
|
|
212
|
+
]
|
|
213
|
+
|
|
214
|
+
if (props == null) {
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let bold
|
|
219
|
+
|
|
220
|
+
if (addStyles) {
|
|
221
|
+
bold = chalk.bold
|
|
222
|
+
} else {
|
|
223
|
+
bold = (i) => i
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const propsKeys = Array.isArray(props) ? props : Object.keys(props)
|
|
227
|
+
const totalKeys = propsKeys.length
|
|
228
|
+
|
|
229
|
+
propsKeys.forEach((key, index) => {
|
|
230
|
+
const isLastKey = index === totalKeys - 1
|
|
231
|
+
let propName
|
|
232
|
+
let schema
|
|
233
|
+
let customCase
|
|
234
|
+
let defaultToUse
|
|
235
|
+
let shouldStringifyDefault = true
|
|
236
|
+
let isRequired = false
|
|
237
|
+
|
|
238
|
+
if (Array.isArray(key)) {
|
|
239
|
+
propName = key[0]
|
|
240
|
+
schema = key[1]
|
|
241
|
+
} else {
|
|
242
|
+
propName = key
|
|
243
|
+
schema = props[propName]
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
let shouldAddTopPadding = true
|
|
247
|
+
|
|
248
|
+
if (index === 0 && level === 1) {
|
|
249
|
+
shouldAddTopPadding = false
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const getPadding = (l) => {
|
|
253
|
+
return [shouldAddTopPadding ? 1 : 0, 0, 0, l * baseLeftPadding]
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const content = {
|
|
257
|
+
padding: getPadding(level)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (propName !== '') {
|
|
261
|
+
content.text = `"${bold(propName)}":`
|
|
262
|
+
} else {
|
|
263
|
+
content.text = '-'
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (propName !== '' && required.indexOf(propName) !== -1) {
|
|
267
|
+
isRequired = true
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (schema.type) {
|
|
271
|
+
let type = schema.type
|
|
272
|
+
|
|
273
|
+
if (Array.isArray(type)) {
|
|
274
|
+
type = type.join(' | ')
|
|
275
|
+
} else if (type === 'array' && schema.items && schema.items.type) {
|
|
276
|
+
type = Array.isArray(schema.items.type) ? schema.items.type.join(' | ') : schema.items.type
|
|
277
|
+
type = `array<${type}>`
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
content.text += ` <${bold(type)}>`
|
|
281
|
+
} else {
|
|
282
|
+
if (schema.not != null && typeof schema.not === 'object') {
|
|
283
|
+
content.text += ` <${bold('any type that is not valid against the description below')}>`
|
|
284
|
+
customCase = 'not'
|
|
285
|
+
} else if (Array.isArray(schema.anyOf)) {
|
|
286
|
+
content.text += ` <${bold('any type that is valid against at least with one of the descriptions below')}>`
|
|
287
|
+
customCase = 'anyOf'
|
|
288
|
+
} else if (Array.isArray(schema.allOf)) {
|
|
289
|
+
content.text += ` <${bold('any type that is valid against all the descriptions below')}>`
|
|
290
|
+
customCase = 'allOf'
|
|
291
|
+
} else if (Array.isArray(schema.oneOf)) {
|
|
292
|
+
content.text += ` <${bold('any type that is valid against just one of the descriptions below')}>`
|
|
293
|
+
customCase = 'oneOf'
|
|
294
|
+
} else if (schema.description != null) {
|
|
295
|
+
content.text += ` <${bold('any')}>`
|
|
296
|
+
} else {
|
|
297
|
+
// only schemas structures that are not implemented gets printed in raw form,
|
|
298
|
+
// this means that we should analize the raw schema printed and then support it
|
|
299
|
+
content.text += ` <raw schema: ${JSON.stringify(schema)}>`
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (isRequired) {
|
|
304
|
+
content.text += ` (${bold('required')})`
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (
|
|
308
|
+
defaults &&
|
|
309
|
+
typeof defaults === 'object' &&
|
|
310
|
+
defaults[propName] !== undefined &&
|
|
311
|
+
(
|
|
312
|
+
typeof defaults[propName] === 'string' ||
|
|
313
|
+
typeof defaults[propName] === 'boolean' ||
|
|
314
|
+
typeof defaults[propName] === 'number' ||
|
|
315
|
+
defaults[propName] === null
|
|
316
|
+
)
|
|
317
|
+
) {
|
|
318
|
+
defaultToUse = defaults[propName]
|
|
319
|
+
} else if (schema.default !== undefined) {
|
|
320
|
+
defaultToUse = schema.default
|
|
321
|
+
} else if (schema.defaultNotInitialized !== undefined) {
|
|
322
|
+
defaultToUse = schema.defaultNotInitialized
|
|
323
|
+
|
|
324
|
+
if (typeof defaultToUse === 'string' && /^<.*>$/.test(defaultToUse)) {
|
|
325
|
+
shouldStringifyDefault = false
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (defaultToUse !== undefined) {
|
|
330
|
+
if (shouldStringifyDefault) {
|
|
331
|
+
content.text += ` (default: ${bold(JSON.stringify(defaultToUse))})`
|
|
332
|
+
} else {
|
|
333
|
+
content.text += ` (default: ${bold(defaultToUse)})`
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
let allowed
|
|
338
|
+
|
|
339
|
+
if (schema.enum != null) {
|
|
340
|
+
allowed = schema.enum
|
|
341
|
+
} else if (schema.type === 'string' && schema['$jsreport-constantOrArray'] != null) {
|
|
342
|
+
allowed = schema['$jsreport-constantOrArray']
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (Array.isArray(allowed) && allowed.length > 0) {
|
|
346
|
+
content.text += ` (allowed values: ${bold(allowed.map((value) => {
|
|
347
|
+
return JSON.stringify(value)
|
|
348
|
+
}).join(', '))})`
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (
|
|
352
|
+
typeof schema.type === 'string' ||
|
|
353
|
+
(Array.isArray(schema.type) && schema.type.indexOf('string') !== -1)
|
|
354
|
+
) {
|
|
355
|
+
if (schema.format != null) {
|
|
356
|
+
content.text += ` (format: ${schema.format})`
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (schema.pattern != null) {
|
|
360
|
+
content.text += ` (pattern: ${schema.pattern})`
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (printRestProps) {
|
|
365
|
+
const restProps = omit(schema, knowProps)
|
|
366
|
+
|
|
367
|
+
if (restProps && Object.keys(restProps).length > 0) {
|
|
368
|
+
content.text += ` (raw schema: ${JSON.stringify(restProps)})`
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (schema.description != null) {
|
|
373
|
+
content.text += ` -> ${schema.description}`
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (
|
|
377
|
+
schema.type === 'object' &&
|
|
378
|
+
schema.properties != null &&
|
|
379
|
+
Object.keys(schema.properties).length > 0
|
|
380
|
+
) {
|
|
381
|
+
content.text += ' {'
|
|
382
|
+
} else if (
|
|
383
|
+
schema.type === 'array' &&
|
|
384
|
+
(Array.isArray(schema.items) ||
|
|
385
|
+
(schema.items &&
|
|
386
|
+
schema.items.type &&
|
|
387
|
+
schema.items.type === 'object' &&
|
|
388
|
+
schema.items.properties != null &&
|
|
389
|
+
Object.keys(schema.items.properties).length > 0))
|
|
390
|
+
) {
|
|
391
|
+
content.text += ' ['
|
|
392
|
+
} else if (!isLastKey && propName !== '') {
|
|
393
|
+
content.text += ','
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
ui.div(content)
|
|
397
|
+
|
|
398
|
+
if (customCase != null) {
|
|
399
|
+
if (customCase === 'not') {
|
|
400
|
+
printProperties(ui, [['', schema.not]], { level: level + 1 })
|
|
401
|
+
} else if (
|
|
402
|
+
(customCase === 'anyOf' ||
|
|
403
|
+
customCase === 'allOf' ||
|
|
404
|
+
customCase === 'oneOf') &&
|
|
405
|
+
Array.isArray(schema[customCase]) &&
|
|
406
|
+
schema[customCase].length > 0
|
|
407
|
+
) {
|
|
408
|
+
printProperties(ui, schema[customCase].map((s) => {
|
|
409
|
+
return ['', s]
|
|
410
|
+
}), { level: level + 1, printRestProps: true })
|
|
411
|
+
}
|
|
412
|
+
} else if (
|
|
413
|
+
schema.type === 'object' &&
|
|
414
|
+
schema.properties != null &&
|
|
415
|
+
Object.keys(schema.properties).length > 0
|
|
416
|
+
) {
|
|
417
|
+
const hasDefault = (
|
|
418
|
+
defaults &&
|
|
419
|
+
typeof defaults === 'object' &&
|
|
420
|
+
typeof defaults[propName] === 'object'
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
printProperties(ui, schema.properties, {
|
|
424
|
+
level: level + 1,
|
|
425
|
+
required: schema.required,
|
|
426
|
+
defaults: hasDefault ? defaults[propName] : undefined
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
ui.div({ text: `}${!isLastKey ? ',' : ''}`, padding: content.padding })
|
|
430
|
+
} else if (
|
|
431
|
+
schema.type === 'array' &&
|
|
432
|
+
schema.items &&
|
|
433
|
+
schema.items.type === 'object' &&
|
|
434
|
+
schema.items.properties != null &&
|
|
435
|
+
Object.keys(schema.items.properties).length > 0
|
|
436
|
+
) {
|
|
437
|
+
ui.div({ text: '{', padding: getPadding(level + 1) })
|
|
438
|
+
|
|
439
|
+
printProperties(ui, schema.items.properties, {
|
|
440
|
+
level: level + 2,
|
|
441
|
+
required: schema.items.required
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
ui.div({ text: '}', padding: getPadding(level + 1) })
|
|
445
|
+
ui.div({ text: `]${!isLastKey ? ',' : ''}`, padding: content.padding })
|
|
446
|
+
} else if (schema.type === 'array' && Array.isArray(schema.items)) {
|
|
447
|
+
printProperties(ui, schema.items.map((s, idx) => {
|
|
448
|
+
return [`item at ${idx} index should be`, s]
|
|
449
|
+
}), { level: level + 1 })
|
|
450
|
+
ui.div({ text: `]${!isLastKey ? ',' : ''}`, padding: content.padding })
|
|
451
|
+
}
|
|
452
|
+
})
|
|
453
|
+
}
|