@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
|
@@ -1,208 +1,206 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
error
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (fs.existsSync(path.join(cwd, 'node_modules/jsreport'))) {
|
|
102
|
-
detectedJsreport = 'jsreport'
|
|
103
|
-
} else if (fs.existsSync(path.join(cwd, 'node_modules
|
|
104
|
-
detectedJsreport = '
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
versionToInstall = version
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
module.exports = initializeApp
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const install = require('npm-install-package')
|
|
4
|
+
|
|
5
|
+
function initializeApp (cwd, logger, force, selectedVersion, customInstall) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const existsPackageJson = fs.existsSync(path.join(cwd, './package.json'))
|
|
8
|
+
let isMainJsreport = false
|
|
9
|
+
|
|
10
|
+
checkOrInstallJsreport(cwd, logger, existsPackageJson, selectedVersion, customInstall, (err, jsreportPkgInfo) => {
|
|
11
|
+
if (err) {
|
|
12
|
+
const error = new Error('Unexpected error happened while checking jsreport installation')
|
|
13
|
+
|
|
14
|
+
error.originalError = err
|
|
15
|
+
|
|
16
|
+
return reject(error)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
isMainJsreport = (jsreportPkgInfo.name === 'jsreport')
|
|
20
|
+
|
|
21
|
+
if (!fs.existsSync(path.join(cwd, './server.js')) || force) {
|
|
22
|
+
logger.info('Creating server.js')
|
|
23
|
+
fs.writeFileSync(
|
|
24
|
+
path.join(cwd, './server.js'),
|
|
25
|
+
fs.readFileSync(
|
|
26
|
+
path.join(__dirname, '../../example.server.js')
|
|
27
|
+
).toString().replace('$moduleName$', jsreportPkgInfo.name)
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!existsPackageJson || force) {
|
|
32
|
+
logger.info('Creating package.json')
|
|
33
|
+
|
|
34
|
+
const serverPackageJson = {
|
|
35
|
+
name: 'jsreport-server',
|
|
36
|
+
main: 'server.js',
|
|
37
|
+
scripts: {
|
|
38
|
+
start: 'node server'
|
|
39
|
+
},
|
|
40
|
+
jsreport: {
|
|
41
|
+
entryPoint: 'server.js'
|
|
42
|
+
},
|
|
43
|
+
dependencies: {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
serverPackageJson.dependencies[jsreportPkgInfo.name] = jsreportPkgInfo.versionMeta != null
|
|
48
|
+
? (
|
|
49
|
+
jsreportPkgInfo.versionMeta
|
|
50
|
+
)
|
|
51
|
+
: jsreportPkgInfo.version
|
|
52
|
+
|
|
53
|
+
if (isMainJsreport) {
|
|
54
|
+
serverPackageJson.scripts.jsreport = 'jsreport'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fs.writeFileSync(path.join(cwd, './package.json'), JSON.stringify(serverPackageJson, null, 2))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if ((!fs.existsSync(path.join(cwd, './jsreport.config.json')) || force) && isMainJsreport) {
|
|
61
|
+
logger.info('Creating default config jsreport.config.json')
|
|
62
|
+
|
|
63
|
+
const conf = JSON.parse(fs.readFileSync(path.join(__dirname, '../../example.config.json').toString()))
|
|
64
|
+
fs.writeFileSync(path.join(cwd, './jsreport.config.json'), JSON.stringify(conf, null, 2))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
logger.info('Initialized')
|
|
68
|
+
|
|
69
|
+
resolve({
|
|
70
|
+
name: jsreportPkgInfo.name,
|
|
71
|
+
version: jsreportPkgInfo.version
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function checkOrInstallJsreport (cwd, logger, existsPackageJson, version, customInstall, cb) {
|
|
78
|
+
let detectedJsreport
|
|
79
|
+
let detectedVersion
|
|
80
|
+
const originalCWD = process.cwd()
|
|
81
|
+
|
|
82
|
+
if (existsPackageJson) {
|
|
83
|
+
const userPkg = require(path.join(cwd, './package.json'))
|
|
84
|
+
const userDependencies = userPkg.dependencies || {}
|
|
85
|
+
|
|
86
|
+
if (userDependencies.jsreport) {
|
|
87
|
+
detectedJsreport = 'jsreport'
|
|
88
|
+
detectedVersion = userDependencies.jsreport
|
|
89
|
+
} else if (userDependencies['@jsreport/jsreport-core']) {
|
|
90
|
+
detectedJsreport = '@jsreport/jsreport-core'
|
|
91
|
+
detectedVersion = userDependencies['@jsreport/jsreport-core']
|
|
92
|
+
} else if (userDependencies['jsreport-core']) {
|
|
93
|
+
detectedJsreport = 'jsreport-core'
|
|
94
|
+
detectedVersion = userDependencies['jsreport-core']
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!detectedJsreport) {
|
|
99
|
+
if (fs.existsSync(path.join(cwd, 'node_modules/jsreport'))) {
|
|
100
|
+
detectedJsreport = 'jsreport'
|
|
101
|
+
} else if (fs.existsSync(path.join(cwd, 'node_modules/@jsreport/jsreport-core'))) {
|
|
102
|
+
detectedJsreport = '@jsreport/jsreport-core'
|
|
103
|
+
} else if (fs.existsSync(path.join(cwd, 'node_modules/jsreport-core'))) {
|
|
104
|
+
detectedJsreport = 'jsreport-core'
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (detectedJsreport) {
|
|
108
|
+
try {
|
|
109
|
+
detectedVersion = requireJsreportPkg(cwd, detectedJsreport).version
|
|
110
|
+
} catch (e) {
|
|
111
|
+
return cb(e)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!detectedJsreport) {
|
|
117
|
+
let versionToInstall
|
|
118
|
+
|
|
119
|
+
detectedJsreport = 'jsreport'
|
|
120
|
+
|
|
121
|
+
if (version) {
|
|
122
|
+
if (version.startsWith('jsreport/jsreport')) {
|
|
123
|
+
detectedJsreport = 'jsreport'
|
|
124
|
+
versionToInstall = version
|
|
125
|
+
} else if (version.startsWith('jsreport/jsreport-core')) {
|
|
126
|
+
detectedJsreport = 'jsreport-core'
|
|
127
|
+
versionToInstall = version
|
|
128
|
+
} else {
|
|
129
|
+
versionToInstall = 'jsreport@' + version
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
logger.info(`jsreport installation not found, installing ${versionToInstall} now, wait a moment...`)
|
|
133
|
+
} else {
|
|
134
|
+
versionToInstall = 'jsreport'
|
|
135
|
+
logger.info(`jsreport installation not found, installing ${detectedJsreport} the latest version now, wait a moment...`)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
process.chdir(cwd)
|
|
139
|
+
|
|
140
|
+
// creating basic package.json in order to make npm install
|
|
141
|
+
// work normally in current directory, later the real package.json
|
|
142
|
+
// will be created
|
|
143
|
+
if (!existsPackageJson) {
|
|
144
|
+
fs.writeFileSync(
|
|
145
|
+
path.join(cwd, './package.json'),
|
|
146
|
+
JSON.stringify({
|
|
147
|
+
name: 'jsreport-server'
|
|
148
|
+
}, null, 2))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const runInstall = customInstall != null ? customInstall : install
|
|
152
|
+
|
|
153
|
+
runInstall(versionToInstall, { save: true }, (installErr) => {
|
|
154
|
+
process.chdir(originalCWD)
|
|
155
|
+
|
|
156
|
+
if (installErr) {
|
|
157
|
+
return cb(installErr)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
logger.info('jsreport installation finished..')
|
|
161
|
+
|
|
162
|
+
let versionMeta
|
|
163
|
+
|
|
164
|
+
if (!existsPackageJson) {
|
|
165
|
+
try {
|
|
166
|
+
versionMeta = JSON.parse(fs.readFileSync(path.join(cwd, './package.json')).toString()).dependencies[detectedJsreport]
|
|
167
|
+
} catch (e) {}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
detectedVersion = requireJsreportPkg(cwd, detectedJsreport).version
|
|
172
|
+
} catch (e) {
|
|
173
|
+
return cb(e)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
cb(null, {
|
|
177
|
+
name: detectedJsreport,
|
|
178
|
+
version: detectedVersion,
|
|
179
|
+
versionMeta: versionMeta
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
} else {
|
|
183
|
+
cb(null, {
|
|
184
|
+
name: detectedJsreport,
|
|
185
|
+
version: detectedVersion
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function requireJsreportPkg (cwd, jsreportPkgName) {
|
|
191
|
+
try {
|
|
192
|
+
const jsreportModule = require(path.join(cwd, 'node_modules/' + jsreportPkgName + '/package.json'))
|
|
193
|
+
const jsreportVersion = jsreportModule.version
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
name: jsreportPkgName,
|
|
197
|
+
version: jsreportVersion
|
|
198
|
+
}
|
|
199
|
+
} catch (err) {
|
|
200
|
+
const errorToReject = new Error(`problem while trying to require ${jsreportPkgName} package`)
|
|
201
|
+
errorToReject.originalError = err
|
|
202
|
+
throw errorToReject
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
module.exports = initializeApp
|