@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,77 +1,76 @@
1
- 'use strict'
2
-
3
- const path = require('path')
4
- const fs = require('fs')
5
- const initializeApp = require('./_initializeApp')
6
-
7
- const description = 'Initializes the current working directory to start a jsreport application (server.js, *.config.json and package.json)'
8
- const command = 'init'
9
-
10
- exports.command = command
11
- exports.description = description
12
-
13
- exports.builder = (yargs) => {
14
- const examples = getExamples(`jsreport ${command}`)
15
-
16
- examples.forEach((examp) => {
17
- yargs.example(examp[0], examp[1])
18
- })
19
-
20
- const commandOptions = {
21
- target: {
22
- alias: 't',
23
- description: 'Target path in which the init is going to execute',
24
- type: 'string'
25
- }
26
- }
27
-
28
- const options = Object.keys(commandOptions)
29
-
30
- return (
31
- yargs
32
- .usage(
33
- [
34
- `${description}\n`,
35
- `Usage:\n\njsreport ${command} [versionToInstall]\n`,
36
- 'If no jsreport installation was found we will try to install the version of',
37
- 'jsreport specified in `versionToInstall` and if it is not specified we will try to install the latest version'
38
- ].join('\n')
39
- )
40
- .positional('versionToInstall', {
41
- type: 'string',
42
- description: 'Specific jsreport version to install'
43
- })
44
- .group(options, 'Command options:')
45
- .options(commandOptions)
46
- )
47
- }
48
-
49
- exports.handler = (argv) => {
50
- const logger = argv.context.logger
51
- let cwd = argv.context.cwd
52
- let versionToInstall
53
-
54
- if (argv._ && argv._[1]) {
55
- versionToInstall = argv._[1]
56
- }
57
-
58
- if (argv.target != null) {
59
- cwd = path.resolve(cwd, argv.target)
60
- fs.mkdirSync(cwd, { recursive: true })
61
- }
62
-
63
- return initializeApp(
64
- cwd,
65
- logger,
66
- false,
67
- versionToInstall,
68
- typeof argv.context.customInstall === 'function' ? argv.context.customInstall : undefined
69
- )
70
- }
71
-
72
- function getExamples (command) {
73
- return [
74
- [`${command}`, 'Initializes and install the latest jsreport'],
75
- [`${command} 2.5.0`, 'Initializes and install jsreport version 2.5.0']
76
- ]
77
- }
1
+ const path = require('path')
2
+ const fs = require('fs')
3
+ const initializeApp = require('./_initializeApp')
4
+
5
+ const description = 'Initializes the current working directory to start a jsreport application (server.js, *.config.json and package.json)'
6
+ const command = 'init'
7
+ const positionalArgs = '[versionToInstall]'
8
+
9
+ exports.command = `${command} ${positionalArgs}`
10
+ exports.description = description
11
+
12
+ exports.builder = (yargs) => {
13
+ const examples = getExamples(`jsreport ${command}`)
14
+
15
+ examples.forEach((examp) => {
16
+ yargs.example(examp[0], examp[1])
17
+ })
18
+
19
+ const commandOptions = {
20
+ target: {
21
+ alias: 't',
22
+ description: 'Target path in which the init is going to execute',
23
+ type: 'string'
24
+ }
25
+ }
26
+
27
+ const options = Object.keys(commandOptions)
28
+
29
+ return (
30
+ yargs
31
+ .usage(
32
+ [
33
+ `${description}\n`,
34
+ `Usage:\n\njsreport ${command} [versionToInstall]\n`,
35
+ 'If no jsreport installation was found we will try to install the version of',
36
+ 'jsreport specified in `versionToInstall` and if it is not specified we will try to install the latest version'
37
+ ].join('\n')
38
+ )
39
+ .positional('versionToInstall', {
40
+ type: 'string',
41
+ description: 'Specific jsreport version to install'
42
+ })
43
+ .group(options, 'Command options:')
44
+ .options(commandOptions)
45
+ )
46
+ }
47
+
48
+ exports.handler = (argv) => {
49
+ const logger = argv.context.logger
50
+ let cwd = argv.context.cwd
51
+ let versionToInstall
52
+
53
+ if (argv && argv.versionToInstall != null) {
54
+ versionToInstall = argv.versionToInstall
55
+ }
56
+
57
+ if (argv.target != null) {
58
+ cwd = path.resolve(cwd, argv.target)
59
+ fs.mkdirSync(cwd, { recursive: true })
60
+ }
61
+
62
+ return initializeApp(
63
+ cwd,
64
+ logger,
65
+ false,
66
+ versionToInstall,
67
+ typeof argv.context.customInstall === 'function' ? argv.context.customInstall : undefined
68
+ )
69
+ }
70
+
71
+ function getExamples (command) {
72
+ return [
73
+ [`${command}`, 'Initializes and install the latest jsreport'],
74
+ [`${command} 2.5.0`, 'Initializes and install jsreport version 2.5.0']
75
+ ]
76
+ }
@@ -1,86 +1,85 @@
1
- 'use strict'
2
-
3
- const description = 'Kill a daemon jsreport process'
4
- const command = 'kill'
5
-
6
- exports.command = command
7
- exports.description = description
8
-
9
- exports.builder = (yargs) => {
10
- return (
11
- yargs
12
- .usage(
13
- [
14
- `${description}\n`,
15
- `Usage:\n\njsreport ${command} [uidOrpid]\n`,
16
- 'If uid or pid is not specified we will try to kill a daemon process that was started from CWD'
17
- ].join('\n')
18
- )
19
- .positional('uidOrpid', {
20
- type: 'string',
21
- description: 'Process id or uid of the instance to kill'
22
- })
23
- )
24
- }
25
-
26
- exports.handler = async (argv) => {
27
- const context = argv.context
28
- const logger = context.logger
29
- const cwd = context.cwd
30
- const workerSockPath = context.workerSockPath
31
- const daemonHandler = context.daemonHandler
32
-
33
- let identifier
34
- let processInfo
35
-
36
- if (argv._ && argv._[1]) {
37
- identifier = argv._[1]
38
- }
39
-
40
- if (!identifier) {
41
- logger.info('searching for daemon process in:', cwd)
42
-
43
- logger.debug('looking for previously daemonized process in:', workerSockPath, 'cwd:', cwd)
44
-
45
- processInfo = await daemonHandler.findProcessByCWD(workerSockPath, cwd)
46
- } else {
47
- logger.info('searching for daemon process with id:', identifier)
48
-
49
- processInfo = await daemonHandler.findProcessByUidOrPid(workerSockPath, identifier)
50
- }
51
-
52
- if (!processInfo) {
53
- let customError
54
-
55
- if (!identifier) {
56
- customError = new Error(`there is no active daemon process in: ${cwd}`)
57
- } else {
58
- customError = new Error(`there is no active daemon with id: ${identifier}`)
59
- }
60
-
61
- // makes the cli to print clean error (without stack trace)
62
- customError.cleanState = true
63
-
64
- throw customError
65
- }
66
-
67
- if (!identifier) {
68
- logger.debug('daemon process found in:', workerSockPath, 'cwd:', cwd, 'pid:', processInfo.pid)
69
- } else {
70
- logger.debug('daemon process found in:', workerSockPath, 'id:', identifier, 'pid:', processInfo.pid)
71
- }
72
-
73
- logger.debug('killing daemon process.. uid:', processInfo.uid, 'pid:', processInfo.pid)
74
-
75
- try {
76
- await daemonHandler.kill(processInfo)
77
-
78
- logger.info(`daemon process (pid: ${processInfo.pid}) killed successfully`)
79
- } catch (e) {
80
- const error = new Error('Error while trying to kill daemon process')
81
- error.originalError = e
82
- throw error
83
- }
84
-
85
- return processInfo
86
- }
1
+ const description = 'Kill a daemon jsreport process'
2
+ const command = 'kill'
3
+ const positionalArgs = '[uidOrpid]'
4
+
5
+ exports.command = `${command} ${positionalArgs}`
6
+ exports.description = description
7
+
8
+ exports.builder = (yargs) => {
9
+ return (
10
+ yargs
11
+ .usage(
12
+ [
13
+ `${description}\n`,
14
+ `Usage:\n\njsreport ${command} [uidOrpid]\n`,
15
+ 'If uid or pid is not specified we will try to kill a daemon process that was started from CWD'
16
+ ].join('\n')
17
+ )
18
+ .positional('uidOrpid', {
19
+ type: 'string',
20
+ description: 'Process id or uid of the instance to kill'
21
+ })
22
+ )
23
+ }
24
+
25
+ exports.handler = async (argv) => {
26
+ const context = argv.context
27
+ const logger = context.logger
28
+ const cwd = context.cwd
29
+ const workerSockPath = context.workerSockPath
30
+ const daemonHandler = context.daemonHandler
31
+
32
+ let identifier
33
+ let processInfo
34
+
35
+ if (argv && argv.uidOrpid != null) {
36
+ identifier = argv.uidOrpid
37
+ }
38
+
39
+ if (!identifier) {
40
+ logger.info('searching for daemon process in:', cwd)
41
+
42
+ logger.debug('looking for previously daemonized process in:', workerSockPath, 'cwd:', cwd)
43
+
44
+ processInfo = await daemonHandler.findProcessByCWD(workerSockPath, cwd)
45
+ } else {
46
+ logger.info('searching for daemon process with id:', identifier)
47
+
48
+ processInfo = await daemonHandler.findProcessByUidOrPid(workerSockPath, identifier)
49
+ }
50
+
51
+ if (!processInfo) {
52
+ let customError
53
+
54
+ if (!identifier) {
55
+ customError = new Error(`there is no active daemon process in: ${cwd}`)
56
+ } else {
57
+ customError = new Error(`there is no active daemon with id: ${identifier}`)
58
+ }
59
+
60
+ // makes the cli to print clean error (without stack trace)
61
+ customError.cleanState = true
62
+
63
+ throw customError
64
+ }
65
+
66
+ if (!identifier) {
67
+ logger.debug('daemon process found in:', workerSockPath, 'cwd:', cwd, 'pid:', processInfo.pid)
68
+ } else {
69
+ logger.debug('daemon process found in:', workerSockPath, 'id:', identifier, 'pid:', processInfo.pid)
70
+ }
71
+
72
+ logger.debug('killing daemon process.. uid:', processInfo.uid, 'pid:', processInfo.pid)
73
+
74
+ try {
75
+ await daemonHandler.kill(processInfo)
76
+
77
+ logger.info(`daemon process (pid: ${processInfo.pid}) killed successfully`)
78
+ } catch (e) {
79
+ const error = new Error('Error while trying to kill daemon process')
80
+ error.originalError = e
81
+ throw error
82
+ }
83
+
84
+ return processInfo
85
+ }