@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/init.js
CHANGED
|
@@ -1,77 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
let
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
[`${command}`, 'Initializes and install
|
|
75
|
-
|
|
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
|
+
}
|
package/lib/commands/kill.js
CHANGED
|
@@ -1,86 +1,85 @@
|
|
|
1
|
-
'
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
let
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
error
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
+
}
|