@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.
Files changed (41) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +16 -12
  3. package/cli.js +93 -93
  4. package/example.config.json +43 -43
  5. package/example.server.js +14 -14
  6. package/index.js +20 -22
  7. package/jsreport.config.js +8 -8
  8. package/lib/cliExtension.js +59 -59
  9. package/lib/{createCommandParser.js → commander/createCommandParser.js} +44 -45
  10. package/lib/commander/createCustomCommandBuilder.js +150 -0
  11. package/lib/commander/createLogger.js +51 -0
  12. package/lib/commander/executeCommand.js +37 -0
  13. package/lib/commander/getCommandEventName.js +4 -0
  14. package/lib/commander/index.js +279 -0
  15. package/lib/commander/jsreportInstance.js +98 -0
  16. package/lib/commander/registerCommand.js +91 -0
  17. package/lib/commander/startCommand.js +234 -0
  18. package/lib/commander/startProcessing.js +208 -0
  19. package/lib/commands/_initializeApp.js +206 -208
  20. package/lib/commands/configure.js +393 -395
  21. package/lib/commands/help.js +453 -454
  22. package/lib/commands/init.js +76 -77
  23. package/lib/commands/kill.js +85 -86
  24. package/lib/commands/render.js +490 -488
  25. package/lib/commands/repair.js +55 -56
  26. package/lib/commands/start.js +72 -74
  27. package/lib/commands/win-install.js +124 -126
  28. package/lib/commands/win-uninstall.js +100 -102
  29. package/lib/daemonHandler.js +164 -164
  30. package/lib/daemonInstance.js +225 -225
  31. package/lib/{registerExtensionsCommands.js → detectAndRegisterExtensionsCommands.js} +74 -74
  32. package/lib/instanceHandler.js +316 -316
  33. package/lib/keepAliveProcess.js +205 -205
  34. package/lib/{errorUtils.js → utils/error.js} +149 -127
  35. package/lib/{getTempPaths.js → utils/getTempPaths.js} +39 -39
  36. package/lib/{normalizePathOptionOrArg.js → utils/normalizePathOptionOrArg.js} +41 -41
  37. package/lib/{normalizeSocketPath.js → utils/normalizeSocketPath.js} +9 -9
  38. package/lib/{startSocketServer.js → utils/startSocketServer.js} +53 -53
  39. package/package.json +105 -106
  40. package/test/testUtils.js +197 -198
  41. package/lib/commander.js +0 -1108
@@ -1,56 +1,55 @@
1
- 'use strict'
2
-
3
- const initializeApp = require('./_initializeApp')
4
-
5
- const description = 'Repairs current working directory to start a jsreport application (It re-creates files server.js, *.config.json and package.json)'
6
- const command = 'repair'
7
-
8
- exports.command = command
9
- exports.description = description
10
-
11
- exports.builder = (yargs) => {
12
- const examples = getExamples(`jsreport ${command}`)
13
-
14
- examples.forEach((examp) => {
15
- yargs.example(examp[0], examp[1])
16
- })
17
-
18
- return (
19
- yargs
20
- .usage([
21
- `${description}\n`,
22
- `Usage:\n\njsreport ${command} [versionToInstall]\n`,
23
- 'If no jsreport installation was found we will try to install the version of',
24
- 'jsreport specified in `versionToInstall` and if it is not specified we will try to install the latest version'
25
- ].join('\n'))
26
- .positional('versionToInstall', {
27
- type: 'string',
28
- description: 'Specific jsreport version to install'
29
- })
30
- )
31
- }
32
-
33
- exports.handler = (argv) => {
34
- const logger = argv.context.logger
35
- const cwd = argv.context.cwd
36
- let versionToInstall
37
-
38
- if (argv._ && argv._[1]) {
39
- versionToInstall = argv._[1]
40
- }
41
-
42
- return initializeApp(
43
- cwd,
44
- logger,
45
- true,
46
- versionToInstall,
47
- typeof argv.context.customInstall === 'function' ? argv.context.customInstall : undefined
48
- )
49
- }
50
-
51
- function getExamples (command) {
52
- return [
53
- [`${command}`, 'Repairs and install the latest jsreport if not found'],
54
- [`${command} 2.5.0`, 'Repairs and install jsreport version 2.5.0 if not found']
55
- ]
56
- }
1
+ const initializeApp = require('./_initializeApp')
2
+
3
+ const description = 'Repairs current working directory to start a jsreport application (It re-creates files server.js, *.config.json and package.json)'
4
+ const command = 'repair'
5
+ const positionalArgs = '[versionToInstall]'
6
+
7
+ exports.command = `${command} ${positionalArgs}`
8
+ exports.description = description
9
+
10
+ exports.builder = (yargs) => {
11
+ const examples = getExamples(`jsreport ${command}`)
12
+
13
+ examples.forEach((examp) => {
14
+ yargs.example(examp[0], examp[1])
15
+ })
16
+
17
+ return (
18
+ yargs
19
+ .usage([
20
+ `${description}\n`,
21
+ `Usage:\n\njsreport ${command} [versionToInstall]\n`,
22
+ 'If no jsreport installation was found we will try to install the version of',
23
+ 'jsreport specified in `versionToInstall` and if it is not specified we will try to install the latest version'
24
+ ].join('\n'))
25
+ .positional('versionToInstall', {
26
+ type: 'string',
27
+ description: 'Specific jsreport version to install'
28
+ })
29
+ )
30
+ }
31
+
32
+ exports.handler = (argv) => {
33
+ const logger = argv.context.logger
34
+ const cwd = argv.context.cwd
35
+ let versionToInstall
36
+
37
+ if (argv && argv.versionToInstall != null) {
38
+ versionToInstall = argv.versionToInstall
39
+ }
40
+
41
+ return initializeApp(
42
+ cwd,
43
+ logger,
44
+ true,
45
+ versionToInstall,
46
+ typeof argv.context.customInstall === 'function' ? argv.context.customInstall : undefined
47
+ )
48
+ }
49
+
50
+ function getExamples (command) {
51
+ return [
52
+ [`${command}`, 'Repairs and install the latest jsreport if not found'],
53
+ [`${command} 2.5.0`, 'Repairs and install jsreport version 2.5.0 if not found']
54
+ ]
55
+ }
@@ -1,74 +1,72 @@
1
- 'use strict'
2
-
3
- const description = 'Starts a jsreport process in current working directory'
4
- const command = 'start'
5
-
6
- exports.command = command
7
- exports.description = description
8
-
9
- exports.configuration = {
10
- disableStrictOptions: true,
11
- disableProcessExit: true
12
- }
13
-
14
- exports.builder = (yargs) => {
15
- return (
16
- yargs.usage([
17
- `${description}\n`,
18
- `Usage:\n\njsreport ${command}\n`,
19
- 'You can set any jsreport configuration option using arguments or env vars',
20
- 'For example, to set httpPort option using arguments:\n',
21
- 'simple option:',
22
- ' jsreport start --httpPort=9000\n',
23
- 'nested option:',
24
- ' jsreport start --store:provider=fs\n',
25
- 'Or using env vars:\n',
26
- ' Linux/macOS:',
27
- ' simple option:',
28
- ' $> env httpPort=9000 jsreport start\n',
29
- ' nested option:',
30
- ' $> env store:provider=fs jsreport start\n',
31
- ' Windows:',
32
- ' simple option:',
33
- ' $> set httpPort=9000',
34
- ' $> jsreport start\n',
35
- ' nested option:',
36
- ' $> set store:provider=fs',
37
- ' $> jsreport start\n\n',
38
- 'Also, you can put configuration in jsreport.config.json,',
39
- 'You can learn more about jsreport configuration, conditional config files and available options here: https://jsreport.net/learn/configuration'
40
- ].join('\n'))
41
- )
42
- }
43
-
44
- exports.handler = (argv) => {
45
- const context = argv.context
46
- const logger = context.logger
47
- const cwd = context.cwd
48
- const getInstance = context.getInstance
49
- const initInstance = context.initInstance
50
-
51
- logger.debug('resolving jsreport location..')
52
-
53
- return (
54
- getInstance(cwd)
55
- .then((_instance) => {
56
- let jsreportInstance
57
-
58
- logger.debug('starting jsreport..')
59
-
60
- if (typeof _instance === 'function') {
61
- jsreportInstance = _instance()
62
- } else {
63
- jsreportInstance = _instance
64
- }
65
-
66
- // init and resolving the promise with the instance
67
- return initInstance(jsreportInstance, true)
68
- }).then((result) => {
69
- logger.debug('jsreport successfully started')
70
-
71
- return result
72
- })
73
- )
74
- }
1
+ const description = 'Starts a jsreport process in current working directory'
2
+ const command = 'start'
3
+
4
+ exports.command = command
5
+ exports.description = description
6
+
7
+ exports.configuration = {
8
+ disableStrictOptions: true,
9
+ disableProcessExit: true
10
+ }
11
+
12
+ exports.builder = (yargs) => {
13
+ return (
14
+ yargs.usage([
15
+ `${description}\n`,
16
+ `Usage:\n\njsreport ${command}\n`,
17
+ 'You can set any jsreport configuration option using arguments or env vars',
18
+ 'For example, to set httpPort option using arguments:\n',
19
+ 'simple option:',
20
+ ' jsreport start --httpPort=9000\n',
21
+ 'nested option:',
22
+ ' jsreport start --store:provider=fs\n',
23
+ 'Or using env vars:\n',
24
+ ' Linux/macOS:',
25
+ ' simple option:',
26
+ ' $> env httpPort=9000 jsreport start\n',
27
+ ' nested option:',
28
+ ' $> env store:provider=fs jsreport start\n',
29
+ ' Windows:',
30
+ ' simple option:',
31
+ ' $> set httpPort=9000',
32
+ ' $> jsreport start\n',
33
+ ' nested option:',
34
+ ' $> set store:provider=fs',
35
+ ' $> jsreport start\n\n',
36
+ 'Also, you can put configuration in jsreport.config.json,',
37
+ 'You can learn more about jsreport configuration, conditional config files and available options here: https://jsreport.net/learn/configuration'
38
+ ].join('\n'))
39
+ )
40
+ }
41
+
42
+ exports.handler = (argv) => {
43
+ const context = argv.context
44
+ const logger = context.logger
45
+ const cwd = context.cwd
46
+ const getInstance = context.getInstance
47
+ const initInstance = context.initInstance
48
+
49
+ logger.debug('resolving jsreport location..')
50
+
51
+ return (
52
+ getInstance(cwd)
53
+ .then((_instance) => {
54
+ let jsreportInstance
55
+
56
+ logger.debug('starting jsreport..')
57
+
58
+ if (typeof _instance === 'function') {
59
+ jsreportInstance = _instance()
60
+ } else {
61
+ jsreportInstance = _instance
62
+ }
63
+
64
+ // init and resolving the promise with the instance
65
+ return initInstance(jsreportInstance, true)
66
+ }).then((result) => {
67
+ logger.debug('jsreport successfully started')
68
+
69
+ return result
70
+ })
71
+ )
72
+ }
@@ -1,126 +1,124 @@
1
- 'use strict'
2
-
3
- const path = require('path')
4
- const fs = require('fs')
5
- const platform = require('os').platform()
6
- const Winser = require('winser-with-api').Winser
7
-
8
- const description = 'WINDOWS ONLY - install app as windows service, For other platforms see http://jsreport.net/on-prem/downloads'
9
- const command = 'win-install'
10
-
11
- exports.command = command
12
- exports.description = description
13
-
14
- exports.handler = (argv) => {
15
- return new Promise((resolve, reject) => {
16
- const verbose = argv.verbose
17
- const context = argv.context
18
- const logger = context.logger
19
- const cwd = context.cwd
20
- const staticPaths = context.staticPaths || {}
21
- const appInfo = context.appInfo
22
- const existsPackageJson = fs.existsSync(path.join(cwd, './package.json'))
23
- let hasEntry = false
24
- let pathToApp
25
- let serviceName
26
- let customError
27
-
28
- logger.info('Platform is ' + platform)
29
-
30
- if (platform !== 'win32') {
31
- logger.info('Installing app as windows service only works on windows platforms..')
32
- logger.info('Installing jsreport as startup service for your platform should be described at http://jsreport.net/downloads')
33
-
34
- return resolve({
35
- installed: false,
36
- serviceName: null
37
- })
38
- }
39
-
40
- if (!existsPackageJson && !appInfo) {
41
- customError = new Error('To install app as windows service you need a package.json file')
42
- customError.cleanState = true
43
- return reject(customError)
44
- }
45
-
46
- if (appInfo) {
47
- if (!appInfo.path) {
48
- customError = new Error('To install app as windows service you need to pass "path" in appInfo')
49
- customError.cleanState = true
50
- return reject(customError)
51
- }
52
-
53
- pathToApp = appInfo.path
54
-
55
- if (!appInfo.name) {
56
- customError = new Error('To install app as windows service you need to pass "name" in appInfo')
57
- customError.cleanState = true
58
- return reject(customError)
59
- }
60
-
61
- serviceName = appInfo.name
62
-
63
- if (appInfo.startcmd) {
64
- hasEntry = true
65
- }
66
-
67
- if (!hasEntry) {
68
- customError = new Error('To install app as windows service you need to pass "startcmd" in appInfo')
69
- customError.cleanState = true
70
- return reject(customError)
71
- }
72
- } else {
73
- pathToApp = cwd
74
-
75
- const userPkg = require(path.join(pathToApp, './package.json'))
76
-
77
- if (!userPkg.name) {
78
- customError = new Error('To install app as windows service you need a "name" field in package.json file')
79
- customError.cleanState = true
80
- return reject(customError)
81
- }
82
-
83
- serviceName = userPkg.name
84
-
85
- if (userPkg.scripts && userPkg.scripts.start) {
86
- hasEntry = true
87
- } else if (userPkg.main) {
88
- hasEntry = true
89
- }
90
-
91
- if (!hasEntry) {
92
- customError = new Error('To install app as windows service you need to have a "start" script or a "main" field in package.json file')
93
- customError.cleanState = true
94
- return reject(customError)
95
- }
96
- }
97
-
98
- logger.info('Installing windows service "' + serviceName + '" for app..')
99
-
100
- let winser
101
-
102
- if (appInfo) {
103
- winser = Winser({ silent: !verbose, nssmPath: staticPaths.nssm, app: appInfo })
104
- } else {
105
- winser = Winser({ silent: !verbose, nssmPath: staticPaths.nssm })
106
- }
107
-
108
- winser.install({
109
- path: pathToApp,
110
- autostart: true
111
- }, (err) => {
112
- if (err) {
113
- const error = new Error('Error while trying to install windows service')
114
- error.originalError = err
115
- return reject(error)
116
- }
117
-
118
- logger.info('Service "' + serviceName + '" is running.')
119
-
120
- resolve({
121
- installed: true,
122
- serviceName: serviceName
123
- })
124
- })
125
- })
126
- }
1
+ const path = require('path')
2
+ const fs = require('fs')
3
+ const platform = require('os').platform()
4
+ const Winser = require('winser-with-api').Winser
5
+
6
+ const description = 'WINDOWS ONLY - install app as windows service, For other platforms see http://jsreport.net/on-prem/downloads'
7
+ const command = 'win-install'
8
+
9
+ exports.command = command
10
+ exports.description = description
11
+
12
+ exports.handler = (argv) => {
13
+ return new Promise((resolve, reject) => {
14
+ const verbose = argv.verbose
15
+ const context = argv.context
16
+ const logger = context.logger
17
+ const cwd = context.cwd
18
+ const staticPaths = context.staticPaths || {}
19
+ const appInfo = context.appInfo
20
+ const existsPackageJson = fs.existsSync(path.join(cwd, './package.json'))
21
+ let hasEntry = false
22
+ let pathToApp
23
+ let serviceName
24
+ let customError
25
+
26
+ logger.info('Platform is ' + platform)
27
+
28
+ if (platform !== 'win32') {
29
+ logger.info('Installing app as windows service only works on windows platforms..')
30
+ logger.info('Installing jsreport as startup service for your platform should be described at http://jsreport.net/downloads')
31
+
32
+ return resolve({
33
+ installed: false,
34
+ serviceName: null
35
+ })
36
+ }
37
+
38
+ if (!existsPackageJson && !appInfo) {
39
+ customError = new Error('To install app as windows service you need a package.json file')
40
+ customError.cleanState = true
41
+ return reject(customError)
42
+ }
43
+
44
+ if (appInfo) {
45
+ if (!appInfo.path) {
46
+ customError = new Error('To install app as windows service you need to pass "path" in appInfo')
47
+ customError.cleanState = true
48
+ return reject(customError)
49
+ }
50
+
51
+ pathToApp = appInfo.path
52
+
53
+ if (!appInfo.name) {
54
+ customError = new Error('To install app as windows service you need to pass "name" in appInfo')
55
+ customError.cleanState = true
56
+ return reject(customError)
57
+ }
58
+
59
+ serviceName = appInfo.name
60
+
61
+ if (appInfo.startcmd) {
62
+ hasEntry = true
63
+ }
64
+
65
+ if (!hasEntry) {
66
+ customError = new Error('To install app as windows service you need to pass "startcmd" in appInfo')
67
+ customError.cleanState = true
68
+ return reject(customError)
69
+ }
70
+ } else {
71
+ pathToApp = cwd
72
+
73
+ const userPkg = require(path.join(pathToApp, './package.json'))
74
+
75
+ if (!userPkg.name) {
76
+ customError = new Error('To install app as windows service you need a "name" field in package.json file')
77
+ customError.cleanState = true
78
+ return reject(customError)
79
+ }
80
+
81
+ serviceName = userPkg.name
82
+
83
+ if (userPkg.scripts && userPkg.scripts.start) {
84
+ hasEntry = true
85
+ } else if (userPkg.main) {
86
+ hasEntry = true
87
+ }
88
+
89
+ if (!hasEntry) {
90
+ customError = new Error('To install app as windows service you need to have a "start" script or a "main" field in package.json file')
91
+ customError.cleanState = true
92
+ return reject(customError)
93
+ }
94
+ }
95
+
96
+ logger.info('Installing windows service "' + serviceName + '" for app..')
97
+
98
+ let winser
99
+
100
+ if (appInfo) {
101
+ winser = Winser({ silent: !verbose, nssmPath: staticPaths.nssm, app: appInfo })
102
+ } else {
103
+ winser = Winser({ silent: !verbose, nssmPath: staticPaths.nssm })
104
+ }
105
+
106
+ winser.install({
107
+ path: pathToApp,
108
+ autostart: true
109
+ }, (err) => {
110
+ if (err) {
111
+ const error = new Error('Error while trying to install windows service')
112
+ error.originalError = err
113
+ return reject(error)
114
+ }
115
+
116
+ logger.info('Service "' + serviceName + '" is running.')
117
+
118
+ resolve({
119
+ installed: true,
120
+ serviceName: serviceName
121
+ })
122
+ })
123
+ })
124
+ }