launch-editor-middleware 2.0.0 → 2.3.0
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/index.js +19 -4
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
+
const url = require('url')
|
|
2
|
+
const path = require('path')
|
|
1
3
|
const launch = require('launch-editor')
|
|
2
4
|
|
|
3
|
-
module.exports = (specifiedEditor, onErrorCallback) => {
|
|
5
|
+
module.exports = (specifiedEditor, srcRoot, onErrorCallback) => {
|
|
6
|
+
if (typeof specifiedEditor === 'function') {
|
|
7
|
+
onErrorCallback = specifiedEditor
|
|
8
|
+
specifiedEditor = undefined
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (typeof srcRoot === 'function') {
|
|
12
|
+
onErrorCallback = srcRoot
|
|
13
|
+
srcRoot = undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
srcRoot = srcRoot || process.cwd()
|
|
17
|
+
|
|
4
18
|
return function launchEditorMiddleware (req, res, next) {
|
|
5
|
-
const { file } = req.query
|
|
19
|
+
const { file } = url.parse(req.url, true).query || {}
|
|
6
20
|
if (!file) {
|
|
7
|
-
res.
|
|
21
|
+
res.statusCode = 500
|
|
22
|
+
res.end(`launch-editor-middleware: required query param "file" is missing.`)
|
|
8
23
|
} else {
|
|
9
|
-
launch(file, specifiedEditor, onErrorCallback)
|
|
24
|
+
launch(path.resolve(srcRoot, file), specifiedEditor, onErrorCallback)
|
|
10
25
|
res.end()
|
|
11
26
|
}
|
|
12
27
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "launch-editor-middleware",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "express middleware for launching editor",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/yyx990803/launch-editor#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"launch-editor": "^2.
|
|
22
|
+
"launch-editor": "^2.3.0"
|
|
23
23
|
}
|
|
24
24
|
}
|