@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/package.json
CHANGED
|
@@ -1,106 +1,105 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@jsreport/jsreport-cli",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "Command line interface for jsreport",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"jsreport",
|
|
7
|
-
"cli",
|
|
8
|
-
"commands",
|
|
9
|
-
"jsreport commands"
|
|
10
|
-
],
|
|
11
|
-
"homepage": "https://github.com/jsreport/jsreport/tree/master/packages/jsreport-cli",
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/jsreport/jsreport.git"
|
|
15
|
-
},
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"author": {
|
|
18
|
-
"name": "BJR Matos",
|
|
19
|
-
"email": "bjrmatos@gmail.com",
|
|
20
|
-
"url": "https://github.com/bjrmatos"
|
|
21
|
-
},
|
|
22
|
-
"contributors": [
|
|
23
|
-
{
|
|
24
|
-
"name": "BJR Matos",
|
|
25
|
-
"email": "bjrmatos@gmail.com",
|
|
26
|
-
"url": "https://github.com/bjrmatos"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"name": "Jan Blaha"
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
"main": "index.js",
|
|
33
|
-
"bin": {
|
|
34
|
-
"jsreport": "cli.js"
|
|
35
|
-
},
|
|
36
|
-
"files": [
|
|
37
|
-
"lib",
|
|
38
|
-
"studio",
|
|
39
|
-
"index.js",
|
|
40
|
-
"cli.js",
|
|
41
|
-
"test/testUtils.js",
|
|
42
|
-
"example.server.js",
|
|
43
|
-
"example.config.json",
|
|
44
|
-
"jsreport.config.js"
|
|
45
|
-
],
|
|
46
|
-
"scripts": {
|
|
47
|
-
"lint": "standard",
|
|
48
|
-
"start": "cross-env JSREPORT_CLI_DEV=enabled node cli.js",
|
|
49
|
-
"test": "mocha --recursive \"./test/*.spec.js\" \"./test/commands/**/*.spec.js\" --timeout 28000 --exit",
|
|
50
|
-
"test:watch": "mocha --recursive \"./test/*.spec.js\" \"./test/commands/**/*.spec.js\" --timeout 28000 --exit --watch"
|
|
51
|
-
},
|
|
52
|
-
"dependencies": {
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"is-
|
|
59
|
-
"
|
|
60
|
-
"liftoff": "3.
|
|
61
|
-
"lockfile": "1.0.4",
|
|
62
|
-
"lodash.omit": "4.5.0",
|
|
63
|
-
"nanoid": "
|
|
64
|
-
"npm-install-package": "2.1.0",
|
|
65
|
-
"nssocket": "0.6.0",
|
|
66
|
-
"once": "1.4.0",
|
|
67
|
-
"prompt-tmp": "1.0.0",
|
|
68
|
-
"semver": "5.6.0",
|
|
69
|
-
"silent-spawn": "0.4.0",
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"@jsreport/jsreport-
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@jsreport/jsreport-cli",
|
|
3
|
+
"version": "3.1.1",
|
|
4
|
+
"description": "Command line interface for jsreport",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"jsreport",
|
|
7
|
+
"cli",
|
|
8
|
+
"commands",
|
|
9
|
+
"jsreport commands"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/jsreport/jsreport/tree/master/packages/jsreport-cli",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/jsreport/jsreport.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "BJR Matos",
|
|
19
|
+
"email": "bjrmatos@gmail.com",
|
|
20
|
+
"url": "https://github.com/bjrmatos"
|
|
21
|
+
},
|
|
22
|
+
"contributors": [
|
|
23
|
+
{
|
|
24
|
+
"name": "BJR Matos",
|
|
25
|
+
"email": "bjrmatos@gmail.com",
|
|
26
|
+
"url": "https://github.com/bjrmatos"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "Jan Blaha"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"main": "index.js",
|
|
33
|
+
"bin": {
|
|
34
|
+
"jsreport": "cli.js"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"lib",
|
|
38
|
+
"studio",
|
|
39
|
+
"index.js",
|
|
40
|
+
"cli.js",
|
|
41
|
+
"test/testUtils.js",
|
|
42
|
+
"example.server.js",
|
|
43
|
+
"example.config.json",
|
|
44
|
+
"jsreport.config.js"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"lint": "standard",
|
|
48
|
+
"start": "cross-env JSREPORT_CLI_DEV=enabled node cli.js",
|
|
49
|
+
"test": "mocha --recursive \"./test/*.spec.js\" \"./test/commands/**/*.spec.js\" --timeout 28000 --exit && standard",
|
|
50
|
+
"test:watch": "mocha --recursive \"./test/*.spec.js\" \"./test/commands/**/*.spec.js\" --timeout 28000 --exit --watch"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@jsreport/nodejs-client": "3.0.0",
|
|
54
|
+
"chalk": "2.4.2",
|
|
55
|
+
"cliui": "7.0.4",
|
|
56
|
+
"inquirer": "8.2.0",
|
|
57
|
+
"ip-address": "5.8.9",
|
|
58
|
+
"is-absolute-url": "2.1.0",
|
|
59
|
+
"is-promise": "2.1.0",
|
|
60
|
+
"liftoff": "3.1.0",
|
|
61
|
+
"lockfile": "1.0.4",
|
|
62
|
+
"lodash.omit": "4.5.0",
|
|
63
|
+
"nanoid": "3.2.0",
|
|
64
|
+
"npm-install-package": "2.1.0",
|
|
65
|
+
"nssocket": "0.6.0",
|
|
66
|
+
"once": "1.4.0",
|
|
67
|
+
"prompt-tmp": "1.0.0",
|
|
68
|
+
"semver": "5.6.0",
|
|
69
|
+
"silent-spawn": "0.4.0",
|
|
70
|
+
"yargs": "17.3.1"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@jsreport/jsreport-authentication": "3.3.0",
|
|
74
|
+
"@jsreport/jsreport-core": "3.5.0",
|
|
75
|
+
"@jsreport/jsreport-express": "3.4.0",
|
|
76
|
+
"@jsreport/jsreport-fs-store": "3.2.0",
|
|
77
|
+
"@jsreport/jsreport-handlebars": "3.1.0",
|
|
78
|
+
"cross-env": "5.2.1",
|
|
79
|
+
"execa": "1.0.0",
|
|
80
|
+
"handlebars": "4.7.7",
|
|
81
|
+
"mkdirp": "0.5.5",
|
|
82
|
+
"mocha": "5.2.0",
|
|
83
|
+
"node.extend.without.arrays": "1.1.6",
|
|
84
|
+
"rimraf": "2.6.3",
|
|
85
|
+
"should": "13.2.3",
|
|
86
|
+
"sinon": "4.4.0",
|
|
87
|
+
"standard": "16.0.4",
|
|
88
|
+
"std-mocks": "1.0.1"
|
|
89
|
+
},
|
|
90
|
+
"optionalDependencies": {
|
|
91
|
+
"winser-with-api": "1.0.2"
|
|
92
|
+
},
|
|
93
|
+
"engines": {
|
|
94
|
+
"node": ">=16.11"
|
|
95
|
+
},
|
|
96
|
+
"standard": {
|
|
97
|
+
"ignore": [
|
|
98
|
+
"/test/temp"
|
|
99
|
+
],
|
|
100
|
+
"env": {
|
|
101
|
+
"node": true,
|
|
102
|
+
"mocha": true
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
package/test/testUtils.js
CHANGED
|
@@ -1,198 +1,197 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
|
|
4
|
-
module.exports = ({
|
|
5
|
-
baseDir,
|
|
6
|
-
rootDirectory,
|
|
7
|
-
defaultOpts,
|
|
8
|
-
defaultExtensions = [],
|
|
9
|
-
cliModuleName = 'jsreport-cli',
|
|
10
|
-
deps
|
|
11
|
-
}) => {
|
|
12
|
-
const {
|
|
13
|
-
extend,
|
|
14
|
-
mkdirp,
|
|
15
|
-
rimraf,
|
|
16
|
-
execa
|
|
17
|
-
} = deps
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
getTempDir: getTempDir.bind(undefined, baseDir),
|
|
21
|
-
cleanTempDir: cleanTempDir.bind(undefined, baseDir),
|
|
22
|
-
createTempDir: createTempDir.bind(undefined, baseDir),
|
|
23
|
-
setup: setup.bind(undefined, baseDir),
|
|
24
|
-
init: init.bind(undefined, baseDir),
|
|
25
|
-
exec: exec.bind(undefined, baseDir)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function getTempDir (baseDir, dir) {
|
|
29
|
-
return path.join(baseDir, dir)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function cleanTempDir (baseDir, dir) {
|
|
33
|
-
const fullDir = getTempDir(baseDir, dir)
|
|
34
|
-
let dirs
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
dirs = fs.readdirSync(fullDir)
|
|
38
|
-
} catch (e) {}
|
|
39
|
-
|
|
40
|
-
if (!dirs) {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
dirs.forEach((d) => {
|
|
45
|
-
rimraf.sync(path.join(fullDir, d))
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function createTempDir (baseDir, dir) {
|
|
50
|
-
const fullDir = getTempDir(baseDir, dir)
|
|
51
|
-
mkdirp.sync(fullDir)
|
|
52
|
-
return fullDir
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function setup (baseDir, dir, extensions = [], cliRunnerExtension, opts) {
|
|
56
|
-
cleanTempDir(baseDir, dir)
|
|
57
|
-
|
|
58
|
-
const tempDir = createTempDir(baseDir, dir)
|
|
59
|
-
|
|
60
|
-
const tempDataDir = createTempDir(baseDir, `${dir}/data`)
|
|
61
|
-
|
|
62
|
-
let optionsToUse = extend(true, {
|
|
63
|
-
rootDirectory,
|
|
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
|
-
|
|
102
|
-
.use(require(\`${escapePath(
|
|
103
|
-
${
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
console.error(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
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
|
-
}
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
|
|
4
|
+
module.exports = ({
|
|
5
|
+
baseDir,
|
|
6
|
+
rootDirectory,
|
|
7
|
+
defaultOpts,
|
|
8
|
+
defaultExtensions = [],
|
|
9
|
+
cliModuleName = '@jsreport/jsreport-cli',
|
|
10
|
+
deps
|
|
11
|
+
}) => {
|
|
12
|
+
const {
|
|
13
|
+
extend,
|
|
14
|
+
mkdirp,
|
|
15
|
+
rimraf,
|
|
16
|
+
execa
|
|
17
|
+
} = deps
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
getTempDir: getTempDir.bind(undefined, baseDir),
|
|
21
|
+
cleanTempDir: cleanTempDir.bind(undefined, baseDir),
|
|
22
|
+
createTempDir: createTempDir.bind(undefined, baseDir),
|
|
23
|
+
setup: setup.bind(undefined, baseDir),
|
|
24
|
+
init: init.bind(undefined, baseDir),
|
|
25
|
+
exec: exec.bind(undefined, baseDir)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getTempDir (baseDir, dir) {
|
|
29
|
+
return path.join(baseDir, dir)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function cleanTempDir (baseDir, dir) {
|
|
33
|
+
const fullDir = getTempDir(baseDir, dir)
|
|
34
|
+
let dirs
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
dirs = fs.readdirSync(fullDir)
|
|
38
|
+
} catch (e) {}
|
|
39
|
+
|
|
40
|
+
if (!dirs) {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dirs.forEach((d) => {
|
|
45
|
+
rimraf.sync(path.join(fullDir, d))
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function createTempDir (baseDir, dir) {
|
|
50
|
+
const fullDir = getTempDir(baseDir, dir)
|
|
51
|
+
mkdirp.sync(fullDir)
|
|
52
|
+
return fullDir
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function setup (baseDir, dir, extensions = [], cliRunnerExtension, opts) {
|
|
56
|
+
cleanTempDir(baseDir, dir)
|
|
57
|
+
|
|
58
|
+
const tempDir = createTempDir(baseDir, dir)
|
|
59
|
+
|
|
60
|
+
const tempDataDir = createTempDir(baseDir, `${dir}/data`)
|
|
61
|
+
|
|
62
|
+
let optionsToUse = extend(true, {
|
|
63
|
+
rootDirectory,
|
|
64
|
+
store: {
|
|
65
|
+
provider: 'memory'
|
|
66
|
+
},
|
|
67
|
+
extensions: {
|
|
68
|
+
'fs-store': {
|
|
69
|
+
dataDirectory: tempDataDir
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, defaultOpts)
|
|
73
|
+
|
|
74
|
+
if (opts) {
|
|
75
|
+
optionsToUse = extend(true, {}, optionsToUse, opts)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fs.writeFileSync(
|
|
79
|
+
path.join(tempDir, './package.json'),
|
|
80
|
+
JSON.stringify({
|
|
81
|
+
name: dir,
|
|
82
|
+
dependencies: {
|
|
83
|
+
'@jsreport/jsreport-core': '*'
|
|
84
|
+
},
|
|
85
|
+
jsreport: {
|
|
86
|
+
entryPoint: 'server.js'
|
|
87
|
+
}
|
|
88
|
+
}, null, 2)
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
fs.writeFileSync(
|
|
92
|
+
path.join(tempDir, './instance.js'),
|
|
93
|
+
`
|
|
94
|
+
process.env.cli_instance_lookup_fallback = process.env.cli_instance_lookup_fallback != null ? process.env.cli_instance_lookup_fallback : 'enabled'
|
|
95
|
+
|
|
96
|
+
const defaultOpts = ${optionsToUse != null ? JSON.stringify(optionsToUse) : 'undefined'}
|
|
97
|
+
|
|
98
|
+
module.exports = (initOpts) => {
|
|
99
|
+
return (
|
|
100
|
+
require('@jsreport/jsreport-core')(initOpts != null ? initOpts : defaultOpts)
|
|
101
|
+
.use(require(\`${escapePath(cliModuleName)}\`)())
|
|
102
|
+
${defaultExtensions && defaultExtensions.length > 0 ? defaultExtensions.map((e) => `.use(require(\`${escapePath(e)}\`)())`).join('') : ''}
|
|
103
|
+
${extensions && extensions.length > 0 ? extensions.map((e) => `.use(require(\`${escapePath(e)}\`)())`).join('') : ''}
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports.defaultOpts = defaultOpts
|
|
108
|
+
`
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
fs.writeFileSync(
|
|
112
|
+
path.join(tempDir, './server.js'),
|
|
113
|
+
`
|
|
114
|
+
const createJsreport = require('./instance')
|
|
115
|
+
|
|
116
|
+
if (process.env.JSREPORT_CLI) {
|
|
117
|
+
module.exports = createJsreport()
|
|
118
|
+
} else {
|
|
119
|
+
createJsreport().init().catch(function (e) {
|
|
120
|
+
console.error("error on jsreport init")
|
|
121
|
+
console.error(e.stack)
|
|
122
|
+
process.exit(1)
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
`
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
fs.writeFileSync(
|
|
129
|
+
path.join(tempDir, './cliRunner.js'),
|
|
130
|
+
`
|
|
131
|
+
const createJsreport = require('./instance')
|
|
132
|
+
|
|
133
|
+
const commander = require(\`${escapePath(cliModuleName)}\`).commander(undefined, {
|
|
134
|
+
instance: process.env.noDefaultInstance != null ? undefined : createJsreport()
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
${cliRunnerExtension != null ? cliRunnerExtension : ''}
|
|
138
|
+
|
|
139
|
+
commander.start(process.argv.slice(2))
|
|
140
|
+
`
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function init (baseDir, dir, opts) {
|
|
145
|
+
const fullDir = getTempDir(baseDir, dir)
|
|
146
|
+
|
|
147
|
+
const createJsreport = require(path.join(fullDir, 'instance.js'))
|
|
148
|
+
|
|
149
|
+
const jsreport = createJsreport(
|
|
150
|
+
extend(true, {}, createJsreport.defaultOpts, opts)
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
await jsreport.init()
|
|
154
|
+
|
|
155
|
+
return jsreport
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function exec (baseDir, dir, cmd = '', opts) {
|
|
159
|
+
const defaultCWD = getTempDir(baseDir, dir)
|
|
160
|
+
const cliRunner = path.join(defaultCWD, 'cliRunner.js')
|
|
161
|
+
|
|
162
|
+
const file = process.execPath
|
|
163
|
+
const fullCmd = `${process.env.debugCLI ? '--inspect-brk ' : ''}${cliRunner} ${cmd}`
|
|
164
|
+
|
|
165
|
+
// this should be replaced when execa.command (v2) is released
|
|
166
|
+
const args = (
|
|
167
|
+
fullCmd
|
|
168
|
+
.trim()
|
|
169
|
+
.split(/ +/g)
|
|
170
|
+
.reduce((tokens, token, index) => {
|
|
171
|
+
if (index === 0) {
|
|
172
|
+
return [token]
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const previousToken = tokens[tokens.length - 1]
|
|
176
|
+
|
|
177
|
+
if (previousToken.endsWith('\\')) {
|
|
178
|
+
return [...tokens.slice(0, -1), `${previousToken.slice(0, -1)} ${token}`]
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return [...tokens, token]
|
|
182
|
+
}, [])
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
const execaResult = execa(file, args, {
|
|
186
|
+
env: Object.assign({ DEBUG: 'jsreport' }, opts != null ? opts.env : undefined),
|
|
187
|
+
cwd: opts && opts.cwd != null ? opts.cwd : defaultCWD,
|
|
188
|
+
windowsHide: true
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
return execaResult
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function escapePath (pathStr) {
|
|
196
|
+
return pathStr.replace(/\\/g, '\\\\')
|
|
197
|
+
}
|