@jsreport/jsreport-cli 3.2.1 → 3.2.3

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 CHANGED
@@ -7,6 +7,14 @@ See http://jsreport.net/learn/cli for documentation
7
7
 
8
8
  ## Changelog
9
9
 
10
+ ### 3.2.3
11
+
12
+ - improve error logging
13
+
14
+ ### 3.2.2
15
+
16
+ - add support for tempDirectory and service name to win-install command
17
+
10
18
  ### 3.2.0
11
19
 
12
20
  - change the configure command questions to fit better with new `trustUserCode` option
@@ -9,6 +9,17 @@ const command = 'win-install'
9
9
  exports.command = command
10
10
  exports.description = description
11
11
 
12
+ exports.builder = (yargs) => {
13
+ return (
14
+ yargs
15
+ .usage('install jsreport as a windows service\njsreport win-install\njsreport win-install --name my-service --tempDirectory=mytemp')
16
+ .option('name', {
17
+ description: 'ServiceName',
18
+ type: 'string'
19
+ })
20
+ )
21
+ }
22
+
12
23
  exports.handler = (argv) => {
13
24
  return new Promise((resolve, reject) => {
14
25
  const verbose = argv.verbose
@@ -50,13 +61,14 @@ exports.handler = (argv) => {
50
61
 
51
62
  pathToApp = appInfo.path
52
63
 
53
- if (!appInfo.name) {
54
- customError = new Error('To install app as windows service you need to pass "name" in appInfo')
64
+ serviceName = argv.name || appInfo.name
65
+ if (!serviceName) {
66
+ customError = new Error('To install app as windows service you need to pass "name" args or in appInfo')
55
67
  customError.cleanState = true
56
68
  return reject(customError)
57
69
  }
58
70
 
59
- serviceName = appInfo.name
71
+ appInfo.name = serviceName
60
72
 
61
73
  if (appInfo.startcmd) {
62
74
  hasEntry = true
@@ -103,9 +115,15 @@ exports.handler = (argv) => {
103
115
  winser = Winser({ silent: !verbose, nssmPath: staticPaths.nssm })
104
116
  }
105
117
 
118
+ let tempDirectory = process.env.tempDirectory || argv.tempDirectory
119
+ if (tempDirectory) {
120
+ tempDirectory = path.isAbsolute(tempDirectory) ? tempDirectory : path.join(pathToApp, tempDirectory)
121
+ }
122
+
106
123
  winser.install({
107
124
  path: pathToApp,
108
- autostart: true
125
+ autostart: true,
126
+ env: tempDirectory ? [`tempDirectory=${tempDirectory}`] : null
109
127
  }, (err) => {
110
128
  if (err) {
111
129
  const error = new Error('Error while trying to install windows service')
@@ -9,6 +9,17 @@ const command = 'win-uninstall'
9
9
  exports.command = command
10
10
  exports.description = description
11
11
 
12
+ exports.builder = (yargs) => {
13
+ return (
14
+ yargs
15
+ .usage('uninstall jsreport windows service\njsreport win-uninstall\njsreport win-uninstall --name my-service')
16
+ .option('name', {
17
+ description: 'ServiceName',
18
+ type: 'string'
19
+ })
20
+ )
21
+ }
22
+
12
23
  exports.handler = (argv) => {
13
24
  return new Promise((resolve, reject) => {
14
25
  const verbose = argv.verbose
@@ -48,13 +59,14 @@ exports.handler = (argv) => {
48
59
 
49
60
  pathToApp = appInfo.path
50
61
 
51
- if (!appInfo.name) {
52
- customError = new Error('To uninstall windows service for app you need to pass "name" in appInfo')
62
+ serviceName = argv.name || appInfo.name
63
+ if (!serviceName) {
64
+ customError = new Error('To uninstall windows service for app you need to pass "name" in args or in appInfo')
53
65
  customError.cleanState = true
54
66
  return reject(customError)
55
67
  }
56
68
 
57
- serviceName = appInfo.name
69
+ appInfo.name = serviceName
58
70
  } else {
59
71
  pathToApp = cwd
60
72
 
@@ -70,7 +70,6 @@ function getErrors (err) {
70
70
 
71
71
  function getErrorMessages (err) {
72
72
  const errors = getErrors(err)
73
- let count = errors.length
74
73
  let cleanState = false
75
74
  const messages = []
76
75
  const stacks = []
@@ -85,34 +84,26 @@ function getErrorMessages (err) {
85
84
 
86
85
  customProps = JSON.stringify(customProps)
87
86
 
88
- if (cleanState) {
89
- messages.push(`${formatError(error)}`)
90
- } else {
91
- messages.push(`${formatError(error)} (${count})`)
92
- }
87
+ messages.push(`${formatError(error)}`)
93
88
 
94
89
  if (customProps === '{}') {
95
90
  customProps = ''
96
91
  }
97
92
 
98
93
  if (currentStack !== '') {
99
- const causedBy = `caused by error (${count}):`
100
-
101
94
  if (customProps !== '') {
102
- stacks.push(`${causedBy}\n-> meta = ${customProps}\n-> stack\n${currentStack}`)
95
+ stacks.push(`-> meta = ${customProps}\n-> stack\n${currentStack}`)
103
96
  } else {
104
- stacks.push(`${causedBy}\n-> stack\n${currentStack}`)
97
+ stacks.push(`-> stack\n${currentStack}`)
105
98
  }
106
99
  }
107
-
108
- count--
109
100
  })
110
101
 
111
102
  if (!cleanState && stacks.length > 0) {
112
- messages.push(`\n${stacks.join('\n')}`)
103
+ return [messages, stacks]
113
104
  }
114
105
 
115
- return messages
106
+ return [messages, []]
116
107
  }
117
108
 
118
109
  function getSimpleProperties (obj) {
@@ -138,9 +129,37 @@ function getSimpleProperties (obj) {
138
129
  }
139
130
 
140
131
  function printError (err, logger) {
141
- const messages = getErrorMessages(err)
132
+ const [messages, stacks] = getErrorMessages(err)
133
+
134
+ for (let idx = 0; idx < messages.length; idx++) {
135
+ messages[idx] += ` (${messages.length - idx})`
136
+
137
+ if (idx > 0) {
138
+ messages[idx] = lowerCaseFirstLetter(messages[idx])
139
+ }
140
+ }
141
+
142
+ let errorLog = messages.join('\n(because) ')
143
+
144
+ if (stacks.length > 0) {
145
+ const reversedStacks = [...stacks].reverse()
146
+
147
+ for (let idx = 0; idx < reversedStacks.length; idx++) {
148
+ reversedStacks[idx] = `-- error (${idx + 1}) --\n${reversedStacks[idx]}`
149
+ }
150
+
151
+ errorLog += `\n\n${reversedStacks.join('\nwrapped by:\n')}`
152
+ }
153
+
154
+ logger.error(errorLog)
155
+ }
156
+
157
+ function lowerCaseFirstLetter (str) {
158
+ if (str === '' || typeof str !== 'string') {
159
+ return str
160
+ }
142
161
 
143
- logger.error(messages.join('. '))
162
+ return str.charAt(0).toLowerCase() + str.slice(1)
144
163
  }
145
164
 
146
165
  module.exports.printError = printError
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsreport/jsreport-cli",
3
- "version": "3.2.1",
3
+ "version": "3.2.3",
4
4
  "description": "Command line interface for jsreport",
5
5
  "keywords": [
6
6
  "jsreport",
@@ -70,11 +70,11 @@
70
70
  "yargs": "17.3.1"
71
71
  },
72
72
  "devDependencies": {
73
- "@jsreport/jsreport-authentication": "3.3.1",
74
- "@jsreport/jsreport-core": "3.6.1",
75
- "@jsreport/jsreport-express": "3.4.1",
76
- "@jsreport/jsreport-fs-store": "3.2.1",
77
- "@jsreport/jsreport-handlebars": "3.1.0",
73
+ "@jsreport/jsreport-authentication": "3.3.2",
74
+ "@jsreport/jsreport-core": "3.9.0",
75
+ "@jsreport/jsreport-express": "3.5.0",
76
+ "@jsreport/jsreport-fs-store": "3.2.3",
77
+ "@jsreport/jsreport-handlebars": "3.2.1",
78
78
  "cross-env": "5.2.1",
79
79
  "execa": "1.0.0",
80
80
  "handlebars": "4.7.7",