@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/repair.js
CHANGED
|
@@ -1,56 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
'
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
[`${command}`, 'Repairs and install
|
|
54
|
-
|
|
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
|
+
}
|
package/lib/commands/start.js
CHANGED
|
@@ -1,74 +1,72 @@
|
|
|
1
|
-
'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
' jsreport start --
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
' $> env
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
' $>
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
jsreportInstance = _instance
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
let
|
|
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
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (userPkg.
|
|
86
|
-
hasEntry = true
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
winser = Winser({ silent: !verbose, nssmPath: staticPaths.nssm
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
}
|