mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
feat: open in editor
This commit is contained in:
parent
2db304e222
commit
b41fcbc789
@ -275,6 +275,9 @@ Options.defaults = {
|
||||
},
|
||||
chokidar: {}
|
||||
},
|
||||
editor: {
|
||||
editor: 'code'
|
||||
},
|
||||
messages: {
|
||||
error_404: 'This page could not be found',
|
||||
server_error: 'Server error',
|
||||
|
@ -232,6 +232,32 @@ export default class Renderer extends Tapable {
|
||||
})
|
||||
}
|
||||
|
||||
// open in editor for debug mode only
|
||||
const _this = this
|
||||
if (this.options.debug) {
|
||||
this.useMiddleware({
|
||||
path: '_open',
|
||||
handler (req, res) {
|
||||
// Lazy load open-in-editor
|
||||
const openInEditor = require('open-in-editor')
|
||||
const editor = openInEditor.configure(_this.options.editor)
|
||||
// Parse Query
|
||||
const query = req.url.split('?')[1].split('&').reduce((q, part) => {
|
||||
const s = part.split('=')
|
||||
q[s[0]] = decodeURIComponent(s[1])
|
||||
return q
|
||||
}, {})
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[open in editor]', query.file)
|
||||
editor.open(query.file).then(() => {
|
||||
res.end('opened in editor!')
|
||||
}).catch(err => {
|
||||
res.end(err)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// For serving static/ files to /
|
||||
this.useMiddleware(serveStatic(resolve(this.options.srcDir, 'static'), this.options.render.static))
|
||||
|
||||
@ -405,7 +431,6 @@ export default class Renderer extends Tapable {
|
||||
const contents = smc.sourceContentFor(source)
|
||||
if (contents) {
|
||||
frame.contents = contents
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -431,12 +456,15 @@ export default class Renderer extends Tapable {
|
||||
this.options.buildDir
|
||||
]
|
||||
|
||||
// Scan filesystem
|
||||
// Scan filesystem for real path
|
||||
for (let pathDir of searchPath) {
|
||||
let fullPath = resolve(pathDir, frame.fileName)
|
||||
let source = await fs.readFile(fullPath, 'utf-8').catch(() => null)
|
||||
if (source) {
|
||||
frame.contents = source
|
||||
if (!frame.contents) {
|
||||
frame.contents = source
|
||||
}
|
||||
frame.fullPath = fullPath
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@
|
||||
"npm": ">=3.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nuxtjs/youch": "3.0.2",
|
||||
"@nuxtjs/youch": "3.1.0",
|
||||
"ansi-html": "^0.0.7",
|
||||
"autoprefixer": "^7.1.3",
|
||||
"babel-core": "^6.26.0",
|
||||
@ -93,6 +93,7 @@
|
||||
"lru-cache": "^4.1.1",
|
||||
"memory-fs": "^0.4.1",
|
||||
"minimist": "^1.2.0",
|
||||
"open-in-editor": "^2.2.0",
|
||||
"opencollective": "^1.0.3",
|
||||
"pify": "^3.0.0",
|
||||
"postcss": "^6.0.10",
|
||||
|
Loading…
Reference in New Issue
Block a user