@jsreport/jsreport-cli 4.0.3 → 4.0.4
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 +4 -0
- package/example.server.js +14 -14
- package/package.json +3 -3
- package/test/testUtils.js +197 -197
package/README.md
CHANGED
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsreport/jsreport-cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Command line interface for jsreport",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jsreport",
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@jsreport/jsreport-authentication": "4.1.0",
|
|
74
|
-
"@jsreport/jsreport-core": "4.2.
|
|
74
|
+
"@jsreport/jsreport-core": "4.2.2",
|
|
75
75
|
"@jsreport/jsreport-express": "4.1.0",
|
|
76
|
-
"@jsreport/jsreport-fs-store": "4.0.
|
|
76
|
+
"@jsreport/jsreport-fs-store": "4.0.3",
|
|
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
|
+
}
|