@jsreport/jsreport-cli 3.0.0 → 3.1.0
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/README.md +5 -1
- package/cli.js +3 -3
- package/index.js +0 -2
- package/lib/cliExtension.js +2 -2
- package/lib/{createCommandParser.js → commander/createCommandParser.js} +2 -3
- 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 +0 -2
- package/lib/commands/configure.js +1 -3
- package/lib/commands/help.js +7 -8
- package/lib/commands/init.js +4 -5
- package/lib/commands/kill.js +4 -5
- package/lib/commands/render.js +37 -35
- package/lib/commands/repair.js +4 -5
- package/lib/commands/start.js +0 -2
- package/lib/commands/win-install.js +0 -2
- package/lib/commands/win-uninstall.js +0 -2
- package/lib/daemonHandler.js +2 -2
- package/lib/daemonInstance.js +5 -5
- package/lib/{registerExtensionsCommands.js → detectAndRegisterExtensionsCommands.js} +1 -1
- package/lib/keepAliveProcess.js +3 -3
- package/lib/{errorUtils.js → utils/error.js} +23 -1
- package/lib/{getTempPaths.js → utils/getTempPaths.js} +0 -0
- package/lib/{normalizePathOptionOrArg.js → utils/normalizePathOptionOrArg.js} +0 -0
- package/lib/{normalizeSocketPath.js → utils/normalizeSocketPath.js} +0 -0
- package/lib/{startSocketServer.js → utils/startSocketServer.js} +1 -1
- package/package.json +9 -9
- package/lib/commander.js +0 -1108
package/lib/commands/render.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
const util = require('util')
|
|
4
2
|
const fs = require('fs')
|
|
5
3
|
const jsreportClient = require('@jsreport/nodejs-client')
|
|
6
|
-
const normalizePathOptionOrArg = require('../normalizePathOptionOrArg')
|
|
4
|
+
const normalizePathOptionOrArg = require('../utils/normalizePathOptionOrArg')
|
|
7
5
|
|
|
8
6
|
const writeFileAsync = util.promisify(fs.writeFile)
|
|
9
7
|
|
|
@@ -20,10 +18,7 @@ exports.builder = (yargs) => {
|
|
|
20
18
|
request: {
|
|
21
19
|
alias: 'r',
|
|
22
20
|
description: 'Specifies a path to a json file containing option for the entire rendering request',
|
|
23
|
-
requiresArg: true
|
|
24
|
-
coerce: (value) => {
|
|
25
|
-
return normalizePathOptionOrArg(cwd, 'request', value, { json: true, strict: true })
|
|
26
|
-
}
|
|
21
|
+
requiresArg: true
|
|
27
22
|
},
|
|
28
23
|
keepAlive: {
|
|
29
24
|
alias: 'k',
|
|
@@ -33,50 +28,26 @@ exports.builder = (yargs) => {
|
|
|
33
28
|
template: {
|
|
34
29
|
alias: 't',
|
|
35
30
|
description: 'Specifies a path to a json file containing options for template input or you can specify singular options doing --template.[option_name] value',
|
|
36
|
-
requiresArg: true
|
|
37
|
-
coerce: (value) => {
|
|
38
|
-
if (typeof value !== 'string') {
|
|
39
|
-
if (value.content != null) {
|
|
40
|
-
value.content = normalizePathOptionOrArg(cwd, 'template.content', value.content, { strict: true })
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (value.helpers != null) {
|
|
44
|
-
value.helpers = normalizePathOptionOrArg(cwd, 'template.helpers', value.helpers, { strict: true })
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return value
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return normalizePathOptionOrArg(cwd, 'template', value, { json: true, strict: true })
|
|
51
|
-
}
|
|
31
|
+
requiresArg: true
|
|
52
32
|
},
|
|
53
33
|
data: {
|
|
54
34
|
alias: 'd',
|
|
55
35
|
description: 'Specifies a path to a json file containing options for data input',
|
|
56
|
-
requiresArg: true
|
|
57
|
-
coerce: (value) => {
|
|
58
|
-
return normalizePathOptionOrArg(cwd, 'data', value, { json: true, strict: false })
|
|
59
|
-
}
|
|
36
|
+
requiresArg: true
|
|
60
37
|
},
|
|
61
38
|
out: {
|
|
62
39
|
alias: 'o',
|
|
63
40
|
description: 'Save rendering result into a file path',
|
|
64
41
|
type: 'string',
|
|
65
42
|
demandOption: true,
|
|
66
|
-
requiresArg: true
|
|
67
|
-
coerce: (value) => {
|
|
68
|
-
return normalizePathOptionOrArg(cwd, 'out', value, { read: false, strict: true })
|
|
69
|
-
}
|
|
43
|
+
requiresArg: true
|
|
70
44
|
},
|
|
71
45
|
meta: {
|
|
72
46
|
alias: 'm',
|
|
73
47
|
description: 'Save response meta information into a file path',
|
|
74
48
|
type: 'string',
|
|
75
49
|
demandOption: false,
|
|
76
|
-
requiresArg: true
|
|
77
|
-
coerce: (value) => {
|
|
78
|
-
return normalizePathOptionOrArg(cwd, 'meta', value, { read: false, strict: true })
|
|
79
|
-
}
|
|
50
|
+
requiresArg: true
|
|
80
51
|
}
|
|
81
52
|
}
|
|
82
53
|
|
|
@@ -93,6 +64,37 @@ exports.builder = (yargs) => {
|
|
|
93
64
|
.usage(`${description}\n\n${getUsage('jsreport ' + command)}`)
|
|
94
65
|
.group(options, 'Command options:')
|
|
95
66
|
.options(commandOptions)
|
|
67
|
+
.middleware((argv) => {
|
|
68
|
+
if (argv.request != null) {
|
|
69
|
+
argv.request = normalizePathOptionOrArg(cwd, 'request', argv.request, { json: true, strict: true })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (argv.template != null) {
|
|
73
|
+
if (typeof argv.template !== 'string') {
|
|
74
|
+
if (argv.template.content != null) {
|
|
75
|
+
argv.template.content = normalizePathOptionOrArg(cwd, 'template.content', argv.template.content, { strict: true })
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (argv.template.helpers != null) {
|
|
79
|
+
argv.template.helpers = normalizePathOptionOrArg(cwd, 'template.helpers', argv.template.helpers, { strict: true })
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
argv.template = normalizePathOptionOrArg(cwd, 'template', argv.template, { json: true, strict: true })
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (argv.data != null) {
|
|
87
|
+
argv.data = normalizePathOptionOrArg(cwd, 'data', argv.data, { json: true, strict: false })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (argv.out != null) {
|
|
91
|
+
argv.out = normalizePathOptionOrArg(cwd, 'out', argv.out, { read: false, strict: true })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (argv.meta != null) {
|
|
95
|
+
argv.meta = normalizePathOptionOrArg(cwd, 'meta', argv.meta, { read: false, strict: true })
|
|
96
|
+
}
|
|
97
|
+
}, true)
|
|
96
98
|
.check((argv, hash) => {
|
|
97
99
|
if (argv.user && !argv.serverUrl) {
|
|
98
100
|
throw new Error('user option needs to be used with --serverUrl option')
|
package/lib/commands/repair.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
const initializeApp = require('./_initializeApp')
|
|
4
2
|
|
|
5
3
|
const description = 'Repairs current working directory to start a jsreport application (It re-creates files server.js, *.config.json and package.json)'
|
|
6
4
|
const command = 'repair'
|
|
5
|
+
const positionalArgs = '[versionToInstall]'
|
|
7
6
|
|
|
8
|
-
exports.command = command
|
|
7
|
+
exports.command = `${command} ${positionalArgs}`
|
|
9
8
|
exports.description = description
|
|
10
9
|
|
|
11
10
|
exports.builder = (yargs) => {
|
|
@@ -35,8 +34,8 @@ exports.handler = (argv) => {
|
|
|
35
34
|
const cwd = argv.context.cwd
|
|
36
35
|
let versionToInstall
|
|
37
36
|
|
|
38
|
-
if (argv
|
|
39
|
-
versionToInstall = argv.
|
|
37
|
+
if (argv && argv.versionToInstall != null) {
|
|
38
|
+
versionToInstall = argv.versionToInstall
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
return initializeApp(
|
package/lib/commands/start.js
CHANGED
package/lib/daemonHandler.js
CHANGED
|
@@ -5,8 +5,8 @@ const path = require('path')
|
|
|
5
5
|
const fs = require('fs')
|
|
6
6
|
const nssocket = require('nssocket')
|
|
7
7
|
const lockfile = require('lockfile')
|
|
8
|
-
const getTempPaths = require('./getTempPaths')
|
|
9
|
-
const normalizeSocketPath = require('./normalizeSocketPath')
|
|
8
|
+
const getTempPaths = require('./utils/getTempPaths')
|
|
9
|
+
const normalizeSocketPath = require('./utils/normalizeSocketPath')
|
|
10
10
|
|
|
11
11
|
const lock = util.promisify(lockfile.lock.bind(lockfile))
|
|
12
12
|
const unlock = util.promisify(lockfile.unlock.bind(lockfile))
|
package/lib/daemonInstance.js
CHANGED
|
@@ -4,9 +4,9 @@ const fs = require('fs')
|
|
|
4
4
|
const HttpsServer = require('https').Server
|
|
5
5
|
const ipAddress = require('ip-address')
|
|
6
6
|
const nssocket = require('nssocket')
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
const instanceHandler = require('./instanceHandler')
|
|
8
|
+
const startSocketServer = require('./utils/startSocketServer')
|
|
9
|
+
const { getErrors } = require('./utils/error')
|
|
10
10
|
|
|
11
11
|
const PID = process.pid
|
|
12
12
|
|
|
@@ -126,7 +126,7 @@ function start (customInstance, socketFile) {
|
|
|
126
126
|
if (socketInitErr) {
|
|
127
127
|
return socketToMaster.send(['init'], {
|
|
128
128
|
error: socketInitErr.message,
|
|
129
|
-
stacks:
|
|
129
|
+
stacks: getErrors(socketInitErr).map(e => e.stack)
|
|
130
130
|
})
|
|
131
131
|
}
|
|
132
132
|
|
|
@@ -155,7 +155,7 @@ function start (customInstance, socketFile) {
|
|
|
155
155
|
|
|
156
156
|
socketToMaster.send(['init'], {
|
|
157
157
|
error: err.message,
|
|
158
|
-
stacks:
|
|
158
|
+
stacks: getErrors(err).map(e => e.stack),
|
|
159
159
|
meta: Object.keys(meta).length > 0 ? meta : undefined
|
|
160
160
|
})
|
|
161
161
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const util = require('util')
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const fs = require('fs')
|
|
6
|
-
const { addStack } = require('./
|
|
6
|
+
const { addStack } = require('./utils/error')
|
|
7
7
|
const accessAsync = util.promisify(fs.access)
|
|
8
8
|
|
|
9
9
|
module.exports = async (extensions, commander) => {
|
package/lib/keepAliveProcess.js
CHANGED
|
@@ -6,10 +6,10 @@ const fs = require('fs')
|
|
|
6
6
|
const spawn = require('silent-spawn')
|
|
7
7
|
const lockfile = require('lockfile')
|
|
8
8
|
const omit = require('lodash.omit')
|
|
9
|
-
const { addStack } = require('./
|
|
10
|
-
const getTempPaths = require('./getTempPaths')
|
|
9
|
+
const { addStack } = require('./utils/error')
|
|
10
|
+
const getTempPaths = require('./utils/getTempPaths')
|
|
11
|
+
const startSocketServer = require('./utils/startSocketServer')
|
|
11
12
|
const daemonHandler = require('./daemonHandler')
|
|
12
|
-
const startSocketServer = require('./startSocketServer')
|
|
13
13
|
|
|
14
14
|
const lock = util.promisify(lockfile.lock.bind(lockfile))
|
|
15
15
|
const unlock = util.promisify(lockfile.unlock.bind(lockfile))
|
|
@@ -58,7 +58,7 @@ function getErrors (err) {
|
|
|
58
58
|
errors.push({
|
|
59
59
|
message: parent.message,
|
|
60
60
|
stack: currentStack || '',
|
|
61
|
-
meta: Object.keys(customProps).length > 0 ? customProps : undefined,
|
|
61
|
+
meta: Object.keys(customProps).length > 0 ? getSimpleProperties(customProps) : undefined,
|
|
62
62
|
cleanState
|
|
63
63
|
})
|
|
64
64
|
|
|
@@ -115,6 +115,28 @@ function getErrorMessages (err) {
|
|
|
115
115
|
return messages
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
function getSimpleProperties (obj) {
|
|
119
|
+
const newObj = {}
|
|
120
|
+
|
|
121
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
122
|
+
if (
|
|
123
|
+
value == null ||
|
|
124
|
+
typeof value === 'string' ||
|
|
125
|
+
typeof value === 'number' ||
|
|
126
|
+
typeof value === 'boolean' ||
|
|
127
|
+
typeof value === 'bigint'
|
|
128
|
+
) {
|
|
129
|
+
newObj[key] = value
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (Object.keys(newObj).length === 0) {
|
|
134
|
+
return undefined
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return newObj
|
|
138
|
+
}
|
|
139
|
+
|
|
118
140
|
function printError (err, logger) {
|
|
119
141
|
const messages = getErrorMessages(err)
|
|
120
142
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsreport/jsreport-cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Command line interface for jsreport",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jsreport",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"scripts": {
|
|
47
47
|
"lint": "standard",
|
|
48
48
|
"start": "cross-env JSREPORT_CLI_DEV=enabled node cli.js",
|
|
49
|
-
"test": "mocha --recursive \"./test/*.spec.js\" \"./test/commands/**/*.spec.js\" --timeout 28000 --exit",
|
|
49
|
+
"test": "mocha --recursive \"./test/*.spec.js\" \"./test/commands/**/*.spec.js\" --timeout 28000 --exit && standard",
|
|
50
50
|
"test:watch": "mocha --recursive \"./test/*.spec.js\" \"./test/commands/**/*.spec.js\" --timeout 28000 --exit --watch"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
@@ -60,20 +60,20 @@
|
|
|
60
60
|
"liftoff": "3.1.0",
|
|
61
61
|
"lockfile": "1.0.4",
|
|
62
62
|
"lodash.omit": "4.5.0",
|
|
63
|
-
"nanoid": "
|
|
63
|
+
"nanoid": "3.2.0",
|
|
64
64
|
"npm-install-package": "2.1.0",
|
|
65
65
|
"nssocket": "0.6.0",
|
|
66
66
|
"once": "1.4.0",
|
|
67
67
|
"prompt-tmp": "1.0.0",
|
|
68
68
|
"semver": "5.6.0",
|
|
69
69
|
"silent-spawn": "0.4.0",
|
|
70
|
-
"yargs": "
|
|
70
|
+
"yargs": "17.3.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@jsreport/jsreport-authentication": "3.
|
|
74
|
-
"@jsreport/jsreport-core": "3.
|
|
75
|
-
"@jsreport/jsreport-express": "3.
|
|
76
|
-
"@jsreport/jsreport-fs-store": "3.
|
|
73
|
+
"@jsreport/jsreport-authentication": "3.2.0",
|
|
74
|
+
"@jsreport/jsreport-core": "3.4.0",
|
|
75
|
+
"@jsreport/jsreport-express": "3.3.0",
|
|
76
|
+
"@jsreport/jsreport-fs-store": "3.1.0",
|
|
77
77
|
"@jsreport/jsreport-handlebars": "3.0.0",
|
|
78
78
|
"cross-env": "5.2.1",
|
|
79
79
|
"execa": "1.0.0",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"rimraf": "2.6.3",
|
|
85
85
|
"should": "13.2.3",
|
|
86
86
|
"sinon": "4.4.0",
|
|
87
|
-
"standard": "16.0.
|
|
87
|
+
"standard": "16.0.4",
|
|
88
88
|
"std-mocks": "1.0.1"
|
|
89
89
|
},
|
|
90
90
|
"optionalDependencies": {
|