@jsreport/jsreport-cli 4.0.3 → 4.0.5
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/README.md +8 -0
- package/example.server.js +14 -14
- package/lib/commander/startProcessing.js +19 -29
- package/package.json +7 -7
- package/test/testUtils.js +197 -197
package/README.md
CHANGED
|
@@ -7,6 +7,14 @@ See http://jsreport.net/learn/cli for documentation
|
|
|
7
7
|
|
|
8
8
|
## Changelog
|
|
9
9
|
|
|
10
|
+
### 4.0.5
|
|
11
|
+
|
|
12
|
+
- update dev prompt to prompts to fix audit
|
|
13
|
+
|
|
14
|
+
### 4.0.4
|
|
15
|
+
|
|
16
|
+
- dont use console.error(e.stack) and just console.error(e) to avoid loosing e.cause inner error
|
|
17
|
+
|
|
10
18
|
### 4.0.3
|
|
11
19
|
|
|
12
20
|
- update nodejs-client to fix audit
|
package/example.server.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const jsreport = require('$moduleName$')()
|
|
2
|
-
|
|
3
|
-
if (process.env.JSREPORT_CLI) {
|
|
4
|
-
// export jsreport instance to make it possible to use jsreport-cli
|
|
5
|
-
module.exports = jsreport
|
|
6
|
-
} else {
|
|
7
|
-
jsreport.init().then(() => {
|
|
8
|
-
// running
|
|
9
|
-
}).catch((e) => {
|
|
10
|
-
// error during startup
|
|
11
|
-
console.error(e
|
|
12
|
-
process.exit(1)
|
|
13
|
-
})
|
|
14
|
-
}
|
|
1
|
+
const jsreport = require('$moduleName$')()
|
|
2
|
+
|
|
3
|
+
if (process.env.JSREPORT_CLI) {
|
|
4
|
+
// export jsreport instance to make it possible to use jsreport-cli
|
|
5
|
+
module.exports = jsreport
|
|
6
|
+
} else {
|
|
7
|
+
jsreport.init().then(() => {
|
|
8
|
+
// running
|
|
9
|
+
}).catch((e) => {
|
|
10
|
+
// error during startup
|
|
11
|
+
console.error(e)
|
|
12
|
+
process.exit(1)
|
|
13
|
+
})
|
|
14
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const yargs = require('yargs')
|
|
2
|
-
const
|
|
2
|
+
const prompts = require('prompts')
|
|
3
3
|
const startCommand = require('./startCommand')
|
|
4
4
|
const jsreportInstance = require('./jsreportInstance')
|
|
5
5
|
const cliPackageJson = require('../../package.json')
|
|
@@ -158,37 +158,27 @@ module.exports = async function startProcessing (commander, logger, args) {
|
|
|
158
158
|
argv.password = needsPassword
|
|
159
159
|
}, true)
|
|
160
160
|
} else {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
prompt.message = ''
|
|
165
|
-
|
|
166
|
-
prompt.get([{
|
|
161
|
+
try {
|
|
162
|
+
const response = await prompts({
|
|
163
|
+
type: 'password',
|
|
167
164
|
name: 'password',
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
hidden: true,
|
|
172
|
-
required: true
|
|
173
|
-
}], (err, result) => {
|
|
174
|
-
if (err) {
|
|
175
|
-
const errorToReject = new Error('No value for password option')
|
|
176
|
-
errorToReject.cleanState = true
|
|
177
|
-
|
|
178
|
-
commander.emit('started', errorToReject, null)
|
|
179
|
-
|
|
180
|
-
return reject(errorToReject)
|
|
181
|
-
}
|
|
165
|
+
message: 'Password',
|
|
166
|
+
validate: value => value.trim() === '' ? 'Password can\'t be empty' : true
|
|
167
|
+
})
|
|
182
168
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
169
|
+
// we add middleware to pre-define the "p/password" option to
|
|
170
|
+
commander._cli.middleware((argv) => {
|
|
171
|
+
argv.p = response.password
|
|
172
|
+
argv.password = response.password
|
|
173
|
+
}, true)
|
|
174
|
+
} catch (error) {
|
|
175
|
+
const errorToReject = new Error('No value for password option')
|
|
176
|
+
errorToReject.cleanState = true
|
|
188
177
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
178
|
+
commander.emit('started', errorToReject, null)
|
|
179
|
+
|
|
180
|
+
throw errorToReject
|
|
181
|
+
}
|
|
192
182
|
}
|
|
193
183
|
}
|
|
194
184
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsreport/jsreport-cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "Command line interface for jsreport",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jsreport",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"test:watch": "mocha --recursive \"./test/*.spec.js\" \"./test/commands/**/*.spec.js\" --timeout 28000 --exit --watch"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@jsreport/nodejs-client": "4.0.
|
|
53
|
+
"@jsreport/nodejs-client": "4.0.3",
|
|
54
54
|
"chalk": "2.4.2",
|
|
55
55
|
"cliui": "7.0.4",
|
|
56
56
|
"inquirer": "8.2.0",
|
|
@@ -64,16 +64,16 @@
|
|
|
64
64
|
"npm-install-package": "2.1.0",
|
|
65
65
|
"nssocket": "0.6.0",
|
|
66
66
|
"once": "1.4.0",
|
|
67
|
-
"
|
|
67
|
+
"prompts": "2.4.2",
|
|
68
68
|
"semver": "7.5.4",
|
|
69
69
|
"silent-spawn": "0.4.0",
|
|
70
70
|
"yargs": "17.3.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@jsreport/jsreport-authentication": "4.
|
|
74
|
-
"@jsreport/jsreport-core": "4.
|
|
75
|
-
"@jsreport/jsreport-express": "4.1.
|
|
76
|
-
"@jsreport/jsreport-fs-store": "4.0.
|
|
73
|
+
"@jsreport/jsreport-authentication": "4.2.2",
|
|
74
|
+
"@jsreport/jsreport-core": "4.5.0",
|
|
75
|
+
"@jsreport/jsreport-express": "4.1.3",
|
|
76
|
+
"@jsreport/jsreport-fs-store": "4.0.4",
|
|
77
77
|
"@jsreport/jsreport-handlebars": "4.0.1",
|
|
78
78
|
"cross-env": "5.2.1",
|
|
79
79
|
"execa": "1.0.0",
|
package/test/testUtils.js
CHANGED
|
@@ -1,197 +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/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
|
|
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
|
-
}
|
|
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)
|
|
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
|
+
}
|